aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sc.moon
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sc.moon')
-rw-r--r--lib/sc.moon42
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/sc.moon b/lib/sc.moon
index 7ffd16c..b30e30d 100644
--- a/lib/sc.moon
+++ b/lib/sc.moon
@@ -1,36 +1,30 @@
-import Op, Value, Scope from require 'core'
+import Op, EventInput, ColdInput, match from require 'core'
import pack from require 'osc'
import dns, udp from require 'socket'
class play extends Op
- @doc: "(sc/play remote synth trigger [name-str val]...) - play a SC SynthDef"
+ @doc: "(sc/play socket synth trigger [name-str val]...) - play a SC SynthDef"
- new: =>
- super!
- @@udp or= udp!
+ setup: (inputs) =>
+ { socket, synth, trig, ctrls } = match 'udp/socket str bang *any?', inputs
- setup: (params) =>
- super params
- @assert_first_types 'udp/remote', 'str', 'bool'
+ assert #ctrls % 2 == 0, "parameters need to be specified as pairs"
+ for key in *ctrls[1,,2]
+ assert key\type! == 'str', "ony strings are supported as control names"
+ for val in *ctrls[2,,2]
+ assert val\type! == 'num', "only numbers are supported as control values"
- assert #@inputs % 2 == 1, "parameters need to be specified as pairs"
- for key in *@inputs[4,,2]
- assert key.type == 'str', "ony strings are supported as control names"
- for val in *@inputs[5,,2]
- assert val.type == 'num', "only numbers are supported as control values"
+ super
+ socket: ColdInput socket
+ synth: ColdInput synth
+ trig: EventInput trig
+ ctrls: [ColdInput v for v in *ctrls]
tick: =>
- { remote, synth, trig, p } = @inputs
-
- if trig\dirty! and trig!
- controls = {}
- for i = 4, #@inputs, 2
- table.insert controls, @inputs[i]!
- table.insert controls, @inputs[i+1]!
- msg = pack '/s_new', synth!, -1, 0, 1, unpack controls
-
- { :ip, :port } = remote!
- @@udp\sendto msg, ip, port
+ if @inputs.trig\dirty! and @inputs.trig!
+ { :socket, :synth, :ctrls } = @unwrap_all!
+ msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls
+ socket\send msg
{
:play