attwad / python-osc Goto Github PK
View Code? Open in Web Editor NEWOpen Sound Control server and client in pure python
License: The Unlicense
Open Sound Control server and client in pure python
License: The Unlicense
Hello,
I'm trying to work out a way to run the UDP Server and a TKinter window in the same application. In the reaktor example, I noticed it was possible to run another winder using a multiprocessing queue
The TKinter mainloop() and server_forvever() run in an infinite loop, and Tkinter command must be run from the main thread. Has anyone managed to bypass either of these and have them running simultaneously?
Thanks
Hi,
Thanks so much for your cool OSC implementation!
I am sorry to bother you but I am trying to communicate with an arduino-like device sending OSC messages over SLIP Serial protocol.
My goal is to receive and interpret the OSC messages via serial in python3. In other words, the device would build an OSC message, then send it SLIP encoded on the serial line to my linux box. In python3, I would read a SLIPencoded message and convert it back to the original OSC message and then be able to extract the data fields from it.
I was not able to see a way of using your python-osc to interpret the messages coming in over python slipSerial.
Would you be able to help me code something like the following?
import SerialComm
from pythonosc import dispatcher
from pythonosc import osc_server
s = SerialComm.connectToSerialPort('/dev/ttyACM0')
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/test", print)
server = osc_server.SlipSerialServer(s, dispatcher); ## THIS SERVER is what is needed ##
server.serve_forever()
Thanks so much,
Bob
Hi there,
I downloaded your code two days ago and tried it on Python 3.5.2, Anaconda 4.2.0 (64-bit). I got the following error:
Traceback (most recent call last):
File "simple_client.py", line 21, in
client = udp_client.SimpleUDPClient(args.ip, args.port)
AttributeError: module 'pythonosc.udp_client' has no attribute 'SimpleUDPClient'
I changed the line:
client = udp_client.SimpleUDPClient(args.ip, args.port)
for:
client = udp_client.UDPClient(args.ip, args.port)
and then everything worked fine.
Hope this helps.
Great code. Thank you.
I installed python-osc with: pip install python-osc on a Ubuntu 14.04 with Python 2.7.6.
During the install I get the following error though:
Installing collected packages: python-osc
Running setup.py install for python-osc
File "/usr/local/lib/python2.7/dist-packages/pythonosc/dispatcher.py", line 53
yield from handlers
^
SyntaxError: invalid syntax
Also when trying: it gives the error:
File "service/responder_no-kv.py", line 1, in
from pythonosc import dispatcher
File "/usr/local/lib/python2.7/dist-packages/pythonosc/dispatcher.py", line 53
yield from handlers
^
SyntaxError: invalid syntax
and gives the error:
Traceback (most recent call last):
File "service/responder_no-kv.py", line 1, in
from pythonosc import osc_server as osc
File "/usr/local/lib/python2.7/dist-packages/pythonosc/osc_server.py", line 33, in
import asyncio
ImportError: No module named asyncio
I just wanted to try out the examples, did I do something wrong?
Great work with your package !
Though, when I send lists trough OSC, these lists are cropped to 256 elements. I looked in the code trying to find where this limit could come from, but I didn't find any explicit limit.. Is it in the package or it is imposed by the native SocketServer package?
Thank you very much!
Is there a way for the server to know it has been connected to by a new device, perhaps with the device's IP? I'm looking for a way to allow a persistent server to update a newly connecting device with the current state, without having to explicitly include an "update" button on the TouchOSC form. I understand that I have to handle the ports myself, and ensure new devices comply with the convention, but that's a different issue.
Attempting to create/update a viewpoint with libvlc 3.0.1 results in a runtime error:
import vlc
view = vlc.libvlc_video_new_viewpoint()
Results in:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/Projects/vlc.py", line 7131, in libvlc_video_new_viewpoint
return f()
RuntimeError: ffi_prep_cif failed
As far as I can see there is no license information in any of the files. Not in the readme, not as headers in the files.
What is the license? LGPL (I hope)?
Can you please add licensing information to the files?
Hello
Is it possible to get the source IP and port of received datagrams, in the handler?
Thank you
I'm getting the following error when trying to run the example code. Installing from pip on python 2.7.2, reported install version is 1.4.1.
python oscdump.py Traceback (most recent call last): File "oscdump.py", line 5, in <module> from pythonosc import osc_server File "/Users/****/code/oscdump/oscdump-env/lib/python2.7/site-packages/pythonosc/osc_server.py", line 24, in <module> import socketserver ImportError: No module named socketserver
It's easy to get stuck while testing this out with the example when trying to send from another machine to python-osc since the default example binds to localhost only. I suggestion changing the example to bind to 0.0.0.0 to allow any client to send.
Hi!
I package python-osc for Arch Linux (currently AUR, but soon [community]). Would you consider adding the LICENSE.txt to the source tarball on pypi.org, so I can include it properly?
Currently, when using pypi as upstream I have to get the license from github separately.
Also, the examples and scripts folder is not packaged on pypi, but included in source tarballs on github (the examples are also included in the README.rst, so for me those are not that much of a problem).
Thanks!
python-osc does not implement parameter type h which I think is int64.
It might be me but I can't get python-osc to send to a broadcast address. It keeps coming back with a permission denied message. Any thoughts on how to fix this? I can post the exact message tomorrow.
Cheers!
In version 1.6.4 and previous I could use code as below to send messages with data 0 or 1
sender=udp_client,SimpleUDPClient('192.168.1.128',4559)
sender.send_message('/test',1)
time.sleep(1)
sender.send_message('/test',0)
Now the 1 and 0 are not received but seem to be treated as booleans according to OSC_Data_Monitor which I used to inspect the output.
I have used such messages extensively in sending message data to Sonic Pi, but now I either
have to use values say 2 and 4, or send the data as strings "1" and "0"
Obviously I can change my code to suit, but is there a way to send integers 1 and 0 which can be received as such? I'm not very experienced in using python so I may be missing something obvious.
For the moment I have reverted to version 1.6.4
Hi
I am using your interface in my project https://github.com/gkvoelkl/python-sonic
It works great
Now I want to work with supercollider. I send a message on a specific port and supercollider sends back an acknowledgement on the same port. If I use an client and an oscserver on the same port no messages go out.
Any suggestions?
best regards
Gerhard
Currently a asyncio server can only be started from outside of the loop. We need to start it from a coroutine in the Mission Pinball Framework. Will submit a PR for this later.
First let me apologize if I don't understand the code fully and I am wrong. I was trying to write a "simple" debug tool using your library, so I have a piece of code like this:
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/*", my_print')
My code does not work (my_print
is never invoked). So I looked at the dispatcher.py
code and the method: https://github.com/attwad/python-osc/blob/master/pythonosc/dispatcher.py#L30
uses the address of the message received as the regex pattern when I was expecting the address provided in the map
method to be used as the regex pattern. In my use cases, I receive messages like this (generated by the Motu CueMix FX software):
/bin/fvEB+0/fvInCS+0/pflS
/bin/fvEB+0/fvInCS+1/pflS
/bin/fvEB+0/fvInCS+2/pflS
/bin/fvEB+0/fvInCS+3/pflS
/bin/fvEB+0/fvInCS+4/pflS
/bin/fvEB+0/fvInCS+5/pflS
/bin/fvEB+0/fvInCS+6/pflS
If a message like this is treated as a pattern, then that could be an issue (+
has a special meaning in regex land).
Again I may not be looking at it the right way and I do apologize if I am wrong. I suppose it is probably the intent because if you were to allow "generic" dispatching, then the address would also need to be provided in the callback in order to distinguish.
Heya, maybe a dumb question, but how can I have the client receive messages from the OSC server?
Hello.
(please bear with me, as I'm a n00b.. as evidenced by the history :D)
I'm trying to setup a program that is always running and both sends and receives messages via OSC (I'm talking to and listening from TouchDesigner). So, from the provided examples, I'm trying to have both a client and server running. I'd like to be able to send a message via my client to TouchDesigner at any moment (say at a keypress), have TouchDesigner spit it back to me and be able to read it via my server.
Seems like my issue (from hacking together the two examples) is that my server code is blocking any attempts for sending (most likely because of: server.serve_forever()). What is the better way to approach this?
in python 3.6 changelog (https://docs.python.org/3.6/whatsnew/changelog.html#python-3-6-0):
"bpo-25931: Don’t define socketserver.Forking* names on platforms such as Windows that do not support os.fork()."
due to this change,
there's an error:
osc_server.py line 136
class ForkingOSCUDPServer(socketserver.ForkingMixIn, OSCUDPServer):
with message:
AttributeError: module 'socketserver' has no attribute 'ForkingMixIn'
when running python3 -m pip install -r ./requirements.txt
I get the following error:
Collecting pyOSC==0.3.5b5294 (from -r ./requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/7c/e4/6abb118cf110813a7922119ed0d53e5fe51c570296785ec2a39f37606d85/pyOSC-0.3.5b-5294.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-by82t4hi/pyOSC/setup.py", line 5, in <module>
import OSC
File "/tmp/pip-build-by82t4hi/pyOSC/OSC.py", line 735
binary = struct.pack('>ll', 0L, 1L)
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-by82t4hi/pyOSC/
What is the maximum size for sending an OSC string? I get the above error.
Using the github version, I can create a UDP client with udp_client.SimpleUDPClient(endpoint['ip'], endpoint['port'], allow_broadcast=True)
. However, when I install from Pip, this no longer works, and after looking at the source it appears that allow_broadcast is missing from the Pip version.
I am fine installing from github, but I am trying to publish a package built on this library and can't instruct all my users to download from GitHub. I would appreciate if you could investigate this discrepancy and update the Pip repository if needed.
I get the message
ValueError: Infered arg_value type is not supported
when I try to run the example bundle code. I have tried adding an explicit arg_type, and it still tries to infer the type and raises the ValueError above.
This was done in python 3.5.2
Hey there,
Getting started with simple messages is straightforward because you included the client/server examples. However I am not sure how to create OSC-bundles, as there is no documentation.
It would be useful to have a similar bundle example next to the message example.
Hello,
I'm looking to replace PyLiblo in my project with your module, but it seems not to be able to listen to messages created by a C binary using Liblo.
Both the Python process and the C process create a client and a server to communicate. The python-osc client can successfully send a message to the C Liblo server, but it seems that all messages originating from the C client (using lo_address) are dropped. From the research I've done, this seems to be related to Liblo using multicast messages, which are not compatible with Python's socketserver module. I did confirm that both were using UDP on the same port, and tried various permutations of "localhost", "127.0.0.1" and "0.0.0.0" for both client and server, as well as the blocking, threading and forking servers.
I did find some literature about making socketserver listen to multicast messages (it's Python2 code, but should be easily ported to Python3):
I am trying to acquire the timestamps associated with each packet that I am receiving, rather than using the system time for when each packet is being received. I modified the osc_server function _call_handlers_for_packet, by adding timed_msg.time to the callback(). This seems to be the system time from when the package was received. Is there a way for me to acquire the time stamp from the incoming osc packets?
I can reproduce this ad lib in Python 2.7.6. It works fine in Python 3.
>>> from pythonosc import osc_message_builder, udp_client
>>> msg = osc_message_builder.OscMessageBuilder(address = "/foo")
>>> msg.add_arg("bar")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pythonosc/osc_message_builder.py", line 69, in add_arg
if builtin_type == builtins.str:
AttributeError: 'dict' object has no attribute 'str'
And if I try to specify the type directly it goes well at first, but breaks when you want to build the datagram.
>>> msg.add_arg("bar", msg.ARG_TYPE_STRING)
>>> msg.build()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pythonosc/osc_message_builder.py", line 120, in build
return osc_message.OscMessage(dgram)
File "/usr/lib/python2.7/site-packages/pythonosc/osc_message.py", line 22, in __init__
self._parse_datagram()
File "/usr/lib/python2.7/site-packages/pythonosc/osc_message.py", line 56, in _parse_datagram
raise ParseError('Found incorrect datagram, ignoring it', pe)
pythonosc.osc_message.ParseError: ('Found incorrect datagram, ignoring it', ParseError('Could not parse datagram string index out of range',))
I'm working with SLIPSerial and after I have decoded the packet I can't quickly parse it into an osc message, though all the methods are there to do it easily.
Would make this handy library even handier!
Trying to send [0,1,2] results in [2, nil, nil] being seen on the server (SonicPi)
python-osc: v1.6.5
Python: 3.5.3
SonicPi: 3.0.1
Pi3 Raspbian Stretch
Test case:
Python:
from pythonosc import udp_client
sender = udp_client.SimpleUDPClient('127.0.0.1', 4559)
sender.send_message('/trigger/prophet', [0, 1, 2])
Sonic Pi:
live_loop :foo do
use_real_time
a, b, c = sync "/osc/trigger/prophet"
print(a,b,c)
end
Sonic Pi log:
{run: 9, time: 108.8493}
└─ 2 nil nil
Sorry, not sure if this is python-osc or SonicPi issue.
I am trying to send OSC messages through a 127.0.0.1 UDP Port from an app called MuseDirect to python using python-osc.
If I start the python-osc client example the server works perfect.
If I try to receive the OSC messages from MuseDirect the print message "Serving on .." shows up but I never get a message.
If I test my python settings with a simple udp server, all messages arrive and the paths are correct.
Is it a UDP issue? Any ideas or recommandations?
Thank you very much
unhandled type: d
warnings are all that gets returned, no handlers even end up running.
I'm trying to set up communication between chuck and python-osc. Chuck natively supports the OSC protocol. It appears that the messages we send from the python side do not arrive at the chuck side. All other combinations, i.e. python to python, chuck to chuck and chuck to python are working fine though.
I'm running python 3.4.4 on windows 7.
What could be going wrong here?
Here are the four files with the client/server implementations I'm using for testing.
OscSend xmit;
xmit.setHost("localhost", 5005);
<<<"Sending">>>;
xmit.startMsg("/debug");
OscRecv orec;
5005 => orec.port;
orec.listen();
orec.event("/debug") @=> OscEvent e;
<<<"Waiting">>>;
e => now;
<<<"Received">>>;
from pythonosc import osc_message_builder
from pythonosc import udp_client
client = udp_client.UDPClient('localhost', 5005)
msg = osc_message_builder.OscMessageBuilder(address="/debug")
msg = msg.build()
print('Sending')
client.send(msg)
from pythonosc import dispatcher
from pythonosc import osc_server
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/debug", lambda _: print('Received'))
print('Waiting')
server = osc_server.ThreadingOSCUDPServer(
('localhost', 5005), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
A client can use wildcard to point to many dispatcher mappings
Dispatcher CANNOT use wildcard to map many addresses to a single callback
I'd like to use the latter pattern so that the client needs only to specify the name of a target, perhaps with a prefix, and the rest of the string can be parsed further manually.
i tried the example of server, and understand that dispatcher.map can fetch the /xx/xx 1.0, and print it.
but how can i get the "/xx/xx 1.0"string ?so that i can deal with other jobs using the raw string.
Standard asyncio loop works fine but uvloop generates an error with this lib:
ERROR : root : '_OSCProtocolFactory' object has no attribute 'dispatcher'
Traceback (most recent call last):
File "/data/home/jan/cloud/flipper/src/mpf/mpf/commands/game.py", line 217, in __init__
MachineController(mpf_path, machine_path, vars(self.args)).run()
File "/data/home/jan/cloud/flipper/src/mpf/mpf/core/machine.py", line 681, in run
self._run_loop()
File "/data/home/jan/cloud/flipper/src/mpf/mpf/core/machine.py", line 727, in _run_loop
raise self._exception['exception']
File "uvloop/cbhandles.pyx", line 52, in uvloop.loop.Handle._run
File "uvloop/handles/udp.pyx", line 64, in uvloop.loop.UDPTransport._on_read_ready
File "/data/home/jan/cloud/flipper/src/python-osc/pythonosc/osc_server.py", line 171, in datagram_received
_call_handlers_for_packet(data, self.dispatcher)
This seems to be related to passing a class instance as factory to create_datagram_endpoint
.
Hello,
the datagram strip causes some problems for me, can you please release an updated pip version so it's easier to install? Thanks!
First of all, great thanks for this extremely useful lib! It works totally fine on Python 3.4.
For some strange reasons, I need to get it working on Python 3.3
I downloaded the 1.4.2 (which states Python 3.3+). Everything is fine but when I initiate a send message I get the "AttributeError: 'OscMessageBuilder' object has no attribute 'dgram'" error.
Any hints on how to overcome this on Python 3.3?
Hello
Would you be interested in TCP support?
I have some sample code which implements a TCP client
TCP would allow to lift the restriction on the maximum object size that can be sent through OSC
This is a feature request to simplify a common use case of the package.
In few projects I found myself subclassing the UDPClient to send messages more easily:
from collections import Iterable
class SimpleOSCClient(udp_client.UDPClient):
"""Simple OSC client with a `send_message` method."""
def send_message(self, address, value):
builder = osc_message_builder.OscMessageBuilder(address=address)
if not isinstance(value, Iterable) or isinstance(value, (str, bytes)):
values = [value]
else:
values = value
for val in values:
builder.add_arg(val)
builder = builder.build()
self.send(msg)
I think that this is a very usual case for an OSC client, and would like it to be implemented in the package itself. I understand the current attempt to decouple the client from the message, so adding this method to the existing UDPClient might be problematic. However, subclassing it in a new module will be equally sufficient. What do you think?
BTW, I will be happy to send a PR. Just want to understand if this is something you want and what implementation is preferable in your opinion.
python-osc version: 1.6.1
python version: 3.5.2
numpy version: 1.11.2
I'm trying to call add_arg
with an argument of type numpy.float64
.
The call succeeds but keeps an incorrect data in the builder args
property.
In [1]: import numpy as np
In [2]: from pythonosc.osc_message_builder import OscMessageBuilder
In [3]: builder = OscMessageBuilder(address='/whatever')
In [4]: builder.add_arg(np.float64(1.23))
In [5]: builder.args
Out[5]: [(None, 1.23)]
Calling builder.build()
fails with unclear error.
In [6]: builder.build()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-28171a806b58> in <module>()
----> 1 builder.build()
/home/nagasaki45/code/CruftFest/wheel_speed_analyser/env/lib/python3.5/site-packages/pythonosc/osc_message_builder.py in build(self)
102
103 # Write the parameters.
--> 104 arg_types = "".join([arg[0] for arg in self._args])
105 dgram += osc_types.write_string(',' + arg_types)
106 for arg_type, value in self._args:
TypeError: sequence item 0: expected str instance, NoneType found
Solving this in add_arg
itself will be better of course. I'm not sure if aditional validation in build
make sense here because there is no explicit way to add arguments except from add_arg
.
In my opinion, there is really no reason for restricting the usage of types that "looks like" floats, e.g. np.float64
. Moreover, notice that
In [7]: isinstance(np.float64(1.23), float)
Out[7]: True
Would you consider changing the type guessing to use isinstance
instead of equality check altogether? I can't see a reason not to...
Thanks!
Will tackle that this week once I familiarized myself with the new paradigm/syntax of coroutines in Python. Sounds like fun.
Results:
samuel@samrmbp in ~/: ➤ sudo pip install pyosc
Downloading/unpacking pyosc
Could not find a version that satisfies the requirement pyosc (from versions: 0.3.4b-4959, 0.3.4b-4959, 0.3.4b-4993, 0.3.4b-4993, 0.3.4b-4996, 0.3.4b-4996, 0.3.5b-4996, 0.3.5b-5294)
Some externally hosted files were ignored (use --allow-external to allow).
Cleaning up...
No distributions matching the version for pyosc
Storing debug log for failure in /Users/samuel/.pip/pip.log
The examples in the README.md do not match each others configuration. Would a pull request changing both ports to 5005 and matching up the addresses + message be eligible fo rmerge?
Hi,
I get the following error either by installing it manual or using pip
File "/usr/local/lib/python3.2/dist-packages/pythonosc/dispatcher.py", line 53
yield from handlers
^
SyntaxError: invalid syntax
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.