Update infrastructure and SC classes for RT queries

nix
Owen Green 6 years ago
parent 684a614ae9
commit 806a3414d7

@ -20,7 +20,7 @@ FluidDataSet : FluidManipulationClient {
FluidDataSetExistsError("A FluidDataset called % already exists.".format(name)).throw; FluidDataSetExistsError("A FluidDataset called % already exists.".format(name)).throw;
^nil ^nil
} }
^super.new(server,*FluidManipulationClient.prServerString(name))!?{|inst|inst.init(name);inst} ^super.new(server,FluidManipulationClient.prServerString(name))!?{|inst|inst.init(name);inst}
} }
init {|name| init {|name|

@ -1,14 +1,25 @@
FluidKDTree : FluidManipulationClient { FluidKDTree : FluidDataClient {
var id; *new {|server,numNeighbours = 1,lookupDataSet = ""|
var env;
var names = [\numNeighbours]
++ this.prServerString(lookupDataSet.asSymbol).collect{|x,i|
("lookupDataSet"++i).asSymbol;
};
*new {|server| var values = [numNeighbours] ++ this.prServerString(lookupDataSet.asSymbol);
var uid = UniqueID.next; var params = [names,values].lace;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
/* env = Environment();
synthControls[1..].do{|x|
env.put(x,0);
};
env.put(\numNeighbours,1); */
init {|uid| ^super.new1(server,params);
id = uid; /* env,
[\numNeighbours]++lookupDataSet); */
} }
fit{|dataset,action| fit{|dataset,action|
@ -16,16 +27,16 @@ FluidKDTree : FluidManipulationClient {
this.prSendMsg(\fit, [dataset.asSymbol], action); this.prSendMsg(\fit, [dataset.asSymbol], action);
} }
kNearest{ |buffer, k,action| kNearest{ |buffer, action|
this.prSendMsg(\kNearest, this.prSendMsg(\kNearest,
[buffer.asUGenInput,k], action, [buffer.asUGenInput], action,
k.collect{string(FluidMessageResponse,_,_)} this.numNeighbours.collect{string(FluidMessageResponse,_,_)}
); );
} }
kNearestDist { |buffer, k,action| kNearestDist { |buffer, action|
this.prSendMsg(\kNearestDist, [buffer.asUGenInput,k], action, this.prSendMsg(\kNearestDist, [buffer.asUGenInput], action,
[numbers(FluidMessageResponse,_,k,_)] [numbers(FluidMessageResponse,_,this.numNeighbours,_)]
); );
} }
} }

@ -1,27 +1,27 @@
FluidKMeans : FluidDataClient { FluidKMeans : FluidDataClient {
var <>k; *new {|server, numClusters = 4, maxIter = 100|
^super.new1(server,[\numClusters,numClusters,\maxIter,maxIter]);
}
fit{|dataset,k, maxIter = 100, action| fit{|dataset,action|
this.k = k;
this.prSendMsg(\fit, this.prSendMsg(\fit,
[dataset.asSymbol, k,maxIter], action, [dataset.asSymbol], action,
[numbers(FluidMessageResponse,_,k,_)] [numbers(FluidMessageResponse,_,this.numClusters,_)]
); );
} }
fitPredict{|dataset, labelset, k, maxIter = 100, action| fitPredict{|dataset, labelset,action|
this.k = k;
this.prSendMsg(\fitPredict, this.prSendMsg(\fitPredict,
[dataset.asSymbol,labelset.asSymbol, k,maxIter], [dataset.asSymbol,labelset.asSymbol],
action,[numbers(FluidMessageResponse,_,k,_)] action,[numbers(FluidMessageResponse,_,this.numClusters,_)]
); );
} }
predict{ |dataset, labelset,action| predict{ |dataset, labelset,action|
this.prSendMsg(\predict, this.prSendMsg(\predict,
[dataset.asSymbol, labelset.asSymbol], action, [dataset.asSymbol, labelset.asSymbol], action,
[numbers(FluidMessageResponse,_,this.k,_)] [numbers(FluidMessageResponse,_,this.numClusters,_)]
); );
} }

@ -1,29 +1,23 @@
FluidKNNClassifier : FluidManipulationClient { FluidKNNClassifier : FluidDataClient {
*new {|server| *new {|server, numNeighbours = 3, weight = 1|
var uid = UniqueID.next; ^super.new1(server,[\numNeighbours,numNeighbours,\weight,weight]);
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
} }
fit{|dataset, labelset, action| fit{|dataset, labelset, action|
this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action); this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action);
} }
predict{|dataset, labelset, k, uniform = 0, action| predict{|dataset, labelset, action|
this.prSendMsg(\predict, this.prSendMsg(\predict,
[dataset.asSymbol, labelset.asSymbol, k, uniform], [dataset.asSymbol, labelset.asSymbol],
action); action);
} }
predictPoint {|buffer, k, uniform = 0, action| predictPoint {|buffer, action|
this.prSendMsg(\predictPoint, this.prSendMsg(\predictPoint,
[buffer.asUGenInput, k, uniform], action, [buffer.asUGenInput], action,
[string(FluidMessageResponse,_,_)] [string(FluidMessageResponse,_,_)]
); );
} }
} }

@ -1,12 +1,7 @@
FluidKNNRegressor : FluidManipulationClient { FluidKNNRegressor : FluidDataClient {
*new {|server| *new {|server, numNeighbours = 3, weight = 1|
var uid = UniqueID.next; ^super.new1(server,[\numNeighbours,numNeighbours,\weight,weight]);
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
} }
fit{|sourceDataset, targetDataset, action| fit{|sourceDataset, targetDataset, action|
@ -16,14 +11,14 @@ FluidKNNRegressor : FluidManipulationClient {
); );
} }
predict{ |sourceDataset, targetDataset, k, uniform = 0, action| predict{ |sourceDataset, targetDataset,action|
this.prSendMsg(\predict, this.prSendMsg(\predict,
[sourceDataset.asSymbol, targetDataset.asSymbol, k, uniform], [sourceDataset.asSymbol, targetDataset.asSymbol],
action); action);
} }
predictPoint { |buffer, k, uniform = 0, action| predictPoint { |buffer, action|
this.prSendMsg(\predictPoint, [buffer.asUGenInput, k, uniform], action, this.prSendMsg(\predictPoint, [buffer.asUGenInput], action,
[number(FluidMessageResponse,_,_)]); [number(FluidMessageResponse,_,_)]);
} }
} }

@ -18,7 +18,7 @@ FluidLabelSet : FluidManipulationClient {
serverCaches.at(server,name) !? { serverCaches.at(server,name) !? {
FluidLabelSetExistsError("A FluidLabelSet called % already exists.".format(name)).throw; FluidLabelSetExistsError("A FluidLabelSet called % already exists.".format(name)).throw;
}; };
^super.new(server,*FluidManipulationClient.prServerString(name))!?{|inst|inst.init(name);inst} ^super.new(server,FluidManipulationClient.prServerString(name))!?{|inst|inst.init(name);inst}
} }
init { |name| init { |name|

@ -8,7 +8,12 @@ FluidProxyUgen : UGen {
init { |pluginname...args| init { |pluginname...args|
this.pluginname = pluginname; this.pluginname = pluginname;
inputs = args++Done.none++0; inputs = args;
pluginname
.asSymbol
.asClass
.superclasses
.indexOf(FluidDataClient) ??{inputs= inputs ++ [Done.none,0]};
rate = inputs.rate; rate = inputs.rate;
} }
@ -43,17 +48,17 @@ FluidManipulationClient {
^FluidProxyUgen.newFromDesc(rate, numOutputs, inputs, specialIndex) ^FluidProxyUgen.newFromDesc(rate, numOutputs, inputs, specialIndex)
} }
*new{ |server...args| *new{ |server,objectID...args|
server = server ? Server.default; server = server ? Server.default;
if(server.serverRunning.not,{ if(server.serverRunning.not,{
(this.asString + " server not running").error; ^nil (this.asString + " server not running").error; ^nil
}); });
^super.newCopyArgs(server ?? {Server.default}).baseinit(*args) ^super.newCopyArgs(server ?? {Server.default}).baseinit(objectID,*args)
} }
makeDef { |defName...args| makeDef { |defName,objectID|
^SynthDef(defName,{ ^SynthDef(defName,{
var ugen = FluidProxyUgen.kr(this.class.name, *args); var ugen = FluidProxyUgen.kr(this.class.name, *objectID);
this.ugen = ugen; this.ugen = ugen;
ugen ugen
}); });
@ -61,15 +66,15 @@ FluidManipulationClient {
updateSynthControls {} updateSynthControls {}
baseinit { |...args| baseinit { |objectID...args|
var makeFirstSynth,synthMsg; var makeFirstSynth,synthMsg,synthArgs;
id = UniqueID.next; id = UniqueID.next;
postit = {|x| x.postln;}; postit = {|x| x.postln;};
keepAlive = true; keepAlive = true;
defName = (this.class.name.asString ++ id).asSymbol; defName = (this.class.name.asString ++ id).asSymbol;
def = this.makeDef(defName,*args); def = this.makeDef(defName,objectID);
synth = Synth.basicNew(def.name, server); synth = Synth.basicNew(def.name, server);
synthMsg = synth.newMsg(RootNode(server)); synthMsg = synth.newMsg(RootNode(server),args);
def.doSend(server,synthMsg); def.doSend(server,synthMsg);
onSynthFree = { onSynthFree = {
@ -82,7 +87,6 @@ FluidManipulationClient {
}; };
CmdPeriod.add({synth = nil}); CmdPeriod.add({synth = nil});
synth.onFree{clock.sched(0,onSynthFree)}; synth.onFree{clock.sched(0,onSynthFree)};
this.updateSynthControls;
} }
free{ free{
@ -129,65 +133,66 @@ FluidManipulationClient {
FluidDataClient : FluidManipulationClient { FluidDataClient : FluidManipulationClient {
var <id; classvar synthControls = #[];
var <inBus, <outBus;
var <inBuffer, <outBuffer;
*new {|server,inbus, outbus,inbuf,outbuf|
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|
inst.init(uid);
inst.inBus = inbus;
inst.outBus = outbus;
inst.inBuffer = inbuf;
inst.outBuffer = outbuf;
inst
}
}
updateSynthControls{ var <id;
synth !? { var parameters;
if(synth.isRunning){ var parameterDefaults;
synth.set(
\in, inBus !? {inBus.index} ?? {0},
\out, outBus !? {outBus.index} ?? {0},
\inBuffer,inBuffer !? {inBuffer.asUGenInput} ?? {-1},
\outBuffer,outBuffer !? {outBuffer.asUGenInput} ?? {-1}
) }
};
}
inBuffer_{|newBuffer| *new {|server|
inBuffer = newBuffer; ^this.new1(server,#[])
this.updateSynthControls;
} }
outBuffer_{|newBuffer| *new1{ |server, params|
outBuffer = newBuffer; var uid = UniqueID.next;
this.updateSynthControls; params = params ?? {[]};
if(params.size > 0) {synthControls = params.unlace[0]};
params = params ++ [\inBus,Bus.control,\outBus,Bus.control,\inBuffer,-1,\outBuffer,-1];
^super.new(server, uid, *params) !? { |inst| inst.init(uid, params) }
} }
init {|uid| init { |uid, params|
id = uid; id = uid;
parameters = ().putPairs(params);
parameterDefaults = parameters.copy;
this.makePropertyMethods;
}
makePropertyMethods{
if (parameters.keys.size > 0) {
parameters.keys.do{|c,i|
this.addUniqueMethod(c,{ parameters.at(c) });
this.addUniqueMethod((c++\_).asSymbol,{|responder,x|
//if we have a default or initial value set, then fall back to
//this if val is nil. Otherwise, fallback even furter to -1 as
// a best guess
x = x ?? { parameterDefaults !? { parameterDefaults[c] } ?? {-1} };
parameters.put(c, x.asUGenInput);
synth !? { if(synth.isRunning){ synth.set(c,x); } };
responder
});
} }
};
inBus_{ |newBus|
inBus = newBus;
this.updateSynthControls;
}
outBus_{ |newBus|
outBus = newBus;
this.updateSynthControls;
} }
makeDef{|defName...args| updateSynthControls{
^SynthDef(defName, { |in,out,inBuffer,outBuffer| synth !? { synth.set(*parameters.asKeyValuePairs); };
var ugen = FluidProxyUgen.kr(this.class.name, T2A.ar(T2K.kr(In.ar(in))), inBuffer, outBuffer, *args); }
this.ugen = ugen;
Out.kr(out,ugen); makeDef{|defName,uid|
ugen var defControls = [\inBus, \outBus] ++ synthControls ++ [\inBuffer,\outBuffer];
}); var ugenControls = [this.class.name,"T2A.ar(In.kr(inBus))"] ++ synthControls ++ [\inBuffer,\outBuffer,uid];
var f = (
"{ |dataClient|"
" SynthDef("++defName.asCompileString++", { |" ++ defControls.join(",") ++ "|"
" var ugen = FluidProxyUgen.kr(" ++ ugenControls.join(",") ++ ");"
" dataClient.ugen = ugen;"
" Out.kr(outBus,ugen);"
" })"
"}"
);
var res = f.interpret.value(this);
^res
} }
} }

@ -1,12 +1,7 @@
FluidNormalize : FluidManipulationClient { FluidNormalize : FluidDataClient {
*new {|server, min = 0, max = 1| *new {|server, min = 0, max = 1|
var uid = UniqueID.next; ^super.new1(server,[\min,min,\max,max]);
^super.new(server,min,max,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
} }
fit{|dataset, action| fit{|dataset, action|

@ -1,25 +1,19 @@
FluidPCA : FluidManipulationClient { FluidPCA : FluidDataClient {
*new {|server, numDimensions = 2|
*new {|server| ^super.new1(server,[\numDimensions,numDimensions]);
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
} }
fit{|dataset, k, action| fit{|dataset, action|
this.prSendMsg(\fit,[dataset.asSymbol, k],action); this.prSendMsg(\fit,[dataset.asSymbol], action);
} }
transform{|sourceDataset, destDataset, action| transform{|sourceDataset, destDataset, action|
this.prSendMsg(\transform,[sourceDataset.asSymbol, destDataset.asSymbol], action); this.prSendMsg(\transform,[sourceDataset.asSymbol, destDataset.asSymbol], action);
} }
fitTransform{|sourceDataset, destDataset, k, action| fitTransform{|sourceDataset, destDataset, action|
this.prSendMsg(\fitTransform,[sourceDataset.asSymbol, destDataset.asSymbol, k],action); this.prSendMsg(\fitTransform,[sourceDataset.asSymbol, destDataset.asSymbol], action);
} }

@ -1,14 +1,4 @@
FluidStandardize : FluidManipulationClient { FluidStandardize : FluidDataClient {
*new {|server|
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
}
fit{|dataset, action| fit{|dataset, action|
this.prSendMsg(\fit, [dataset.asSymbol], action); this.prSendMsg(\fit, [dataset.asSymbol], action);
} }

Loading…
Cancel
Save