Using a new java library in jython

Hello everyone!

I would like to implement an OSC server on myrobotlab. I wanted to use the java oscP5 library in the jython service.

So far I tried to put the .java files frome the src folder of oscP5 to the src folder of myrobotlab.

And the .jar frome the library to the repo. Is it supposed to work?

Thank you for your time.

Here is the link to the library:
http://www.sojamo.de/libraries/oscP5/

GroG's picture

Hello and Welcome nicolas

Hello and Welcome nicolas taguet !

It depends on how you want it to run.

Regular User Way

  • download the latest myrobotlab.jar in a new directory and install the "usual" way
  • type the following to install all the services
         java -jar myrobotlab.jar -install    
  • there is now a sub directory called libraries/jar, download and copy the oscP5.jar from the zip into the libraries/jar
  • download and copy the oscP5.jar into the libraries/jar directory
  • start with 
        java -jar myrobotlab.jar
  • run script

It worked this way for me 

But I didn't have a cool musical instrument to send the data .. just netcat listening on port 8000
You have to be careful the Python tab needs to be selected (in focus) to run .. I always forget this and just press run and nothing happens ...  I think someone will fix it next release ..

Run It As A Developer

So  if you want to make a MRL Service or hack on some Java code - you add just the jar to the repo, adjust the class path, and begin creating your service.  This would be like a wrapper to the OscP5 library.  Probably not want you do until you get some experience playing with it as a user.  But if  do want to go that way you can google for related links.

Cheers - please post your project (pictures are always appreciated) when you get time !

nicolas taguet's picture

Thank you a lot Grog!

Thank you for yout awesome answer i will do that.

Just as a brief presentation of the project I work as an intern in an audio visual compagny and they want to control on stage some of the inmoov robot's part via OSC... so here i am!

I will post the project and some picture once done.

Cheers!

 

nicolas taguet's picture

Hello again! So i figured it

Hello again!

So i figured it out thanks to you!

I have a problem on the displaying of the incomming messages.

Here is how it is supposed to work to handle incomming messages, you define a method that is to be called on the receiving from the specified source (ip, adress and port).

Here is my problem, the udpServer works it is listening on right port, but i don't know how to display it on myrobotlab. Here is my code so far :

import oscP5.OscP5 as OscP5
import netP5.NetAddress as NetAddress
 
 
oscP5 = OscP5(python,13000)
oscP5.plug(python,"test","/test") #call function test when an osc message has /test as address
puredata = NetAddress("127.0.0.1",13000)
 
def test(theOscMessage):
   print "### received an osc message."
   print "### addrpattern\t"+theOscMessage.addrPattern()
   print "### typetag\t"+theOscMessage.typetag()
 
for x in range(0,6):
   sleep(0.5)
   print x
   oscP5.send(OscMessage("/test").add(x), puredata)
 
The test function is supposed to be called but it is not, any input on why?
 
Thank you!
nicolas taguet's picture

Edit listener

Hello again, i have an update, so i tried different libraries the OSC sending part is worky on all of them, but I can't get the receiving part to work. I am almost certain that the listeners handling the call of function at the reception of messages are not worky.

Is there something specific to myrobotlab you are supposed to do to get the listeners to work?
The listener in the library i'm using are started in threads, is it supported in myrobotlab?

Cheers!

GroG's picture

Threads are supported, in

Threads are supported, in fact MRL is "massively" multi-threaded ..

Never worked with this library before, what are the requirements of a "Listener" ?

There is the possiblity that we make an official "Service" for this library ... 

The purpose of many of the services is provide a wrapper of easy functionality, which works in the same framework as all the other services.  I'd be willing to do this, but it would be helpful to get a good comment or post of references of what you can do with this library. 

Do you think you can make a comment which has a list & pictures of the "potentially" nifty things to control or get data back from ?

If we make a service we might even make a gui (or 2) for it - what things would be useful in the gui ?  Does it have a gui ?

nicolas taguet's picture

potentially nifty things using OSC

OSC

