Osc json format to send to open stage control (a must-have software !) [Solved]

Hi there,

I keep exploring open stage control (https://osc.ammd.net/) to create a visual interface for Sonic Pi.

the doc concerning edit the interface in open stage control https://osc.ammd.net/extras/remote-control/

I need to send the osc message
In python using the python-osc it works with this code

Test d'envoi vers open stage control d'un message osc
pour changer un label dynamiquement
import argparse
import random
import time

import json

from pythonosc import osc_message_builder
from pythonosc import udp_client

jsonData = '{"label":"New Label"}'
jsonToPython = json.loads(jsonData)

pythonDictionary = {'label':'nouveau nom', 'color':'pink'}
dictionaryToJson = json.dumps(pythonDictionary)

if __name__ == "__main__":
  parser = argparse.ArgumentParser()
  parser.add_argument("--ip", default="",
      help="adresse du serveur openstagecontrol")
  parser.add_argument("--port", type=int, default=8080,
      help="8080 the port is listening on")
  args = parser.parse_args()

  client = udp_client.SimpleUDPClient(args.ip, args.port)

client.send_message("/EDIT", ("push_4", dictionaryToJson))
client.send_message("/EDIT", ("push_4", '{"label":"New Label"}'))

Now i need to make it work in Sonic Pi but i miss something about the syntax.

live_loop :changeLabelPush_4 do
  options = {"label" => "depuis sonic pi"}
  require 'json'
  # => true
  puts options
  osc_send "",8080,"/EDIT", "push_4", options
  sleep 4

it give this in the sonic pi journal

{run: 17, time: 4.0, thread: :live_loop_changeLabelPush_4}
 ├─ {"label"=>"depuis sonic pi"}
 └─ OSC ->, 8080, /EDIT, ["push_4", {"label"=>"depuis sonic pi"}]

and causes an error in the open stage control log

OSC received: { address: '/EDIT', args: 'push_4' } From :
[Renderer process error]
Uncaught SyntaxError: JSON5: invalid character 'u' at 1:1
at default (node_modules/json5/dist/index.js:1:0)
at default (node_modules/json5/dist/index.js:1:0)
at default (node_modules/json5/dist/index.js:1:0)
at default (node_modules/json5/dist/index.js:1:0)
at default (node_modules/json5/dist/index.js:1:0)
at EDIT (src/browser/js/app/remote-control.js:11:53)
at exec (src/browser/js/app/remote-control.js:163:28)
at receive (src/browser/js/app/osc.js:38:72)
at receiveOsc (src/browser/js/app/ipc/callbacks.js:17:12)
at require (src/browser/js/app/ipc/index.js:40:16)

Open stage control needs this

OSC received: { address: '/EDIT',
args: [ 'push_4', '{"label":"New Label"}' ] }

Some clever ideas to help ?

well i find the good syntax. May it helps.

live_loop :changeLabelPush_4 do
 require 'json'
 options = { :label => "from sonic pi"}.to_json
 puts options
 osc_send "",8080,"/EDIT", "push_4", options
 sleep 4  

I only used OSC with processing and haven’t sent OSC yet, but it seems to me that what SP is sending is what you want.
From the error message I guess that the second argument is not recieved, possibly a type conversion error?

yes with my last post it works :slight_smile: that’s why i put [solved]