-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit_midi_channels.sh
More file actions
executable file
·96 lines (84 loc) · 2.94 KB
/
split_midi_channels.sh
File metadata and controls
executable file
·96 lines (84 loc) · 2.94 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Split MIDI file into separate WAV files per channel
# Useful for identifying which channel contains the vocal/melody track
#
# Supports two synthesis modes:
# - FluidSynth (default): Uses SoundFont for realistic instrument sounds
# - Simple synthesis (--no-fluidsynth): Basic sine wave synthesis
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${BLUE}=== MIDI Channel Splitter ===${NC}\n"
# Show help if no arguments or --help/-h flag
if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: $0 <midi_file> [output_dir] [options]"
echo ""
echo "Exports each MIDI channel as a separate WAV file with correct instrument sounds."
echo ""
echo "Arguments:"
echo " midi_file Path to MIDI file"
echo " output_dir Output directory (default: data/temp/midi_channels)"
echo ""
echo "Options (pass after arguments):"
echo " --soundfont PATH Path to SoundFont file (.sf2)"
echo " --no-fluidsynth Use simple synthesis instead of FluidSynth"
echo " --list-only List channels without exporting"
echo " --sample-rate N Audio sample rate for simple synthesis (default: 22050)"
echo ""
echo "FluidSynth Mode (default):"
echo " Uses SoundFonts for realistic instrument sounds. Requires:"
echo " - FluidSynth library: brew install fluidsynth (macOS)"
echo " - pyfluidsynth: pip install pyfluidsynth"
echo " - SoundFont file: Download to data/soundfonts/"
echo ""
echo " Recommended SoundFont (free, ~30MB):"
echo " https://schristiancollins.com/generaluser.php"
echo " Save to: data/soundfonts/GeneralUser_GS.sf2"
echo ""
echo "Examples:"
echo " $0 song.mid"
echo " $0 song.mid --soundfont data/soundfonts/GeneralUser_GS.sf2"
echo " $0 song.mid data/output/channels"
echo " $0 song.mid --list-only"
echo " $0 song.mid --no-fluidsynth"
echo ""
echo "After running, listen to each WAV file to identify the melody,"
echo "then use that channel with: ./test_midi_guide.sh song.mid <channel>"
exit 1
fi
MIDI_FILE="$1"
shift
# Check if file exists
if [ ! -f "$MIDI_FILE" ]; then
echo -e "${YELLOW}Error: MIDI file not found: $MIDI_FILE${NC}"
exit 1
fi
# Default output directory
OUTPUT_DIR="data/temp/midi_channels"
# Check if second argument is a directory path (not an option)
if [ $# -ge 1 ] && [[ ! "$1" == --* ]]; then
OUTPUT_DIR="$1"
shift
fi
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Detect Python command
if command -v python &> /dev/null; then
PYTHON_CMD=python
elif command -v python3 &> /dev/null; then
PYTHON_CMD=python3
else
echo -e "${YELLOW}Error: Python not found${NC}"
exit 1
fi
echo -e "${GREEN}Splitting MIDI channels${NC}"
echo "Input: $MIDI_FILE"
echo "Output: $OUTPUT_DIR"
echo ""
$PYTHON_CMD src/midi_channel_splitter.py \
--midi "$MIDI_FILE" \
--output-dir "$OUTPUT_DIR" \
"$@"