In [ ]:
import os
from symbtrextras.scoreextras import ScoreExtras
from symbtrextras.txtextras import TxtExtras
In [ ]:
# I/O, change the name to the desired SymbTr-score accordingly
symbtr_name = 'makam--form--usul--name--composer'
# txt and mu2 filepaths, default is the path in the SymbTr collection\
txt_file = os.path.join('..', 'txt', symbtr_name + '.txt')
mu2_file = os.path.join('..', 'mu2', symbtr_name + '.mu2')
# txt and MusicXML files to save
# WARNING: The default overwrites the files in the SymbTr collection
save_txt_file = os.path.join('..', 'txt', symbtr_name + '.txt')
save_xml_file = os.path.join('..', 'MusicXML', symbtr_name + '.xml')
In [ ]:
# Change encoding to UTF-8
ScoreExtras.change_encoding_to_utf8(txt_file)
ScoreExtras.change_encoding_to_utf8(mu2_file)
In [ ]:
# Change the line break from \r\n (Windows) to \n (Unix)
ScoreExtras.change_to_unix_linebreak(txt_file)
ScoreExtras.change_to_unix_linebreak(mu2_file)
In [ ]:
# Make sure the rest row is always "Es Es -1 -1"
symbtr_csv = TxtExtras.correct_rests(txt_file)
with open(save_txt_file, 'w') as text_file:
text_file.write(symbtr_csv)
In [ ]:
# Add usul row if it is not present in the first row
symbtr_csv = TxtExtras.add_usul_to_first_row(txt_file, mu2_file)
with open(save_txt_file, 'w') as text_file:
text_file.write(symbtr_csv)
In [ ]:
# Check usul rows and attempt to fill missing information
symbtr_csv = TxtExtras.check_usul_row(txt_file)
with open(txt_file, 'w') as text_file:
text_file.write(symbtr_csv)
In [ ]:
# Force the duration of all gracenotes to 0 and recompute the offset column
# according to the usul cycle(s)
symbtr_csv = TxtExtras.correct_offset_gracenote(txt_file, mu2_file)
with open(save_txt_file, 'w') as text_file:
text_file.write(symbtr_csv)
In [ ]:
# Convert the txt file to MusicXML using the additional metadata from mu2 files
# (and the MusicBrainz mbid)
symbtr_xml = TxtExtras.to_musicxml(symbtr_name, txt_file, mu2_file)
with open(save_xml_file, 'w') as xml_file:
xml_file.write(symbtr_xml)