aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-02 14:40:00 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-02 16:48:09 +0000
commit4ebb6f4408600f3c0f2a745b7ed0ba951bf521b3 (patch)
treecdf0953fdee07a6c83c510470a7b8ab8d832d25d /lib/midi
parentupdate lib.math and lib.logic to new op interface (diff)
downloadalive-4ebb6f4408600f3c0f2a745b7ed0ba951bf521b3.tar.gz
alive-4ebb6f4408600f3c0f2a745b7ed0ba951bf521b3.zip
lift remaining libs to new op interface
Diffstat (limited to 'lib/midi')
-rw-r--r--lib/midi/core.moon1
-rw-r--r--lib/midi/init.moon32
-rw-r--r--lib/midi/launchctl.moon1
3 files changed, 32 insertions, 2 deletions
diff --git a/lib/midi/core.moon b/lib/midi/core.moon
index aeef861..d91fdcb 100644
--- a/lib/midi/core.moon
+++ b/lib/midi/core.moon
@@ -105,6 +105,7 @@ apply_range = (range, val) ->
when 'uni' then val / 128
when 'bip' then val / 64 - 1
when 'rad' then val / 64 * math.pi
+ when 'deg' then val / 128 * 360
else
error "unknown range #{@range}"
elseif range.type == 'num'
diff --git a/lib/midi/init.moon b/lib/midi/init.moon
index 3bfba48..daf0088 100644
--- a/lib/midi/init.moon
+++ b/lib/midi/init.moon
@@ -8,14 +8,14 @@ class gate extends Op
super 'bool', false
setup: (inputs) =>
- { :port, :note, :chan } = match 'midi/port num num?', inputs
+ { port, note, chan } = match 'midi/port num num?', inputs
super
port: IOInput port
note: ValueInput note
chan: ValueInput chan or Value.num -1
tick: =>
- { port, note, chan } = @inputs
+ { :port, :note, :chan } = @inputs
if note\dirty! or chan\dirty!
@out\set false
@@ -28,6 +28,32 @@ class gate extends Op
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: IOInput port
+ note: ValueInput note
+ chan: ValueInput 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
@@ -36,6 +62,7 @@ range can be one of:
- 'uni' [ 0 - 1[ (default)
- 'bip' [-1 - 1[
- 'rad' [ 0 - tau[
+- 'deg' [ 0 - 360[
- (num) [ 0 - num["
new: =>
@@ -66,5 +93,6 @@ range can be one of:
:output
:inout
:gate
+ :trig
:cc
}
diff --git a/lib/midi/launchctl.moon b/lib/midi/launchctl.moon
index b3bf5da..1acafdc 100644
--- a/lib/midi/launchctl.moon
+++ b/lib/midi/launchctl.moon
@@ -16,6 +16,7 @@ range can be one of:
- 'uni' [ 0 - 1[ (default)
- 'bip' [-1 - 1[
- 'rad' [ 0 - tau[
+- 'deg' [ 0 - 360[
- (num) [ 0 - num["
new: =>