Hello there,
I used to load and control script via CLI with sonic 3 but now in new sonic 4 none of the script worked? how to load script on boot?
Thanks
Hello there,
I used to load and control script via CLI with sonic 3 but now in new sonic 4 none of the script worked? how to load script on boot?
Thanks
Hi there,
working with Sonic Pi from the command line has never been officially supported. Whilst there have been (and still are) external tools that enable this, they do need to continually be updated as they rely on Sonic Pi’s internals which are highly subject to change. For example, v4 increased security measures which conflicted with existing tools - which is likely what you’re experiencing.
The supported way to load an external script when booting Sonic Pi is to put your code in ~/.sonic-pi/config/init.rb
. Sonic Pi will load and execute that script when it boots - this is useful for putting functions and other code you wish to always have available in your session.
Further to Sam’s comments, this can still be done by rewriting sonic-pi-cli to accommodate the changes that have taken place since version 3.3.1 You now need to to know the security token which is regenerated when Sonic Pi starts and the port to which OSC messages are sent which again can be dynamically allocated. I have a working version for Sonic Pi 4.x versions and at present it works also for the version 5 previews. However, it obtains data in unsupported ways and there is no guarantee that it will continue to work, nor can I accept any responsibility if it doesn’t.
having said that you can install if from RubyGems.org where I have just uploaded it
gem install sonic-pi-cli4
It works as the previous version but uses sonic_pi4 as the command
eg sonic_pi4 play 72
or sonic_pi4 "run_file 'path_to_file'"
It can be a little slow to respond the first time you run it.
@samaaron thanks that worked and it loads and play the script!
Thanks @robin.newman , you always know the answers!
I have tried that but not sure how to obtain the token, it used to be from log files i think?
I am getting this on Pi 64 bit with
Maintainer: Robin Newman <rbnpiman@gmail.com>
Architecture: arm64
Version: 1:4.3.0
When run your gem
root@tower:/srv# sonic_pi4 play 2
ERROR: Sonic Pi is not listening on 32211 - is it running?
root@tower:/srv# ps axfu|grep sonic
pi 1255 0.0 0.0 2064 504 ? S 02:37 0:00 \_ /bin/sh /usr/bin/sonic-pi --geometry 700x1200
pi 1260 0.0 0.0 6556 2944 ? S 02:37 0:00 | \_ /bin/bash /opt/sonic-pi/bin/sonic-pi
pi 1275 3.0 2.6 945660 103884 ? Sl 02:37 4:06 | \_ /opt/sonic-pi/bin/../app/build/gui/qt/sonic-pi
pi 1367 0.0 0.5 1162116 19936 ? Sl 02:37 0:01 | \_ ruby /opt/sonic-pi/app/server/ruby/bin/daemon.rb --no-scsynth-inputs
pi 1604 0.0 0.0 2064 480 ? S 02:37 0:00 | \_ sh /opt/sonic-pi/app/server/beam/tau/boot-lin.sh
pi 1614 0.3 2.1 2792696 83216 ? Sl 02:37 0:32 | | \_ /opt/sonic-pi/app/server/beam/tau/_build/prod/rel/tau/erts-12.2.1/bin/beam.smp -C multi_time_warp -c true -- -root /opt/sonic-pi/app/server/beam/tau/_build/prod/rel/tau -progname erl -- -home /home/pi -- -noshell -s elixir start_cli -mode embedded -setcookie 7MPBYL37DBNWGCHBUVUVTSTTUVHVG4MVQ6IPS5LXT2BDKSFMUNKA==== -config /opt/sonic-pi/app/server/beam/tau/_build/prod/rel/tau/releases/0.1.0/sys -boot /opt/sonic-pi/app/server/beam/tau/_build/prod/rel/tau/releases/0.1.0/start -boot_var RELEASE_LIB /opt/sonic-pi/app/server/beam/tau/_build/prod/rel/tau/lib -- -- -extra --no-halt
pi 1607 0.1 1.6 2011764 65224 ? Sl 02:37 0:08 | \_ /usr/bin/ruby2.7 --enable-frozen-string-literal -E utf-8 /opt/sonic-pi/app/server/ruby/bin/spider-server.rb -u 38767 38768 38769 38769 4560 38770 38774 883616406
root 53111 0.0 0.0 5924 696 pts/3 S+ 04:52 0:00 \_ grep sonic
root@tower:/srv#
What I am missing?
Thank you both.
P
Hm. Are you sure you have sonic pi running? The gem is finding a port from your log file but can’t communicate with sonic pi.
It finds the token from a current log file. It changes each time sonic pi is started.
I assume the gem is giving help info if you just type.
sonic_pi4
I’ve just done a fresh install onto a memory card running latest os and sonic pi 4.3 and it works fine for me.
You right I have the sonic pi running as pi
but running the nodejs
server as root,it works when running as correct user pi
Thanks!
However I am not sure if ended up using the SonicPI as on aarm64 PI somehow the sounds eventually stops happening, SonicPi still runs but nothing comes out?. PulseAudio?
I also noticed my older project on 3.x used Jackd new 4x does not?
Thanks
How about re-loading a script? Would that be posible?
I’d like to leave a stream running and, when someone edits the code, it auto-reloads…
Command line tools was my first thought, but considering this thread it might be easier to just hack it into the UI …
Sonic Pi does still use jackd, but by default on the raspberry pi it defaults to sending audio output to pulseaudio via a jack to pulseaudio plugin. However if you wish you can start up Qjackctl BEFORE starting Sonic Pi and configure that to connect to your external usb soundcard and then start it. In that case Sonic Pi will realise that jack is already running and will not attempt to connect it to pulseaudio. Of course it’s a good idea in that case to select an alternative audio output eg HDMI or built in av jacksocket for pulse use by right clicking the speaker icon.
Not sure why Sonic PI should stop, unless of course your program is steadily creating further resources which are not released. For example with_fx inside a live_loop will create a fresh instance each time the loop runs. Also if your machine sleeps that may create a problem.
As far as jfaerman’s comment is concerned. The cli can send changed script to sonic pi, but you should send a sonic_pi4 stop command in between, otherwise it will start a new instance running on top of the previous one. I did a jukebox project six years ago with TouchOSC as an interface which utilised this. The software is here but that version needs updating for Sonic Pi 4.3 (which I have done but not published)
Hello there and thanks again,
so the init.rb does the job but does not actually shows the code in the Sonic EDITOR?
The CLI utility works when I am right user pi
but after 20h i get this and sonic PI dies… ? it seem the whole X with it…
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 284185 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = PulseAudio_to_JACK was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = PulseAudio_to_JACK was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 13053 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client JACK_to_PulseAudio finished after current callback
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client PulseAudio_to_JACK finished after current callback
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 879246 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 8162 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 253098 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = PulseAudio_to_JACK was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 194653 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackTimedDriver::Process XRun = 151797 usec
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = SuperCollider was not finished, state = Running
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackEngine::XRun: client = JACK_to_PulseAudio was not finished, state = Triggered
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackAudioDriver::ProcessGraphAsyncMaster: Process error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckSize error size = -1 Size() = 4
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckRead error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, Jack main caught signal 15
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckSize error size = 0 Size() = 12
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckRead error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckSize error size = -1 Size() = 4
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckRead error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckSize error size = 0 Size() = 12
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckRead error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, WARNING: 17 message buffer overruns!
[2023-03-29 07:11:01] Process 2158 still running, waiting for it to finish... [4]
[2023-03-29 07:11:01] log: UTF-8, UTF-8, Cannot read socket fd = 6 err = Success
[2023-03-29 07:11:01] log: UTF-8, UTF-8, CheckRes error
[2023-03-29 07:11:01] log: UTF-8, UTF-8, JackSocketClientChannel read fail
[2023-03-29 07:11:02] Process 1946 still running, waiting for it to finish... [4]
[2023-03-29 07:11:02] Process 2165 still running, waiting for it to finish... [4]
[2023-03-29 07:11:02] Process 2158 still running, waiting for it to finish... [3]
[2023-03-29 07:11:02] log: UTF-8, UTF-8, Exiting - shutting down scsynth server...
[2023-03-29 07:11:02] log: UTF-8, UTF-8, Sending /quit command to scsynth
[2023-03-29 07:11:02] log: UTF-8, UTF-8, Stopping OSC server...
[2023-03-29 07:11:02] log: UTF-8, UTF-8, Stopped OSC server...
[2023-03-29 07:11:03] Process 1946 terminated
[2023-03-29 07:11:03] Process Booter - killing scsynth with pid 1949 and args ["-u", "36502", "-a", "1024", "-m", "131072", "-D", "0", "-R", "0", "-l", "1", "-i", "0", "-o", "2", "-b", "4096", "-B", "127.0.0.1", "-c", "128", "-z", "128", "-U", "/usr/lib/SuperCollider/plugins"], wait_thr status: #<Process::Waiter:0x00000055902d75b8 sleep>, sleep
[2023-03-29 07:11:03] Sending TERM kill command to 1949
[2023-03-29 07:11:03] Process 1949 still running, waiting for it to finish... [5]
[2023-03-29 07:11:03] Process 2165 still running, waiting for it to finish... [3]
[2023-03-29 07:11:03] Process 2158 still running, waiting for it to finish... [2]
[2023-03-29 07:11:04] Process 1949 terminated
[2023-03-29 07:11:04] Process 2165 still running, waiting for it to finish... [2]
[2023-03-29 07:11:04] Process 2158 terminated
[2023-03-29 07:11:05] Process 2165 still running, waiting for it to finish... [1]
[2023-03-29 07:11:06] Process 2165 still running, waiting for it to finish... [0]
[2023-03-29 07:11:07] Sending KILL kill command to 2165
[2023-03-29 07:11:07] Process 2165 still running, waiting for it to finish... [5]
[2023-03-29 07:11:08] Process 2165 terminated
[2023-03-29 07:11:08] Daemon Booter - Over and Out.
At this stage I don\t think I can help without having further details of what exactly you are sending to Sonic Pi via the cli are you using run_file or run_code commands? The former will start a fresh instance each time unless you send a stop command first. If the original code remains running then this can build up dem,ands on scsynth and in time it can’t keep up and xruns will occur. Alternatively what buffer size do you have with scsynth? too low and you can get xruns as well.
I think this thread is probably getting a bit specific to your situation, so if you like to send me a direct message on in-thread that might be a better place to continue this.