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

Re: A browser integration script for Pianoteq

That's cool, man!
Working professionally with Linux Servers, I guess..

Re: A browser integration script for Pianoteq

tzinieris wrote:

That's cool, man!
Working professionally with Linux Servers, I guess..

This started off because I like to listen to those excellent e-competition midi files. But it took a long time to download, unzip and start up a playlist for Pianoteq. I had just upgraded to standard myself and I wanted to try all the cool user made fxp presets. So I started a simple click and play script with a preset option. I quickly got tired of clicking and the idea of a running queue was added. That was good enough for a while but when I heard something I liked it was called something like ChenC05.mid. They name it using the performer's name. I had no idea what the piece was called. The composer and piece name was clear on the website until you download it. I knew there was an easier way so after a bit more tweaking and adding a little bell and whistle here and there we have this script. However, I still have to do a lot of clicking. Perhaps there is a better way...

Re: A browser integration script for Pianoteq

Once you checked marked Display tooltips, under General under Options, afterwards if you position and release your cursor just over the name of the MIDI file appearing at the top of the interface, it should show any metadata saved within that file.

I’ve an example of the metadata in a file I just got from the Piano-e-Competition website:

BianF01XP.MID
BianFeng_BachPF-8492018 Alaska International Piano-e-Competition
Captured in May 2018 in Fairbanks, Alaska 5/23/2018
http://www.piano-e-competition.com
XP mode (high-resolution MIDI) version
File processed for distribution with software designed
and coded by Dr. John Q. Walker
Title: Prelude and Fuge in D Major, Book II
Composer: Johann Sebastian Bach
Performer: Feng Bian

Last edited by Amen Ptah Ra (30-10-2020 19:11)
Pianoteq 8 Studio Bundle, Pearl malletSTATION EM1, Roland (DRUM SOUND MODULE TD-30, HandSonic 10, AX-1), Akai EWI USB, Yamaha DIGITAL PIANO P-95, M-Audio STUDIOPHILE BX5, Focusrite Saffire PRO 24 DSP.

Re: A browser integration script for Pianoteq

Amen Ptah Ra wrote:

Whenever you have previously checked marked Display tooltips, under General under Options, afterwards as you position and release your cursor just over the name of the MIDI file appearing at the top of the interface, it will show any meta data saved within that file.

I’ve an example of the meta data in a file I just got from the Piano-e-Competition website:

BianF01XP.MID
BianFeng_BachPF-8492018 Alaska International Piano-e-Competition
Captured in May 2018 in Fairbanks, Alaska 5/23/2018
http://www.piano-e-competition.com
XP mode (high-resolution MIDI) version
File processed for distribution with software designed
and coded by Dr. John Q. Walker
Title: Prelude and Fuge in D Major, Book II
Composer: Johann Sebastian Bach
Performer: Feng Bian

You are correct but some files don't use metadata. The e-competition downloaded files are named by their performer.
The idea is most of the information is known from the website at the time you are using it.

This script uses the selected names for possible later sorting and selecting files. After using this script, I could easily find all my Bach files and copy them to a separate folder and Pianoteq is not required for this. It is useful to organise a collection of midi files that I have previously downloaded or for simply queuing up files for pianoteq and makes it easy to try fxp files. Anyway, I find it very useful and I thought I would share my code. The downside is getting it all setup and working.