git.s-ol.nu alive / dbdfb13
lib: switch to losc s-ol 4 months ago
8 changed file(s) with 131 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
1515 - [LPeg][lpeg]*: `luarocks install lpeg`
1616 - [socket][socket]: `luarocks install luasocket`
1717 - [system][system]: `luarocks install luasystem`
18 - [oscpack][oscpack]: `luarocks install oscpack` (optional)
18 - [losc][losc]: `luarocks install losc` (optional)
1919 - [lua-rtmidi][rtmidi]: `luarocks install
2020 https://raw.githubusercontent.com/s-ol/lua-rtmidi/master/lua-rtmidi-dev-1.rockspec` (optional)
2121 - [busted][busted]: `luarocks install busted` (optional, for tests)
5353 [moonscript]: https://moonscript.org/
5454 [lfs]: https://keplerproject.github.io/luafilesystem/
5555 [lpeg]: http://www.inf.puc-rio.br/~roberto/lpeg/
56 [oscpack]: https://github.com/s-ol/lua-oscpack
56 [losc]: https://github.com/davidgranstrom/losc
5757 [system]: https://github.com/o-lim/luasystem
5858 [socket]: http://w3.impa.br/~diego/software/luasocket/
5959 [rtmidi]: https://github.com/s-ol/lua-rtmidi/
0 import new_message from require 'losc'
1 import opairs from require 'alv.util'
2 import T, Array, Struct from require 'alv.base'
3
4 add_item = (message, type, val) ->
5 switch type.__class
6 when Array
7 -- message\add '['
8 for i=1,type.size
9 add_item message, type.type, val[i]
10 -- message\add ']'
11 when Struct
12 -- message\add '['
13 for key, subtype in opairs type.types
14 -- message\add '['
15 message\add 's', key
16 add_item message, subtype, val[key]
17 -- message\add ']'
18 -- message\add ']'
19 else
20 ts = switch type
21 when T.num then 'f'
22 when T.str, T.sym then 's'
23 when T.bool, T.bang
24 if val then 'T' else 'F'
25 else
26 error "unknown primitive type"
27 message\add ts, val
28
29 {
30 :new_message
31 :add_item
32 }
0 import Op, Constant, SigStream, Input, T, sig, evt from require 'alv.base'
1 import pack from require 'oscpack'
0 import Op, PureOp, Constant, SigStream, Input, T, sig, evt from require 'alv.base'
1 import new_message, add_item from require 'alv-lib._osc'
22 import dns, udp from require 'socket'
33
44 unpack or= table.unpack
2828 send = Constant.meta
2929 meta:
3030 name: 'send'
31 summary: "Send events via OSC."
32 examples: { '(osc/send [socket] path evt)' }
33 description: "Sends an OSC message with `evt` as an argument.
31 summary: "Send an OSC message."
32 examples: { '(osc/send [socket] path val…)' }
33 description: "Sends an OSC message to `path` with `val…` as arguments.
3434
3535 - `socket` should be a `udp/socket` value. This argument can be omitted and the
3636 value be passed as a dynamic definition in `*sock*` instead.
3737 - `path` is the OSC path to send the message to. It should be a string-value.
38 - `evt` is the argument to send. It should be an event stream."
39 value: class extends Op
40 pattern = -sig['udp/socket'] + sig.str + evt!
38 - the arguments can be any type:
39 - `num` will be sent as `f`
40 - `str` will be sent as `s`
41 - `bool` will be sent as `T`/`F`
42 - `bang` will be sent as `T`
43 - arrays will be unwrapped
44 - structs will be sent as a series of key/value tuples
45
46 This is a pure op, so between the values at most one !-stream input is allowed."
47
48 value: class extends PureOp
49 pattern: (evt! / sig!)^0
50
51 full_pattern = -sig['udp/socket'] + sig.str + (evt! / sig!)^0
4152 setup: (inputs, scope) =>
42 { socket, path, value } = pattern\match inputs
43 super
53 { socket, path, values } = full_pattern\match inputs
54 super values, scope, {
4455 socket: Input.cold socket or scope\get '*sock*'
4556 path: Input.cold path
46 value: Input.hot value
57 }
4758
4859 tick: =>
49 { :socket, :path, :value } = @unwrap_all!
50 if value
51 msg = pack path, if 'table' == type value then unpack value else value
52 socket\send msg
53
54 sync = Constant.meta
55 meta:
56 name: 'sync'
57 summary: "Synchronize a value via OSC."
58 examples: { '(osc/sync [socket] path val)' }
59 description: "sends a message whenever any parameter is dirty."
60 description: "Sends an OSC message with `val` as an argument whenever any
61 of the arguments change.
62
63 - `socket` should be a `udp/socket` value. This argument can be omitted and the
64 value be passed as a dynamic definition in `*sock*` instead.
65 - `path` is the OSC path to send the message to. It should be a string-value.
66 - `val` is the value to Synchronize. It should be a value stream."
67
68 value: class extends Op
69 pattern = -sig['udp/socket'] + sig.str + sig!
70 setup: (inputs, scope) =>
71 { socket, path, value } = pattern\match inputs
72 super
73 socket: Input.hot socket or scope\get '*sock*'
74 path: Input.hot path
75 value: Input.hot value
76
77 tick: =>
78 { :socket, :path, :value } = @unwrap_all!
79 msg = pack path, if 'table' == type value then unpack value else value
80 socket\send msg
60 args = @unwrap_all!
61 { :socket, :path } = args
62 msg = new_message path
63 for i=1,#args
64 add_item msg, @inputs[i]\type!, args[i]
65 socket\send msg.pack msg.content
8166
8267 Constant.meta
8368 meta:
0 import Op, Constant, Input, sig, evt from require 'alv.base'
1 import pack from require 'oscpack'
2 import dns, udp from require 'socket'
0 import Op, Constant, Input, Array, Struct, T, sig, evt from require 'alv.base'
1 import new_message, add_item from require 'alv-lib._osc'
32
43 unpack or= table.unpack
54
6 play = Constant.meta
5 validate_ctrls = (type) ->
6 switch type.__class
7 when Array
8 assert (type.type == T.num) or (type.type == T.str),
9 "synthdef control values have to be either num or str"
10 when Struct
11 for k, t in pairs type.types
12 assert (t == T.num) or (t == T.str),
13 "synthdef control value '#{k}' has to be either num or str"
14
15 play_ = Constant.meta
716 meta:
8 name: 'play'
17 name: 'play!'
918 summary: 'Play a SuperCollider SynthDef on bangs.'
10 examples: { '(play [socket] synth trig [param val…])' }
19 examples: { '(play [socket] synth trig ctrls)' }
1120 description: "
1221 Plays the synth `synth` on the `udp/socket` `socket` whenever `trig` is live.
1322
1423 - `socket` should be a `udp/socket` value. This argument can be omitted and the
1524 value be passed as a dynamic definition in `*sock*` instead.
1625 - `synth` is the SC synthdef name. It should be a string-value.
17 - `trig` is the trigger signal. It should be a stream of bang-events.
18 - `param` is the name of a synthdef parameter. It should be a string-value."
26 - `trig` is the trigger signal. It should be a !-stream of bang-events.
27 - `ctrls` is a struct of synthdef controls. It should be a ~-stream."
1928 value: class extends Op
20 pattern = -sig['udp/socket'] + sig.str + evt.bang + (sig.str + sig.num)\rep 0
29 pattern = -sig['udp/socket'] + sig.str + evt.bang + sig!
2130 setup: (inputs, scope) =>
2231 { socket, synth, trig, ctrls } = pattern\match inputs
2332
24 flat_ctrls = {}
25 for { key, value } in *ctrls
26 table.insert flat_ctrls, key
27 table.insert flat_ctrls, value
33 validate_ctrls ctrls\type!
2834
2935 super
3036 trig: Input.hot trig
3137 socket: Input.cold socket or scope\get '*sock*'
3238 synth: Input.cold synth
33 ctrls: [Input.cold v for v in *flat_ctrls]
39 ctrls: Input.cold ctrls
3440
3541 tick: =>
36 if @inputs.trig\dirty! and @inputs.trig!
37 { :socket, :synth, :ctrls } = @unwrap_all!
38 msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls
39 socket\send msg
42 { :socket, :synth, :ctrls } = @unwrap_all!
43 msg = new_message '/s_new'
44 msg\add 's', synth
45 msg\add 'i', -1
46 msg\add 'i', 0
47 msg\add 'i', 1
48 add_item msg, @inputs.ctrls\type!, ctrls
49 socket\send msg.pack msg.content
4050
41 play_ = Constant.meta
51
52 play = Constant.meta
4253 meta:
43 name: 'play!'
54 name: 'play'
4455 summary: 'Play a SuperCollider SynthDef on events.'
45 examples: { '(play [socket] synth [param evt/val…])' }
56 examples: { '(play [socket] synth ctrls)' }
4657 description: "
47 Plays the synth `synth` on the `udp/socket` `socket` whenever any `evt` is live.
58 Plays the synth `synth` on the `udp/socket` `socket` whenever an event arrives.
4859
4960 - `socket` should be a `udp/socket` value. This argument can be omitted and the
5061 value be passed as a dynamic definition in `*sock*` instead.
5162 - `synth` is the SC synthdef name. It should be a string-value.
52 - `param` is the name of a synthdef parameter. It should be a string-value.
53 - `val` and `evt` are the parameter values to send. They should be number
54 streams. Incoming events will cause a note to be played, while value changes
55 will not."
63 - `ctrls` is a struct of synthdef controls. It should be a !-stream."
5664 value: class extends Op
57 pattern = -sig['udp/socket'] + sig.str + (sig.str + (sig.num / evt.num))\rep 0
65 pattern = -sig['udp/socket'] + sig.str + evt!
5866 setup: (inputs, scope) =>
59 { socket, synth, trig, ctrls } = pattern\match inputs
67 { socket, synth, ctrls } = pattern\match inputs
6068
61 flat = {}
62 for { key, value } in *ctrls
63 table.insert flat, Input.cold key
64 table.insert flat, if value\metatype! == 'event'
65 Input.hot value
66 else
67 Input.cold value
69 validate_ctrls ctrls\type!
6870
6971 super
7072 socket: Input.cold socket or scope\get '*sock*'
7173 synth: Input.cold synth
72 ctrls: flat
74 ctrls: Input.hot ctrls
7375
7476 tick: =>
7577 { :socket, :synth, :ctrls } = @unwrap_all!
76 msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls
77 socket\send msg
78 msg = new_message '/s_new'
79 msg\add 's', synth
80 msg\add 'i', -1
81 msg\add 'i', 0
82 msg\add 'i', 1
83 add_item msg, @inputs.ctrls\type!, ctrls
84 socket\send msg.pack msg.content
7885
7986 Constant.meta
8087 meta:
1818
1919 cd dist\%BUNDLE%\lua
2020 call luarocks install busted
21 call luarocks install %DEPS%\osc-1.0.1-1.rockspec
2221 call luarocks install luarocks-fetch-gitrec
2322 call luarocks install luarocks-build-cpp
2423 call luarocks install %DEPS%\fltk4lua-0.1-1.rockspec FLTK_LIBDIR=%DEPS%\fltk-1.3.5\lib FLTK_INCDIR=%DEPS%\fltk-1.3.5
9090 "luafilesystem",
9191 "luasystem",
9292 "luasocket",
93 "losc",
9394 }
9495
9596 build = {
33
44 require = do
55 old_require = require
6 blacklist = {k, true for k in *{'oscpack', 'socket', 'system', 'luartmidi'}}
6 blacklist = {k, true for k in *{'losc', 'socket', 'system', 'luartmidi'}}
77 (mod, ...) ->
88 return {} if blacklist[mod]
99 old_require mod, ...
3434 url = "mirror://luarocks//${pname}-${version}.src.rock";
3535 sha256 = "Dp3bKIG4swrD4+1NNtRTgyj68Di2cSUlh1r7Z2Rkzn0=";
3636 };
37 propagatedBuildInputs = [ pkgs.lua5_3 pkgs.git ];
37 propagatedBuildInputs = with pkgs; [ lua5_3 git ];
3838
3939 meta = with pkgs.stdenv.lib; {
4040 homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
5151 url = "mirror://luarocks//${pname}-${version}.src.rock";
5252 sha256 = "fD31FruqVriMecFcvSV4W7JRia38+bg7j3T5k5pFZec=";
5353 };
54 buildInputs = with pkgs; [ pkgs.fltk libjpeg ];
54 buildInputs = with pkgs; [ fltk libjpeg ];
5555 propagatedBuildInputs = [ pkgs.lua5_3 luarocks-build-cpp luarocks-fetch-gitrec ];
5656
5757 meta = with pkgs.stdenv.lib; {
5858 homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
5959 description = "Lua binding to FLTK, the Fast Light ToolKit";
60 license.fullName = "MIT";
61 };
62 };
63
64 losc = pkgs.lua53Packages.buildLuarocksPackage rec {
65 pname = "losc";
66 version = "1.0.0-1";
67
68 src = pkgs.fetchurl {
69 url = "mirror://luarocks//${pname}-${version}.src.rock";
70 sha256 = "MArhj51V1awF5k2zToFYEXpS2c6o8bnNDn4wLhooHos=";
71 };
72 buildInputs = with pkgs; [ stdenv.cc.cc.lib ];
73 propagatedBuildInputs = [ pkgs.lua5_3 ];
74
75 meta = with pkgs.stdenv.lib; {
76 homepage = "https://github.com/davidgranstrom/losc";
77 description = "Open Sound Control (OSC) for lua/luajit with no external dependencies.";
6078 license.fullName = "MIT";
6179 };
6280 };
116134 buildInputs = with pkgs; [
117135 (lua5_3.withPackages (p: with p; [
118136 moonscript lpeg
119 luafilesystem luasocket luasystem fltk4lua bit32
137 luafilesystem luasocket luasystem fltk4lua losc bit32
120138 ldoc busted discount
121139 ]))
122140 ];