OSC stands for Opend Sound Control. OSC is a protocol of communication that usually goes over ethernet.
It was mainly invented for the communication of electronical instrument such as synthetizers and controller. Also a lot of today's musical software are using OSC to send their data. Here are its features from wikipedia:

  • Open-ended, dynamic, URI-style symbolic naming scheme (uniform resource identifier)
  • Symbolic and high-resolution numeric data
  • Pattern matching language to specify multiple recipients of a single message
  • High resolution time tags
  • "Bundles" of messages whose effects must occur simultaneously

For example this guys are implementing/using OSC to send/process data :

OSC controller

touchOSC

Processing

There is a more exhaustive list of wikipedia :
https://en.wikipedia.org/wiki/Open_Sound_Control#Applications

For more information here is pdf giving some of the OSC specificity in regard with MIDI
http://opensoundcontrol.org/files/OSC-Demo.pdf

Implementation with javaOSC

In order to implement OSC in myrobotlab and join the osc family the library called javaOSC could be used

It has a gui :

It is easy to use, choose:

  • The port for communication.
  • The ip to send to.
  • The adress of the message you want to send or receive (using the form /address/channel)
  • Set a value (supporting integer, Double Precision Floating Point, Strings, and more)
  • Send

For the server part i don't know how it is supported in this case.

But a gui supporting the server port could be neat with these functions:

  • set the number of servers
  • set the port to listen to for each server
  • filter the messages by addresses (using the form: /address/channel)
  • the possibility to trigger service/function on the reception of the messages

 

Finally here is a link to project done thanks to OSC:
http://opensoundcontrol.org/osc-application-areas

 

I hope this post gave the information you wanted Grog, thank you for all the support!

Cheers!

 

GroG's picture

This is great ! ... very

This is great ! ... very useful.

I'm now in the process of creating a MRL Service Osc.

I saw there were a couple of choices for interface libraries.  Initially I started looking at JavaOsc .. OscP5 is "made" specifically for Processing.  However, JavaOsc latest does not compile with Java 8.  Although this could be fixed relatively quickly, it made me look more closely at OscP5.  I believe its a well written library, and it does not appear to have any Processing dependencies.

So .. the MRL Osc service will be a wrapper for OscP5 ..

At least that is the current plan...

GroG's picture

That just said...  I just

That just said...  I just discovered the following in OscP5 libarary

 

I've looked at P5 libraries before, and see they reference P5's PApplet.  I was hoping this library did not - but it does in a different way.  It dynamically references PApplet.  And this is why the receiving data is borked.  I could create a new constructor with an input string which would make things work, then submit the addition back to the OscP5 group ... but maybe not...

So, Althought this library is written well, it would require me hacking on it to make it work completely in MRL.  So now I'm switching to plan B ..  "try using JavaOsc"

 

GroG's picture

Now on the JavaOSC side

Now on the JavaOSC side ...

He doesn't publish any binary releases.. he has several tagged source versions & a binary in sourceforget (cept I'm not sure of the version there...)

I've decided just to look into the source to see if I can get something to work satisfactorily - I'm going to try his "develop" branch latest checkout, because the latest is usually the best ..

If I get something to work, I'll bundle it as a library and put it in the repo

nicolas taguet's picture

Hello, sorry to bother you

Hello, sorry to bother you with that but is the github up to date? I followed the quick start tuto (well written btw)

and i'm not sure it is the same version as the last build. Here is the link : http://myrobotlab.org/quick_start

Also is there a branch we have to clone rather than another?

Cheers!

 

GroG's picture

"develop" !  is the one to

"develop" !  is the one to use ... we are working on a release - the project page is here https://github.com/orgs/MyRobotLab/projects/1 - if you don't have a GitHub account you'll not be able to see the project page (404 is returned)

Make sure you load the repo project .. otherwise everything will be all red with errors ;)

nicolas taguet's picture

Thank you Kwatters

Ok awesome thank you a lot!

I'll be able to put my lil' hand in all that code!

yours happy to work on this project.

nicolas taguet's picture

