Sensor Tile Project: 29 Oct 2014 Miles, Brian, Gabby

Today we found a bunch of information, and here is said information.

Blue = Gabby

Brown/Red/Maroon..? = Miles

 

(ノ ゜Д゜)ノ ︵ OI∩┴

 

https://trac.v2.nl/wiki/pyOSC

^ 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)

  1. #!/usr/bin/env python3
  2. from OSC import OSCClient, OSCMessage
  3. client = OSCClient()
  4. client.connect( (“localhost”, 7110) )
  5. client.send( OSCMessage(“/user/1”, [1.0, 2.0, 3.0 ] ) )
  6. client.send( OSCMessage(“/user/2”, [2.0, 3.0, 4.0 ] ) )
  7. client.send( OSCMessage(“/user/3”, [2.0, 3.0, 3.1 ] ) )
  8. client.send( OSCMessage(“/user/4”, [3.2, 3.4, 6.0 ] ) )
  9. client.send( OSCMessage(“/quit”) )

 

(receive)

  1. #!/usr/bin/env python3
  2. from OSC import OSCServer
  3. import sys
  4. from time import sleep
  5. server = OSCServer( (“localhost”, 7110) )
  6. server.timeout = 0
  7. run = True
  8. # this method of reporting timeouts only works by convention
  9. # that before calling handle_request() field .timed_out is
  10. # set to False
  11. def handle_timeout(self):
  12.   self.timed_out = True
  13. # funny python’s way to add a method to an instance of a class
  14. import types
  15. server.handle_timeout = types.MethodType(handle_timeout, server)
  16. def user_callback(path, tags, args, source):
  17.   # which user will be determined by path:
  18.   # we just throw away all slashes and join together what’s left
  19.   user = ”.join(path.split(“/”))
  20.   # tags will contain ‘fff’
  21.   # args is a OSCMessage with data
  22.   # source is where the message came from (in case you need to reply)
  23.   print (“Now do something with”, user,args[2],args[0],1-args[1])
  24. def quit_callback(path, tags, args, source):
  25.   # don’t do this at home (or it’ll quit blender)
  26.   global run
  27.   run = False
  28. server.addMsgHandler( “/user/1”, user_callback )
  29. server.addMsgHandler( “/user/2”, user_callback )
  30. server.addMsgHandler( “/user/3”, user_callback )
  31. server.addMsgHandler( “/user/4”, user_callback )
  32. server.addMsgHandler( “/quit”, quit_callback )
  33. # user script that’s called by the game engine every frame
  34. def each_frame():
  35.   # clear timed_out flag
  36.   server.timed_out = False
  37.   # handle all pending requests then return
  38.   while not server.timed_out:
  39.       server.handle_request()
  40. # simulate a “game engine”
  41. while run:
  42.   # do the game stuff:
  43.   sleep(1)
  44.   # call user script
  45.   each_frame()
  46. 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

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *