From 7736fb0f1d4452ba8071dfe2ea18186e5648bc52 Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 6 Dec 2021 13:01:37 +0000 Subject: [PATCH 1/4] FluidBufToKr has optional numFrames argument --- test/FluidBufToKr test.scd | 69 ++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/test/FluidBufToKr test.scd b/test/FluidBufToKr test.scd index e3c2c01..4e93e11 100644 --- a/test/FluidBufToKr test.scd +++ b/test/FluidBufToKr test.scd @@ -94,8 +94,7 @@ s.waitForBoot{ ( // FluidBufToKr -// 100 is fine -/// 1000 is fine + s.waitForBoot{ Routine{ var buf = Buffer.loadCollection(s,Array.fill(1001,{arg i; i})); @@ -112,8 +111,7 @@ s.waitForBoot{ ( // FluidBufToKr -// 100 is fine -/// 1000 is fine +// This should throw an error because this sound file buffer is longer than 1000 samples s.waitForBoot{ Routine{ var buf = Buffer.read(s,"/Users/macprocomputer/Desktop/_flucoma/code/flucoma-core-src/AudioFiles/Harker-DS-TenOboeMultiphonics-M.wav"); @@ -130,8 +128,7 @@ s.waitForBoot{ ( // FluidKrToBuf test with super long buffer -// 100 is fine -// 1000 is fine +// This should throw an error because this sound file buffer is longer than 1000 samples s.waitForBoot{ Routine{ // var buf = Buffer.alloc(s,1000); @@ -151,3 +148,63 @@ s.waitForBoot{ } ) +// ===================== pass a buffer to a running synth ======================= +( +s.waitForBoot{ + Routine{ + ~synth = { + arg buf; + FluidBufToKr.kr(buf,5).poll; + }.play; + + 2.wait; + + "make buffer".postln; + ~buffer = Buffer.alloc(s,5); + s.sync; + ~buffer.setn(0,Array.fill(5,{rrand(0,100)})); + s.sync; + ~synth.set(\buf,~buffer); + }.play; +}; +) + +( +// throws error because number of frames not specified +s.waitForBoot{ + Routine{ + ~synth = { + arg buf; + FluidKrToBuf.kr(SinOsc.kr(Array.fill(5,{rrand(0.0,1.0)})),buf); + + FluidBufToKr.kr(buf).poll; + }.play; + + 2.wait; + + ~buffer = Buffer.alloc(s,5); + s.sync; + ~synth.set(\buf,~buffer); + }.play; +}; +) + +( +// works +s.waitForBoot{ + Routine{ + ~synth = { + arg buf; + FluidKrToBuf.kr(SinOsc.kr(Array.fill(5,{rrand(0.0,1.0)})),buf); + + FluidBufToKr.kr(buf,5).poll; + }.play; + + 2.wait; + + ~buffer = Buffer.alloc(s,5); + s.sync; + ~synth.set(\buf,~buffer); + }.play; +}; +) \ No newline at end of file From 90aef92f356106030b87f1c100041d9d24bb0f1a Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 6 Dec 2021 13:01:37 +0000 Subject: [PATCH 2/4] FluidBufToKr has optional numFrames argument --- release-packaging/Classes/FluidBufToKr.sc | 31 +++++++++++++++++------ test/FluidBufToKr test.scd | 14 +++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/release-packaging/Classes/FluidBufToKr.sc b/release-packaging/Classes/FluidBufToKr.sc index b3d2e88..7d78f4e 100644 --- a/release-packaging/Classes/FluidBufToKr.sc +++ b/release-packaging/Classes/FluidBufToKr.sc @@ -1,9 +1,15 @@ FluidKrToBuf { *kr { arg krStream, buffer; - if(buffer.numFrames == 0) {"FluidKrToBuf: UGen will have 0 outputs!".warn}; - if(buffer.numFrames > 1000) {"FluidKrToBuf: Buffer is % frames. This is probably not the buffer you intended.".format(buffer.numFrames).error}; - ^buffer.numFrames.do{ + + if(buffer.isKindOf(Buffer).or(buffer.isKindOf(LocalBuf)),{ + if(buffer.numFrames == 0) {"FluidKrToBuf:kr Buffer has 0 frames".warn}; + if(buffer.numFrames > 1000) { + Error("FluidKrToBuf:kr Buffer is % frames. This is probably not the buffer you intended.".format(buffer.numFrames)).throw; + }; + }); + + ^krStream.numChannels.do{ arg i; BufWr.kr(krStream[i], buffer, i); } @@ -12,12 +18,21 @@ FluidKrToBuf { FluidBufToKr { *kr { - arg buffer; - if(buffer.numFrames == 0) {"FluidKrToBuf: Buffer has 0 frames!".warn}; - if(buffer.numFrames > 1000) {"FluidKrToBuf: Buffer is % frames. This is probably not the buffer you intended.".format(buffer.numFrames).error}; + arg buffer, numFrames; + + if((buffer.isKindOf(Buffer).or(buffer.isKindOf(LocalBuf))).not.and(numFrames.isNil),{ + Error("FluidBufToKr:kr needs to be passed either an existing buffer or an OutputProxy and a number of frames for the buffer that will be supplied").throw; + }); + + numFrames = numFrames ?? {buffer.numFrames}; + + if(numFrames == 0) {"FluidKrToBuf:kr indicated numFrames is zero.".warn}; + if(numFrames > 1000) { + Error("FluidKrToBuf: Buffer is indicated to have % frames. This is probably not the buffer you intended.".format(numFrames)).throw; + }; - if(buffer.numFrames > 1,{ - ^buffer.numFrames.collect{ + if(numFrames > 1,{ + ^numFrames.collect{ arg i; BufRd.kr(1,buffer,i,0,0); } diff --git a/test/FluidBufToKr test.scd b/test/FluidBufToKr test.scd index 4e93e11..b3c070c 100644 --- a/test/FluidBufToKr test.scd +++ b/test/FluidBufToKr test.scd @@ -64,7 +64,7 @@ s.waitForBoot{ FluidKrToBuf.kr(sig,buf); }.play; - 3.wait; + 1.wait; defer{buf.plot}; }.play; @@ -85,7 +85,7 @@ s.waitForBoot{ FluidKrToBuf.kr(sig,buf); }.play; - 3.wait; + 1.wait; defer{buf.plot}; }.play; @@ -137,7 +137,7 @@ s.waitForBoot{ s.sync; { - var sig = SinOsc.kr(rrand(1.0.dup(buf.numFrames),4.0)); + var sig = SinOsc.kr(rrand(1.0.dup(10),4.0)); FluidKrToBuf.kr(sig,buf); }.play; @@ -177,7 +177,7 @@ s.waitForBoot{ arg buf; FluidKrToBuf.kr(SinOsc.kr(Array.fill(5,{rrand(0.0,1.0)})),buf); - FluidBufToKr.kr(buf).poll; + FluidBufToKr.kr(buf).poll; ///////// this will now throw an error asking for a numFrames }.play; 2.wait; @@ -194,10 +194,10 @@ s.waitForBoot{ s.waitForBoot{ Routine{ ~synth = { - arg buf; + arg buf = 999; FluidKrToBuf.kr(SinOsc.kr(Array.fill(5,{rrand(0.0,1.0)})),buf); - FluidBufToKr.kr(buf,5).poll; + FluidBufToKr.kr(buf,5).poll; ////////// this will work becaues it knows how many frames the buffer will be }.play; 2.wait; @@ -207,4 +207,4 @@ s.waitForBoot{ ~synth.set(\buf,~buffer); }.play; }; -) \ No newline at end of file +) From e6e37130e5c9cdfb29e7ef9a47682f2434081522 Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 6 Dec 2021 19:21:12 +0000 Subject: [PATCH 3/4] default for numFrames argument is -1 --- release-packaging/Classes/FluidBufToKr.sc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/release-packaging/Classes/FluidBufToKr.sc b/release-packaging/Classes/FluidBufToKr.sc index 7d78f4e..1661519 100644 --- a/release-packaging/Classes/FluidBufToKr.sc +++ b/release-packaging/Classes/FluidBufToKr.sc @@ -18,13 +18,15 @@ FluidKrToBuf { FluidBufToKr { *kr { - arg buffer, numFrames; + arg buffer, numFrames = -1; if((buffer.isKindOf(Buffer).or(buffer.isKindOf(LocalBuf))).not.and(numFrames.isNil),{ Error("FluidBufToKr:kr needs to be passed either an existing buffer or an OutputProxy and a number of frames for the buffer that will be supplied").throw; }); - numFrames = numFrames ?? {buffer.numFrames}; + if(numFrames == -1,{ + numFrames = buffer.numFrames; + }); if(numFrames == 0) {"FluidKrToBuf:kr indicated numFrames is zero.".warn}; if(numFrames > 1000) { From 289360f5d31cbcd2077237c366d17385f90a192c Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 6 Dec 2021 19:32:25 +0000 Subject: [PATCH 4/4] FluidBufToKr help file --- .../HelpSource/Classes/FluidBufToKr.schelp | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/release-packaging/HelpSource/Classes/FluidBufToKr.schelp b/release-packaging/HelpSource/Classes/FluidBufToKr.schelp index 5d558a5..ea85655 100644 --- a/release-packaging/HelpSource/Classes/FluidBufToKr.schelp +++ b/release-packaging/HelpSource/Classes/FluidBufToKr.schelp @@ -14,6 +14,9 @@ Initialize an instance of this pseudo UGen ARGUMENT:: buffer The link::Classes/Buffer:: that this pseudo UGen will read out of. Must be a one-channel buffer. +ARGUMENT:: numFrames +How many frames the buffer is that will evenutally passed. If providing a buffer directly (instead of as an argument to a SynthDef), the default of -1 will get the number of frames from the buffer passed. + returns:: a Kr stream that has the same number of channels as frames in the link::Classes/Buffer::. INSTANCEMETHODS:: @@ -21,19 +24,37 @@ INSTANCEMETHODS:: EXAMPLES:: code:: +// make a buffer with some data in it +~buf = Buffer.loadCollection(s,[0,1,2,3,4,7]); + +// play it on the server and read out of this buffer! +( +{ + var sig = FluidBufToKr.kr(~buf); + sig.poll; +}.play; +) + +// =============== passing a buffer as an argument ====================== + +// create a synth that both writes into a buffer (with FluidKrToBuf) and reads +// out of the same buffer (with FluidBufToKr) ( -// FluidBufToKr -s.waitForBoot{ - Routine{ - var buf = Buffer.loadCollection(s,[0,1,2,3,4,7]); - - s.sync; - - { - var sig = FluidBufToKr.kr(buf); - sig.poll; - }.play; - }.play; -} +~synth = { + arg buf = 999; + FluidKrToBuf.kr(SinOsc.kr(Array.fill(5,{rrand(0.0,1.0)})),buf); + + // you need to specify the 5 so the synth here will know how many channels to make + // the output proxy + FluidBufToKr.kr(buf,5).poll; +}.play; +// you should see all zeros! (unless your buffer #999 has something in it already!) ) + +// ...then after it is running, instantiate the buffer +~buffer = Buffer.alloc(s,5); + +// ...then send it to the buffer +~synth.set(\buf,~buffer); +// you should be able to see the sine oscillators now! :: \ No newline at end of file