Topic: A browser integration script for Pianoteq
This Linux script is designed to play midi files from a browser via Pianoteq
Script features:
-- tested on piano-e-competition.com
-- optional queued .fxp file(s) can be used:
very useful for testing .fxp prefix files
-- runs, developed and tested on PI4 Buster using Chromium browser & PT6
-- files are played using FIFO queue order
-- files may be adding during playback
-- notify-send used to post queued files
-- files played are moved to playlist directory
-- cpu set to performance during playback
-- queue may be continued
-- queue may be modified while playing
-- powerful optional rename by clipboard entry:
this allows one to select & copy virtual a "name" using the browser
here is a sample command-line Playlist listing from piano-e-competition:
pi@raspberrypi:~/Downloads/Q/Playlist $ ls
"Debussy 2 Preludes 'Oudine' and 'Lies Tierces Alternees'.mid"
'Paganini Liszt La Campanella.mid'
'Rachmaninov Sonata No. 2, Op. 36.mid'
'Ravel Alborada del Gracioso.mid'
"Schubert Fantasy 'Wanderer' in C Major, Op. 15.mid"
'Schubert Sonata in G Major, Op. 87, D894.mid'
'Schumann Variations "ABEGG", Op. 1.mid'
"Tchaikovsky Plentnev Suite from the ballet 'Nutcracker'.mid"
note: One can now sort by Composer name or use the os to move the composer's
midi files to a seperate folder even though the original midi name was the performer
Newbie warning:
The script needs the system to be setup for use:
Basically, one needs to setup up the browser to download and trigger the script and
setup the proper target folders for downloading
This can be done for Raspberry PI OS using a desktop entry file which calls the script
CPUPOWER and NOTIFY-SEND are not really necessary for basic operation and may vary on some systems. See the script for additional information.
#! /bin/bash
#set -xv
#BASIC OPERATION:
#MIDI FILE CLICKED
#IF RUNNING MOVE TO Q
#ELSE IF Q EMPTY MOVE TO Q ELSE IGNORE
#START PT LOOP
#THIS SCRIPT IS TRIGGERED BY A MIDI FILE DOWNLOAD AND ADDS THAT FILE
#TO A QUEUE. IT EXECUTES PIANOTEQ TO PLAY THE FILE USING OPTIONAL
#QUEUED FXP FILE(S). THE MIDI FILE WILL FIRST BE RENAMED IF THE CLIPBOARD
#IS NOT EMPTY. THIS IS CONTINUED UNTIL THE QUEUE IS EMPTY. THE CPU IS SET
#TO PERFORMANCE BY CPUPOWER UNTIL THE SCRIPT ENDS.
#TYPICALLY USE USING A BROWSER:
#OPTIONALLY CLICK ON AN FXP FILE
#SELECT AND COPY THE NAME TO BE USED FOR THE MIDI FILE.
#CLICK THE ACTUALLY MIDI FILE TO QUEUE IT UP
#CONTINUE TO SELECT, COPY AND CLICK
#TO CONTINUE A QUEUE SIMPLY CLICK ON A MIDI FILE
##### SOME ABSOLUTE PATHS ARE USED MODIFIY AS NECESSARY
##### PREREQUISITES:
##### CPUPOWER set to run without password
##### NOTIFICATION DAEMON (NOTIFY-SEND) SETUP
##### CREATE .DESKTOP file to run playqueue.sh
##### Set browser to execute playqueue.sh via the .DESKTOP file
##### $BROWSER_DIR SET PROPERLY
##### CREATE .DESKTOP file below IN /etc/xdg/autostart/ to autostart notify-send
#[Desktop Entry] (AUTOSTART NOTIFY-SEND DAEMON)
#Name=NotifyStartup
#Type=Application
#Exec=/usr/lib/notification-daemon/notification-daemon &
#Terminal=false
## WARNING:
## fxp and midi files saved to BROWSER_DIR will be removed after playing
## the latest EXISTING fxp file in BROWSER_DIR will be removed!
# set to default save directory of browser and Q create Q & playlist
BROWSER_DIR="/home/pi/Downloads"
Q="$BROWSER_DIR/Q"
mkdir $Q 2>&-
mkdir $Q/Playlist 2>&-
#rename/normalize as necessary
CNAME=$(xsel -b)
CNAME=${CNAME//[$'\t\r\n\/']/ }
xsel -bc
NAME="$(basename -- "$1")"
# if Pianoteq is running add to Q, report and exit
# if no clipboard entry then move midifile to Q
# else rename and move and notify
if pgrep -x "Pianoteq"; then
[ -z "$CNAME" ] && mv "$1" "$Q/${NAME%.*}".mid ||
{ mv "$1" "$Q/$CNAME".mid; NAME="$CNAME".mid; }
fxp_=$(ls -t "$BROWSER_DIR"/*.fxp 2>&- | head -1) && echo "$fxp_"
notify-send "$NAME"
exit 0
fi
# set cpu performance during loop and play with Pianoteq
# sudo cpupower should be set to run without password
sudo cpupower frequency-set -g performance &>/dev/null
# get first midi file in Q or continue
# use latest fxp if any
midi=$(ls -t "$Q"/*.mid | tail -1)
fxp_=$(ls -t "$BROWSER_DIR"/*.fxp 2>&- | head -1)
[ ! -z "$fxp_" ] && notifiy-send "Preset $fxp_ will be used."
if [ -z "$midi" ] ; then
[ -z "$CNAME" ] && mv "$1" "$Q/${NAME%.*}".mid ||
{ mv "$1" "$Q/$CNAME".mid; NAME="$CNAME".mid; }
midi="$Q/${NAME%.*}".mid
fi
#play until Q is empty
while [ -n "$midi" ] ; do
[ -z "$fxp_" ] && ./P* --midi "$midi" --play-and-quit ||
./P* --midi "$midi" --fxp "$fxp_" --play-and-quit
mv -n "$midi" "$Q"/Playlist
rm "$midi" 2>&-
mv "$fxp_" "$Q"/Playlist 2>&-
midi=$(ls -t "$Q"/*.mid | tail -1)
fxp_=$(ls -t "$BROWSER_DIR"/*.fxp 2>&- | head -1)
done
sudo cpupower frequency-set -g ondemand &>/dev/null