JavaFX: Java OSC library and JavaFX-based OSC Router

As part of my Tonome LibGDX project I decided to convert the LibGDX application to use OSC messages instead of triggering samples internally to the application.


The application could broadcast OSC note on and off messages to a Puredata instance and map that down to MIDI with a Puredata script. The first part of that was to use a Java OSC library that I would build into the application.

I had a look at the existing Java OSC libraries available but I couldn’t use them as they relied on creating a new instance of each message for each message sent. This is a no no with Android as you would have the garbage collector running. The OSC specification is up on the OSC website so why not try and write my own using a pooled approach where we reuse messages sent. The result is the osc-common and osc-network components.


This is an almost fully compliant implementation of the OSC message spec. There are bits missing but for my purposes nothing essential.

The library like all the components is fully mavenised and has unit tests to ensure the output of the objects comes out as expected using the encode and decoder components.

Technically you can flood your client app with messages unless you set the pool size to a maximum but hopefully that won’t be an issue if the throughput is high enough. I guess that remains to be seen in the real world. It’s not been an issue for me yet.


This implements a client and server implementation for the encoder and decoder components. It uses NETTY a super fast networking library for all the networking parts and is unique in that I have not seen any examples of NETTY4 using UDP to implement anything like this. This was a big sticking point in the development as I wanted to use NETTY4 but it was still in beta at the time with not many source code examples. There might be more recent version of NETTY but I’ll leave it as it is for now.

I got this component working with my Tonome project against the Puredata script that I had written but I found out that Puredata would choke when sent a lot of messages. Initially my heart sank I as I could see that I would have to write my own application to do this. But any failure is an opportunity right? My Swing skills are non-existent but my Flex skill are strong so I figured I would try to look for a Java UI library that would fit my needs. After looking around I noticed Pivot and JavaFX (which had just reached version 2 at that point). Rather than go straight in I thought I would prototype something easier (and more useful) so I embarked on trying to put a front-end on my Mavenize command line tool instead.

Pivot was eventually thrown out instead of JavaFX which I have successfully used to put a useful UI onto my application for converting any existing Java project to the Maven file structure. Once I had the skills I sat down and started to develop an application which uses the osc-common and osc-network libraries to route OSC messages to MIDI. That application is osc-router.


The osc-router will listen to OSC messages sent to it on the chosen port and then you can assign labels to the message value received. You can’t edit the labels whilst the tool is in ‘listen’ mode but once you pause you can set them. The interface lets you route the messages (as long as they have the expected note-on and note-off values) to a specified MIDI device. It will let you save and load your settings.

This is very much a work in progress. There are possibly latency issues to do with the fact I am creating other objects to represent the incoming messages. I think there is a rewrite of the message path on the books.

The project has been put up onto GitHub here.

Lot’s of interesting JavaFX stuff to look at including file open/save dialogs,  editable label cells, combobox selection cells, icon status cells and a background service. The application also sports a message cache, MIDI device handling  and lots more. I’m also  using XStream to persist the the OSC message values and label settings to an XML file which has proved to be quite seamless.

Update #1

Update #2

The Tonome OSC-aware application is now up on Github. You can find it here. It runs on Android but there are still a few issues to iron out like the inability to edit the hostname and port values. It is here.

If you run it from the desktop it will connect to the stated hostname and port that the OSC-Router application is setup for. I have altered the router to load up the Tonome message definition by default. All you need to do it map the note on/off message and route them to a midi target.

More details in further posts.


6 Responses to “JavaFX: Java OSC library and JavaFX-based OSC Router”

  1. Michael Schmalle on March 12th, 2013 10:33 pm

    This is great stuff!

    I have a couple projects that are audio based on the desktop and android( With the Caustic audio engine, check out my .org site). Did some searching and ran into this site. Your GIT hub account has some exceptional code in it!

    I will definitely be learning some stuff from your code and libgdx. Great source code!

    So you have the Android app as a controller for your desktop? I am looking to do something similar with audio and OSC. Actually OSC searching is what brought me here, but you libgdx git code made me start searching deeper again.

    Ironically, you were into Flex, I am a committer and PMC member for Apache Flex, I wrote the JavaScript cross compiler with the new Falcon compiler (FalconJx). I am also working with some others in the industry creating a JS IoC framework for AS3 to JS. This is going to enable tight Web Audio apps written in AS3 to compile to JS with webkit shims and external view html, no UI components are cross compiled in the framework we are making. Anyway, blah blah 🙂 Great work!


  2. Michael Schmalle on March 12th, 2013 11:31 pm

    Dude, I have looked at a lot more of your code… We have more in common than you think. We seriously need to talk. 🙂 If you go to

    You will see what I am talking about, scroll down to the bottom and see the Tone Matrix app I made a year ago. That screen shot was about 5 months ago.

    You can make Caustic audio apps right now with the core. Now that I am looking at libgdx, I am seriously questioning my implementation, any way I have all my code on GIT …

    There is a huge opportunity here if you want to work with audio on Android AND Windows with Caustic if so you feel inclined you would want to develop something with me. 🙂


  3. admin on March 13th, 2013 12:08 am

    Hey Michael, thanks for your kind words.

    I see you have found my latest update which is the Tonome OSC aware application

    It’s a bit basic but it’s essentially a prototype/demo.

    LibGDX is a great platform to develop for both the desktop and Android. An audio tool with a synth engine is in a sense what I set out to do originally after I ditched the idea of using samples. After a brief flirtation with PureData I had to downgrade my vision a bit because I couldn’t get it to build – after that the easiest solution was to go the OSC way.

    I did know about Caustic but did not Google too much about it since I wasn’t aware it could be controlled with OSC.

    Your TX-101 application looks great. I really liked Flex and got pretty good at it. I kind of drifted away from after I got into Android and mobile applications.

    I would certainly be interested in using the Caustic engine with my Android OSC implementation. I will email you tomorrow and we can talk about it.

    Thanks again.


  4. Michael Schmalle on March 13th, 2013 9:05 am


    I don’t do Flex anymore either. I work on the AS3 compiler and targets. SWF is dead to me, Adobe burned the bridge way back. I was doing Flash since 2002.

    Anyway, Android is where I eventually landed and I have put a considerable amount of time into. Caustic can be controller by OSC in Java because I basically begged Rej to allow it. 🙂

    Anything you can do in Caustic I have OSC for, so all the synths, sequencers etc are controllable. I remade the Tone Matrix is native Android as well.

    Looking at my site, it looks like I just popped on the stage but, I have been around, had blogs for as long as your archives go back. I just never kept them. 🙂

    I really might end up collaborating with you on your libgdx extension, I love the Scene graph idea, I’m going to experiment with your code.


  5. admin on March 13th, 2013 3:29 pm

    Michael, I hope you find my extensions useful. I like the scene-graph approach to the application framework as it is very intuitive and coming from Flex quite familiar too.

    I am going to go through the ‘getting started’ with the Caustic SDK on github when I get a moment.

    Can you tell me if there is a way to synchronise the Android layer with the underlying Caustic beat engine? My little Tonome demo just times the beats itself but I can see this being a problem. Almost like it needs a midi clock-in sort of signal it can latch onto from Caustic.

  6. Michael Schmalle on March 14th, 2013 9:26 am


    There are native beat and measure call backs when the app is running.

    I also wrote a thread the actually calculates steps in between the beats at a pretty high precision as well for my apps.

    BTW, I have to update the key in the lib, or you won’t hear sound.

    I am totally rethinking all app my app framework now. I do use RoboGuice and Gucie for IoC.

    mike at, we should chat.

    PS I’m getting into JavaFX because of you. 🙂