diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-11 13:08:36 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-11 13:08:36 +0000 |
| commit | f3be981d180f8bf7aba9c16a19cf7aab8567e223 (patch) | |
| tree | 79839533edf22b26f2fe0ac83ef1e1234db3fab4 | |
| parent | fix def-and-reused op updaterate (diff) | |
| download | alive-f3be981d180f8bf7aba9c16a19cf7aab8567e223.tar.gz alive-f3be981d180f8bf7aba9c16a19cf7aab8567e223.zip | |
add edge and pilot/*
| -rw-r--r-- | lib/pilot.moon | 50 | ||||
| -rw-r--r-- | lib/util.moon | 14 |
2 files changed, 64 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 +} diff --git a/lib/util.moon b/lib/util.moon index 6da3698..af5d8f8 100644 --- a/lib/util.moon +++ b/lib/util.moon @@ -51,6 +51,19 @@ like (switch ...) except that the unused inputs are paused." active\update dt active\get! +class edge extends Op + setup: (@i) => + @value = false + @last = false + + update: (dt) => + @i\update dt + + now = @i\get! + + @value = not @last and now + @last = now + class keep extends Op @doc: "(keep value [default]) - keep the last non-nil value @@ -68,5 +81,6 @@ default defaults to zero." { 'switch': switch_ 'switch-': switch_pause + :edge :keep } |
