Changing Patchbox Modules with "The Button"

Hello Community,

i’m trying to setup patchbox so that i can switch between different modules with The Button.
I want to use the Modep module and alternatively switch to a custom module named “vcvrack”. I installed VCVRack on my Pi as described here https://github.com/hexdump0815/vcvrack-dockerbuild-v1 and it works as advertised, though i have yet to check the performance.
I made a custom script named deactivate_module.sh which i placed in the /usr/local/pisound/scripts/pisound-btn and bound it to HOLD_3S in the pisound-btn.conf of each module i want to use (modep, vcvrack). Also chmod -ed it to make it executable.
I proceeded the same way with two scripts named change_modep.sh and ‘change_vcvrack.sh’ which i bound to CLICK_1 and CLICK_2 in the default patchbox OS setting of the button.
The content of these scripts is just #!/bin/sh and then

. /usr/local/pisound/scripts/common/common.sh
patchbox module deactivate >/usr/local/pisound/scripts/pisound-btn/logdeactivate.txt

...

. /usr/local/pisound/scripts/common/common.sh
patchbox module activate modep >/usr/local/pisound/scripts/pisound-btn/logmodep.txt

...

. /usr/local/pisound/scripts/common/common.sh
patchbox module activate vcvrack >/usr/local/pisound/scripts/pisound-btn/logvcvrack.txt

When I’m calling these scripts manually by cd-ing into the folder and then starting them everything works as intended and the logfiles show the correct output. Also when I’m changing modules via the Patchbox UI, everything works just fine. But when pressing the Button to execute the scripts the process kind of breaks in unpredictable ways. The logfiles are created, but they are completely empty.
When deactivating, the status of patchbox module status shows None, but the patchbox button status remains unchanged. Also i can still reach the MODEP-UI with other devices via Pi’s Hotspot. When i then deactivate the module (again) via patchbox UI, there are still services getting deactivated, which wouldn’t happen, when executing the scripts manually.

My guess is, it has something to do with the Button’s permissions.
Does anyone have a solution for this issue? Maybe @Giedrius can help? I saw this post https://community.blokas.io/t/the-button-user-and-permission/1249 but couldn’t really get to the ground of it.
Any help would be appreciated :slight_smile:

For reference: I’m working on a Pi 4 B, 4GB. I am also using a FanShim on my Pi as described in this post https://community.blokas.io/t/pisound-with-raspberry-pi-4/1238/9 and it works fine for me. (Didn’t install the FanShim Software because i read somewhere that it might conflict with the Pisound Button. So the fan just runs permanently, which produces a little noise, but is not really a problem for me). Also i activated the “pi 4 fix” described here https://community.blokas.io/t/pisound-with-raspberry-pi-4/1238/12 with pisound-config, because otherwise the pi wouldnt correctly boot with the FanShim and Pisound mounted.

Hey, the Pisound’s set of button scripts get changed when switching Patchbox module, so that each module can have its own set of interactions, like when MODEP is up, it allows for switching between pedalboards, when PD is up, it restarts PD, searching for main.pd in defined search locations, etc…

I think this could be overridden without having to modify patchbox itself - if a config file path is specified for pisound-btn process, it overrides the PISOUND_BTN_CFG environment variable, which is used by patchbox for controlling the currently active button config.

You can force your own config to always be used:

# Make your own copy of the config that you can modify to your needs:
sudo cp /etc/pisound.conf /etc/my-pisound.conf

# Customize pisound-btn.service:
sudo cp /usr/lib/systemd/system/pisound-btn.service /etc/systemd/system/
sudo nano /etc/systemd/system/pisound-btn.service

# Edit ExecStart= line so it looks like this:
# ExecStart=/usr/bin/pisound-btn --conf /etc/my-pisound.conf

sudo systemctl daemon-reload
sudo systemctl restart pisound-btn

Now the pisound-btn should always use the scripts as set in /etc/my-pisound.conf.

The patchbox utility will still restart the pisound-btn when swtiching modules though, which may still interfere. In that case, nohup may have to be used in your scripts to disassociate the commands it executes from the pisound-btn process itself, so they’re not impacted by the service restarts.