aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pilot.moon
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/pilot.moon
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/pilot.moon')
-rw-r--r--lib/pilot.moon56
1 files changed, 43 insertions, 13 deletions
diff --git a/lib/pilot.moon b/lib/pilot.moon
index 2a7d21a..a442b77 100644
--- a/lib/pilot.moon
+++ b/lib/pilot.moon
@@ -1,4 +1,4 @@
-import Op from require 'core'
+import Op, EventInput, ValueInput, ColdInput, match from require 'core'
import udp from require 'socket'
conn = udp!
@@ -11,32 +11,62 @@ encode = (arg) ->
when 'string' then arg
else error "invalid type: #{type arg}"
-send = (tbl) ->
- str = table.concat [encode v for v in *tbl]
+send = (...) ->
+ str = ''
+ for i = 1, select '#', ...
+ tbl = select i, ...
+ str ..= table.concat [encode v for v in *tbl]
conn\sendto str, '127.0.0.1', 49161
class play extends Op
@doc: "(play trig ch oct note [vel [len]]) - play a note when trig is live"
- setup: (@trig, ...) =>
- @vals = { ... }
+ setup: (inputs) =>
+ { trig, args } = match 'bang *any', inputs
+ assert #args < 6, "too many arguments!"
+ super
+ trig: EventInput trig
+ args: [ColdInput a for a in *args]
- update: (dt) =>
- if @trig\unwrap 'bool'
- send [c\unwrap! for c in *@vals]
+ tick: =>
+ { :trig, :args } = @inputs
+ if trig\dirty! and trig!
+ send [a! for a in *@inputs.args]
+
+class play_ extends Op
+ @doc: "(play! ch oct note [vel [len]]) - play a note when note is live"
+
+ setup: (inputs) =>
+ { chan, octv, note, args } = match 'any any any *any', inputs
+ assert #args < 3, "too many arguments!"
+ super
+ chan: ColdInput chan
+ octv: ColdInput octv
+ note: EventInput note
+ args: [ColdInput a for a in *args]
+
+ tick: =>
+ if @inputs.note\dirty!
+ { :chan, :oct, :note, :args } = @unwrap_all!
+ send { chan, oct, note }, args
class effect extends Op
@doc: "(effect which a b) - set an effect
which is one of 'DIS', 'CHO', 'REV' or 'FEE'"
- setup: (@which, @a, @b) =>
+ setup: (inputs) =>
+ { which, a, b } = match 'str num num', inputs
+ super {
+ ColdInput which
+ ValueInput a
+ ValueInput b
+ }
- update: (dt) =>
- which, a, b = (@which\unwrap 'str'), @a\unwrap!, @b\unwrap!
- if which and a and b
- send { which, a, b }
+ tick: =>
+ send @unwrap_all!
{
:play
+ 'play!': play_
:effect
}