From ae198fa7592e7bf801f3678b11a854c5a4e6d04d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 11 Sep 2012 14:31:04 +0200 Subject: moved value scaling functions from NanoEvent into "GenEvent" base class so it can be used for other controller events as well --- lib.ck | 1 + lib/GenEvent.ck | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/NanoEvent.ck | 41 ++++------------------------------------- 3 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 lib/GenEvent.ck diff --git a/lib.ck b/lib.ck index a9b6517..2915a17 100644 --- a/lib.ck +++ b/lib.ck @@ -4,6 +4,7 @@ Machine.add("lib/SampOsc.ck"); Machine.add("lib/Scale.ck"); Machine.add("lib/Element.ck"); Machine.add("lib/List.ck"); +Machine.add("lib/GenEvent.ck"); Machine.add("lib/NanoEvent.ck"); /* platform independant Clipper classes */ diff --git a/lib/GenEvent.ck b/lib/GenEvent.ck new file mode 100644 index 0000000..63328ea --- /dev/null +++ b/lib/GenEvent.ck @@ -0,0 +1,43 @@ +/* + * Base class for controller events + */ +public class GenEvent extends Event { + /* normalized value between [0, 1] */ + float value; + + /* + * Getter functions to scale `value' + */ + fun float + getFloat() + { + return value; + } + fun float + getFloat(float max) + { + return max*value; + } + fun float + getFloat(float min, float max) + { + return min + (max - min)*value; + } + + fun dur + getDur(dur max) + { + return max*value; + } + fun dur + getDur(dur min, dur max) + { + return min + (max - min)*value; + } + + fun int + getBool() + { + return value $ int; + } +} diff --git a/lib/NanoEvent.ck b/lib/NanoEvent.ck index 57a89e3..1ae9c59 100644 --- a/lib/NanoEvent.ck +++ b/lib/NanoEvent.ck @@ -1,11 +1,11 @@ /* * nanoKONTROL event class */ -public class NanoEvent extends Event { +public class NanoEvent extends GenEvent { /* map channel (0-15) to scene name */ - static string @__channelToScene[]; /* pseudo-private */ + static string @__channelToScene[]; /* pseudo-private */ /* map scene name and control id (0-255) to control name */ - static string @__controlToName[][]; /* pseudo-private */ + static string @__controlToName[][]; /* pseudo-private */ class Port extends Step { fun void @@ -40,7 +40,6 @@ public class NanoEvent extends Event { string scene; string control; int CCId; - float value; fun int isScene(string s) @@ -64,39 +63,6 @@ public class NanoEvent extends Event { return p; } - fun float - getFloat() - { - return value; - } - fun float - getFloat(float max) - { - return max*value; - } - fun float - getFloat(float min, float max) - { - return min + (max - min)*value; - } - - fun dur - getDur(dur max) - { - return max*value; - } - fun dur - getDur(dur min, dur max) - { - return min + (max - min)*value; - } - - fun int - getBool() - { - return value $ int; - } - fun void __midi_loop() /* pseudo-private */ { @@ -140,6 +106,7 @@ public class NanoEvent extends Event { broadcast(); } } + /* not reached */ } spork ~ __midi_loop(); -- cgit v1.2.3