-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappend_missing_performance_notes.py
More file actions
50 lines (45 loc) · 1.85 KB
/
Copy pathappend_missing_performance_notes.py
File metadata and controls
50 lines (45 loc) · 1.85 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
import partitura
from partitura.io.exportparangonada import alignment_dicts_to_array
import numpy as np
import os
from classes import aligned_dataset as ad
import utils
def save_alignment_csv(alignment, outdir):
"""
Save an alignment to a csv file.
Parameters
----------
alignment : list
A list of note alignment dictionaries.
filename : str
The name of the file to save the alignment to.
"""
alignarray = alignment_dicts_to_array(alignment)
np.savetxt(
os.path.join(outdir, "manual_alignment.csv"),
# outdir + os.path.sep + "align.csv",
alignarray,
fmt="%.20s",
delimiter=",",
header=",".join(alignarray.dtype.names),
comments="",
)
if __name__ == "__main__":
root = "Golden_bass_alignments"
performance_root = "Performances"
save_root = root + "_completed"
#create save_root if doesn't exist
if not os.path.exists(save_root):
os.makedirs(save_root)
for dirname in os.listdir(root):
if not dirname.startswith("."):
if not os.path.exists(os.path.join(save_root, dirname)):
os.makedirs(os.path.join(save_root, dirname))
for filename in os.listdir(os.path.join(root, dirname)):
if filename.endswith(".csv"):
performer, piece, attempt = dirname.split("_")
performance_name = "{}/{}/{}_{}_cembalo_{}.mid".format(performance_root, performer, performer, piece, attempt)
performance = partitura.load_performance(performance_name)
alignment = utils.load_parangonada_alignment(os.path.join(root, dirname, filename))
alignment = ad.AlignedDataset.add_missing_performance_notes(alignment, performance)
save_alignment_csv(alignment, "{}/{}".format(save_root, dirname))