I do have an account.

Hello Grog,

I do have an account and i still get page not found with the error 404.

Is there something special i am supposed on my account to be able to access it?

GroG's picture

JavaOSC source from github

JavaOSC source from github with develop branch (origin) compiles fine ...  its just the maven build project and/or tests which fail to create the binary ...

Testing functionality, I started the UI and did the same netcat -ul -p 57110 ..

A little strange the port is hardcoded ..  it sent udp messages

There is some docs to set up a receiver .. but the docs of course are way out of date, and do not compile ...

might be able to figure it out...

GroG's picture

Can't help look at the

Can't help look at the history of JavaOSC - I think originally it was created to interface with SuperCollider - http://supercollider.github.io/ 

Never heard of it .. looks like an IDE - audio dsp sound studio with an interpretive scripting interface.  Downloaded it and installed it for fun .. but looks like a very steep learning curve ...

nicolas taguet's picture

Hello Grog when do you sleep!

Hello!

I see that it was a tough day of work! 

I finally succeeded to set up the receiver.

Here it is:

import com.illposed.osc.OSCPortIn as OSCPortIn
import com.illposed.osc.OSCPort as OSCPort
import com.illposed.osc.OSCListener as OSCListener
 
port = 1234
address = "/test"
 
receiver = OSCPortIn(1246)
 
class PyOSCListener(OSCListener):
    def __init__(OSCListener,python):
        return
    def acceptMessage(message,time,python):
        print "address is : "+python.getAddress()
        print "arguments are : "+python.getArguments().toString()
 
listener = PyOSCListener(OSCListener)
receiver.addListener('/test', listener)
receiver.startListening()
print receiver.getPort()
receiver.run()
 
 
Here is the sender:
 
import com.illposed.osc.OSCPortOut as OSCPortOut
import com.illposed.osc.OSCMessage as OSCMessage
from java.net import InetAddress as InetAddress
 
ip = '127.0.0.1'
port = 1234
address = "/isadora/1"
message = "Grog was here"
 
def getByAddress(ip):
    return InetAddress.getByAddress(map(int, ip.split('.')))
 
d = timedelta(microseconds=-1)
 
sender = OSCPortOut(getByAddress(ip),port)
args = [1]
args[0] =message
message = OSCMessage(address,args)
sender.send(message)

 

GroG's picture

Wow .. really

Wow .. really nice..

Impressive Python "class" / Java declaration ..

I'm glad you figured it out ... I'd like to finish this myrobotlab Osc service and make it easier for others - because that's what we do ;)

I'll finish it, and give an example of how to use it in Python, then perhaps you could test and give some suggestions..

... goodtimes ...

GroG's picture

Hmmmm... OSCPortIn.addListene

Hmmmm... OSCPortIn.addListener does not exist in the version I have (latest on develop) ... going to try the "released" jar

It seems they have removed addListener, and created a different class for handling the filtering called OSCPatternAddressMessageSelector - but I see no example of how to properly use it ...

nicolas taguet's picture

I hope it helped to do the service

Hello, thank you for the work acknowledgement :)!

I hoped that my codes could help you write the service, i have to admit that i don't know anything about how your services really work and how you write your Gui and myrobotlab as whole but it'll come when i'll read through the code!

I can give you the version of javaOSC i got.

I'm now working on a heartbeat sending through osc (got it to work) and soon i'll have two code to control the inmoov robot from an osc sender (myrobotlab or not) to myrobotlab.

I comment everything and i'll post it here soon.

https://mvnrepository.com/artifact/com.illposed.osc/javaosc-parent/0.4

GroG's picture

You gave me a reference to

You gave me a reference to the maven repository....
Usually they have artifacts here ..
So I copied the dependency xml and put it in a minimal maven pom

then ...

mvn dependency:copy-dependencies

That should have copied the jar to a folder, I could then check into the "repo"
But instead it gave me errors that it couldn't resolve.
I looked at the maven page... and sure enough - there is no binary jar checked in !!!

