Merge branch 'clients/inter_client_comms' of https://bitbucket.org/flucoma/flucoma-supercollider into clients/inter_client_comms

nix
Owen Green 6 years ago
commit 34f4119d13

@ -43,5 +43,6 @@ The maximum FFT size for processing
EXAMPLES::
code::
(some example code)
//the mouse X axis interpolates between the two sinewaves
{FluidAudioTransport.ar(SinOsc.ar(220),SinOsc.ar(440),MouseX.kr())}.play;
::

@ -122,18 +122,28 @@ c = Buffer.new(s)
//FluidKMeans
~kMeans= FluidKMeans.new(s)
~kMeans.fit(~dataset,k:5,action:{"fit".postln})
// predicts in which cluster a point would be
~kMeans.predictPoint(c,{|x|x.postln})
// predicts which cluster each points of a dataset would be in, as a label
~labels = FluidLabelSet.new(s,"clusters")
~kMeans.predict(~dataset,~labels, {|x| x.postln})
~labels.getLabel(~audioBuffers[2].path,action:{|c| c.postln})
//query each item
(
Routine{
~labels.size({|x|x.do {|i|
forkIfNeeded{
~audioBuffers[i].path.postln;
~labels.getLabel(~audioBuffers[i].path,action:{|c| c.postln});
s.sync;
~audioBuffers[i].path.postln;
~labels.getLabel(~audioBuffers[i].path,action:{|c| c.postln});
s.sync;
}
}
});
}.play
)
//labelset can be written as json
~labels.write(~path+/+"labels.json")

@ -0,0 +1,64 @@
(
~simpleInput = FluidDataSet(s,\simpleInput,2);
~simpleOutput = FluidLabelSet(s,\simpleOutput,2);
b = Buffer.alloc(s,2);
~knn = FluidKNN(s);
k = 3
)
(
var w,v,myx,myy;
//initialise the mouse position holder
myx=0;
myy=0;
//make a window and a full size view
w = Window.new("Viewer", Rect(100,Window.screenBounds.height - 400, 310, 310)).front;
v = View.new(w,Rect(0,0, 310, 310));
//creates a function that reacts to mousedown
// v.mouseMoveAction = {|view, x, y|myx=x;myy=y;w.refresh;};
v.mouseDownAction = {|view, x, y|myx=x;myy=y;w.refresh;
myx.postln;myy.postln;
Routine{
b.setn(0,[myx,myy]);
s.sync;
~knn.classifyPoint(b, ~simpleOutput, k, {|x|x.postln;});
}.play;};
//custom redraw function
w.drawFunc = {
100.do { |i|
if (i < 50, {Pen.color = Color.white;} ,{Pen.color = Color.red;});
Pen.addRect(Rect(i.div(10)*30+10,i.mod(10)*30+10,20,20));
Pen.perform(\fill);
};
Pen.color = Color.black;
Pen.addOval(Rect(myx-5, myy-5,10,10));
Pen.perform(\stroke);
};
)
(
//populates a dataset with the same squares as the gui (their centres)
Routine{
50.do{|i|
var x = i.div(10)*30+20;
var y = i.mod(10)*30+20;
b.setn(0,[x,y]);
s.sync;
~simpleInput.addPoint(i.asString,b,{("Added Input" + i).postln});
~simpleOutput.addLabel(i.asString,"White",{("Added Output" + i).postln});
b.setn(0,[x+150,y]);
s.sync;
~simpleInput.addPoint((i+50).asString,b,{("Added Input" + (i+50)).postln});
~simpleOutput.addLabel((i+50).asString,"Red",{("Added Output" + (i+50)).postln});
}
}.play;
)
// fit the dataset
~knn.fit(~simpleInput,action:{"fitting done".postln})
// now click on the grid and read the estimated class according to the nearest K neighbours.
Loading…
Cancel
Save