aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pilot.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-25 10:43:29 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-25 11:25:05 +0000
commit7cb862f6f6079509dafd466fff83c719cb2fd89e (patch)
tree843f92c4d4b2507e88a525b7c56c29d343958e5b /lib/pilot.moon
parentValue -> Value/Event/IO-Stream (diff)
downloadalive-7cb862f6f6079509dafd466fff83c719cb2fd89e.tar.gz
alive-7cb862f6f6079509dafd466fff83c719cb2fd89e.zip
new core.base.match, update lib
Diffstat (limited to 'lib/pilot.moon')
-rw-r--r--lib/pilot.moon39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/pilot.moon b/lib/pilot.moon
index b851440..1d6b554 100644
--- a/lib/pilot.moon
+++ b/lib/pilot.moon
@@ -1,4 +1,4 @@
-import Op, Value, Input, Error, match from require 'core.base'
+import Op, ValueStream, Input, val, evt from require 'core.base'
import udp from require 'socket'
local conn
@@ -20,47 +20,49 @@ send = (...) ->
conn or= udp!
conn\sendto str, '127.0.0.1', 49161
-play = Value.meta
+arg = val.num / val.str
+
+play = ValueStream.meta
meta:
name: 'play'
summary: "Play a note when a bang arrives."
examples: { '(pilot/play trig ch oct note [vel [len]])' }
value: class extends Op
+ pattern = evt.bang + arg^5
setup: (inputs) =>
- { trig, args } = match 'bang *any', inputs
- assert #args < 6, Error 'argument', "too many arguments!"
+ { trig, args } = pattern\match inputs
super
- trig: Input.event trig
+ trig: Input.hot trig
args: [Input.cold a for a in *args]
tick: =>
{ :trig, :args } = @inputs
- if trig\dirty! and trig!
+ for _ in *trig!
send [a! for a in *@inputs.args]
-play_ = Value.meta
+play_ = ValueStream.meta
meta:
name: 'play!'
summary: "Play a note when a note arrives."
examples: { '(pilot/play! ch oct note [vel [len]])' }
value: class extends Op
+ pattern = arg + arg + (evt.num / evt.str) + arg^2
setup: (inputs) =>
- { chan, octv, note, args } = match 'any any any *any', inputs
- assert #args < 3, Error 'argument', "too many arguments!"
+ { chan, octv, note, args } = pattern\match inputs
super
chan: Input.cold chan
octv: Input.cold octv
- note: Input.event note
+ note: Input.hot note
args: [Input.cold a for a in *args]
tick: =>
- if @inputs.note\dirty!
- { :chan, :oct, :note, :args } = @unwrap_all!
- send { chan, oct, note }, args
+ { :chan, :octv, :note, :args } = @inputs
+ for note in *note!
+ send { chan!, octv!, note! }, args
-effect = Value.meta
+effect = ValueStream.meta
meta:
name: 'effect'
summary: "Set effect parameters."
@@ -68,12 +70,13 @@ effect = Value.meta
description: "`effect` should be one of 'DIS', 'CHO', 'REV' or 'FEE'"
value: class extends Op
+ pattern = val.str + arg + arg
setup: (inputs) =>
- { which, a, b } = match 'str num num', inputs
+ { which, a, b } = pattern\match inputs
super {
- Input.cold which
- Input.value a
- Input.value b
+ Input.hot which
+ Input.hot a
+ Input.hot b
}
tick: =>