aboutsummaryrefslogtreecommitdiffstats
path: root/lib/midi
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-18 17:50:33 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-18 18:03:04 +0000
commita49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a (patch)
treec1f800736e1905514aa913630ee31a720e770c9e /lib/midi
parentdocs/internal: add builtins and invoke modules (diff)
downloadalive-a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a.tar.gz
alive-a49382c7b46c7bdf1c105c0783c7bdcd0bb70e4a.zip
fork ops before eval cycle
Diffstat (limited to 'lib/midi')
-rw-r--r--lib/midi/core.moon2
-rw-r--r--lib/midi/launchctl.moon44
2 files changed, 22 insertions, 24 deletions
diff --git a/lib/midi/core.moon b/lib/midi/core.moon
index d5259ad..8378b1d 100644
--- a/lib/midi/core.moon
+++ b/lib/midi/core.moon
@@ -101,7 +101,7 @@ apply_range = (range, val) ->
when 'rad' then val / 64 * math.pi
when 'deg' then val / 128 * 360
else
- error "unknown range #{@range}"
+ error "unknown range #{range}"
elseif range.type == 'num'
val / 128 * range\unwrap!
else
diff --git a/lib/midi/launchctl.moon b/lib/midi/launchctl.moon
index 6408528..9f29922 100644
--- a/lib/midi/launchctl.moon
+++ b/lib/midi/launchctl.moon
@@ -19,9 +19,7 @@ range can be one of:
- 'deg' [ 0 - 360[
- (num) [ 0 - num["
- new: =>
- super 'num'
- @steps = {}
+ new: => super 'num'
setup: (inputs) =>
{ port, i, start,
@@ -42,23 +40,23 @@ range can be one of:
{ :port, :i, :start, :chan, :steps, :range } = @inputs
if steps\dirty!
- while steps! > #@steps
- table.insert @steps, 0
- while steps! < #@steps
- table.remove @steps
+ while steps! > #@state
+ table.insert @state, 0
+ while steps! < #@state
+ table.remove @state
- curr_i = i! % #@steps
+ curr_i = i! % #@state
if port\dirty!
changed = false
for msg in port!\receive!
if msg.status == 'control-change' and msg.chan == chan!
rel_i = msg.a - start!
- if rel_i >= 0 and rel_i < #@steps
- @steps[rel_i+1] = msg.b
+ if rel_i >= 0 and rel_i < #@state
+ @state[rel_i+1] = msg.b
changed = rel_i == curr_i
- @out\set apply_range range, @steps[curr_i+1] if changed
+ @out\set apply_range range, @state[curr_i+1] if changed
else
- @out\set apply_range range, @steps[curr_i+1]
+ @out\set apply_range range, @state[curr_i+1]
class gate_seq extends Op
@doc: "(launctl/gate-seq port i start chan [steps]) - Gate-Sequencer
@@ -68,7 +66,7 @@ steps defaults to 8."
new: =>
super 'bool', false
- @steps = {}
+ @state = {}
setup: (inputs) =>
{ port, i, start, chan, steps } = match 'midi/port num num num num?', inputs
@@ -91,34 +89,34 @@ steps defaults to 8."
display: (i, active) =>
{ :port, :start, :chan } = @unwrap_all!
- port\send 'note-on', chan, (start + i), light @steps[i+1], active
+ port\send 'note-on', chan, (start + i), light @state[i+1], active
tick: =>
{ :port, :i, :start, :chan, :steps } = @inputs
if steps\dirty!
- while steps! > #@steps
- table.insert @steps, false
- while steps! < #@steps
- table.remove @steps
+ while steps! > #@state
+ table.insert @state, false
+ while steps! < #@state
+ table.remove @state
- curr_i = i! % #@steps
+ curr_i = i! % #@state
if port\dirty!
for msg in port!\receive!
if msg.status == 'note-on' and msg.chan == chan!
rel_i = msg.a - start!
- if rel_i >= 0 and rel_i < #@steps
- @steps[rel_i+1] = not @steps[rel_i+1]
+ if rel_i >= 0 and rel_i < #@state
+ @state[rel_i+1] = not @state[rel_i+1]
@display rel_i, rel_i == curr_i
if i\dirty!
- prev_i = (curr_i - 1) % #@steps
+ prev_i = (curr_i - 1) % #@state
@display curr_i, true
@display prev_i, false
- @out\set @steps[curr_i+1]
+ @out\set @state[curr_i+1]
{
'gate-seq': gate_seq