Improve order async behaviour for synth; fix symbol vs string; default behaviour for cols/size; update interfaces

nix
Owen Green 6 years ago
parent 4c2d96f244
commit 00a238dae7

@ -43,23 +43,28 @@ FluidDataSet : FluidManipulationClient {
^"FluidDataSet(%)".format(id).asString; ^"FluidDataSet(%)".format(id).asString;
} }
asSymbol {
^id.asSymbol
}
addPoint{|label, buffer, action| addPoint{|label, buffer, action|
this.prSendMsg(\addPoint,[label.asString,buffer.asUGenInput],action); this.prSendMsg(\addPoint,[label.asSymbol,buffer.asUGenInput],action);
} }
getPoint{|label, buffer, action| getPoint{|label, buffer, action|
this.prSendMsg(\getPoint,[label.asString,buffer.asUGenInput],action); this.prSendMsg(\getPoint,[label.asSymbol,buffer.asUGenInput],action);
} }
updatePoint{|label, buffer, action| updatePoint{|label, buffer, action|
this.prSendMsg(\updatePoint,[label.asString,buffer.asUGenInput],action); this.prSendMsg(\updatePoint,[label.asSymbol,buffer.asUGenInput],action);
} }
deletePoint{|label, action| deletePoint{|label, action|
this.prSendMsg(\deletePoint,[label.asString],action); this.prSendMsg(\deletePoint,[label.asSymbol],action);
} }
cols {|action| cols {|action|
action ?? {action = postit};
this.prSendMsg(\cols,[],action,[numbers(FluidMessageResponse,_,1,_)]); this.prSendMsg(\cols,[],action,[numbers(FluidMessageResponse,_,1,_)]);
} }
@ -72,6 +77,7 @@ FluidDataSet : FluidManipulationClient {
} }
size { |action| size { |action|
action ?? {action = postit};
this.prSendMsg(\size,[],action,[numbers(FluidMessageResponse,_,1,_)]); this.prSendMsg(\size,[],action,[numbers(FluidMessageResponse,_,1,_)]);
} }

@ -12,7 +12,8 @@ FluidKDTree : FluidManipulationClient {
} }
fit{|dataset,action| fit{|dataset,action|
this.prSendMsg(\fit,[dataset.asUGenInput],action); dataset.asSymbol.postln;
this.prSendMsg(\fit,[dataset.asSymbol],action);
} }
kNearest{ |buffer, k,action| kNearest{ |buffer, k,action|
@ -24,6 +25,9 @@ FluidKDTree : FluidManipulationClient {
} }
cols { |action| cols { |action|
action ?? {action = postit};
this.prSendMsg(\cols,[],action,[numbers(FluidMessageResponse,_,1,_)]); this.prSendMsg(\cols,[],action,[numbers(FluidMessageResponse,_,1,_)]);
} }

@ -14,20 +14,16 @@ FluidKMeans : FluidManipulationClient {
fit{|dataset,k, maxIter = 100, buffer, action| fit{|dataset,k, maxIter = 100, buffer, action|
buffer = buffer ? -1; buffer = buffer ? -1;
this.k = k; this.k = k;
this.prSendMsg(\fit,[dataset.asString, k,maxIter, buffer.asUGenInput],action,[numbers(FluidMessageResponse,_,k,_)]); this.prSendMsg(\fit,[dataset.asSymbol, k,maxIter, buffer.asUGenInput],action,[numbers(FluidMessageResponse,_,k,_)]);
} }
fitPredict{|dataset,labelset, k, maxIter = 100, action| fitPredict{|dataset,labelset, k, maxIter = 100, action|
this.k = k; this.k = k;
this.pr_sendMsg(\fitPredict,[dataset.asString,labelset.asString, k,maxIter],action,[numbers(FluidMessageResponse,_,k,_)]); this.prSendMsg(\fitPredict,[dataset.asSymbol,labelset.asSymbol, k,maxIter],action,[numbers(FluidMessageResponse,_,k,_)]);
} }
predict{ |dataset, labelset,action| predict{ |dataset, labelset,action|
this.prSendMsg(\predict,[dataset.asString, labelset.asString],action,[numbers(FluidMessageResponse,_,this.k,_)]); this.prSendMsg(\predict,[dataset.asSymbol, labelset.asSymbol],action,[numbers(FluidMessageResponse,_,this.k,_)]);
}
getClusters{ |dataset, labelset,action|
this.prSendMsg(\getClusters,[dataset.asString, labelset.asString],action);
} }
predictPoint { |buffer, action| predictPoint { |buffer, action|
@ -35,6 +31,7 @@ FluidKMeans : FluidManipulationClient {
} }
cols { |action| cols { |action|
action ?? action = postit;
this.prSendMsg(\cols,[],action,[number(FluidMessageResponse,_,_)]); this.prSendMsg(\cols,[],action,[number(FluidMessageResponse,_,_)]);
} }

@ -22,7 +22,7 @@ FluidLabelSet : FluidManipulationClient {
} }
init { |name| init { |name|
this.id = name; id = name;
this.cache; this.cache;
} }
@ -35,6 +35,11 @@ FluidLabelSet : FluidManipulationClient {
^"FluidLabelSet(%)".format(id).asString; ^"FluidLabelSet(%)".format(id).asString;
} }
asSymbol {
^id
}
*asUGenInput { |input| *asUGenInput { |input|
var ascii = input.asString.ascii; var ascii = input.asString.ascii;
@ -45,6 +50,11 @@ FluidLabelSet : FluidManipulationClient {
this.prSendMsg(\addLabel,[id.asString, label.asString],action); this.prSendMsg(\addLabel,[id.asString, label.asString],action);
} }
updateLabel{|id, label, action|
this.prSendMsg(\updateLabel,[id.asString, label.asString],action);
}
getLabel{|id, action| getLabel{|id, action|
this.prSendMsg(\getLabel,[id.asString],action,[string(FluidMessageResponse,_,_)]); this.prSendMsg(\getLabel,[id.asString],action,[string(FluidMessageResponse,_,_)]);
} }
@ -54,6 +64,7 @@ FluidLabelSet : FluidManipulationClient {
} }
cols {|action| cols {|action|
action ?? {action = postit};
this.prSendMsg(\cols,[],action,[number(FluidMessageResponse,_,_)]); this.prSendMsg(\cols,[],action,[number(FluidMessageResponse,_,_)]);
} }
@ -66,6 +77,7 @@ FluidLabelSet : FluidManipulationClient {
} }
size { |action| size { |action|
action ?? {action = postit};
this.prSendMsg(\size,[],action,[number(FluidMessageResponse,_,_)]); this.prSendMsg(\size,[],action,[number(FluidMessageResponse,_,_)]);
} }

