aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi/init.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-16 11:47:24 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-16 11:47:24 +0000
commit2953f1e56b408fc26eb54fa65935505dd128ce82 (patch)
tree8c7c513ccf03df06c4e9e2e70ba68031d2d0b7a5 /lib/midi/init.moon
parentadd ==, mod (diff)
downloadalive-2953f1e56b408fc26eb54fa65935505dd128ce82.tar.gz
alive-2953f1e56b408fc26eb54fa65935505dd128ce82.zip
major refactoring: Const, Stream + ResultNode
Diffstat (limited to 'lib/midi/init.moon')
-rw-r--r--lib/midi/init.moon44
1 files changed, 17 insertions, 27 deletions
diff --git a/lib/midi/init.moon b/lib/midi/init.moon
index f522b6c..c9e2476 100644
--- a/lib/midi/init.moon
+++ b/lib/midi/init.moon
@@ -1,29 +1,29 @@
-import Const, Op from require 'core'
-import Input from require 'lib.midi.core'
+import Stream, Const, Op from require 'core'
+import Input, apply_range from require 'lib.midi.core'
-dispatch = Input 'system:midi_capture_6'
+dispatch = Input 'system:midi_capture_4'
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'
+ note = note\const!\unwrap 'num'
+ chan = chan and chan\const!\unwrap 'num'
@value = false
@mask = dispatch\attach { :chan, a: note }, (status) ->
if status == 'note-on'
- @value = true
+ @out\set true
else if status == 'note-off'
- @value = false
+ @out\set false
+
+ @out = Stream 'bool', false
+ @out
update: (dt) => dispatch\tick!
@@ -43,26 +43,16 @@ range can be one of:
setup: (cc, chan, @range=Const.str'uni') =>
dispatch\detach @mask if @mask
- cc = cc\getc 'num'
- chan = chan and chan\getc 'num'
+ cc = cc\const!\unwrap 'num'
+ chan = chan and chan\const!\unwrap 'num'
- @mask = dispatch\attach { status: 'control-change', :chan, a: cc }, (_, _, _, val) -> @apply val
+ @mask = dispatch\attach { status: 'control-change', :chan, a: cc }, (_, _, _, val) ->
+ @out\set apply_range @range, val
- update: (dt) => dispatch\tick!
+ @out = Stream 'num', 0
+ @out
- 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"
+ update: (dt) => dispatch\tick!
{
:gate