diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-01 17:44:56 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-01 17:46:04 +0000 |
| commit | a1312100fad100190e20b1b3443b5cd962dc8999 (patch) | |
| tree | 8fc6194fc4b326ee39a9ca6d798cd208664f5fc3 /lib/midi/init.moon | |
| parent | add type-pattern matching language (diff) | |
| download | alive-a1312100fad100190e20b1b3443b5cd962dc8999.tar.gz alive-a1312100fad100190e20b1b3443b5cd962dc8999.zip | |
new op interface part one
Diffstat (limited to 'lib/midi/init.moon')
| -rw-r--r-- | lib/midi/init.moon | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/midi/init.moon b/lib/midi/init.moon index b0f2f6a..0cbe5e0 100644 --- a/lib/midi/init.moon +++ b/lib/midi/init.moon @@ -1,5 +1,7 @@ import Value, Op from require 'core' import input, output, inout, apply_range from require 'lib.midi.core' +import ValueInput, EventInput from require 'core.base' +import match from require 'core.pattern' class gate extends Op @doc: "(midi/gate port note [chan]) - gate from note-on and note-off messages" @@ -7,18 +9,21 @@ class gate extends Op new: => super 'bool', false - setup: (params) => - super params - @inputs[3] or= Value.num -1 - @assert_types 'midi/port', 'num', 'num' - @impulses = { @inputs[1]\unwrap! } + setup: (inputs) => + { port, note, chan } = match '=midi/port num num?', inputs + super + port: EventInput port.value! + note: ValueInput note + chan: ValueInput chan or Value.num -1 tick: => - local port, note, chan - { port, note, chan } = [i\unwrap! for i in *@inputs] + { port, note, chan } = @inputs + + if note\dirty! or chan\dirty! + @out\set false for msg in port\receive! - if msg.a == note and (chan == -1 or msg.chan == chan) + if msg.a == note! and (chan == -1 or msg.chan == chan!) if msg.status == 'note-on' @out\set true elseif msg.status == 'note-off' @@ -37,30 +42,25 @@ range can be one of: new: => super 'num' - destroy: => - dispatch\detach @mask if @mask - setup: (params) => - super params - @inputs[3] or= Value.num -1 - @inputs[4] or= Value.str 'uni' - assert #@inputs == 4 - assert @inputs[4].type == 'num' or @inputs[4].type == 'str' - @assert_types 'midi/port', 'num', 'num' - @impulses = { @inputs[1]\unwrap! } + setup: (inputs) => + { port, cc, chan, range } = match '=midi/port num num? any?', inputs + super + port: EventInput port.value! + cc: ValueInput cc + chan: ValueInput chan or Value.num -1 + range: ValueInput range or Value.str 'uni' if not @out\unwrap! - @out\set apply_range @inputs[4], 0 + @out\set apply_range @inputs.range, 0 tick: => - local port, cc, chan - { port, cc, chan } = [i\unwrap! for i in *@inputs] - + { port, cc, chan, range } = @inputs 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 @inputs[4], msg.b + (chan == -1 or msg.chan == chan!) and + msg.a == cc! + @out\set apply_range range, msg.b { :input |
