osc receive server
This is a simple UDP server (based on lens.Socket) to receive OSC messages.
The server must be created and run inside lens.Scheduler (see example below).
NOTE This class needs the lens library.
Usage example
local lens = require 'lens' -- Using live coding lens.run(function() lens.FileWatch() end) local osc = require 'osc' server = server or osc.Server(11000) function server:receive(url, ...) print(url, ...) end
.new (port, map)
Create a new server. If port
is '0', a random available port will be chosen. If an optional map
table is provided, it is used to trigger functions from message url (see map).
:map (map)
Trigger functions from message urls. Calling this function overwrites the receive callback.
Example:
server:map { ['/1/fader1'] = function(url, value) print('HEY, fader 1 changed', value) end, ['/1/pad1'] = function(url, x, y) box:move(x, y) end, unknown = function(url, ...) print('Missing entry in map table', url, ...) end, }
The 'unknown' entry is used to map all urls not present in the table.
Callback
:receive (url, ...)
This callback is called when osc messages arrive. If map is used, this callback is changed.