Skip to content

Instantly share code, notes, and snippets.

@rgiot

rgiot/player.sh

Created Jan 11, 2018
Embed
What would you like to do?
Music player for CPC with M4
#!/bin/bash
CPCIP=${CPCIP:-192.168.1.22}
DB=${DB:-DSK}
shopt -s nocaseglob
function playdsk {
# Get the exact filename
local dsk="$1"
if ! test -e "$dsk"
then
dsk=$(ls "$DB"/*"$dsk"* 2>/dev/null)
if test -z "$dsk"
then
echo unable to find a DSK
exit 1
fi
fi
# Extract the unique file
local fname=$(iDSK "$dsk" -l 2>&1 | grep '0$' | sed -e 's/0$//')
iDSK "$dsk" -g "$fname" > /dev/null 2> /dev/null || (iDSK "$dsk" -g "$fname" ; exit -1)
test -e "$fname" || (echo ERROR while extracting $fname from $dsk ; exit 1)
# Play it
local fname2=$(echo $fname| sed -e 's/ //g')
mv "$fname" "$fname2"
xfer -y "$CPCIP" "$fname2"
rm "$fname2"
}
function list {
ls "$DB"/*.dsk | column
}
function random {
while read dsk
do
echo $dsk
playdsk "$dsk"
read -p "PRESS ENTER TO PLAY NEXT MUSIC" < /dev/tty
done < <(list | sort -R)
}
case $1 in
play)
playdsk "$2"
;;
list)
list
;;
sync)
#TODO add something to automatically download all these great songs (a list of links ?)
;;
random)
random
;;
help)
cat<<EOF
Music player for CPC with M4 by Krusty/Benediction.
This small script has been mainly created to listened on a real CPC the musics of SuTekH Of Epyteor.
It can of course be used for any other music spreaded in a similar way (but to DSK of SuTekH are way more interesting with animations).
Usage:
$0 play DSK/B2B6\ By\ Triace\ \(2017\)\(SuTekH\ Of\ Epyteor\).dsk # Play the music contained in the specified DSK
$0 play b2b6 # Play the music in the DSK file in the database that continas the specified string
$0 list # List the collection
$0 random # Play the collection in a random order
Known limitations:
- Do not work with DSK containing several files
- Random play needs to manually change the music
- If the CPC player needs the user to press a key before playing the music you still have to do it
Pre-requisits:
- iDSK
- xfer
Environement vaariables of interest:
- CPCIP: IP address of the M4 card
- DB: folder of the database of DSK
EOF
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.