From e83df1af2cdad8c2d61ba790a96875cd260eceaf Mon Sep 17 00:00:00 2001 From: s-ol Date: Sat, 21 Mar 2020 20:06:18 +0100 Subject: new meta/doc system --- lib/sc.moon | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) (limited to 'lib/sc.moon') diff --git a/lib/sc.moon b/lib/sc.moon index 7562620..dd9e826 100644 --- a/lib/sc.moon +++ b/lib/sc.moon @@ -1,30 +1,37 @@ -import Op, Input, Error, match from require 'core.base' +import Op, Value, Input, Error, match from require 'core.base' import pack from require 'osc' import dns, udp from require 'socket' -class play extends Op - @doc: "(sc/play socket synth trigger [name-str val]...) - play a SC SynthDef" +play = Value.meta + meta: + name: 'play' + summary: 'Play a SuperCollider SynthDef.' + examples: { '(play socket synth trig [param val…])' } + description: " +Plays the synth `synth` on the `udp/socket` `socket` whenever `trig` is live. +Any number of parameter-value pairs can be specified and are captured and sent +together with the note when triggered." + value: class extends Op + setup: (inputs) => + { socket, synth, trig, ctrls } = match 'udp/socket str bang *any?', inputs - setup: (inputs) => - { socket, synth, trig, ctrls } = match 'udp/socket str bang *any?', inputs + assert #ctrls % 2 == 0, Error 'argument', "parameters need to be specified as pairs" + for key in *ctrls[1,,2] + assert key\type! == 'str', Error 'argument', "ony strings are supported as control names" + for val in *ctrls[2,,2] + assert val\type! == 'num', Error 'argument', "only numbers are supported as control values" - assert #ctrls % 2 == 0, Error 'argument', "parameters need to be specified as pairs" - for key in *ctrls[1,,2] - assert key\type! == 'str', Error 'argument', "ony strings are supported as control names" - for val in *ctrls[2,,2] - assert val\type! == 'num', Error 'argument', "only numbers are supported as control values" + super + trig: Input.event trig + socket: Input.cold socket + synth: Input.cold synth + ctrls: [Input.cold v for v in *ctrls] - super - trig: Input.event trig - socket: Input.cold socket - synth: Input.cold synth - ctrls: [Input.cold v for v in *ctrls] - - tick: => - 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 + tick: => + 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 -- cgit v1.2.3