diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-11 14:31:04 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-11 14:31:04 +0200 |
commit | ae198fa7592e7bf801f3678b11a854c5a4e6d04d (patch) | |
tree | ee50a455e45e4c403be78a4b6bc1bc261c1cf847 | |
parent | e711fce0ae256a18f9034d43888821c86219e15f (diff) | |
download | digitale-debutanten-ae198fa7592e7bf801f3678b11a854c5a4e6d04d.tar.gz |
moved value scaling functions from NanoEvent into "GenEvent" base class
so it can be used for other controller events as well
-rw-r--r-- | lib.ck | 1 | ||||
-rw-r--r-- | lib/GenEvent.ck | 43 | ||||
-rw-r--r-- | lib/NanoEvent.ck | 41 |
3 files changed, 48 insertions, 37 deletions
@@ -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(); |