tur/msg

stdlib/msg.tur
defn

osc-message

(osc-message [address])

Allocate a new OSC message for the given address.

addressOSC address pattern string (e.g., "/s_new").
Opaque pointer to the allocated message. Must be freed with osc-free!
  if not consumed by osc-send!.

  (let [m (osc-message "/s_new")] (osc-free! m))
defn

osc-free!

(osc-free! [msg])

Free an OSC message, ignoring nil/null pointers.

msgOpaque message pointer returned by osc-message.
(osc-free! msg)
defn

osc-add!

(osc-add! [msg arg])

Append a typed argument to an OSC message.

msgOSC message pointer.
argValue to append (int32, float, cstr, or slice<uint8>).
(osc-add! msg 440.0)
defn

osc-send!

(osc-send! [world_id msg])

Send an OSC message to a world and free it afterward.

world_idTarget world handle.
msgOSC message pointer (will be freed after sending).
0 on success, -1 on error.

  (osc-send! w msg)
defn

osc-send

(osc-send [world_id address & args])

Build and send an OSC message in a single call.

world_idTarget world handle.
addressOSC address pattern string.
argsZero or more arguments to append to the message.
0 on success, -1 on error.

  (osc-send w "/s_new" "mySynth" 1001 2 1)
defmacro

with-osc-message

(with-osc-message [msg-var address])

Build and send an OSC message with automatic cleanup.

msg-varSymbol to bind the new message pointer to.
addressOSC address pattern string.
world_idTarget world handle.
bodyForms that add arguments or otherwise manipulate the message.
(with-osc-message [m "/n_set"] w
    (osc-add! m 1001)
    (osc-add! m 0)
    (osc-add! m 440.0))
defn

osc-ping

(osc-ping [world_id])

Send a /ping message to check server responsiveness.

world_idTarget world handle.

0 on success, -1 on error.

defn

osc-status

(osc-status [world_id])

Send a /status message to query server state.

world_idTarget world handle.

0 on success, -1 on error.

defn

osc-sync

(osc-sync [world_id])

Send a /sync message to synchronize with the server.

world_idTarget world handle.

0 on success, -1 on error.

defn

osc-s_new

(osc-s_new [world_id synthdef_name node_id add_action target & args])

Send a /s_new message to instantiate a SynthDef.

world_idTarget world handle.
synthdef_nameName of the SynthDef to instantiate.
node_idNode ID to assign (0 for auto-allocate).
add_actionPlacement action keyword or integer.
targetTarget node ID (typically ROOT_GROUP_ID = 1).
argsAdditional control parameter values.
0 on success, -1 on error.

  (osc-s_new w "mySynth" 1001 2 1)
defn

osc-n_set

(osc-n_set [world_id node_id & param-value-pairs])

Send a /n_set message to update control parameters on a node.

world_idTarget world handle.
node_idTarget synth node ID.
param-value-pairsAlternating parameter name and value pairs.
0 on success, -1 on error.

  (osc-n_set w 1001 "freq" 880.0 "amp" 0.5)
defn

osc-n_free

(osc-n_free [world_id node_id])

Send a /n_free message to stop and remove a node.

world_idTarget world handle.
node_idNode ID to free.

0 on success, -1 on error.

defn

osc-n_run

(osc-n_run [world_id node_id run?])

Send a /n_run message to start or pause a node.

world_idTarget world handle.
node_idTarget node ID.
run?true to run, false to pause.

0 on success, -1 on error.

defn

osc-n_free_all

(osc-n_free_all [world_id])

Send a /n_free_all message to clear every node.

world_idTarget world handle.

0 on success, -1 on error.

defn

osc-g_new

(osc-g_new [world_id node_id add_action target])

Send a /g_new message to create a new group node.

world_idTarget world handle.
node_idNode ID to assign (0 for auto-allocate).
add_actionPlacement action.
targetTarget node ID.
0 on success, -1 on error.

  (osc-g_new w 100 2 1)
defn

osc-g_free

(osc-g_free [world_id node_id])

Send a /g_free message to free a group node.

world_idTarget world handle.
node_idGroup node ID to free.

0 on success, -1 on error.

defn

osc-d_load

(osc-d_load [world_id synthdef_name])

Send a /d_load message to load a SynthDef by name.

world_idTarget world handle.
synthdef_nameSynthDef name or file path.

0 on success, -1 on error.

defn

osc-d_free

(osc-d_free [world_id synthdef_name])

Send a /d_free message to unload a SynthDef.

world_idTarget world handle.
synthdef_nameName of the SynthDef to remove.

0 on success, -1 on error.

defn

osc-d_recv

(osc-d_recv [world_id on?])

Send a /d_recv message to toggle SynthDef-receive notifications.

world_idTarget world handle.
on?true to enable, false to disable.

0 on success, -1 on error.

defn

osc-notify

(osc-notify [world_id on?])

Send a /notify message to toggle server notifications.

world_idTarget world handle.
on?true to enable, false to disable.

0 on success, -1 on error.

defn

osc-clear-sched

(osc-clear-sched [world_id])

Send a /clearSched message to flush the scheduler queue.

world_idTarget world handle.

0 on success, -1 on error.

defn

midi->hz

(midi->hz [note])

Convert a MIDI note number to frequency in Hz.

noteMIDI note number (0-127; 69 = A4 = 440 Hz).
Frequency in Hz as a float.

  (midi->hz 69)  ; => 440.0
defn

vel->amp

(vel->amp [vel])

Convert a MIDI velocity to a linear amplitude value.

velMIDI velocity (0-127).
Amplitude in the range [0.0, 1.0].

  (vel->amp 127)  ; => 1.0
defn

db->amp

(db->amp [db])

Convert a decibel level to linear amplitude.

dbLevel in decibels (0 dB = amplitude 1.0).
Linear amplitude as a float.

  (db->amp 0.0)  ; => 1.0
defn

amp->db

(amp->db [amp])

Convert a linear amplitude to decibels.

ampLinear amplitude (must be > 0; returns -90.0 for zero).
Level in decibels.

  (amp->db 1.0)  ; => 0.0