====== Open Sound Control ======
Open Sound Control (OSC) is a messaging protocol that is used for sending control signals between many popular digital music tools. We can write a small script in Folk to easily transform Folk signals into OSC messages.
===== The OSC Script =====
This script adds two utility functions for turning Tcl values into serialized OSC values, and also starts watching for a ''Wish the NetAddr is /n/'' assertion to start running an OSC producer.
# Null terminates a Tcl value and pads it's length to a multiple of four
# (needed for OSC spec)
# \x01 -> \x01\x00\x00\x00
# \x01\x02\x03 -> \x01\x02\x03\x00
# \x01\x02\x03\x04 -> \x01\x02\x03\x04\x00\x00\x00\x00
fn oscPad {s} {
set n [string bytelength $s]
set count [expr {4 - $n % 4}]
set nulls [string repeat \x00 $count]
return $s$nulls
}
fn oscPacket {target args} {
set tags ","
set payload ""
foreach a $args {
if {[string is integer $a]} {
append tags i
append payload [binary format I $a]
} elseif {[string is double $a]} {
append tags f
append payload [binary format R $a]
} else {
append tags s
append payload [oscPad $a]
}
}
return "[oscPad $target][oscPad $tags]$payload"
}
When the NetAddr is /n/ {
Subscribe: OSC at /target/ with args /...arguments/ {
set s [socket dgram]
$s sendto [oscPacket $target {*}$arguments] $n
$s close
}
}
===== Start the Subscriber: =====
Place a program that asserts ''Claim the NetAddr is /addr/''. NetAddr is a string with form '':''
For my current SuperCollider-based setup the assertion looks like this:
Claim the NetAddr is 192.168.4.71:57120
This script currently only //sends// values to a single OSC receiver. Features like multiple targets and OSC Bundles are still TODO.
===== Send OSC Packets =====
When the OSC Script and NetAddr claims are being run, we can now easily send messages using Folk via the syntax:
Notify: OSC at /tone with args 440
This sends an OSC message to NetAddr with path ''/tone'' and value ''220'' the OSC helper utils will parse 220 into an int and send it as a proper OSC integer.
For any questions please tag Paul on the discord!