Hi, I'm building out a new component, and was wondering what the best practice is regarding transferring data over OSC.
Is it preferrable to serialize/deserialize a large JSON object and send it as a single OSC message, or send a bunch of smaller OSC messages with specific information corresponding to individual widget fields?
My question is mostly in regards to packet loss, speed and stability. Thank you!
I think both approaches are valid, just beware the maximum packet size when sending JSON over udp.
I don't have a definitive answer for the speed / stability part, I guess it depends heavily on the implementation details and needs to be tested / measured.
Regarding packet loss, my take on it is the following : I only use osc over udp over the loopback network so that there's no chance of packet loss (on linux you must increase the udp buffer size to make sure of that, I think the other main platforms don't need that) and by no chance I mean I stress-test it like hell until no packet is lost.
So far, what I've found to be the most effective pattern, for reasonable data structures, is to serialize JSON from my DAW, then receive and deserialize it in a custom module, where I can easily debug, then send pretty benign OSC message from the custom module to my widgets to set up their parameters. This seems to work quite well and keep things nice and tidy.
to learn something new, which daw do you use and what kind of data you have to send in json format ?
thanks
Using Ableton, one example is an object containing all the clips and their related information (color, state, etc.)
Ableton suite ? a screenshot to show me where this can be aet ?
A screenshot won't show much. It's using their Python Remote Scripting API https://nsuspray.github.io/Live_API_Doc/11.0.0.xml
I'd use JSON objects too for this kind of data.
okay but what is your steps to export these data from ableton live. where to see these options ?
Need Max ?
You don't need max. Here's a bunch of examples:
https://github.com/gluon/AbletonLive11_MIDIRemoteScripts
Here's some loose doc:
It's kind of a dark art, as there's no real official documentation that outlines calllbacks and lifecycle and such, but using the above, it's figure out a-ble
thanks for these explanations
so actually, you write some python code using the api to tell ableton "export these data into json format" right ?
Would you show some example of this code, please ? Just few lines to catch a little example.
Cheers
idx = self.startingIdx
songToSend = {
"name" : self.name,
"parts" : {},
"clips" : {},
"tempo" : "",
"timeSig" : "",
"numScenes" : self.endingIdx - self.startingIdx,
"deckNum" : deckNum
}
while(idx < self.endingIdx):
if '[' and ']' in self.song.scenes[idx].name:
partName = self.song.scenes[idx].name.split('[')[1].split(']')[0]
partIdx = idx-self.startingIdx
songToSend["parts"][partIdx] = {"name" : partName}
for track in tracks:
if track.name not in self.clips:
self.clips[track.name] = {}
if track.name not in songToSend["clips"]:
songToSend["clips"][track.name] = {}
if track.clip_slots[idx].has_clip:
clip = track.clip_slots[idx].clip
songToSend["clips"][track.name][idx] = {"name" : clip.name, "color" : clip.color, "idx" : idx, "isPlaying" : clip.is_playing}
self.clips[track.name][idx] = Clip(track.clip_slots[idx], track.name, idx)
idx +=1
Constants.sendOSCMsg("/songs/song_loaded", json.dumps(songToSend))
1 Like
nice ! thanks for this piece of code.
Is there repo containing some examples to start with this api ?
Yep, this one:
https://github.com/gluon/AbletonLive11_MIDIRemoteScripts
That's about all you'll get though. Like I said, it's kind of a dark art.