-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_midi_guide.sh
More file actions
executable file
·95 lines (84 loc) · 2.77 KB
/
test_midi_guide.sh
File metadata and controls
executable file
·95 lines (84 loc) · 2.77 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
#!/bin/bash
# Convert MIDI file to guide sequence for pitch matching pipeline
# Usage: ./test_midi_guide.sh <midi_file.mid> <channel> [options]
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check arguments
if [ $# -lt 2 ]; then
echo "Usage: $0 <midi_file.mid> <channel> [options]"
echo ""
echo "Arguments:"
echo " midi_file.mid Path to MIDI file"
echo " channel MIDI channel to extract (0-15)"
echo ""
echo "Options:"
echo " --output PATH Output JSON path (default: data/segments/guide_sequence.json)"
echo " --min-rest N Minimum rest duration to preserve (default: 0.1s)"
echo " --sample-rate N Sample rate for audio preview (default: 22050)"
echo " --no-audio Skip audio preview generation"
echo " --list-channels List available channels and exit"
echo ""
echo "Examples:"
echo " # List channels in a MIDI file:"
echo " $0 data/input/song.mid 0 --list-channels"
echo ""
echo " # Convert melody from channel 1:"
echo " $0 data/input/song.mid 1"
echo ""
echo " # Convert with smaller minimum rest:"
echo " $0 data/input/song.mid 1 --min-rest 0.05"
exit 1
fi
MIDI_FILE="$1"
CHANNEL="$2"
shift 2 # Remove first two arguments
# Check if file exists
if [ ! -f "$MIDI_FILE" ]; then
echo -e "${YELLOW}Error: MIDI file not found: $MIDI_FILE${NC}"
exit 1
fi
# Parse --output from extra args if provided, and build filtered args
TEMP_DIR="data/temp"
OUTPUT_JSON="data/segments/guide_sequence.json"
ARGS=("$@")
FILTERED_ARGS=()
i=0
while [ $i -lt ${#ARGS[@]} ]; do
if [[ "${ARGS[$i]}" == "--output" ]] && [ $((i + 1)) -lt ${#ARGS[@]} ]; then
OUTPUT_JSON="${ARGS[$((i + 1))]}"
i=$((i + 2)) # Skip --output and its value
else
FILTERED_ARGS+=("${ARGS[$i]}")
i=$((i + 1))
fi
done
# Create directories
mkdir -p "$(dirname "$OUTPUT_JSON")"
mkdir -p "$TEMP_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
$PYTHON_CMD src/midi_guide_converter.py \
--midi "$MIDI_FILE" \
--channel "$CHANNEL" \
--output "$OUTPUT_JSON" \
--temp-dir "$TEMP_DIR" \
"${FILTERED_ARGS[@]}"
# Get the basename without extension for audio preview path
MIDI_BASENAME=$(basename "$MIDI_FILE" | sed 's/\.[^.]*$//')
echo ""
echo "Next steps:"
echo " 1. Listen to the audio preview: $TEMP_DIR/${MIDI_BASENAME}_midi_preview.wav"
echo " 2. Run pitch matcher to match against source database:"
echo " ./test_pitch_matcher.sh $OUTPUT_JSON data/segments/source_database.json"
echo ""