From 7f8536b4a6d7fd06b1cd4929f548d241183c09cd Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 16 Apr 2012 17:09:49 +0200 Subject: initial import of files relevant for noise project --- lib/Bus.ck | 30 +++++++++++++++ lib/Clipper.ck | 18 +++++++++ lib/MIDI.ck | 18 +++++++++ lib/Oscope.ck | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/Queue.ck | 48 +++++++++++++++++++++++ 5 files changed, 234 insertions(+) create mode 100644 lib/Bus.ck create mode 100644 lib/Clipper.ck create mode 100644 lib/MIDI.ck create mode 100644 lib/Oscope.ck create mode 100644 lib/Queue.ck (limited to 'lib') diff --git a/lib/Bus.ck b/lib/Bus.ck new file mode 100644 index 0000000..fbbca74 --- /dev/null +++ b/lib/Bus.ck @@ -0,0 +1,30 @@ +/* + * Public data bus + */ +public class Bus { + static Gain @out_left; + static Gain @out_right; + + /* chucked in Oscope.ck */ + static Gain @oscope[]; + + static Gain @channels[]; +} +/* initialization */ +new Gain @=> Bus.out_left; +new Gain @=> Bus.out_right; +new Gain[3] @=> Bus.oscope; +new Gain[8] @=> Bus.channels; + +/* limiting and clipping for main stereo outputs */ +Clipper clipper1; +Bus.out_left => Dyno dyn1 => clipper1.input; +clipper1.output => dac.chan(0); +dyn1.limit(); + +Clipper clipper2; +Bus.out_right => Dyno dyn2 => clipper2.input; +clipper2.output => dac.chan(1); +dyn2.limit(); + +while (day => now); diff --git a/lib/Clipper.ck b/lib/Clipper.ck new file mode 100644 index 0000000..c11d3c2 --- /dev/null +++ b/lib/Clipper.ck @@ -0,0 +1,18 @@ +/* + * clip signal within -1 to 1 with simple UGens + */ +public class Clipper { + Gain input; // chuck input signal to this + Gain output; // chuck this out to have the result + + Step one; 1 => one.next; + input => HalfRect a; + one => a; // calculate a from HalfRect(input + 1) + one => Gain two; 2 => two.gain; + -1 => a.gain; + a => HalfRect b; + two => b; // calculate b from HalfRect(2 - HalfRect(input + 1)) + -1 => b.gain; + one => output; + b => output; // the result we want: 1 - HalfRect(2 - HalfRect(input + 1)) +} diff --git a/lib/MIDI.ck b/lib/MIDI.ck new file mode 100644 index 0000000..be808db --- /dev/null +++ b/lib/MIDI.ck @@ -0,0 +1,18 @@ +/* + * Global MIDI tools + */ +public class MIDI { + static int channels; + + static int noteOff; + static int noteOn; + + fun static int + isCmd(int data, int cmd) + { + return data >= cmd && data < cmd + channels; + } +} +0x10 => MIDI.channels; +0x80 => MIDI.noteOff; +0x90 => MIDI.noteOn; diff --git a/lib/Oscope.ck b/lib/Oscope.ck new file mode 100644 index 0000000..5849b3f --- /dev/null +++ b/lib/Oscope.ck @@ -0,0 +1,120 @@ +/* + * Oscilloscope (jack.scope) helpers + */ +public class Oscope { + static OscSend @jack_scope; + + /* + * "signal" or "embed" + */ + fun static void + mode(string m) + { + jack_scope.startMsg("/mode", "s"); + m => jack_scope.addString; + } + + /* + * "dot", "fill" or "line" + */ + fun static void + style(string s) + { + jack_scope.startMsg("/style", "s"); + s => jack_scope.addString; + } + + fun static void + frames(dur f) + { + // <<< "set frame size:", (f / samp) $ int >>>; + jack_scope.startMsg("/frames", "i"); + (f / samp) $ int => jack_scope.addInt; + } + + fun static void + delay(dur d) + { + // <<< "set delay length:", d / ms >>>; + jack_scope.startMsg("/delay", "f"); + d / ms => jack_scope.addFloat; + } + + /* + * "sample delay" in "embed" mode + * Can this be a ChucK duration??? + */ + fun static void + embed(int em) + { + jack_scope.startMsg("/embed", "i"); + em => jack_scope.addInt; + } + + fun static void + incr(float i) + { + jack_scope.startMsg("/incr", "f"); + i => jack_scope.addFloat; + } +} +/* initialization */ +new OscSend @=> Oscope.jack_scope; +Oscope.jack_scope.setHost("localhost", 57140); + +"signal" => Oscope.mode; +"line" => Oscope.style; +512::samp => Oscope.frames; +100::ms => Oscope.delay; + +/* + * connect oscilloscope Bus channels to dedicated output ports that are patched + * to jack.scope + */ +for (0 => int i; i < Bus.oscope.cap(); i++) + Bus.oscope[i] => dac.chan(4 + i); + +/* + * jack.scope configuration via MIDI (Channel/Scene 1) + */ +/* FIXME: custom nanoKONTROL events */ +if (me.args() > 1) + me.exit(); + +1 => int device; +if (me.args() == 1) + me.arg(0) => Std.atoi => device; + +MidiIn min; + +if (!min.open(device)) + me.exit(); +<<< "MIDI device:", min.num(), " -> ", min.name() >>>; + +while (min => now) { + while (MidiMsg msg => min.recv) { + msg.data1 & 0x0F => int channel; + msg.data1 & 0xF0 => int cmd; + (msg.data3 $ float)/127 => float value; + + if (channel == 1 && cmd == 0xB0) { + <<< "Channel:", channel, "Command:", cmd, "Controller:", msg.data2, "Value:", value >>>; + + if (msg.data2 == 67) { + if (value $ int) + "embed" => Oscope.mode; + else + "signal" => Oscope.mode; + } else if (msg.data2 == 76) { + if (value $ int) + "fill" => Oscope.style; + else + "line" => Oscope.style; + } else if (msg.data2 == 42) { + 512::samp + value*2::second => Oscope.frames; + } else if (msg.data2 == 57) { + 50::ms + value*second => Oscope.delay; + } + } + } +} diff --git a/lib/Queue.ck b/lib/Queue.ck new file mode 100644 index 0000000..f05ae5e --- /dev/null +++ b/lib/Queue.ck @@ -0,0 +1,48 @@ +/* + * Queue data structure + */ +public class Queue { + class Element { + Element @next; + Object @payload; + } + Element head @=> Element @tail; + + fun void + push(Object @data) + { + new Element @=> tail.next @=> tail; + data @=> tail.payload; + } + + fun Object @ + peek() + { + if (head.next == null) + /* empty */ + return null; + else + return head.next.payload; + } + + fun Object @ + pop() + { + head.next @=> Element @el; + if (el == null) + /* empty */ + return null; + + el.next @=> head.next; + if (el == tail) + /* but now it's empty! */ + head @=> tail; + return el.payload; + } + + fun void + flush() + { + while (pop() != null); + } +} -- cgit v1.2.3