First refactored version which compiles and makes sounds

feature-refactor-osc
Mike Lynch 2022-04-03 09:50:04 +10:00
parent c2ee2a31d3
commit 4f5365ee1e
1 changed files with 18 additions and 10 deletions

View File

@ -5,32 +5,37 @@ Server.killAll
Server.default.options.inDevice_("Scarlett 2i2 USB"); Server.default.options.inDevice_("Scarlett 2i2 USB");
( (
~to = TouchOsc("192.168.0.209", 9000); ~to = TouchOSC("192.168.0.209", 9000);
~patchdir = "~/Music/SuperCollider/Patches/granulator/"; ~patchdir = "~/Music/SuperCollider/Patches/granulator/";
~to.button('/record', 1, { | v | ~bufrecorder.set("record", v) }); ~buflen = 4.0;
// sidebar -
~to.button('/record', 1, { | v | ~bufrecorder.set(\record, v) });
~to.button('/clear', 0, { | v | ~to.button('/clear', 0, { | v |
if( v > 0, { if( v > 0, {
var bl = ~to.v('/buflength'), ~to.v('/grains/speed')[0]; var sp = ~to.v('/grains/speed')[0];
~newbuffer = Buffer.alloc(s, s.sampleRate * bl, 1); ~buflen = ~to.v('/grains/length');
~newbuffer = Buffer.alloc(s, s.sampleRate * ~buflen, 1);
~granulator.set(\buffer, ~newbuffer); ~granulator.set(\buffer, ~newbuffer);
~bufrecorder.set(\buffer, ~newbuffer); ~bufrecorder.set(\buffer, ~newbuffer);
~frippbuffer.free; ~frippbuffer.free;
~frippbuffer = ~newbuffer; ~frippbuffer = ~newbuffer;
~currentpos.set(\speed, sp / bl); ~currentpos.set(\speed, sp / ~buflen);
}); });
}) });
~to.slider('/mix', 0.25, TouchOSCScale(0, 1), { |v| ~bufrecorder.set(\mix, v) } ); ~to.slider('/mix', 0.25, TouchOSCScale(0, 1), { |v| ~bufrecorder.set(\mix, v) } );
~to.slider('/grainamp', 0.5, TouchOSCScale(0, 1), { |v| ~granulator.set(\amp, v) } ); ~to.slider('/grainamp', 0.5, TouchOSCScale(0, 1), { |v| ~granulator.set(\amp, v) } );
~to.slider('/passthrough', 0.5, TouchOSCScale(0, 1), { |v| ~mixer.set(\passthrough, v) } ); ~to.slider('/passthrough', 0.5, TouchOSCScale(0, 1), { |v| ~mixer.set(\passthrough, v) } );
// page 1: grains // page 1: grains
~modes = [ ~modes = [
@ -39,7 +44,7 @@ Server.default.options.inDevice_("Scarlett 2i2 USB");
[ ~grainsin, ~grainsinb ], [ ~grainsin, ~grainsinb ],
[ ~graintri, ~graintrib ], [ ~graintri, ~graintrib ],
[ ~grainrand, ~grainrandb ] [ ~grainrand, ~grainrandb ]
] ];
~to.button('/grains/mode', 0, { |v| ~to.button('/grains/mode', 0, { |v|
var mode = ~modes[v]; var mode = ~modes[v];
@ -48,7 +53,10 @@ Server.default.options.inDevice_("Scarlett 2i2 USB");
~currentpos.set(\speed, ~to.v('/grains/speed')[0]); ~currentpos.set(\speed, ~to.v('/grains/speed')[0]);
}); });
~to.slider('/grains/length', 4.0, TouchOSCScale(0.1, 10.0), {}); // note: ~buflen is the variable for buffer length, which only gets set to
// ~to.v('/grains/length') when the buffer is reset with the clear button
~to.slider('/grains/length', ~buflen, TouchOSCScale(0.1, 10.0), {});
~to.xy('/grains/speed', [ 0, 4 ], TouchOSCScale(-4, 4), TouchOSCScale(0, 10), { | v | ~to.xy('/grains/speed', [ 0, 4 ], TouchOSCScale(-4, 4), TouchOSCScale(0, 10), { | v |
var trate, qspeed; var trate, qspeed;
@ -186,7 +194,7 @@ Server.default.options.inDevice_("Scarlett 2i2 USB");
// buffer recorder // buffer recorder
~frippbuffer = Buffer.alloc(s, s.sampleRate * ~sets.at(\buflength).v, 1); ~frippbuffer = Buffer.alloc(s, s.sampleRate * ~buflen, 1);
~bufrecorder = SynthDef( ~bufrecorder = SynthDef(
\fripp_record, \fripp_record,