Skip to content

Instantly share code, notes, and snippets.

@stephenll
Forked from richardanaya/play_piano
Created January 6, 2026 02:10
Show Gist options
  • Select an option

  • Save stephenll/c5f49f7cffb0ebf7be1990a6fe3b866b to your computer and use it in GitHub Desktop.

Select an option

Save stephenll/c5f49f7cffb0ebf7be1990a6fe3b866b to your computer and use it in GitHub Desktop.
#!/bin/bash
PIANOTEQ_EXEC="$HOME/piano/x86-64bit/Pianoteq 9"
# Usage check
if [ -z "$1" ]; then
echo "Usage: play_piano <filename.mid> [\"Preset Name\"] [output_filename]"
exit 1
fi
MIDI_FILE="$1"
PRESET_NAME="$2"
OUTPUT_FILE="$3"
if [ ! -f "$MIDI_FILE" ]; then
echo "Error: File '$MIDI_FILE' not found."
exit 1
fi
# Base command
CMD=("$PIANOTEQ_EXEC" "--headless" "--midi" "$MIDI_FILE")
# Add preset if provided (Second Argument)
if [ -n "$PRESET_NAME" ]; then
CMD+=("--preset" "$PRESET_NAME")
fi
# Check for output file (Third Argument)
if [ -n "$OUTPUT_FILE" ]; then
# If a 3rd argument exists, we RENDER to file
if [[ "$OUTPUT_FILE" == *.flac ]]; then
CMD+=("--flac" "$OUTPUT_FILE")
elif [[ "$OUTPUT_FILE" == *.mp3 ]]; then
CMD+=("--mp3" "$OUTPUT_FILE")
else
CMD+=("--wav" "$OUTPUT_FILE")
fi
echo "Rendering to $OUTPUT_FILE..."
else
# If no 3rd argument, we PLAY live
CMD+=("--play-and-quit")
echo "Playing..."
fi
# Execute
"${CMD[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment