Added a trigger to sync the recorder with the playback buffer

Also turns off granulator input mix when recording stops
feature-multitrack
Mike Lynch 2023-09-17 10:11:31 +10:00
parent a83b8be362
commit f880ac5831
4 changed files with 104 additions and 23 deletions

View File

@ -12,32 +12,49 @@
~granulators = Array.new(4); ~granulators = Array.new(4);
~posb = Array.new(4); ~posb = Array.new(4);
~rectriggerb = Array.new(4);
~possynths = Array.new(4); ~possynths = Array.new(4);
~triggersynths = Array.new(4);
// create the control busses
(0..3).do({ (0..3).do({
var pb = Bus.control(s, 1), ps; var ps;
~posb.add(pb); ~posb.add(Bus.control(s, 1));
ps = Synth(\pos_saw, [ \out, pb, \speed, 1 / ~buflen ]); ~rectriggerb.add(Bus.control(s, 1));
~possynths.add(ps);
}); });
// start the granulators
(0..3).do({ |i| (0..3).do({ |i|
var pb = ~posb.at(i); var pb = ~posb[i], rtb = ~rectriggerb[i];
~granulators.add(Granulator.new(~buflen, ~infxb, ~grainsb, pb, ~triggerb, ~pitchb)); ~granulators.add(Granulator.new(~buflen, ~infxb, ~grainsb, pb, rtb));
}); });
"Granulators running".postln;
// launch the pos synths and triggers to sync the buffer recorders
(0..3).do({ |i|
var pb = ~posb[i], rtb = ~rectriggerb[i];
~possynths.add(Synth(\pos_saw, [ \out, pb, \speed, 1 / ~buflen ]));
~triggersynths.add(Synth(\trigger, [ \out, rtb ]));
});
// TODO - retrigger the buffer records when changing the length etc
~setmode = { ~setmode = {
arg track, mode; arg track, mode;
var synth = ~modes[mode][1]; var synth = ~modes[mode][1];
~possynths[track].get(\speed, { | speed | ~possynths[track].get(\speed, { | speed |
~possynths[track].free; ~possynths[track].free;
~triggersynths[track].free;
~possynths[track] = Synth(synth, [\out, ~posb[track], \speed, speed]); ~possynths[track] = Synth(synth, [\out, ~posb[track], \speed, speed]);
~triggersynths[track] = Synth(\trigger, [ \out, ~rectriggerb[track] ]);
}); });
~granulators[track].mode_(mode); ~granulators[track].mode_(mode);
}; };
"Granulator running".postln;
) )

View File

