summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-04-29 01:28:17 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-04-29 01:28:17 +0200
commit7654db0a3c1a56ccd30e991080c61d3043ad40c6 (patch)
tree914287ef9d8fe0a6a18f9aa14d8403d276ed5a3c
parent4906cda4b79aca262d8227e2c9461144439106d4 (diff)
downloaddigitale-debutanten-7654db0a3c1a56ccd30e991080c61d3043ad40c6.tar.gz
added MIDI event recorder (Scene 2)
all MIDI events can be recorded and played back again (optionally using looping)
-rw-r--r--midi_recorder.ck93
-rw-r--r--settings.nktrl_setbin1184 -> 1184 bytes
2 files changed, 93 insertions, 0 deletions
diff --git a/midi_recorder.ck b/midi_recorder.ck
new file mode 100644
index 0000000..b3a7155
--- /dev/null
+++ b/midi_recorder.ck
@@ -0,0 +1,93 @@
+class RecEvent {
+ dur pit;
+ MidiMsg @msg;
+}
+Queue buffer;
+
+/* FIXME: custom nanoKONTROL events */
+if (me.args() > 0)
+ me.exit();
+
+MidiOut mout;
+MidiIn min;
+
+/* always open MIDI Through port, actual connection is done by Jack */
+if (!min.open(0))
+ me.exit();
+if (!mout.open(0))
+ me.exit();
+
+<<< "MIDI device:", min.num(), " -> ", min.name() >>>;
+
+1 => int on_channel; /* Scene 2 */
+
+false => int recording;
+time start;
+
+false => int looping;
+
+fun void
+do_playback(int looping)
+{
+ if (buffer.peek() == null)
+ return;
+
+ while (true) {
+ for (buffer.head.next @=> Element @cur; cur != null; cur.next @=> cur) {
+ cur.payload $ RecEvent @=> RecEvent @recev;
+
+ recev.pit => now;
+ recev.msg => mout.send;
+
+ <<< "PLAY Channel:", recev.msg.data1 & 0x0F,
+ "Command:", recev.msg.data1 & 0xF0,
+ "Controller:", recev.msg.data2,
+ "Value:", (recev.msg.data3 $ float)/127 >>>;
+ }
+
+ if (!looping)
+ break;
+ }
+
+ <<< "PLAY FIN", 1 >>>;
+}
+Shred @playback_shred;
+
+while (min => now) {
+ while (MidiMsg msg => min.recv) {
+ msg.data1 & 0x0F => int channel;
+ msg.data1 & 0xF0 => int cmd;
+ (msg.data3 $ float)/127 => float value;
+ //<<< "Channel:", channel, "Command:", cmd, "Controller:", msg.data2, "Value:", value >>>;
+
+ channel == on_channel && cmd == 0xB0 => int is_cmd;
+
+ if (is_cmd && msg.data2 == 44) {
+ if (value $ int => recording) {
+ now => start;
+ buffer.flush();
+ }
+ } else if (is_cmd && msg.data2 == 45) {
+ if (value $ int) {
+ if (playback_shred != null)
+ playback_shred.exit();
+ spork ~ do_playback(looping) @=> playback_shred;
+ }
+ } else if (is_cmd && msg.data2 == 46) {
+ if (value $ int && playback_shred != null) {
+ playback_shred.exit();
+ null @=> playback_shred;
+ }
+ } else if (is_cmd && msg.data2 == 49) {
+ value $ int => looping;
+ } else if (recording) {
+ <<< "REC Channel:", channel, "Command:", cmd, "Controller:", msg.data2, "Value:", value >>>;
+
+ RecEvent recev => buffer.push;
+ now - start => recev.pit;
+ msg @=> recev.msg;
+
+ now => start;
+ }
+ }
+} \ No newline at end of file
diff --git a/settings.nktrl_set b/settings.nktrl_set
index 5682f73..94500bf 100644
--- a/settings.nktrl_set
+++ b/settings.nktrl_set
Binary files differ