diff options
Diffstat (limited to 'lib/pilot.moon')
| -rw-r--r-- | lib/pilot.moon | 56 |
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 } |
