From 90e4ad3032c2f338456a6f134af6c20c077631d0 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sun, 1 Oct 2023 13:21:40 +1100 Subject: [PATCH 1/3] Moved metronome out to sequencer.scd --- sequencer.scd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sequencer.scd diff --git a/sequencer.scd b/sequencer.scd new file mode 100644 index 0000000..4516a4e --- /dev/null +++ b/sequencer.scd @@ -0,0 +1,46 @@ +// 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) + +}); + + From bc282aa727ffcf87ef96dbc03a4e8a9d408d7038 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sun, 1 Oct 2023 14:58:20 +1100 Subject: [PATCH 2/3] Sorted out separation between sequencer and interface code, added harmonic quantisation for chorus --- interface.scd | 74 +++++++++++++++++++-------------------------------- main.scd | 14 +++++++--- sequencer.scd | 18 +++---------- synths.scd | 7 ----- 4 files changed, 42 insertions(+), 71 deletions(-) diff --git a/interface.scd b/interface.scd index a1aaebb..6cf1a7a 100644 --- a/interface.scd +++ b/interface.scd @@ -24,9 +24,24 @@ OSCdef.freeAll; ~quantspeed = { |v| 2.pow((v * 4 + 0.5).round - 5) }; + +~quantharmonics = { + arg f, quantise=0; + quantise.postln; + if(quantise != 0, { + var fraction = f.asFraction(7, false); + [f, fraction].postln; + fraction[0] / fraction[1]; + }, + { f } + ); +}; + + // 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; @@ -94,6 +109,15 @@ OSCdef.freeAll; ~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 @@ -110,6 +134,9 @@ OSCdef.freeAll; ~to.button('/track/slope', 0, { |v| ~granulator.slope_(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/pitch', 0, TouchOSCScale(-2, 2), { |v| ~granulator.pitch_(v.round) }); @@ -134,6 +161,7 @@ OSCdef.freeAll; ~to.v_('/track/slope', ~granulator.slope); ~to.v_('/track/back', ~granulator.back); ~to.v_('/track/chorus', ~granulator.chorus); + ~to.v_('/track/harmonics', ~granulator.harmonics); ~to.v_('/track/detune', ~granulator.detune); ~to.v_('/track/pitch', ~granulator.pitch); }); @@ -186,52 +214,6 @@ OSCdef.freeAll; ~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) }); -// 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) - -}); - - ) diff --git a/main.scd b/main.scd index ce672c2..5fc64e4 100644 --- a/main.scd +++ b/main.scd @@ -11,6 +11,15 @@ Server.killAll; ( Routine.run({ + ~usbinput = 2; + ~usbinput1 = 2; + ~usbinput2 = 3; + + ~buflen = 4.0; + ~beatsperbar = 4; + + ~touchosc_ip = "192.168.0.209"; + ("./synths.scd").loadRelative; Granulator.init(s); s.sync; @@ -20,11 +29,10 @@ Routine.run({ s.sync; ("./effects.scd").loadRelative; s.sync; - ~touchosc_ip = "192.168.0.209"; + ("./sequencer.scd").loadRelative; + s.sync; ("./interface.scd").loadRelative; }); ) - - diff --git a/sequencer.scd b/sequencer.scd index 4516a4e..0a1983f 100644 --- a/sequencer.scd +++ b/sequencer.scd @@ -1,6 +1,6 @@ -// metronome code here is a bit gross but easier -~beatsperbar = 4; +( + ~bps = ~beatsperbar / ~buflen; ~tc = TempoClock.new(~bps); @@ -21,8 +21,6 @@ SynthDef(\metronome, { }).play(s, [\in, ~metrob, \out, 0, \amp, 0]); - - ~metronome = Pbind( \instrument, \metronome, \dur, 1, @@ -32,15 +30,5 @@ SynthDef(\metronome, { ).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) - -}); - +) diff --git a/synths.scd b/synths.scd index 9fdb0dd..9a8a294 100644 --- a/synths.scd +++ b/synths.scd @@ -1,12 +1,5 @@ ( -~usbinput = 2; -~usbinput1 = 2; -~usbinput2 = 3; - -~buflen = 4.0; -~beatsperbar = 4; - SynthDef(\pos_sine, { arg out, speed=1; Out.kr(out, 0.5 + SinOsc.kr(speed * 0.5, 0, 0.5)); From fc1b68da060062bb28cdcbb07e54a9ae57401594 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sat, 7 Oct 2023 07:58:14 +1100 Subject: [PATCH 3/3] Put all of the timing stuff in main --- interface.scd | 2 -- main.scd | 11 ++++++++++- sequencer.scd | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/interface.scd b/interface.scd index 6cf1a7a..279e862 100644 --- a/interface.scd +++ b/interface.scd @@ -27,10 +27,8 @@ OSCdef.freeAll; ~quantharmonics = { arg f, quantise=0; - quantise.postln; if(quantise != 0, { var fraction = f.asFraction(7, false); - [f, fraction].postln; fraction[0] / fraction[1]; }, { f } diff --git a/main.scd b/main.scd index 5fc64e4..8564112 100644 --- a/main.scd +++ b/main.scd @@ -15,8 +15,16 @@ Routine.run({ ~usbinput1 = 2; ~usbinput2 = 3; - ~buflen = 4.0; + ~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"; @@ -36,3 +44,4 @@ Routine.run({ ) + diff --git a/sequencer.scd b/sequencer.scd index 0a1983f..ce93b85 100644 --- a/sequencer.scd +++ b/sequencer.scd @@ -1,8 +1,6 @@ ( -~bps = ~beatsperbar / ~buflen; -~tc = TempoClock.new(~bps); SynthDef(\metronome, { arg out=0, amp=1, pan=0, filter=1000, atk=0.01, rel=0.1; @@ -32,3 +30,5 @@ SynthDef(\metronome, { ) + +