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;
^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|

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

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

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

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

@ -18,7 +18,7 @@ FluidLabelSet : FluidManipulationClient {
serverCaches.at(server,name) !? {
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|

@ -8,7 +8,12 @@ FluidProxyUgen : UGen {
init { |pluginname...args|
this.pluginname = pluginname;
inputs = args++Done.none++0;
inputs = args;
pluginname
.asSymbol
.asClass
.superclasses
.indexOf(FluidDataClient) ??{inputs= inputs ++ [Done.none,0]};
rate = inputs.rate;
}
@ -43,17 +48,17 @@ FluidManipulationClient {
^FluidProxyUgen.newFromDesc(rate, numOutputs, inputs, specialIndex)
}
*new{ |server...args|
*new{ |server,objectID...args|
server = server ? Server.default;
if(server.serverRunning.not,{
(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,{
var ugen = FluidProxyUgen.kr(this.class.name, *args);
var ugen = FluidProxyUgen.kr(this.class.name, *objectID);
this.ugen = ugen;
ugen
});
@ -61,15 +66,15 @@ FluidManipulationClient {
updateSynthControls {}
baseinit { |...args|
var makeFirstSynth,synthMsg;
baseinit { |objectID...args|
var makeFirstSynth,synthMsg,synthArgs;
id = UniqueID.next;
postit = {|x| x.postln;};
keepAlive = true;
defName = (this.class.name.asString ++ id).asSymbol;
def = this.makeDef(defName,*args);
def = this.makeDef(defName,objectID);
synth = Synth.basicNew(def.name, server);
synthMsg = synth.newMsg(RootNode(server));
synthMsg = synth.newMsg(RootNode(server),args);
def.doSend(server,synthMsg);
onSynthFree = {
@ -82,7 +87,6 @@ FluidManipulationClient {
};
CmdPeriod.add({synth = nil});
synth.onFree{clock.sched(0,onSynthFree)};
this.updateSynthControls;
}
free{
@ -129,65 +133,66 @@ FluidManipulationClient {
FluidDataClient : FluidManipulationClient {
var <id;
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
}
}
classvar synthControls = #[];
updateSynthControls{
synth !? {
if(synth.isRunning){
synth.set(
\in, inBus !? {inBus.index} ?? {0},
\out, outBus !? {outBus.index} ?? {0},
\inBuffer,inBuffer !? {inBuffer.asUGenInput} ?? {-1},
\outBuffer,outBuffer !? {outBuffer.asUGenInput} ?? {-1}
) }
};
}
var <id;
var parameters;
var parameterDefaults;
inBuffer_{|newBuffer|
inBuffer = newBuffer;
this.updateSynthControls;
*new {|server|
^this.new1(server,#[])
}
outBuffer_{|newBuffer|
outBuffer = newBuffer;
this.updateSynthControls;
*new1{ |server, params|
var uid = UniqueID.next;
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;
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|
^SynthDef(defName, { |in,out,inBuffer,outBuffer|
var ugen = FluidProxyUgen.kr(this.class.name, T2A.ar(T2K.kr(In.ar(in))), inBuffer, outBuffer, *args);
this.ugen = ugen;
Out.kr(out,ugen);
ugen
});
updateSynthControls{
synth !? { synth.set(*parameters.asKeyValuePairs); };
}
makeDef{|defName,uid|
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|
var uid = UniqueID.next;
^super.new(server,min,max,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
*new {|server, min = 0, max = 1|
^super.new1(server,[\min,min,\max,max]);
}
fit{|dataset, action|

@ -1,29 +1,23 @@
FluidPCA : FluidManipulationClient {
FluidPCA : FluidDataClient {
*new {|server|
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
*new {|server, numDimensions = 2|
^super.new1(server,[\numDimensions,numDimensions]);
}
fit{|dataset, k, action|
this.prSendMsg(\fit,[dataset.asSymbol, k],action);
fit{|dataset, action|
this.prSendMsg(\fit,[dataset.asSymbol], 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|
this.prSendMsg(\fitTransform,[sourceDataset.asSymbol, destDataset.asSymbol, k],action);
fitTransform{|sourceDataset, destDataset, action|
this.prSendMsg(\fitTransform,[sourceDataset.asSymbol, destDataset.asSymbol], action);
}
transformPoint{|sourceBuffer, destBuffer, action|
this.prSendMsg(\transformPoint,[sourceBuffer.asUGenInput, destBuffer.asUGenInput],action);
this.prSendMsg(\transformPoint,[sourceBuffer.asUGenInput, destBuffer.asUGenInput], action);
}
}

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

Loading…
Cancel
Save