Adding more button clicks

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.

/usr/local/pisound/scripts/pisound-btn/multi_clicks.sh:

#!/bin/sh

. /usr/local/pisound/scripts/common/common.sh
. /usr/local/pisound/scripts/common/start_puredata.sh

log "Searching for main.pd in USB storage!"

PURE_DATA_PATCH=`find /media 2> /dev/null | grep main.pd | head -1`

if [ -z "$PURE_DATA_PATCH" ]; then
    log "No patch found in attached media, trying to mount USB devices..."
    for usb_dev in `ls /dev/disk/by-id/ | grep usb`; do
        DISKPATH="/dev/disk/by-id/$usb_dev"
        DEV=$(readlink -f $DISKPATH)

        LABEL=`sudo blkid -s LABEL -o value $DEV`
        if [ -z "$LABEL" ]; then
            log "Skipping $DISKPATH"
            continue
        fi

        MEDIAPATH="/media/$USER/$LABEL"
        log "Mounting $DEV ($LABEL) to $MEDIAPATH"
        sudo mkdir -p "$MEDIAPATH"
        sudo chown $USER "$MEDIAPATH"
        sudo chgrp $USER "$MEDIAPATH"
        sudo mount "$DEV" "$MEDIAPATH"
    done

    log Executing multi_click.sh $@
    
    case "$1" in
        "1")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/first"
            ;;
        "2")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/second"
            ;;
        "3")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/third"
            ;;        
        "4")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/fourth"
            ;;
        "5")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/fifth"
            ;;
        "6")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/sixth"
            ;;
        "7")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/seventh"
            ;;
        "8")
            PATCH_DATA_DIR="/usr/local/puredata-patches/pd_patches/eighth"
            ;;
        #...
    esac
    
    PURE_DATA_PATCH=`find ${PATCH_DATA_DIR}/ 2> /dev/null | grep main.pd | head -1`
    
    log Used "${PATCH_DATA_DIR}" for searching, found "${PURE_DATA_PATCH}"
    
#...
fi

if [ -z "$PURE_DATA_PATCH" ]; then
    log "No patch found! Doing nothing..."
    sleep 0.5
    flash_leds 100
    exit 0
else
    log "Found patch: $PURE_DATA_PATCH"
fi

log "All sanity checks succeeded."

start_puredata "$PURE_DATA_PATCH" &
1 Like