Old 02-26-2016, 04:26 PM   #1
beyond
Human being with feelings
 
Join Date: Jun 2007
Location: Palm Beach FL
Posts: 265
Default Here is a little help for Python OSC programmers:

Simple Python OSC:

Code:
import socket, struct

def OSCBinary(*l):
  Binary = b""
  for e in l:
    t = type(e)
    if t is bytes:
      b = e
      b += b"\0" * (4 - len(b) % 4)
    elif t is str:
      b = e.encode("utf-8")
      b += b"\0" * (4 - len(b) % 4)
    elif t is int:
      b = struct.pack(">i", e)
    elif t is float:
      b = struct.pack(">f", e)
    Binary += b
  return Binary

def OSCSendAction(Address, Action):
  if type(Action) is int:
    Binary = OSCBinary("/action", ",i", Action)
  else:
    Binary = OSCBinary("/action/str", ",s", Action)
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.sendto(Binary, Address)
  s.close()


OSCSendAction(("localhost", 8000), 40007) # Reaper About
OSCSendAction(("localhost", 8000), "_RS9f248dbb3abdc0abac1b5182342297de37ef72d2") # String CommandID
beyond is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.