-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmidiport.sh
More file actions
executable file
·59 lines (52 loc) · 2.74 KB
/
Copy pathmidiport.sh
File metadata and controls
executable file
·59 lines (52 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# This script sets up and runs a MIDI playback chain:
# MIDI player → ALSA MIDI port → FluidSynth synth engine.
# It handles error checking, auto-detects the synth port,
# and ensures each component launches in the correct order.
set -euo pipefail
IFS=$'\n\t'
# -e: exit on any command failure
# -u: treat unset variables as errors
# -o pipefail: fail if any part of a pipeline fails
# ── Configuration ─────────────────────────────────────────────────────────────
MIDI_PORT="14:0" # Your MIDI input port (hw:client:port)
SYNTH_CMD="fluidsynth -m alsa_seq -s" # Command to start FluidSynth in ALSA MIDI mode
SYNTH_PORT="" # Leave empty to auto-detect below
PLAYER_DIR="$HOME/my_github" # Directory where your MIDI player lives
PLAYER_APP="dmidiplayer-1.7.5-x86_64.AppImage" # MIDI player executable
# ── Launch FluidSynth in Its Own Terminal ────────────────────────────────────
# We start FluidSynth in a dedicated window so it can receive signals directly.
if command -v xterm >/dev/null; then
xterm -e bash -c "exec $SYNTH_CMD" &
elif command -v gnome-terminal >/dev/null; then
gnome-terminal -- bash -c "exec $SYNTH_CMD" &
elif command -v konsole >/dev/null; then
konsole -e bash -c "exec $SYNTH_CMD" &
else
echo "⚠️ No supported terminal found; running FluidSynth in background."
exec $SYNTH_CMD &
fi
# Give FluidSynth a moment to register with ALSA
sleep 2
# ── Auto-detect FluidSynth Port ───────────────────────────────────────────────
# If SYNTH_PORT is unset, scan aconnect output for FluidSynth's input port.
if [[ -z "$SYNTH_PORT" ]]; then
SYNTH_PORT=$(aconnect -l \
| awk '
/^client [0-9]+: .*FLUID Synth/ {
sub(/:/, "", $2); client=$2
}
client && /Synth input port/ {
print client ":" $1
exit
}')
# Fallback to 128:0 if detection fails
SYNTH_PORT=${SYNTH_PORT:-"128:0"}
fi
# ── Wire Your MIDI Chain ───────────────────────────────────────────────────────
echo "Connecting $MIDI_PORT → $SYNTH_PORT"
aconnect "$MIDI_PORT" "$SYNTH_PORT"
# ── Launch Your MIDI Player ───────────────────────────────────────────────────
echo "Starting player in $PLAYER_DIR"
cd "$PLAYER_DIR"
./"$PLAYER_APP" &