I could check out the 0.4 tag in github and build it, but I'm wondering why you gave me this link, and if it worked for you .. perhaps in some other way ?\

nicolas taguet's picture

I hope it helped to do the service

 

 

 

GroG's picture

This is the tentaive

This is the tentaive interface in Java ... but basically it would be the same in Python, but less code ;)
Was thinking of having an

osc.connect("somehost", 7777)

then all subsequent would be osc.send("/path", var, args, 123, "hello"), that way the "somehost", 7777 would not need to be specified on every call ... still might do it, the only thing which gave me pause was the fact its udp protocol underneath - which is "connectionless" - so connect might be a little deceiving 

 

 

GroG's picture

Ah .. here it

Ah .. here it is...

https://mvnrepository.com/artifact/com.illposed.osc/javaosc-core/0.4 

GroG's picture

Ok, I got listen to work by

Ok, I got listen to work by connecting 2 Osc services together ...

Some stuff I've learned:

  • At the bottom of the service page - http://myrobotlab.org/service/osc , you'll find the current working script.   I decided to go with the "connect" method because the notation is less cluttered.


    #file : service/Osc.py edit raw
    # start the service
    osc = Runtime.start("osc","Osc")
    
    # connect - which is not 'really' connecting - but
    # specifying the host/port of where we'll be sending 
    # the messages to
    osc.connect("localhost", 12000)
    
    # now start sending messages 
    # the format is
    # sendMsg(topic, arg1, arg2, arg3, ...)
    osc.sendMsg("/test", "this is a string", 3, 7.5, "another string")
    osc.sendMsg("/newTopic", 18, "hello", 4.5)
    osc.sendMsg("/somewhere", "this", "is", 7, 3.3, "variable arguments")
    
    # to listen we choose a port - and an address filter
    osc.listen("/*", 6000) # this should be everything ..
    # we could just listen to a single topic like this
    # osc.listen("/test", 6000)
    
    # we want them sent to python so we subscribe to
    # the publishOSCMessage method
    python.subscribe("osc", "publishOscMessage")
    
    # the messages will come back to us in onOscMessage
    def onOscMessage(message):
      print(message)
      data = message.getArguments()
      for d in data:
        print("data - ", d)
    
    
    
    

     
  • The OSCMessage vs Osc is bothersome, but OSCMessage is a class from the original JavaOSC.  In Mrl .. all abbreviations follow the same capitalization rules.  Its camelcase for everything as Java traditionally is.  But we try to follow a strict policy of capitalizing "only" the first letter of abbreviations too.  So camelCase makes abbreviation look like words.  I think its easier to read too.  

    For example it would be XmlParser vs XMLParser.   I'm very close to refactoring and creating a new Mrl class called OscMessage where it will contain the same contents (and perhaps more) of the OSCMessage - probably should do that sooner than later, otherwise risk breaking peoples python scripts.

    Refactoring done, there is a static inner class named OscMessage - all interface methods or data is now done with Mrl standard Osc
     

  • The "address" as they refer to it (e.g. "/test") reminds me very much of Mqtt & Kafka's "topics". Mqtt protocol has a rich regular expression to support subscribing to "topics".
    O.K.  just tested it and "/*" looks like it might do what I would expect - found some helpful examples of addressing here - http://opensoundcontrol.org/spec-1_0-examples#OSCaddress 
  • One thing which did not work is 
    osc.sendMsg("/somewhere/else", "this", "is", 7, 3.3, "variable arguments")
    not sure if it did not receive or could not send.
     
GroG's picture

I think there might be be a

I think there might be be a bug in JavaOSC - where any address which is mutiple levels like

/test/data/1

is not received by listening to /*

/test

generates a event - but /test/data/1  does not

nicolas taguet's picture

And the service is already on it's way

Hello, sorry for the absence this WE i had some family matters i had to attend to!

Sorry also for the wrong link...

Good idea to do the refactoring, feels cleaner now :).

Is /*/* working? If "/" is an escaping character it might be it... Even if it would be strange if it is trying to match strings thanks to regular expressions.