Help with PiSound Button Script for Changing Pianoteq Instruments/Presets

Hi! I’m working on setting up my Raspberry Pi with PiSound and Pianoteq to create a standalone instrument. I’m using the Patchbox OS and I’ve configured a Pianoteq module using the steps outlined in this thread:


I’m playing Pianoteq headless using my Doepfer PK88 keyboard and running audio into my mixer. Audio is great, no issues there.



My goal is to use The Button to send MIDI CC commands to Pianoteq, letting me change instruments and presets without a computer interface. I’ve assigned MIDI CC values for cycling through instruments and presets.

So far, I’ve tried creating a shell script to send MIDI commands using amidi, but encountered issues with the device being reported as “busy.” I’ve considered using Pianoteq’s command-line options but haven’t found a direct way to achieve this goal.

Has anyone accomplished something similar or have any insights on sending MIDI commands to Pianoteq via a script? Any help would be greatly appreciated!

Thanks!

I would think that a simply python program to send the CC would work in your case. If you’re comfortable with Python, look at the rtmidi package. A simple (non-tested) example:

import rtmidi
from rtmidi.midiconstants import CONTROL_CHANGE

midiout = rtmidi.MidiOut()
available_poart - midiout.get_ports()

if available_ports:
   midiout.open_port(0)
   control = [CONTROL_CHANGE, x, y] # where x=midi control change, y=value (127=on, 0=off)
   midiout.send_message(control)

del midiout

Of course you’ll need to call this python from a shell script.

1 Like

I’m working on something quite similar. The approach I’m taking is to skip midi for controlling Pianoteq. Pianoteq is quite controllable using presets and commands. So in a python script you can run a command like

os.system(‘[path]/Pianoteq\ 8 --preset “Celtic Harp Sweet”’)

And it will open to that preset. You can configure quite a lot in a preset.

In my case I’m not using the PiSound button, but instead am building a little thing with a rotary encoder, to flip through presets. My goal (not yet done) is to create a little preset dial, sort of like the one on a Yamaha Reface CP, where you can flip between a Rhodes, a Wurlitzer, etc.

2 Likes

@Ted1 thanks for the insights into how Pianoteq works.

1 Like

yep sure thing. One tip — in a terminal window if you run

--help on the Pianoteq app, you get this output, that shows all of the useful things you can do via the command line

Copyright (c) 2023 Modartt.
Options from command-line:
--help             : show this help, and quit
--version          : show current version number and date, and quit
--no-prefs         : start Pianoteq without using any saved preference
--no-audio-prefs   : start Pianoteq with a clean audio/midi configuration
--prefs FILENAME   : stores the preferences in the specified file
--fxp FILENAME     : load an FXP file on startup
--preset NAME      : load a preset on startup
--list-presets     : display the list of all presets
--midimapping NAME : load a midimapping preset on startup
--midi-channel CH  : listen only to MIDI events on the specified channel (1<=value<=16 or 'all')
--midi-transpose x : transpose note events by the specified amount (-36<=x<=36)
--midi FILENAME    : load a midi file, or a *.m3u playlist content. If filename is a folder,
                      the midi files contained in that folder
--open file1 file2 ...     : load files, which can be midi, fxp, mfxp, ptq, scl or kbm files.
                      Must be used as the *last* option
--wav FILENAME     : export midi file as WAV file, and quit
--flac FILENAME    : export as FLAC
--mp3 FILENAME     : export as MP3
--rate FREQ        : change the sample rate for the exported wav
--bit-depth D      : change the bit-depth for the exported wav (16,24 or 32)
--dither ON/OFF    : turn dithering when exporting on or off
--normalize        : turn on volume normalization for the exported wav
--normalize-db DB  : change the normalization level (default value is -1dB)
--mono             : export the wav file as mono
--headless         : do not show the graphical interface
--fullscreen       : start in fullscreen mode
--export-lv2-presets PATH : export all presets as LV2 presets
--export-lv2-presets-std  : export lv2 preset to their default location, which is:
                    /home/tedpower/.lv2/
--export-presets-filter all|builtin|ptq|user : select which presets are exported, default is 'builtin'
--restore-windows  : restore the a previously saved set of windows
--do-not-block-screensaver : prevent Pianoteq from keeping the screen on
--quiet            : be less verbose
--play             : immediately start playing the midi file
--play-and-quit    : start playing the midi file, and quit when it ends
--serve [IP:]PORT  : start a JSON-RPC server for remote control of Pianoteq.
                      When using --serve "" , the server listens on localhost:8081

Example of use: Pianoteq --preset "U4 Small" --midi foo.mid --wav foo.wav
1 Like

Oh wow. Thanks both of you! I think I’m gonna go down @Ted1 path using the command line.

I’m thinking of dumping a bunch of presets into a folder. Then creating two scripts for the Pisound button to cycle forward and backward through the presets in that folder.

This also solves another annoying problem. For some strange reason Pianoteq on my Pi will not let me permanently hide the demo instruments from my preset list. I can hide them each time I launch Pianoteq but once I relaunch they’re unhidden.

Using the folder, I won’t have to worry about cycling through a bunch of demo instruments.

Quick q, is there a way to send a command to an already running instance of Pianoteq?

I can send

/usr/local/pianoteq/pianoteq --preset "My Presets/W1 Basic Mono"

And it opens a new instance of Pianoteq with that preset loaded.

This option seems to enable remote control of a single pianoteq instance via sockets - you could look into that. It’s probably possible to make use of curl to make things happen, or write a quick python script. There’s also existing projects making use of it like this remote control project.

I’m not in front of a computer / pi right now, but if you run from the command line

/usr/local/pianoteq/pianoteq --preset "My Presets/W1 Basic Mono"

and then run

/usr/local/pianoteq/pianoteq --preset "My Presets/Instrument 2"

you’re saying it opens a second instance of Pianoteq? I would have guessed it would just foreground Pianoteq and switch the instrument.

Yes. I end up with two separate Pianoteq instances. If you get a chance, could you test on your end? I’m hoping it’s just user error on my side.

Would this be an option towards using The Button? The remote control project looks really cool but I was hoping to streamline things with the Pisound.

I’m not super familiar with curl. I’ve tried using a python script to send terminal messages to Pianoteq but I haven’t been able to control the Patchbox module you suggested in the other thread.

I can start Pianoteq with all my preferences/preset loaded. But using The Button to change presets hasn’t worked.

I’m currently using VNC on my phone to change presets/instruments through the desktop UI. It’s clunky but the best I’ve been able to achieve.

Any help you can provide is super appreciated. Thanks!

ah you are right, it does open multiple instances. Hmm bummer. This might be a question for the Modartt forums. It seems like the challenge is to update the existing app instance, vs. loading dupes. Or alternatively, I guess you could close any existing Pianoteq instances, and then start up a new one with the correct preset. Maybe something like this How to Close a program using python? - Stack Overflow

Thanks for checking it out! For now I’m gonna grab a Korg Nano Kontrol as a dedicated controller. Good luck with your project!

Try running the command sudo killall pianoteq before starting the new instance. :slight_smile: It terminates all processes with matching name.