MIDI sequencer and timing improvements #8

Merged
bombinans merged 3 commits from feature-midi-sequencer into main 2023-10-06 21:00:42 +00:00
4 changed files with 79 additions and 55 deletions

View File

@ -24,9 +24,22 @@ OSCdef.freeAll;
~quantspeed = { |v| 2.pow((v * 4 + 0.5).round - 5) }; ~quantspeed = { |v| 2.pow((v * 4 + 0.5).round - 5) };
~quantharmonics = {
arg f, quantise=0;
if(quantise != 0, {
var fraction = f.asFraction(7, false);
fraction[0] / fraction[1];
},
{ f }
);
};
// control ganging is hella laggy, do it in TouchOSC // control ganging is hella laggy, do it in TouchOSC
~setspeed = { | track, v | ~setspeed = { | track, v |
var speed, qv = if(~speedquant > 0, { ~quantspeed.value(v) }, { v }); var speed, qv = if(~speedquant > 0, { ~quantspeed.value(v) }, { v });
speed = qv / ~buflen; speed = qv / ~buflen;
@ -94,6 +107,15 @@ OSCdef.freeAll;
~to.button('/grains/quant', 0, { |v| ~speedquant = v }); ~to.button('/grains/quant', 0, { |v| ~speedquant = v });
~to.button('/grains/metronome', 0, { |v|
if( v == 1, {
~bps = ~beatsperbar / ~buflen;
~tc.tempo_(~bps);
});
~metromix.set(\amp, v)
});
// Page 2: track // Page 2: track
@ -110,6 +132,9 @@ OSCdef.freeAll;
~to.button('/track/slope', 0, { |v| ~granulator.slope_(v) }); ~to.button('/track/slope', 0, { |v| ~granulator.slope_(v) });
~to.button('/track/chorus', 0, { |v| ~granulator.chorus_(v) }); ~to.button('/track/chorus', 0, { |v| ~granulator.chorus_(v) });
~to.slider('/track/harmonics', 2, TouchOSCScale(0.5, 3), { |v|
~granulator.harmonics_(~quantharmonics.value(v, 1))
});
~to.slider('/track/detune', 0, TouchOSCScale(0, 0.059), { |v| ~granulator.detune_(v) }); ~to.slider('/track/detune', 0, TouchOSCScale(0, 0.059), { |v| ~granulator.detune_(v) });
~to.slider('/track/pitch', 0, TouchOSCScale(-2, 2), { |v| ~granulator.pitch_(v.round) }); ~to.slider('/track/pitch', 0, TouchOSCScale(-2, 2), { |v| ~granulator.pitch_(v.round) });
@ -134,6 +159,7 @@ OSCdef.freeAll;
~to.v_('/track/slope', ~granulator.slope); ~to.v_('/track/slope', ~granulator.slope);
~to.v_('/track/back', ~granulator.back); ~to.v_('/track/back', ~granulator.back);
~to.v_('/track/chorus', ~granulator.chorus); ~to.v_('/track/chorus', ~granulator.chorus);
~to.v_('/track/harmonics', ~granulator.harmonics);
~to.v_('/track/detune', ~granulator.detune); ~to.v_('/track/detune', ~granulator.detune);
~to.v_('/track/pitch', ~granulator.pitch); ~to.v_('/track/pitch', ~granulator.pitch);
}); });
@ -186,52 +212,6 @@ OSCdef.freeAll;
~to.slider('/lfos/cfreq', 0.5,TouchOSCScale(0.1, 200), { |v| ~lfoc.set(\freq, v) } ); ~to.slider('/lfos/cfreq', 0.5,TouchOSCScale(0.1, 200), { |v| ~lfoc.set(\freq, v) } );
~to.slider('/lfos/camp', 0, TouchOSCScale(0, 1), { |v| ~lfoc.set(\amp, v) }); ~to.slider('/lfos/camp', 0, TouchOSCScale(0, 1), { |v| ~lfoc.set(\amp, v) });
// metronome code here is a bit gross but easier
~beatsperbar = 4;
~bps = ~beatsperbar / ~buflen;
~tc = TempoClock.new(~bps);
SynthDef(\metronome, {
arg out=0, amp=1, pan=0, filter=1000, atk=0.01, rel=0.1;
var sig, env;
env = EnvGen.kr(Env.perc(atk, rel, amp), doneAction: Done.freeSelf);
sig = HPF.ar(WhiteNoise.ar(), filter);
Out.ar(out, Pan2.ar(sig * env, pan));
}
).add;
~metrob = Bus.audio(s, 2);
~metromix = SynthDef(\metromix, {
arg in=1, out=0, amp=1;
Out.ar(out, amp * In.ar(in, 2));
}).play(s, [\in, ~metrob, \out, 0, \amp, 0]);
~metronome = Pbind(
\instrument, \metronome,
\dur, 1,
\amp, 0.5,
\pan, 0,
\out, ~metrob
).play(~tc);
~to.button('/grains/metronome', 0, { |v|
// reset tempo when turning metronome on
if( v == 1, {
~bps = ~beatsperbar / ~buflen;
~tc.tempo_(~bps);
});
// FIXME
~metromix.set(\amp, v)
});
) )

View File

@ -11,6 +11,23 @@ Server.killAll;
( (
Routine.run({ Routine.run({
~usbinput = 2;
~usbinput1 = 2;
~usbinput2 = 3;
~bpm = 55;
~bps = ~bpm / 60;
~beatsperbar = 4;
~buflen = ~beatsperbar / ~bps;
[ "bpm", ~bpm ].postln;
[ "buffer length", ~buflen ].postln;
~tc = TempoClock.new(~bps);
~touchosc_ip = "192.168.0.209";
("./synths.scd").loadRelative; ("./synths.scd").loadRelative;
Granulator.init(s); Granulator.init(s);
s.sync; s.sync;
@ -20,11 +37,11 @@ Routine.run({
s.sync; s.sync;
("./effects.scd").loadRelative; ("./effects.scd").loadRelative;
s.sync; s.sync;
~touchosc_ip = "192.168.0.209"; ("./sequencer.scd").loadRelative;
s.sync;
("./interface.scd").loadRelative; ("./interface.scd").loadRelative;
}); });
) )

34
sequencer.scd 100644
View File

@ -0,0 +1,34 @@
(
SynthDef(\metronome, {
arg out=0, amp=1, pan=0, filter=1000, atk=0.01, rel=0.1;
var sig, env;
env = EnvGen.kr(Env.perc(atk, rel, amp), doneAction: Done.freeSelf);
sig = HPF.ar(WhiteNoise.ar(), filter);
Out.ar(out, Pan2.ar(sig * env, pan));
}
).add;
~metrob = Bus.audio(s, 2);
~metromix = SynthDef(\metromix, {
arg in=1, out=0, amp=1;
Out.ar(out, amp * In.ar(in, 2));
}).play(s, [\in, ~metrob, \out, 0, \amp, 0]);
~metronome = Pbind(
\instrument, \metronome,
\dur, 1,
\amp, 0.5,
\pan, 0,
\out, ~metrob
).play(~tc);
)

View File

@ -1,12 +1,5 @@
( (
~usbinput = 2;
~usbinput1 = 2;
~usbinput2 = 3;
~buflen = 4.0;
~beatsperbar = 4;
SynthDef(\pos_sine, { SynthDef(\pos_sine, {
arg out, speed=1; arg out, speed=1;
Out.kr(out, 0.5 + SinOsc.kr(speed * 0.5, 0, 0.5)); Out.kr(out, 0.5 + SinOsc.kr(speed * 0.5, 0, 0.5));