From dee0b547a5c7c6a2d5770b37788693ad8d9d709c Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Fri, 13 Jul 2018 10:13:54 +0100 Subject: [PATCH] now with a working OSC responder to the done message --- fdfNMF.sc | 14 +++++++++++++- tests.scd | 8 ++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/fdfNMF.sc b/fdfNMF.sc index d05c870..4658c14 100644 --- a/fdfNMF.sc +++ b/fdfNMF.sc @@ -1,7 +1,19 @@ // adds an instance method to the Buffer class + Buffer { - fdNMF { arg dstBuf, rank = 1, iterations = 100, fftSize = 2048, windowSize = 2048, hopSize = 512; + fdNMF { arg dstBuf, rank = 1, iterations = 100, fftSize = 2048, windowSize = 2048, hopSize = 512, action; + var resp; + if(bufnum.isNil) { Error("Cannot call % on a % that has been freed".format(thisMethod.name, this.class.name)).throw }; + + // responder idea stolen from getToFloatArray + resp = OSCFunc({ arg msg; + if(msg[1]== '/b_gen' && msg[2]== dstBuf.bufnum, { + // ("received" + msg).postln; + resp.clear; + action.value(dstBuf.bufnum); + }); + }, '/done', server.addr); + server.listSendMsg([\b_gen, dstBuf.bufnum, "BufNMF", bufnum, rank, iterations, fftSize, windowSize, hopSize]) } } diff --git a/tests.scd b/tests.scd index 415030e..140948a 100644 --- a/tests.scd +++ b/tests.scd @@ -5,6 +5,7 @@ b = Buffer.read(s,"/Applications/Max.app/Contents/Resources/C74/media/msp/jongly b.play; b.plot; c = Buffer.alloc(s,b.numFrames,2); +e = Buffer.alloc(s,b.numFrames,5); // run the code b.fdNMF(c,2) @@ -13,13 +14,8 @@ b.fdNMF(c,2) c.plot; {PlayBuf.ar(2,c.bufnum,doneAction:2)}.play - -// play a sinewave in the background to see if the server freaks out -d = {SinOsc.ar(100,0,0.1)}.play -e = Buffer.alloc(s,b.numFrames,5); - // run the code -b.fdNMF(e,5, 150, 2048,1024,256) +b.fdNMF(e,5, 150, 2048,1024,256,{|x| "itworks".postln; x.postln;}) // read to check e.plot;