Exemple #1
0
def write_MEI(mei_to_write):
    tdir = tempfile.mkdtemp()
    fname = "slice.mei"
    filename = os.path.join(tdir, fname)

    try:
        documentToFile(mei_to_write, filename)
    except FileWriteFailureException as ex:
        raise CannotWriteMEIException("The MEI Slice could not be written. {0}".format(ex.message))

    return filename
Exemple #2
0
def write_MEI(mei_to_write):
    tdir = tempfile.mkdtemp()
    fname = "slice.mei"
    filename = os.path.join(tdir, fname)

    try:
        documentToFile(mei_to_write, filename)
    except FileWriteFailureException as ex:
        raise CannotWriteMEIException(
            "The MEI Slice could not be written. {0}".format(ex.message))

    return filename
Exemple #3
0
def massage_mei(in_file, out_file):
    try:
        analysis = make_analysis(in_file)
        MEI_instructions = TransformData(
            arranger_to_editor=True,
            remove_incipit=True,
            replace_longa=True,
            editorial_resp=analysis.has_arranger_element,
            alternates_list=analysis.alternates_list,
            copyright_text=COPYRIGHT,
            color_for_ficta=ANYCOLOR,
            color_for_variants=ANYCOLOR,
            color_for_emendations=ANYCOLOR,
            double_cut_time=True,
            eliminate_bad_beams=True,
            make_invisible_space=True,
            cleanup=True,
        )
        old_res = documentFromFile(in_file)
        old_MEI_doc = old_res.getMeiDocument()
        new_MEI_doc = transform_mei(old_MEI_doc, MEI_instructions)
        status = documentToFile(new_MEI_doc, out_file)

    except Exception as ex:
        logging.critical(ex)
        logging.critical("Error during massaging " + in_file)
Exemple #4
0
    def test_documentwritefailure(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root
        with self.assertRaises(FileWriteFailureException) as cm:
            ret = documentToFile(doc, "C:/StupidPath")

        self.assertTrue(isinstance(cm.exception, FileWriteFailureException))
Exemple #5
0
    def test_documentwritefailure(self):
        doc = MeiDocument()
        root = MeiElement("mei")
        root.id = "myid"
        doc.root = root
        with self.assertRaises(FileWriteFailureException) as cm:
            ret = documentToFile(doc, "C:/StupidPath")

        self.assertTrue(isinstance(cm.exception, FileWriteFailureException))
Exemple #6
0
 def test_exportwithcomments(self):
     docf = documentFromFile(os.path.join("test", "testdocs", "campion.mei"))
     status = documentToFile(docf.getMeiDocument(), os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Exemple #7
0
 def test_basicexport(self):
     docf = documentFromFile(os.path.join("test", "testdocs", "beethoven.mei"))
     status = documentToFile(docf.getMeiDocument(), os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Exemple #8
0
 def write(self):
     documentToFile(self.meiDoc, self.meiFile)
Exemple #9
0
        def write_transformation(file_path, data=TransformData()):
            old_res = documentFromFile(file_path)
            old_MEI_doc = old_res.getMeiDocument()

            new_MEI_doc = transform_mei(old_MEI_doc, data)
            status = documentToFile(new_MEI_doc, file_path)
Exemple #10
0
 def test_exportwithcomments(self):
     docf = documentFromFile(os.path.join("test", "testdocs",
                                          "campion.mei"))
     status = documentToFile(docf.getMeiDocument(),
                             os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Exemple #11
0
 def test_basicexport(self):
     docf = documentFromFile(
         os.path.join("test", "testdocs", "beethoven.mei"))
     status = documentToFile(docf.getMeiDocument(),
                             os.path.join(self.tempdir, "filename.mei"))
     self.assertTrue(status)
Exemple #12
0
        out_fname_png = './out_png/{}_alignment.png'.format(fname)

        try:
            with open(inJSOMR, 'r') as file:
                jsomr = json.loads(file.read())
            with open(in_syls) as file:
                syls = json.loads(file.read())
        except IOError:
            print('{} not found, skipping...'.format(fname))
            continue

        print('building mei for {}...'.format(fname))

        glyphs = jsomr['glyphs']
        syl_boxes = syls['syl_boxes']
        median_line_spacing = syls['median_line_spacing']

        print('adding flags to glyphs...')
        glyphs = add_flags_to_glyphs(glyphs)
        print('performing neume-to-lyric alignment...')
        pairs = neume_to_lyric_alignment(glyphs, syl_boxes,
                                         median_line_spacing)
        print('building MEI...')
        meiDoc = build_mei(pairs, classifier, jsomr['staves'], jsomr['page'])
        print('neume component spacing > 0, merging nearby components...')
        meiDoc = merge_nearby_neume_components(meiDoc, width_mult=0.25)

        draw_mei_doc(in_png, out_fname_png, meiDoc)

        documentToFile(meiDoc, out_fname)
Exemple #13
0
    args = parser.parse_args()

    sys.stdout = open(args.output_file[:-4] + ".txt", "w")

    # Error in the parameters
    if args.apel and len(args.list_of_input_files)>1:
        parser.error("Must use only one 'input_file' with the flag '-apel'")
    if args.merge and args.compare:
        parser.error("The '-compare' flag must not be used together with the '-merge' flag.\nThe '-compare' flag is only to be used together with the '-apel' flag or with no flag at all, as '-compare' is used to compare the output of the 'apel script' (just by itself, or within the context of the 'scoring up' process) against the 'ground truth file'.")
    if args.merge and args.apel:
        parser.error("Don't use both flags '-merge' and '-apel' at the same time. If you want to perform the whole 'scoring_up' script (doing both the 'merging' of the parts and find the 'actual duration of the notes using apel's rules'), you should not use any flag at all.")
    
    # Running the modules according to the parameters specified by the user
    if args.merge:
        quasiscore = merge.merge_music_section(args.list_of_input_files)
        pymei.documentToFile(quasiscore, args.output_file)
    elif args.apel:
        print("\nAPEL RESUTLS - Warnings with respect to rules in conflict\n")
        input_quasiscore_doc = pymei.documentFromFile(args.list_of_input_files[0]).getMeiDocument()
        out_apel = ApelAlg.lining_up(input_quasiscore_doc)
        if args.compare:
            print("\nCOMPARISON RESUTLS - Notes/Rests (with their xml:id and voice number) that don't match with the ground truth\n")
            accuracy_results = ApelAlg.comparison(out_apel, pymei.documentFromFile(args.compare).getMeiDocument())
            print("\nACCURACY:")
            for i in range (0, len(accuracy_results)):
                print("Voice # " + str(i) + ":\t" + str(accuracy_results[i]) + " = " + str(float(accuracy_results[i])*100))
        pymei.documentToFile(out_apel, args.output_file)
    else:
        quasiscore = merge.merge_music_section(args.list_of_input_files)
        print("\nAPEL RESUTLS - Warnings with respect to rules in conflict\n")
        score = ApelAlg.lining_up(quasiscore)
Exemple #14
0
 def write(self):
     documentToFile(self.meiDoc, self.meiFile)