diff options
author | David Runge <dave@sleepmap.de> | 2017-05-05 17:15:46 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2017-05-05 17:15:46 +0200 |
commit | ddbd3f2ee5baa3466f81171a29148a60f4a82e47 (patch) | |
tree | 08f9026c344537e6c7f68faa160630788f3f1d83 /classes | |
parent | 5f6bb41a2987991c1698d64835c944267f4da839 (diff) | |
download | zzz-ddbd3f2ee5baa3466f81171a29148a60f4a82e47.tar.gz zzz-ddbd3f2ee5baa3466f81171a29148a60f4a82e47.tar.bz2 zzz-ddbd3f2ee5baa3466f81171a29148a60f4a82e47.tar.xz zzz-ddbd3f2ee5baa3466f81171a29148a60f4a82e47.zip |
classes/ZZZES3.sc: Adding convenience functions to add,set,remove clocks and constant tones on defined outputs. setClock is also already able to switch between speeds using an Envelope over a certain amount of time.
Diffstat (limited to 'classes')
-rw-r--r-- | classes/ZZZES3.sc | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/classes/ZZZES3.sc b/classes/ZZZES3.sc index 686ad25..6201bfa 100644 --- a/classes/ZZZES3.sc +++ b/classes/ZZZES3.sc @@ -1,6 +1,8 @@ ZZZES3 : ZZZ{ - var out; + var out, + clocks, + vcos; *new{ arg channels; @@ -8,7 +10,9 @@ ZZZES3 : ZZZ{ } init{ - out = Dictionary.new(); + out = Dictionary(); + clocks = Dictionary(); + vcos = Dictionary(); "Interfacing ZZZ ES-3, using the following channels:".postln; (1..8).do({ arg item, i; @@ -30,4 +34,88 @@ ZZZES3 : ZZZ{ ^nil; }); } + + addClock{ + arg output, freq; + if(vcos.at(output).isNil, { + if(clocks.at(output).isNil, { + clocks.add(output -> Synth(\ZZZClock, [\out, this.out(output), \freq, freq])); + },{ + ("Cannot add clock on output "++ output ++". There is a clock playing.").error; + }); + },{ + ("Cannot add clock on output "++ output ++". There is a VCO playing.").error; + }); + } + + removeClock{ + arg output; + if(clocks.at(output).notNil, { + clocks.at(output).free; + clocks.removeAt(output); + }); + } + + setClock{ + arg output, freq, delta; + var currentFreq, diff, env; + if(clocks.at(output).notNil, { + if(delta.notNil, { + clocks.at(output).get(\freq, { + arg value; + currentFreq = value; + diff = (currentFreq-freq).abs; + if(currentFreq > freq, { + diff = diff*(-1); + }); + env = Env.sine((delta*2), diff).asStream; + { + (delta*10).do({ + clocks.at(output).set(\freq, (currentFreq+env.next)); + 0.1.wait; + }); + clocks.at(output).set(\freq, freq); + }.fork; + }); + },{ + clocks.at(output).set(\freq, freq); + }); + }); + } + + clock{ + arg output; + ^clocks.at(output); + } + + addVCO{ + arg output, mul; + if(clocks.at(output).isNil, { + if(vcos.at(output).isNil, { + vcos.add(output -> Synth(\ZZZConstant, [\out, this.out(output), \mul, mul])); + },{ + ("Cannot add VCO on output "++ output ++". There is a VCO playing.").error; + }); + },{ + ("Cannot add VCO on output "++ output ++". There is a clock playing.").error; + }); + } + + setVCO{ + arg output, mul; + if(vcos.at(output).notNil, { + vcos.at(output).set(\mul, mul); + }); + } + + removeVCO{ + arg output; + vcos.removeAt(output); + } + + vco{ + arg output; + ^vcos.at(output); + } + } |