aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi.moon
diff options
context:
space:
mode:
Diffstat (limited to 'lib/midi.moon')
-rw-r--r--lib/midi.moon169
1 files changed, 90 insertions, 79 deletions
diff --git a/lib/midi.moon b/lib/midi.moon
index 33fe936..e978702 100644
--- a/lib/midi.moon
+++ b/lib/midi.moon
@@ -1,63 +1,73 @@
import Value, Op, Input, match from require 'core.base'
import input, output, inout, apply_range from require 'lib.midi.core'
-class gate extends Op
- @doc: "(midi/gate port note [chan]) - gate from note-on and note-off messages"
-
- new: =>
- super 'bool', false
-
- setup: (inputs) =>
- { port, note, chan } = match 'midi/port num num?', inputs
- super
- port: Input.io port
- note: Input.value note
- chan: Input.value chan or Value.num -1
-
- tick: =>
- { :port, :note, :chan } = @inputs
-
- if note\dirty! or chan\dirty!
- @out\set false
-
- if port\dirty!
- for msg in port!\receive!
- if msg.a == note! and (chan! == -1 or msg.chan == chan!)
- if msg.status == 'note-on'
- @out\set true
- elseif msg.status == 'note-off'
- @out\set false
-
-class trig extends Op
- @doc: "(midi/trig port note [chan]) - gate from note-on and note-off messages"
-
- new: =>
- super 'bang', false
-
- setup: (inputs) =>
- { port, note, chan } = match 'midi/port num num?', inputs
- super
- port: Input.io port
- note: Input.value note
- chan: Input.value chan or Value.num -1
-
- tick: =>
- { :port, :note, :chan } = @inputs
-
- if note\dirty! or chan\dirty!
- @out\set false
-
- if port\dirty!
- for msg in port!\receive!
- if msg.a == note! and (chan! == -1 or msg.chan == chan!)
- if msg.status == 'note-on'
- @out\set true
-
-
-class cc extends Op
- @doc: "(midi/cc port cc [chan [range]]) - MIDI CC to number
-
-range can be one of:
+gate = Value.meta
+ meta:
+ name: 'gate'
+ summary: "gate from note-on and note-off messages."
+ examples: { '(midi/gate port note [chan])' }
+
+ value: class extends Op
+ new: =>
+ super 'bool', false
+
+ setup: (inputs) =>
+ { port, note, chan } = match 'midi/port num num?', inputs
+ super
+ port: Input.io port
+ note: Input.value note
+ chan: Input.value chan or Value.num -1
+
+ tick: =>
+ { :port, :note, :chan } = @inputs
+
+ if note\dirty! or chan\dirty!
+ @out\set false
+
+ if port\dirty!
+ for msg in port!\receive!
+ if msg.a == note! and (chan! == -1 or msg.chan == chan!)
+ if msg.status == 'note-on'
+ @out\set true
+ elseif msg.status == 'note-off'
+ @out\set false
+
+trig = Value.meta
+ meta:
+ name: 'trig'
+ summary: "`bang`s from note-on messages."
+ examples: { '(midi/trig port note [chan])' }
+
+ value: class extends Op
+ new: =>
+ super 'bang', false
+
+ setup: (inputs) =>
+ { port, note, chan } = match 'midi/port num num?', inputs
+ super
+ port: Input.io port
+ note: Input.value note
+ chan: Input.value chan or Value.num -1
+
+ tick: =>
+ { :port, :note, :chan } = @inputs
+
+ if note\dirty! or chan\dirty!
+ @out\set false
+
+ if port\dirty!
+ for msg in port!\receive!
+ if msg.a == note! and (chan! == -1 or msg.chan == chan!)
+ if msg.status == 'note-on'
+ @out\set true
+
+trig = Value.meta
+ meta:
+ name: 'trig'
+ summary: "`num` from cc-change messages."
+ examples: { '(midi/cc port cc [chan [range]])' }
+ description: "
+`range` can be one of:
- 'raw' [ 0 - 128[
- 'uni' [ 0 - 1[ (default)
- 'bip' [-1 - 1[
@@ -65,28 +75,29 @@ range can be one of:
- 'deg' [ 0 - 360[
- (num) [ 0 - num["
- new: =>
- super 'num'
-
- setup: (inputs) =>
- { port, cc, chan, range } = match 'midi/port num num? any?', inputs
- super
- port: Input.io port
- cc: Input.value cc
- chan: Input.value chan or Value.num -1
- range: Input.value range or Value.str 'uni'
-
- if not @out\unwrap!
- @out\set apply_range @inputs.range, 0
-
- tick: =>
- { :port, :cc, :chan, :range } = @inputs
- if port\dirty!
- for msg in port!\receive!
- if msg.status == 'control-change' and
- (chan! == -1 or msg.chan == chan!) and
- msg.a == cc!
- @out\set apply_range range, msg.b
+ value: class extends Op
+ new: =>
+ super 'num'
+
+ setup: (inputs) =>
+ { port, cc, chan, range } = match 'midi/port num num? any?', inputs
+ super
+ port: Input.io port
+ cc: Input.value cc
+ chan: Input.value chan or Value.num -1
+ range: Input.value range or Value.str 'uni'
+
+ if not @out\unwrap!
+ @out\set apply_range @inputs.range, 0
+
+ tick: =>
+ { :port, :cc, :chan, :range } = @inputs
+ if port\dirty!
+ for msg in port!\receive!
+ if msg.status == 'control-change' and
+ (chan! == -1 or msg.chan == chan!) and
+ msg.a == cc!
+ @out\set apply_range range, msg.b
{
:input