aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi/init.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-19 21:17:46 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-19 21:17:53 +0000
commite62ef99244bb3aa906810a5cfd53c0dac68b0f37 (patch)
treee7379e2add7014e7124f678f4a7a8edc699fe914 /lib/midi/init.moon
parentmajor refactoring: Const, Stream + ResultNode (diff)
downloadalive-e62ef99244bb3aa906810a5cfd53c0dac68b0f37.tar.gz
alive-e62ef99244bb3aa906810a5cfd53c0dac68b0f37.zip
merge Const and Stream into Value; Dataflow logic
lib not fully ported / functonial
Diffstat (limited to 'lib/midi/init.moon')
-rw-r--r--lib/midi/init.moon75
1 files changed, 42 insertions, 33 deletions
diff --git a/lib/midi/init.moon b/lib/midi/init.moon
index c9e2476..03f5115 100644
--- a/lib/midi/init.moon
+++ b/lib/midi/init.moon
@@ -1,34 +1,31 @@
-import Stream, Const, Op from require 'core'
-import Input, apply_range from require 'lib.midi.core'
-
-dispatch = Input 'system:midi_capture_4'
+import Value, Op from require 'core'
+import input, output, inout, apply_range from require 'lib.midi.core'
class gate extends Op
- @doc: "(midi/gate note [chan]) - gate from note-on and note-off messages"
+ @doc: "(midi/gate port note [chan]) - gate from note-on and note-off messages"
- destroy: =>
- dispatch\detach @mask if @mask
-
- setup: (note, chan) =>
- dispatch\detach @mask if @mask
+ new: =>
+ super 'bool', false
- note = note\const!\unwrap 'num'
- chan = chan and chan\const!\unwrap 'num'
- @value = false
+ setup: (params) =>
+ super params
+ @inputs[3] or= Value.num -1
+ @assert_types 'midi/port', 'num', 'num'
+ @impulses = { @inputs[1]\unwrap! }
- @mask = dispatch\attach { :chan, a: note }, (status) ->
- if status == 'note-on'
- @out\set true
- else if status == 'note-off'
- @out\set false
+ tick: =>
+ local port, note, chan
+ { port, note, chan } = [i\unwrap! for i in *@inputs]
- @out = Stream 'bool', false
- @out
-
- update: (dt) => dispatch\tick!
+ 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 cc extends Op
- @doc: "(midi/cc cc [chan [range]]) - MIDI CC to number
+ @doc: "(midi/cc port cc [chan [range]]) - MIDI CC to number
range can be one of:
- 'raw' [ 0 - 128[
@@ -37,24 +34,36 @@ range can be one of:
- 'rad' [ 0 - tau[
- (num) [ 0 - num["
- destroy: =>
- dispatch\detach @mask if @mask
+ new: =>
+ super 'num'
- setup: (cc, chan, @range=Const.str'uni') =>
+ destroy: =>
dispatch\detach @mask if @mask
- cc = cc\const!\unwrap 'num'
- chan = chan and chan\const!\unwrap 'num'
+ setup: (params) =>
+ super params
+ @inputs[3] or= Value.num -1
+ @inputs[4] or= Value.str 'uni'
+ @assert_types 'midi/port', 'num', 'num', 'str'
+ @impulses = { @inputs[1]\unwrap! }
- @mask = dispatch\attach { status: 'control-change', :chan, a: cc }, (_, _, _, val) ->
- @out\set apply_range @range, val
+ if not @out\unwrap!
+ @out\set apply_range @inputs[4], 0
- @out = Stream 'num', 0
- @out
+ tick: =>
+ local port, cc, chan
+ { port, cc, chan } = [i\unwrap! for i in *@inputs]
- update: (dt) => dispatch\tick!
+ 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
{
+ :input
+ :output
+ :inout
:gate
:cc
}