@ -24,6 +24,9 @@ FluidManipulationClient {
var defName, def; var defName, def;
var onSynthFree, persist; var onSynthFree, persist;
var postit;
var < ready;
*prServerString{ |s| *prServerString{ |s|
var ascii = s.ascii; var ascii = s.ascii;
^[ascii.size].addAll(ascii) ^[ascii.size].addAll(ascii)
@ -45,29 +48,35 @@ FluidManipulationClient {
baseinit { |...args| baseinit { |...args|
var makeFirstSynth; var makeFirstSynth;
id = UniqueID.next; id = UniqueID.next;
postit = {|x| x.postln;};
defName = (this.class.name.asString ++ id).asSymbol; defName = (this.class.name.asString ++ id).asSymbol;
ready = Condition(false);
def = SynthDef(defName,{ def = SynthDef(defName,{
var ugen = FluidProxyUgen.kr(this.class.name, *args); var ugen = FluidProxyUgen.kr(this.class.name, *args);
this.ugen = ugen; this.ugen = ugen;
ugen ugen
}).add; });
persist = true; persist = true;
onSynthFree = { onSynthFree = {
ready.test = false;
synth = nil; synth = nil;
if(persist){ if(persist){
//If we don't sync here, cmd-. doesn't reset properly (but server.freeAll does) //If we don't sync here, cmd-. doesn't reset properly (but server.freeAll does)
fork { forkIfNeeded {
server.sync; server.sync;
synth = Synth(defName,target: RootNode(server)); synth = Synth(defName,target: RootNode(server));
synth.onFree{onSynthFree.value}; synth.onFree{onSynthFree.value};
ready.test = true;
ready.signal;
} }
} }
}; };
forkIfNeeded{
server.doWhenBooted{onSynthFree.value}; def.add;
server.sync;
onSynthFree.value;
}
} }
free{ free{
@ -79,6 +88,7 @@ FluidManipulationClient {
prSendMsg { |msg, args, action,parser| prSendMsg { |msg, args, action,parser|
if(this.server.serverRunning.not,{(this.asString + " server not running").error; ^nil}); if(this.server.serverRunning.not,{(this.asString + " server not running").error; ^nil});
synth ?? {"Not ready".warn};
synth !? { synth !? {
OSCFunc( OSCFunc(
{ |msg| { |msg|
@ -134,8 +144,8 @@ FluidServerCache {
} }
clearCache { |server| clearCache { |server|
cache.postln;
cache[server] !? { cache.removeAt(server) }; cache[server] !? { cache.removeAt(server) };
} }
} }

@ -20,7 +20,7 @@ FluidMessageResponse : Object
var split = a.find([0],offset); var split = a.find([0],offset);
var res; var res;
if(split.isNil) {"ERROR: can't parse string from server".throw}; if(split.isNil) {"ERROR: can't parse string from server".throw};
^[[a.copyRange(offset,split-1).keep(split).collectAs({|x|x.asInt.asAscii},String)], split + 1] ^[[a.copyRange(offset,split-1).keep(split).collectAs({|x|x.asInteger.asAscii},String)], split + 1]
} }
*numbers{ |a, n, offset| *numbers{ |a, n, offset|

Loading…
Cancel
Save