Skip to content

Instantly share code, notes, and snippets.

@nilskoppelmann
Last active August 29, 2015 14:13
Show Gist options
  • Save nilskoppelmann/bc0a09ebff86106b1f27 to your computer and use it in GitHub Desktop.
Save nilskoppelmann/bc0a09ebff86106b1f27 to your computer and use it in GitHub Desktop.
Jukebox which plays sounds on keypress

jukebox

Jukebox which plays sounds on keypress

How to configure

In the configuration-file .jukeboxrc you mainly can set the desired location in which the sound-files are located and you have to set a few parameters for each "sound-effect".

# be sure note to put this in quotations
dir=~/Musik/sounds/

sounds[0]="Sound1:sound1.mp3:b"
sounds[1]="Sound2:sound2.mp3:c"
...
sounds[n]="Soundn:soundxy.mp3:i"

Explanation:

sounds[x]="Soundx:soundyz.mp3:x"

sound[x] x should be the number coming next in the array
be sure there is the row of numbers (in the example 0-n) is complete.

="Soundx is the name you want your sound-effect to appear as
:soundyz.mp3 is the filename
:x" x is (in this case) actual Key assigned to this sound-effect

Please do NOT forget to put : between the individual arguments!

#!/bin/bash
count=0
# defaults
dir=~/Music/sounds/
. .jukeboxrc
printf 'Press one of the following keys to play a sound:\n'
printf 'Do NOT press ENTER or SPACE,
otherwise the script will loop through the list of sounds
each time you press ENTER or SPACE\n'
for i in "${sounds[@]}"
do
a=(${i//:/ })
printf "${a[2]}\t${a[0]}\n"
done
while [ $count -ge 0 ]
do
read -sn 1 key
for (( i=0;i<=${#sounds[@]};i++ ))
do
if [[ ${sounds[$i]} == *$key ]]
then
a=(${sounds[$i]//:/ })
path=$dir${a[1]}
mplayer $path 2&> /dev/null
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment