Quantcast
Channel: Squeezebox : Community : Forums - Linux / Unix
Viewing all articles
Browse latest Browse all 1518

Knob - Volume - mouse scroll hack

$
0
0
Here is a shell script that takes input from the mouse scroll wheel to change the volume of the named local player. I wrote it with a view to hacking a Poundland mouse plus rotary encoder to put a real volume knob on my LMS / Squeezebox computer. I would welcome any comments or suggestions.
Code:

#!/bin/bash

#use command - xinput - to find id of mouse who's scroll wheel you want to use
mouseID=10
player='Dining Room'
IP="127.0.0.1 9090"




  #Need to convert player name to mac address
  #find number of players
 
  nplayers=$(echo "player count ?" | nc -q1 $IP | tail -c 2 )


  n=0
        #loop through players to determine mac address of player

        while [ $n -lt $nplayers ]
        do
                pmac=$(echo "player id $n ?" | nc -q1 $IP | tail -c 28 | sed -r 's/%3A/:/g' )
                pname=$(echo "player name $n ?" | nc -q1 $IP | cut -c 15- | sed -r 's/%20/ /g')
                        if [ "$pname" = "$player" ]; then
                                playerID=$pmac
                                echo
                                echo "$pname"  "$pmac"
                        fi
                n=$(($n + 1))
        done

echo
OldScroll=$(xinput --query-state $mouseID | grep 'valuator\[2\]\=' | cut -c 14-)
echo "Initial wheel position: $OldScroll"
playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
echo "Initial Volume: $playerVOL"
echo

# Infinite loop checks to see if mouse scroll wheel has turned and in which direction - Ctrl C to quit

while :
do

scroll=$(xinput --query-state $mouseID | grep 'valuator\[2\]\=' | cut -c 14-)

if [ $OldScroll -gt $scroll ]; then
        playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
        setVOL=`expr $playerVOL + 5`
        printf "$playerID mixer volume $setVOL\nexit\n" | nc $IP
fi

if [ $scroll -gt $OldScroll ]; then
        playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
        setVOL=`expr $playerVOL - 5`
        printf  "$playerID mixer volume $setVOL\nexit\n" | nc $IP
fi
 
OldScroll=$scroll 
sleep 0.2

done


Viewing all articles
Browse latest Browse all 1518

Trending Articles