-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimize.py
executable file
·50 lines (37 loc) · 1.34 KB
/
minimize.py
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
#!/usr/bin/env python
import sys
import copy
import guitarpro
import utils
if __name__ == "__main__":
if len(sys.argv) <= 3:
print("This script will combine several tracks into one, "
"after which an attempt to detect and collapse repeats is made. "
"Pass the (0-based) index of the tracks to combine, "
"in order of priority.")
print("Usage: {} <infile> <outfile> <track index>+".
format(sys.argv[0]), file=sys.stderr)
if len(sys.argv) >= 2:
song = guitarpro.parse(sys.argv[1])
for idx, track in enumerate(song.tracks):
print("* track {}: {}".format(idx, track.name))
sys.exit(1)
src = sys.argv[1]
dst = sys.argv[2]
print("Parsing", src)
song = guitarpro.parse(src)
print("Processing", song.title)
indices = []
for s in sys.argv[3:]: indices.append(int(s))
# collect regions
regions = utils.flatten_to_regions(song, indices)
# create new track
flattened = copy.deepcopy(song.tracks[indices[0]])
flattened.number = 1
flattened.name = "Flattened"
flattened.measures = []
# fold repeats and add to track
for r in regions: flattened.measures.extend(utils.fold_repeats(r))
song.tracks = [flattened]
print("Writing to", dst)
guitarpro.write(song, dst)