-
Notifications
You must be signed in to change notification settings - Fork 0
/
rodesplit.sh
executable file
·126 lines (102 loc) · 2.85 KB
/
rodesplit.sh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# Set strict error handling
set -euo pipefail
IFS=$'\n\t'
# Script configuration
readonly DEFAULT_TRACKS=("mic1" "mic2" "mic3" "mic4")
readonly TIME_CORRECTION=1.000137037
readonly TEMP_DIR=".rodesplit"
# Help message
show_help() {
cat << EOF
Usage: $(basename "$0") [track_names...]
Process Rodecaster Pro multi-track WAV recordings.
If no track names are provided, defaults to: $(printf "%s " "${DEFAULT_TRACKS[@]}")
Channel Layout:
1-2: Main Output (L/R)
3-6: Mic Channels 1-4
7-8: USB Channel (L/R)
9-10: Smartphone Channel (L/R)
11-12: Bluetooth Channel (L/R)
13-14: Sound Pads Channel (L/R)
EOF
}
# Error handling function
error() {
echo "Error: $1" >&2
exit 1
}
# Check if required commands exist
check_dependencies() {
local deps=(ffmpeg)
for dep in "${deps[@]}"; do
if ! command -v "$dep" >/dev/null 2>&1; then
error "$dep is required but not installed"
fi
done
}
# Clean up function
cleanup() {
if [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
}
# Process a single track
process_track() {
local track_name="$1"
local track_index="$2"
local track_file="$TEMP_DIR/$track_name.txt"
echo "Processing track: $track_name"
echo "#$track_name" > "$track_file"
# Process each WAV file
local wav_files
wav_files=$(ls POD*.WAV 2>/dev/null) || error "No POD*.WAV files found"
for wav_file in $wav_files; do
echo "Processing file: $wav_file"
local output_flac="${wav_file%.WAV}_${track_name}.flac"
if ! ffmpeg -n -hide_banner -loglevel error \
-i "$wav_file" \
-af "pan=1|c0=c$((track_index+2)),atempo=$TIME_CORRECTION" \
-ac 1 "$TEMP_DIR/$output_flac"; then
error "Failed to process $wav_file"
fi
echo "file '$output_flac'" >> "$track_file"
done
# Combine all FLAC files
if ! ffmpeg -hide_banner -loglevel error \
-f concat -i "$track_file" \
"$track_name.flac"; then
error "Failed to combine FLAC files for $track_name"
fi
}
main() {
# Show help if requested
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
show_help
exit 0
fi
# Check dependencies
check_dependencies
# Set up cleanup trap
trap cleanup EXIT
# Create temp directory
mkdir -p "$TEMP_DIR"
# Get tracks to process
if [ $# -eq 0 ]; then
local tracks=("${DEFAULT_TRACKS[@]}")
else
local tracks=("$@")
fi
# Validate track count
if [ "${#tracks[@]}" -gt 4 ]; then
error "Maximum of 4 tracks allowed (mic channels)"
fi
# Process each track
local track_index=0
for track in "${tracks[@]}"; do
process_track "$track" "$track_index"
track_index=$((track_index + 1))
done
echo "Processing complete!"
}
main "$@"