diff options
Diffstat (limited to 'lib/pilot.moon')
| -rw-r--r-- | lib/pilot.moon | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/pilot.moon b/lib/pilot.moon new file mode 100644 index 0000000..1cbc070 --- /dev/null +++ b/lib/pilot.moon @@ -0,0 +1,50 @@ +import Const, Op, FnDef from require 'core' +import dns, udp from require 'socket' + +conn = udp! +hex = "0123456789abcdef" +encode = (arg) -> + switch type arg + when 'number' then + i = 1 + math.floor arg + hex\sub i, i + when 'string' then arg + else error "invalid type: #{type arg}" + +send = (tbl) -> + 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, @ch, @oct, @note, @vel, @len) => + + update: (dt) => + vals = for c in *{@trig, @ch, @oct, @note, @vel, @len } + c\update dt + c\get! + + trig = table.remove vals, 1 + + if trig + send vals + +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) => + + update: (dt) => + @which\update dt + @a\update dt + @b\update dt + which, a, b = @which\get!, @a\get!, @b\get! + if which and a and b + send { which, a, b } +{ + :play + :effect +} |
