Simple OSC demo?

Hi all, I just picked this up. I would like a simple demo of using OSC to play a note sent via OSC client. I’ve seen the OSC section of the tutorial, but I am not able to get anything to play. How can I debug the OSC client/server connection? I’m seeing nothing in the logs regarding an incoming message, even with log cues option turned on. I’ve tried the following:

# Server code to set a synth note?
live_loop :foo do
  use_real_time
  a, b, c = sync "/osc*/trigger/prophet"
  synth :prophet, note: a, cutoff: b, sustain: c
end
# Server code to play a synth note?
use_synth :prophet
live_loop :foo do
  use_real_time
  a = sync "/osc*/trigger/prophet"
  play a
end
# Default python client code
from pythonosc import osc_message_builder
from pythonosc import udp_client

sender = udp_client.SimpleUDPClient('127.0.0.1', 4560)
# Edit params to [70] if just using `play` function on server
sender.send_message('/trigger/prophet', [70, 100, 8])
;; Default clojure/overtone client code
(use 'overtone.core)
(def c (osc-client "127.0.0.1" 4560))
;; Edit params to just 70 if using `play` function on server
(osc-send c "/trigger/prophet" 70 100 8)

Edit: Environment Info : Sonic Pi v3.2.2 / KDE Plasma 5 / Manjaro Linux 20.1 / Linux 5.8.8-arch1-1-surface / Microsoft Surface Book 2. The kernel comes from the linux-surface project and has stable support for all common types of networking.

Hi @errcsool and welcome :slight_smile:
First things first - can we have a few extra details? What computer Operating System are you using, and which version of Sonic Pi?

Thanks @ethancrawford! I’ve edited my post to include my environment info.

Hi there,

If you’re not seeing any incoming osc messages in the logs, then Sonic Pi isn’t receiving any for some reason.

Note that you don’t have to write a single line of code for the incoming OSC messages to be logged.

The main three reasons I’ve observed in this situation are:

  1. The “allow external OSC messages” checkbox hasn’t been checked in the preferences - assuming the OSC message is being generated by a separate computer.
  2. Firewall issues blocking osc network traffic
  3. Source OSC client not sending correctly (or to the correct up address).

Could you give us more information about your osc client?

You can actually play with OSC messages using just Sonic Pi and getting it to send OSC calls to itself. Once you are confident with this you can use an external client to send messages. I usually use a python script for this, or another easy thing to use is TouchOSC from your phone or tablet. iOS or Android.
Here is an example sending note pitch, duration and volume

use_osc "localhost",4560 #address where osc messages will be sent
use_synth :prophet

live_loop :send do #this live loop composes and sends OSC messages
  n=rrand_i(:c4,:c6)  #choose a note pitch in range :c4 to :c6
  d=[0.125,0.25].choose #choose a note duration
  v=[1,0.5,0.25].choose #choose a note volume (amplitude)
  osc "/play",n,d,v #send an osc message addressed to :localhost port 4560
  sleep d
end

#when program is run you should see cues in the cue log
#eg /osc:127.0.0.1:4560/play  [63, 0.125, 0.25]
#since we dont need the intial data after osc  ie :127.0.0.1:4560 you can wild card match it using /osc*/play
#the live loop below detects the  and extracts and uses the three data items from each
live_loop :receive do
  use_real_time
  note,duration,vol= sync "/osc*/play"
  play note,release: duration,amp: vol
end


#nb if you only send a SINGLE parameter say the note n
#then use n = sync "/osc*/play"
#play n[0]

@samaaron I’ll address those issues.

  1. My OSC client is on the same computer. I have tried with and without the allow external osc messages checked

  2. I have not set up a firewall on this computer

  3. I have also tried both localhost (127.0.0.1) and the ip on my wireless network (192.x.x.x)

My client code is documented by the lower two code blocks on my initial post. One is in python and the other is in clojure. They are equivalent to the tutorial Send/Receive OSC tutorial code.

Probably I am making a small mistake somewhere.

Edit: I have verified that my jack setup is working. I am using Cadence / Catia / pulseaudio-jack. I have verified that I can reliably turn on and off jack and associated pulseaudio bridge by testing with yoshimi, sonic-pi (IDE-only) , and youtube playback

@robin.newman Thank you so much for providing this code! Unfortunately it is producing a runtime error for me.

Runtime Error: [buffer 0, line 7] - Errno::ECONNREFUSED
Thread death +--> :live_loop_send
  Connection refused - send(2)

I see that you are running on Linux. Have you built SP 3.2.2 yourself? If so have you built the two erlang files osc.erl and osc_server.erl tp produce their .beam file equivalents? If you look at the log files in ~/.sonic-pi/log what does your erlang log show? I have seen this error message before with those using linux builds without having the erlang files set up correctly.

2 Likes

@robin.newman I’m using sonic-pi from archlinux’s community repo

OK I wasn’t aware that this existed. Had a brief look and it seems to build the erlang stuff OK. Do you notice anything untoward in the log files in ~/.sonic-pi/log? Another problem could be some other device opening and hogging port 4560. Try the program again after removing any externally connected midi device and restarting the computer.