# Sonic Pi Headless Doesn't receive OSC cues?

**URL:** <https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171>\
**Category:** Support, Help & Resources\
**Created:** [March 26, 2019, 5:58pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171 "2019-03-26T17:58:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 26, 2019, 5:58pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/1 "2019-03-26T17:58:40Z")

</div>

So I’m trying to run Sonic Pi with a RPi without any gui, as I’ll be using it to make a sort of live synth/seqencer. I’m controlling everything using Python and using psonic to interface Python with Sonic Pi.

When I open Sonic Pi non-headless (with the gui and everything) it all works fine.  
But as soon as I start only the Sonic pi Server (i’ve tried both directly starting it with ruby and using ‘sonic-pi-tool’) the server only responds to run commands, and does not receive any OSC cues. Why is this? How can I fix this?

I’ve also tried sending direct OSC cues without using psonic, and to no avail.

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 26, 2019, 11:31pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/2 "2019-03-26T23:31:11Z")

</div>

I ran into that issue when making a Python version of [sonic-pi-tool](https://github.com/emlyn/sonic-pi-tool), and found [this](https://github.com/repl-electric/sonic-pi.el/issues/19#issuecomment-345222832) issue-comment. In short, you can get it working by adding the following to the start of any code you evaluate:

```ruby
@osc_server ||= SonicPi::OSC::UDPServer.new(4559, use_decoder_cache: true) # __nosave__

```

Or if you use my python sonic-pi-tool linked above, this should be taken care of automatically.

---

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 26, 2019, 11:40pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/3 "2019-03-26T23:40:58Z")

</div>

I’d love to use it, but I’m just wondering how I’d run a control command with an OSC cue with the resource without having to send my own OSC cue (the source of my problem)?

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 26, 2019, 11:54pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/4 "2019-03-26T23:54:59Z")

</div>

I’m not sure I’ve understood exactly what’s not working, but I think once the above snippet has been run on the Sonic Pi server (using `sonic-pi-tool eval "code..."`), the OSC server should be running and from that point it should respond to OSC cues.

---

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 27, 2019, 4:04am UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/5 "2019-03-27T04:04:02Z")

</div>

Thanks! I’ll try again tomorrow and see where that gets me!

---

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 27, 2019, 6:15pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/6 "2019-03-27T18:15:44Z")

</div>

When trying to start the server using your tool, I get [this](https://pastebin.com/na1i0NpS) error.

Regardless, I’ve been trying to use the sonic-pi-tool written in rust that your tool is likely based off of. The server starts fine using the rust-based implementation.  
But even with the code header you suggested, my error persists. Allow me to explain my problem in greater detail.

I’m running [this Python Script](https://pastebin.com/N1Wiieyw). Everything works **exactly** as intended (albeit a little slow) when using Sonic Pi with its GUI.

When I start the Sonic Pi server using any method that isn’t opening its’ GUI, my program does not work as intended. The run() part of the code does, but this part does not:  
`sender.send_message('/trigger/prophet', [(72-n), 1]);`

I assume this is because the server is not receiving OSC cues when it is not running with the gui. The problem persists despite that fact that I’ve added  
`@osc_server ||= SonicPi::OSC::UDPServer.new(4559, use_decoder_cache: true)`  
to the beginning of the one piece of code that is ran on the server.

Is there any other way you know of to fix this? Am I implementing the header wrong?

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 27, 2019, 7:25pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/7 "2019-03-27T19:25:32Z")

</div>

I think the error in my script is probably to do with differences between different Python versions, as I haven’t tested it very thoroughly. What version of python are you using? You could try using a different version if you have one installed (e.g. `python3 sonic-pi-tool.py eval ...`).  
However, I’m not very hopeful that will help, as it looks like what you’ve done to add the OSC setup code at the start should be doing the same thing anyway.  
If I get a bit of spare time I’ll see if I can reproduce your problem and work out what’s going on.

---

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 27, 2019, 8:03pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/8 "2019-03-27T20:03:09Z")

</div>

Thanks in advance! I’ve been searching for 20+ hours at this point trying to find a solution, anything you can find that I can’t would be immensely helpful!

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 28, 2019, 10:33am UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/9 "2019-03-28T10:33:56Z")

</div>

I tried out your code, and I see the same thing. The fix above used to work for what I’m pretty sure was the same problem, but maybe that was with an older version of Sonic Pi.  
I’m not really sure what else to try, but I found a Sonic Pi [commit](https://github.com/samaaron/sonic-pi/commit/d1c1ee99d460a38607a8cd654be09eab90c8b419) that looks like it might fix this in the next version, so hopefully that comes out soon and you can try with that. Or you could try compiling it yourself, although it can be a bit fiddly - I’ve done it in the past but can’t get it working at the moment.

---

<div class="post-metadata">

**Author:** ![Speuce](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/speuce/32/902_2.png) [@Speuce](https://in-thread.sonic-pi.net/u/Speuce)\
**Post date:** [March 28, 2019, 3:51pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/10 "2019-03-28T15:51:06Z")

</div>

I might try and compile the development version if it really comes down to it. I’m not too familiar with ruby though, so it might take me a while. Should I submit an issue report on github?

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 31, 2019, 10:39am UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/11 "2019-03-31T10:39:01Z")

</div>

If you do try to build it yourself, I’ve found the `build-osx-app` script in the `app/gui/qt` folder to be a good starting point (if you are on OSX, there are others for other platforms). But it generally doesn’t just work first time, so I usually copy the commands out and execute them one by one manually, trying to fix things as I go along.

You could file an issue if you want. I suspect the response will be that this is not a supported use of Sonic Pi, but you might get some hints on how to work around it (or whether it’s likely to be fixed in the dev version and therefore worth trying to build it).

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [March 31, 2019, 2:57pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/12 "2019-03-31T14:57:37Z")

</div>

I take a slightly differnt approach to running Sonic Pi headless, which is to run it with the gui in a virtual X windows using the tehcnique shown [here](http://in-thread.sonic-pi.net/t/sonic-pi-for-standalone-installations/225/4?u=robin.newman)  
I have used this with quite a few projects and it seems to work well.

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 31, 2019, 7:28pm UTC](https://in-thread.sonic-pi.net/t/sonic-pi-headless-doesnt-receive-osc-cues/2171/13 "2019-03-31T19:28:17Z")

</div>

For the record, headless support with Sonic Pi has never been officially supported. I hope to change this in the future but for now, the GUI is required.

Of course it should be possible to get things working with some coding and experimentation but it’s not something I have the energy to support at this stage.

I can say that my new studio is making the idea of headless Sonic Pi instances useful for me personally so I think there’s a good chance this situation will change in the short to medium term 🙂
