I want to add more clicks to my pisound. click 1 for patch 1, click 2 for patch 2, all the way up to maybe 6 (?) clicks? clicks 1 - 3 are easy to modify obviously.
Seems like I just need to do a bit of hacking here, and (I guess) recompile this for my pi? Not sure how to do that, is there a broad outline of how to do that somewhere?
Hey, it’s actually pretty easy and doesn’t require modifying pisound-btn.c, unless you want to go beyond the limit of 8 clicks.
Just put your script in /usr/local/pisound/scripts/pisound-btn (make sure to chmod +x the script) and using pisound-config, set all of single, double, triple and other actions to execute your script.
The click scripts receive the number of clicks that ocurred as the first argument ($1), so you can differentiate which patch to launch from the same script file.
Basically 8 identical scripts, once for each pure data patch, with each patch looking for main.pd in a different folder.
start_patch_one.sh:
if [ -z "$PURE_DATA_PATCH" ]; then
log "No patch found in attached media, checking /usr/local/puredata-patches..."
PURE_DATA_PATCH=`find /usr/local/puredata-patches/patch_one/ 2> /dev/null | grep main.pd | head -1`
fi
My /usr/local/puredata-patches/ folder looks like:
Hey, you should use a single script for all kinds of clicks to either start the individual script, or to look for the patch, somehing like:
# I have not tested this script, but it should show the general idea.
case $1 in # Might need to use case "$1" in instead (added double-quotes for $1)
1) # Might need to use "1" instead
PATCH_DATA_DIR="/usr/local/puredata-patches/patch_one"
;;
2)
PATCH_DATA_DIR="/usr/local/puredata-patches/patch_two"
;;
#...
esac
PURE_DATA_PATCH=`find ${PATCH_DATA_DIR} 2> /dev/null | grep main.pd | head -1`
#...
$1 will be equal to the amount of clicks you made, so you can use it to figure out what to do.
Here’s some suggested steps on how to debug this issue:
First you should verify that your script does get executed. This can be done by using a simple echo or log from common.sh which for convenience includes the current timestamp in the beginning of the line.
Before case "$1" in add:
...
log Executing multi_click.sh $@
case "$1" in
...
The $@ will be replaced by all of the arguments that were used to exeucte the script. You can place log lines in more locations to inspect some variables or whether some particular lines get executed.
Another good location to place a log line would be near the end:
...
log Used "${PATCH_DATA_DIR}" for searching, found "${PURE_DATA_PATCH}"
start_puredata "$PURE_DATA_PATCH" &
The output can be seen by running sudo journalctl -f -u pisound-btn. Once you execute this command, try triggering different actions to see some output being produced.
Ok, so i got this working. I now know a little bit more about linux scripting and how to debug a script. thank you!
Here is the script, if anyone is curious. I guess you could map this to every click option in pisound-config. The script looks for a usb drive with main.pd, and if it doesn’t find that, it counts the button clicks and launches the corresponding patch.