@ -1,5 +1,6 @@
// FIXME: the touchosc stuff is crashing on intialisation
~quantspeed.value(2);
( (
~to = TouchOSC("192.168.0.209", 9000); ~to = TouchOSC("192.168.0.209", 9000);
@ -8,10 +9,13 @@
~tracknum = 0; ~tracknum = 0;
~granulator = ~granulators[0]; ~granulator = ~granulators[0];
~speedlock = 0;
~speedquant = 0;
OSCdef.freeAll; OSCdef.freeAll;
~to.button('/reset', 0, { | v | ~to.button('/grains/reset', 0, { | v |
if( v > 0, { if( v > 0, {
var sp = ~to.v('/grains/speed')[0]; var sp = ~to.v('/grains/speed')[0];
~buflen = ~to.v('/grains/buflen'); ~buflen = ~to.v('/grains/buflen');
@ -23,26 +27,65 @@ OSCdef.freeAll;
}); });
}); });
~quantspeed = { |v| 2.pow((v * 4).round - 5) };
// control ganging is hella laggy, do it in TouchOSC
~setspeed = { | track, v |
var speed, qv = if(~speedquant > 0, { ~quantspeed.value(v) }, { v });
speed = qv / ~buflen;
if(~speedlock > 0, {
(0..3).do({|n|
~possynths[n].set(\speed, speed);
if( n != track, {
var url = ("/grains/speed" ++ n).asSymbol;
~to.s_(url, v);
});
});
},
{ ~possynths[track].set(\speed, speed) });
};
// setrecord: toggles record on (1) or off (0) for a track, and also sets the
// track's input mix to 0 so that it doesn't start fadeing out. If the track
// is the currently selected track, set its touchosc control to 0.
~setrecord = { | track, v |
~granulators[track].record_(v);
[ v, track, ~tracknum ].postln;
if(v == 0, {
~granulators[track].mix_(0);
if( track == ~tracknum, { ~to.v_('/track/mix', 0); });
});
};
// note: ~buflen is the variable for buffer length, which only gets set to // note: ~buflen is the variable for buffer length, which only gets set to
// ~to.v('/grains/buflen') when the buffer is reset with the clear button // ~to.v('/grains/buflen') when the buffer is reset with the clear button
~to.slider('/grains/buflen', ~buflen, TouchOSCScale(0.1, 10.0), {}); ~to.slider('/grains/buflen', ~buflen, TouchOSCScale(0.1, 10.0), {});
~to.button('/grains/record0', 0, { | v | ~granulators[0].record_(v) });
~to.button('/grains/record1', 0, { | v | ~granulators[1].record_(v) });
~to.button('/grains/record2', 0, { | v | ~granulators[2].record_(v) });
~to.button('/grains/record3', 0, { | v | ~granulators[3].record_(v) }); ~to.button('/grains/record0', 0, { | v | ~setrecord.value(0, v) });
~to.button('/grains/record1', 0, { | v | ~setrecord.value(1, v) });
~to.button('/grains/record2', 0, { | v | ~setrecord.value(2, v) });
~to.button('/grains/record3', 0, { | v | ~setrecord.value(3, v) });
~to.button('/grains/mode0', 0, { |v| ~granulators[0].mode_(v); ~setmode.value(0, v) }); ~to.button('/grains/mode0', 0, { |v| ~granulators[0].mode_(v); ~setmode.value(0, v) });
~to.button('/grains/mode1', 0, { |v| ~granulators[1].mode_(v); ~setmode.value(1, v) }); ~to.button('/grains/mode1', 0, { |v| ~granulators[1].mode_(v); ~setmode.value(1, v) });
~to.button('/grains/mode2', 0, { |v| ~granulators[2].mode_(v); ~setmode.value(2, v) }); ~to.button('/grains/mode2', 0, { |v| ~granulators[2].mode_(v); ~setmode.value(2, v) });
~to.button('/grains/mode3', 0, { |v| ~granulators[3].mode_(v); ~setmode.value(3, v) }); ~to.button('/grains/mode3', 0, { |v| ~granulators[3].mode_(v); ~setmode.value(3, v) });
~to.slider('/grains/speed0', 1, TouchOSCScale(0, 2), { |v| ~possynths[0].set(\speed, v / ~buflen); }); ~to.slider('/grains/speed0', 1, TouchOSCScale(0, 2), { |v| ~setspeed.value(0, v) });
~to.slider('/grains/speed1', 1, TouchOSCScale(0, 2), { |v| ~possynths[1].set(\speed, v / ~buflen); }); ~to.slider('/grains/speed1', 1, TouchOSCScale(0, 2), { |v| ~setspeed.value(1, v) });
~to.slider('/grains/speed2', 1, TouchOSCScale(0, 2), { |v| ~possynths[2].set(\speed, v / ~buflen); }); ~to.slider('/grains/speed2', 1, TouchOSCScale(0, 2), { |v| ~setspeed.value(2, v) });
~to.slider('/grains/speed3', 1, TouchOSCScale(0, 2), { |v| ~possynths[3].set(\speed, v / ~buflen); }); ~to.slider('/grains/speed3', 1, TouchOSCScale(0, 2), { |v| ~setspeed.value(3, v) });
~to.slider('/grains/passthrough', 0.75, TouchOSCScale(0, 1), { |v| ~grainmixer.set(\passthrough, v) }); ~to.slider('/grains/passthrough', 0.75, TouchOSCScale(0, 1), { |v| ~grainmixer.set(\passthrough, v) });
@ -51,13 +94,15 @@ OSCdef.freeAll;
~to.slider('/grains/mix2', 0.5, TouchOSCScale(0, 1),{ | v | ~granulators[2].gain_(v) }); ~to.slider('/grains/mix2', 0.5, TouchOSCScale(0, 1),{ | v | ~granulators[2].gain_(v) });
~to.slider('/grains/mix3', 0.5, TouchOSCScale(0, 1),{ | v | ~granulators[3].gain_(v) }); ~to.slider('/grains/mix3', 0.5, TouchOSCScale(0, 1),{ | v | ~granulators[3].gain_(v) });
~to.button('/grains/speedquant', 0, { |v| }); ~to.button('/grains/lock', 0, { |v| ~speedlock = v });
~to.button('/grains/quant', 0, { |v| ~speedquant = v });
// Page 2: track // Page 2: track
~to.xy('/track/triggersize', [ 120, 0.1 ], TouchOSCScale(0, 640), TouchOSCScale(0, 0.5), { |v| ~to.xy('/track/triggersize', [ 320, 0.25 ], TouchOSCScale(0, 640), TouchOSCScale(0, 0.5), { |v|
~granulator.trigger_(v[0]); ~granulator.trigger_(v[0]);
~granulator.size_(v[1]); ~granulator.size_(v[1]);
}); });

View File

@ -3,7 +3,8 @@
( (
Server.default.options.inDevice_("Scarlett 2i2 USB"); Server.default.options.inDevice_("Scarlett 2i2 USB");
Server.default.options.hardwareBufferSize_(1024); Server.default.options.hardwareBufferSize_(1024);
//Server.default.options.outDevice_("Scarlett 2i2 USB"); Server.default.options.outDevice_("Scarlett 2i2 USB");
//Server.default.options.outDevice_("External Headphones");
) )
Server.killAll; Server.killAll;
@ -25,3 +26,15 @@ Routine.run({
("./synths.scd").loadRelative;
Granulator.init(s);
("./control.scd").loadRelative;
("./granulator.scd").loadRelative;
("./effects.scd").loadRelative;
("./interface.scd").loadRelative;

View File

@ -14,12 +14,12 @@ SynthDef(\pos_sine, {
SynthDef(\pos_saw, { SynthDef(\pos_saw, {
arg out, speed=1; arg out, speed=1;
Out.kr(out, 0.5 + LFSaw.kr(speed, 0, 0.5)); Out.kr(out, 0.5 + LFSaw.kr(speed, 0, 0.5, 0.5));
}).add; }).add;
SynthDef(\pos_reverse, { SynthDef(\pos_reverse, {
arg out, speed=1; arg out, speed=1;
Out.kr(out, 0.5 - LFSaw.kr(speed, 0, 0.5)); Out.kr(out, 0.5 - LFSaw.kr(speed, 0, 0.5, 0.5));
}).add; }).add;
SynthDef(\pos_step, { SynthDef(\pos_step, {
@ -38,4 +38,10 @@ SynthDef( \lfo, {
Out.kr(out, SinOsc.kr(freq, 0, amp)); Out.kr(out, SinOsc.kr(freq, 0, amp));
}).add; }).add;
SynthDef(\trigger, {
arg out=1;
Out.kr(out, Impulse.kr(0))
}).add;
) )