diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-10 22:38:09 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-10 22:38:09 +0200 |
commit | e711fce0ae256a18f9034d43888821c86219e15f (patch) | |
tree | 715be9df44b25e870181617367b2a30a7f168d86 | |
parent | e6309bc6eceefa45b3fdbfcc6ed3dd3cd29a197c (diff) | |
download | digitale-debutanten-e711fce0ae256a18f9034d43888821c86219e15f.tar.gz |
implemented NanoEvent ports: you can request a "port" for a registered control which will emit the control's data as samples
* may be used to simplify situations where a control directly influences a frequency/amplitude/phase
* samples are generated uniformly between [-1, 1] and can be scaled using "Scale"
-rw-r--r-- | lfo.ck | 36 | ||||
-rw-r--r-- | lib/NanoEvent.ck | 61 |
2 files changed, 72 insertions, 25 deletions
@@ -10,8 +10,21 @@ lfo[0] @=> UGen @cur_lfo; [new SawOsc, new PulseOsc] @=> UGen @osc[]; osc[0] @=> UGen @cur_osc; -Step lfo_freq => cur_lfo => Scale lfo_scale => cur_osc => Echo rev => Bus.out_left; -rev => Bus.out_right; +/* + * LFO configuration via MIDI + */ +if (me.args() > 1) + me.exit(); + +NanoEvent nanoev; + +/* first param: scene name */ +"primary" @=> nanoev.wantScene; +if (me.args() > 0) + me.arg(0) @=> nanoev.wantScene; + +nanoev.getPort("lfoFreqKnob") => Scale lfo_freq => cur_lfo => Scale lfo_scale; +lfo_scale => cur_osc => Echo rev => Bus.out_left; rev => Bus.out_right; //50::ms => echo.delay; //.3 => echo.mix; @@ -21,14 +34,12 @@ rev => Bus.out_right; 500::ms => rev.delay; 0.5 => rev.mix; -10 => lfo_freq.next; +20 => lfo_freq.out; 320 => float lfo_pitch; 80 => float lfo_depth; lfo_scale.out(lfo_pitch, lfo_pitch+lfo_depth); -//10 => lfo.harmonics; - fun void change_lfo(int new_lfo) { @@ -55,19 +66,6 @@ change_osc(int new_osc) lfo_scale => osc[new_osc] @=> cur_osc => rev; } -/* - * LFO configuration via MIDI - */ -if (me.args() > 1) - me.exit(); - -NanoEvent nanoev; - -/* first param: scene name */ -"primary" @=> nanoev.wantScene; -if (me.args() > 0) - me.arg(0) @=> nanoev.wantScene; - while (nanoev => now) { if ("lfoVolumeKnob" => nanoev.isControl) { nanoev.getFloat() => rev.gain; @@ -77,8 +75,6 @@ while (nanoev => now) { } else if ("lfoDepthSlider" => nanoev.isControl) { nanoev.getFloat(100) => lfo_depth; lfo_scale.out(lfo_pitch, lfo_pitch+lfo_depth); - } else if ("lfoFreqKnob" => nanoev.isControl) { - nanoev.getFloat(20) => lfo_freq.next; } else if ("lfoRateKnob" => nanoev.isControl) { /* sample rate for SampOsc */ nanoev.getFloat(2) => (lfo[2] $ SampOsc).rate; diff --git a/lib/NanoEvent.ck b/lib/NanoEvent.ck index 6468fd9..57a89e3 100644 --- a/lib/NanoEvent.ck +++ b/lib/NanoEvent.ck @@ -7,6 +7,34 @@ public class NanoEvent extends Event { /* map scene name and control id (0-255) to control name */ static string @__controlToName[][]; /* pseudo-private */ + class Port extends Step { + fun void + fetch(int device, string scene, string control) + { + MidiIn min; + + if (!min.open(device)) { + cherr <= "Cannot open MIDI device " <= device + <= IO.newline(); + me.exit(); + } + chout <= "Opened MIDI device " <= device <= " (" <= min.name() <= ")" + <= IO.newline(); + + while (min => now) { + while (MidiMsg msg => min.recv) { + if (NanoEvent.__channelToScene[msg.data1 & 0x0F] == scene && + NanoEvent.__controlToName[scene] != null && + NanoEvent.__controlToName[scene][msg.data2] == control) + msg.data3*2/127.0 - 1 => next; + } + } + /* not reached */ + } + } + + /* by default open MIDI Through port, actual connection is done by Jack */ + 0 => int device; string wantScene; string scene; @@ -25,6 +53,17 @@ public class NanoEvent extends Event { return control == c; } + fun Step @ + getPort(string control) + { + if (wantScene == "") + return null; + + Port p; + spork ~ p.fetch(device, wantScene, control); + return p; + } + fun float getFloat() { @@ -59,7 +98,7 @@ public class NanoEvent extends Event { } fun void - __midi_loop(int device) /* pseudo-private */ + __midi_loop() /* pseudo-private */ { MidiIn min; @@ -68,6 +107,8 @@ public class NanoEvent extends Event { <= IO.newline(); me.exit(); } + chout <= "Opened MIDI device " <= device <= " (" <= min.name() <= ")" + <= IO.newline(); while (min => now) { while (MidiMsg msg => min.recv) { @@ -92,16 +133,26 @@ public class NanoEvent extends Event { CCId => Std.itoa @=> control; } - (msg.data3 $ float)/127 => value; + msg.data3/127.0 => value; - if (cmd == 0xB0 && (wantScene == "" || scene == wantScene)) + if (cmd == 0xB0 && + (wantScene == "" || scene == wantScene)) broadcast(); } } } - /* always open MIDI Through port, actual connection is done by Jack */ - spork ~ __midi_loop(0); + spork ~ __midi_loop(); + + fun static NanoEvent @ + init(int device, string scene) /* pseudo-constructor */ + { + NanoEvent obj; + + device => obj.device; + scene @=> obj.wantScene; + return obj; + } fun static NanoEvent @ init(string scene) /* pseudo-constructor */ { |