aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi/init.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-13 20:28:13 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-13 20:28:13 +0000
commit42d4109398fd5cf2416ef076af3c2ddea16a5070 (patch)
tree4ef4d9c116a7fd423fcb62d531f97871d5f9d6e0 /lib/midi/init.moon
parentfix tagging (diff)
downloadalive-42d4109398fd5cf2416ef076af3c2ddea16a5070.tar.gz
alive-42d4109398fd5cf2416ef076af3c2ddea16a5070.zip
add launchcontrol midi
Diffstat (limited to 'lib/midi/init.moon')
-rw-r--r--lib/midi/init.moon70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/midi/init.moon b/lib/midi/init.moon
new file mode 100644
index 0000000..f522b6c
--- /dev/null
+++ b/lib/midi/init.moon
@@ -0,0 +1,70 @@
+import Const, Op from require 'core'
+import Input from require 'lib.midi.core'
+
+dispatch = Input 'system:midi_capture_6'
+
+class gate extends Op
+ @doc: "(midi/gate note [chan]) - gate from note-on and note-off messages"
+
+ new: (...) =>
+ super ...
+
+ destroy: =>
+ dispatch\detach @mask if @mask
+
+ setup: (note, chan) =>
+ dispatch\detach @mask if @mask
+
+ note = note\getc 'num'
+ chan = chan and chan\getc 'num'
+ @value = false
+
+ @mask = dispatch\attach { :chan, a: note }, (status) ->
+ if status == 'note-on'
+ @value = true
+ else if status == 'note-off'
+ @value = false
+
+ update: (dt) => dispatch\tick!
+
+class cc extends Op
+ @doc: "(midi/cc cc [chan [range]]) - MIDI CC to number
+
+range can be one of:
+- 'raw' [ 0 - 128[
+- 'uni' [ 0 - 1[ (default)
+- 'bip' [-1 - 1[
+- 'rad' [ 0 - tau[
+- (num) [ 0 - num["
+
+ destroy: =>
+ dispatch\detach @mask if @mask
+
+ setup: (cc, chan, @range=Const.str'uni') =>
+ dispatch\detach @mask if @mask
+
+ cc = cc\getc 'num'
+ chan = chan and chan\getc 'num'
+
+ @mask = dispatch\attach { status: 'control-change', :chan, a: cc }, (_, _, _, val) -> @apply val
+
+ update: (dt) => dispatch\tick!
+
+ apply: (val) =>
+ @value = if @range.type == 'str'
+ switch @range\get!
+ when 'raw' then val
+ when 'uni' then val / 128
+ when 'bip' then val / 64 - 1
+ when 'rad' then val / 64 * math.pi
+ else
+ error "unknown range #{@range}"
+ elseif @range.type == 'num'
+ val / 128 * @range\get!
+ else
+ error "range has to be a string or number"
+
+{
+ :gate
+ :cc
+}