Today we found a bunch of information, and here is said information.
Blue = Gabby
Brown/Red/Maroon..? = Miles
(ノ ゜Д゜)ノ ︵ OI∩┴
^ This is in Python, it’s another implementation of OSC.
http://casparcg.com/wiki/CasparCG_OSC_Protocol
Server side software to relay OSC messages to a client.
http://archive.cnmat.berkeley.edu/OSC/src/sendOSC/
^ that’s for C, Client
oscP5 (for processing)
https://processing.org/reference/libraries/ download it here
http://www.sojamo.de/libraries/oscp5/ last updated in 2012, better than 2008
http://learning.codasign.com/index.php?title=Sending_and_Receiving_OSC_Data_Using_Processing basic example
Python OSC (… for Python, duh)
https://pypi.python.org/pypi/python-osc download it here or pip install it whatevs
https://github.com/attwad/python-osc last updated a few days ago
Examples include making a server and a client
SimpleOSC for python (requires pyOSC, which is linked up top)
http://www.ixi-audio.net/content/body_backyard_python.html supposedly simplifies the API or whatever for pyOSC
osc (for javascript)
https://www.npmjs.org/package/osc Woo
So to compare them…
oscP5 for processing:
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
// start oscP5, telling it to listen for incoming messages at port 5001 */
oscP5 = new OscP5(this,5001);
// set the remote location to be the localhost on port 5001
myRemoteLocation = new NetAddress(“127.0.0.1”,5001);
}
void draw()
{
}
void mousePressed() {
// create an osc message
OscMessage myMessage = new OscMessage(“/test”);
myMessage.add(123); // add an int to the osc message
myMessage.add(12.34); // add a float to the osc message
myMessage.add(“some text!”); // add a string to the osc message
// send the message
oscP5.send(myMessage, myRemoteLocation);
}
void oscEvent(OscMessage theOscMessage)
{
// get the first value as an integer
int firstValue = theOscMessage.get(0).intValue();
// get the second value as a float
float secondValue = theOscMessage.get(1).floatValue();
// get the third value as a string
String thirdValue = theOscMessage.get(2).stringValue();
// print out the message
print(“OSC Message Recieved: “);
print(theOscMessage.addrPattern() + ” “);
println(firstValue + ” ” + secondValue + ” ” + thirdValue);
}
Python OSC:
(server)
import argparse | |
import math | |
from pythonosc import dispatcher | |
from pythonosc import osc_server | |
def print_volume_handler(unused_addr, args, volume): | |
print(“[{0}] ~ {1}”.format(args[0], volume)) | |
def print_compute_handler(unused_addr, args, volume): | |
try: | |
print(“[{0}] ~ {1}”.format(args[0], args[1](volume))) | |
except ValueError: pass | |
if __name__ == “__main__”: | |
parser = argparse.ArgumentParser() | |
parser.add_argument(“–ip”, | |
default=“0.0.0.0”, help=“The ip to listen on”) | |
parser.add_argument(“–port”, | |
type=int, default=5005, help=“The port to listen on”) | |
args = parser.parse_args() | |
dispatcher = dispatcher.Dispatcher() | |
dispatcher.map(“/debug”, print) | |
dispatcher.map(“/volume”, print_volume_handler, “Volume”) | |
dispatcher.map(“/logvolume”, print_compute_handler, “Log volume”, math.log) | |
server = osc_server.ThreadingOSCUDPServer( | |
(args.ip, args.port), dispatcher) | |
print(“Serving on {}”.format(server.server_address)) | |
server.serve_forever() |
(client)
“””Small example OSC client | |
This program sends 10 random values between 0.0 and 1.0 to the /filter address, | |
waiting for 1 seconds between each value. | |
“”” | |
import argparse | |
import random | |
import time | |
from pythonosc import osc_message_builder | |
from pythonosc import udp_client | |
if __name__ == “__main__”: | |
parser = argparse.ArgumentParser() | |
parser.add_argument(“–ip”, default=“127.0.0.1”, | |
help=“The ip of the OSC server”) | |
parser.add_argument(“–port”, type=int, default=8000, | |
help=“The port the OSC server is listening on”) | |
args = parser.parse_args() | |
client = udp_client.UDPClient(args.ip, args.port) | |
for x in range(10): | |
msg = osc_message_builder.OscMessageBuilder(address = “/filter”) | |
msg.add_arg(random.random()) | |
msg = msg.build() | |
client.send(msg) | |
time.sleep(1) |
pyOSC
(send)
- #!/usr/bin/env python3
- from OSC import OSCClient, OSCMessage
- client = OSCClient()
- client.connect( (“localhost”, 7110) )
- client.send( OSCMessage(“/user/1”, [1.0, 2.0, 3.0 ] ) )
- client.send( OSCMessage(“/user/2”, [2.0, 3.0, 4.0 ] ) )
- client.send( OSCMessage(“/user/3”, [2.0, 3.0, 3.1 ] ) )
- client.send( OSCMessage(“/user/4”, [3.2, 3.4, 6.0 ] ) )
- client.send( OSCMessage(“/quit”) )
(receive)
- #!/usr/bin/env python3
- from OSC import OSCServer
- import sys
- from time import sleep
- server = OSCServer( (“localhost”, 7110) )
- server.timeout = 0
- run = True
- # this method of reporting timeouts only works by convention
- # that before calling handle_request() field .timed_out is
- # set to False
- def handle_timeout(self):
- self.timed_out = True
- # funny python’s way to add a method to an instance of a class
- import types
- server.handle_timeout = types.MethodType(handle_timeout, server)
- def user_callback(path, tags, args, source):
- # which user will be determined by path:
- # we just throw away all slashes and join together what’s left
- user = ”.join(path.split(“/”))
- # tags will contain ‘fff’
- # args is a OSCMessage with data
- # source is where the message came from (in case you need to reply)
- print (“Now do something with”, user,args[2],args[0],1-args[1])
- def quit_callback(path, tags, args, source):
- # don’t do this at home (or it’ll quit blender)
- global run
- run = False
- server.addMsgHandler( “/user/1”, user_callback )
- server.addMsgHandler( “/user/2”, user_callback )
- server.addMsgHandler( “/user/3”, user_callback )
- server.addMsgHandler( “/user/4”, user_callback )
- server.addMsgHandler( “/quit”, quit_callback )
- # user script that’s called by the game engine every frame
- def each_frame():
- # clear timed_out flag
- server.timed_out = False
- # handle all pending requests then return
- while not server.timed_out:
- server.handle_request()
- # simulate a “game engine”
- while run:
- # do the game stuff:
- sleep(1)
- # call user script
- each_frame()
- server.close()
SimpleOSC:
from simpleOSC import initOSCClient, initOSCServer, setOSCHandler, sendOSCMsg, closeOSC, \
createOSCBundle, sendOSCBundle, startOSCServer
def myTest():
“”” a simple function that creates the necesary sockets and enters an enless
loop sending and receiving OSC
“””
import time # in this example we will have a small delay in the while loop
initOSCClient() # takes args : ip, port
initOSCServer() # takes args : ip, port, mode –> 0 for basic server, 1 for threading server, 2 for forking server
# bind addresses to functions
setOSCHandler(‘/check’, checkcheckcheck)
startOSCServer() # and now set it into action
print ‘ready to receive and send osc messages …’
try:
while 1:
sendOSCMsg(“/test”, [444]) # !! it sends by default to localhost ip “127.0.0.1” and port 9000
# create and send a bundle
bundle = createOSCBundle(“/test/bndlprt1”)
bundle.append(666) # 1st message appent to bundle
bundle.append(“the number of the beast”) # 2nd message appent to bundle
sendOSCBundle(bundle) # !! it sends by default to localhost ip “127.0.0.1” and port 9000
time.sleep(0.5) # you don’t need this, but otherwise we’re sending as fast as possible.
except KeyboardInterrupt:
print “closing all OSC connections… and exit”
closeOSC() # finally close the connection before exiting or program.
“”” Below a function dealing with OSC messages RECEIVED into Python.
Here you can set all the responders you need to deal with the incoming
OSC messages.
“””
def checkcheckcheck(addr, tags, data, source):
print “CHECK CHECK CHECK…”
print “received new osc msg from %s” % getUrlStr(source)
print “with addr : %s” % addr
print “typetags :%s” % tags
print “the actual data is : %s” % data
if __name__ == ‘__main__’: myTest()
lalala