I’m awaiting my Pisound, should arrive tomorrow! I primarily use SuperCollider for audio projects and I’m looking for ways to autostart patches. Using Cronjob hasn’t been working for me. Could anyone give me any tips on how I could modify the single_click.sh script to start jackd and run a supercollider patch instead of running Pure Data? The commands that I use to start up a patch are as follows:
/usr/bin/jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &
su root -c “sclang -D /home/pi/mycode.scd”
Clicking once will simply execute the
/usr/local/etc/pisound/single_click.sh script as if you’d run it from shell yourself. So you could just replace it with your own script, or modify existing one - it’s not only starting Pure Data, but also does things like mounting attached USB media and connecting ALSA midi devices to the launched Pure Data instance.
The main line is this one: https://github.com/BlokasLabs/pisound/blob/master/pisound-btn/single_click.sh#L88
The key thing is to have & at the end of the command - it causes it to start PD in background, so the button remains responsive.
The ‘nohup’ at the beginning is meant to keep the launched Pure Data running, even if the pisound-btn daemon gets killed. Otherwise, the child processes spawned by it would get terminated upon the daemons termination.
It’d be great to build a library of the button scripts customizations for different kinds of software, we’d definitely accept pull requests or ideas how to go about it.
Thanks for the help! I’ll definitely try to create a modified script for SC. If it works then I’ll make a pull request with an additional file. Probably named single_click_SC_patch.sh or something like that.
Oh also, is there any kind of trick to setting an environment variable within a bash script? When I run a script that has “export DISPLAY=:0.0” in it, the variable doesn’t seem to get set. Do I need a different command?
When I test this, it seems like the variable is set, but within the wrong environment? Or that the variable is set but that the scope is local and thus doesn’t carry forward when the other commands are executed. Is there a way to set a global environment variable that will maintain it’s value once the script is complete?
It depends on how the script gets executed - if it runs in its own shell process, it inherits the parent processes’ environment by copying it, and then it no longer has access to the process it was spawned from.
However, if you ‘source’ a shell script, it runs within the same process, so the environment variables that were set will be accessible from the same process and processes spawned later. If I remember right this can be done in two ways:
It’s similar to doing #include “…” in C/C++.
Thank You! The source command works. I expect it to be to pretty simple to get the script running once I have the Pisound. I’ll just have to change the click.sh script to run single_click.sh with the source command as well. Really looking forward to diving into this.
hey guys, sorry to bump an old thread but I’m looking to do this same thing.
I created my single_click_supercollider.sh in the scripts folder which looks like this:
/usr/local/bin/jackd -P75 -dalsa -dhw:1 -p1024 -n3 -s -r44100 &
sclang -D /home/pi/mycode.scd
I can trigger this from the command line with
and it works like a charm, but I am having problems getting the button to kick it off. Simply subbing in “single_click_supercollider.sh” instead of “single_click.sh” in the “click.sh” does not seem to do it.
I’m guessing my issue is with the sclang command, that it needs to be wrapped and sent as either a su root or sudo su command, but I thought I would check in to see if anyone has had success on this front?
Hey there, so I don’t have my pisound yet, but I should hopefully get it next week. I think I have a method that should work but it will have to wait till I get a chance to test it. I’ll let you know next week.
too good, cheers for looking into it!
Hey, use 48000 for sampling rate, 44.1kHz is not supported natively by Pisound.
I think you should launch sclang in the background the same way as puredata is launched here:
nohup should keep the launched application running even if pisound-btn terminates and & at the end makes the command run in the background, so the control is returned to the button.
After triggering the script with the button you may try checking whether the sclang process is running using
ps -ef | grep sclang
Also it does get launched as root user, on Raspbian Stretch, these new lines had to be added to
single_click.sh in order for the Pure Data GUI to appear for the user: [SOLVED] Not working anymore: single click to launch Pd patch from USB
You may try adding those lines to your single click script.
Okay! Got my pisound today, yay! I’m able to get SuperCollider running when I manually run my script, but it doesn’t run when I replaced the single_click.sh script in click.sh with my own script.
Could you tell me where the log command logs itself? I see this used in the pisound scripts, but I can’t find where this is logging to.
If I can find out if the script is throwing any errors then I can maybe figure out what is wrong.
When I add nohup to the command to start sclang I get the following message: “nohup: nohup: ignoring input and appending output to ‘/home/pi/nohup.out’ignoring input and appending output to ‘/home/pi/nohup.out’”
Any idea what this means?
So I’m still trying to get a SuperCollider patch started after a single click from the Pisound button. The button is working and responding as expected (I’ve verified it’s working using the flash_leds command in a script), but I cannot get Jack and SuperCollider to start. Here is my script:
/usr/bin/jackd -P75 -dalsa -dhw:1 -p64 -n3 -s -r48000 &
echo “Starting Jackd”
sclang -D /home/pi/mycode.scd &
echo “Starting SuperCollider”
The lights flash correctly but Jack and SuperCollider do not start when I run this script from the button. If I run this script manually (by typing ./scstart.sh in the terminal) everything works as expected and Jack and SuperCollider start and it makes sound. Does anyone have any ideas on how I can adjust my script to get it to run from the button? Adding nohup to sclang does not change anything.
try login (or s )in as root, and run the script as toot, see if it displays any errors
… my guess would be you have something about sc setup in your pi user profile (eg. patch to sclang)
the other thing you could do, is to make the script (or at least the application starting bit) run as the PI user.