summaryrefslogtreecommitdiff
path: root/lib/NanoEvent.ck
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-10 22:38:09 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-10 22:38:09 +0200
commite711fce0ae256a18f9034d43888821c86219e15f (patch)
tree715be9df44b25e870181617367b2a30a7f168d86 /lib/NanoEvent.ck
parente6309bc6eceefa45b3fdbfcc6ed3dd3cd29a197c (diff)
downloaddigitale-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"
Diffstat (limited to 'lib/NanoEvent.ck')
-rw-r--r--lib/NanoEvent.ck61
1 files changed, 56 insertions, 5 deletions
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 */
{