def test_annotated_corpus(): da_corpus = DCorpus() da_corpus.append_from_db(client_id='695311d7e88d5f79b4945bf45d00cc77', selection_id='21') da_score = da_corpus.d_score_by_index(0) da_title = da_score.title() assert da_title == 'Prelude 2 (BWV 847)', "Bad fetch by index" da_score = da_corpus.d_score_by_title(da_title) assert da_title == da_score.title(), "Bad fetch by title" annotation = da_score.abcd_header() abcdf = annotation.abcdf() finger_re = re.compile('[12345]+') at_re = re.compile('@') assert finger_re.search(abcdf), "Bad abcdf" assert at_re.search(abcdf), "Bad abcdf" upper_abcdf = annotation.upper_abcdf() assert finger_re.search(upper_abcdf), "Bad upper abcdf" assert not at_re.search(upper_abcdf), "Bad upper abcdf" lower_abcdf = annotation.lower_abcdf() assert finger_re.search(lower_abcdf), "Bad upper abcdf" assert not at_re.search(lower_abcdf), "Bad upper abcdf" assert lower_abcdf != upper_abcdf, "Bad split of abcdf" abcdf_by_index = da_score.abcdf(index=0) abcdf_by_id = da_score.abcdf(identifier=1) assert abcdf_by_index == abcdf_by_id, "Bad DSCore::abcdf" upper_abcdf_by_index = da_score.upper_abcdf(index=0) upper_abcdf_by_id = da_score.upper_abcdf(identifier=1) assert upper_abcdf_by_index == upper_abcdf_by_id, "Bad DSCore::upper_abcdf" lower_abcdf_by_index = da_score.lower_abcdf(index=0) lower_abcdf_by_id = da_score.lower_abcdf(identifier=1) assert lower_abcdf_by_index == lower_abcdf_by_id, "Bad DSCore::lower_abcdf"
def test_distance_metrics(): hart = Hart() d_corpus = DCorpus(corpus_str=TestConstant.A_MAJ_SCALE) hart.load_corpus(d_corpus=d_corpus) complete_rh_advice = hart.advise(staff="upper") complete_rh_advice_len = len(complete_rh_advice) right_re = re.compile('^>\d+$') assert right_re.match( complete_rh_advice), "Bad right-hand, upper-staff advice" rh_advice = hart.advise(staff="upper", offset=3, first_digit=4) short_advice_len = len(rh_advice) assert complete_rh_advice_len - 3 == short_advice_len, "Bad offset for advise() call" ff_re = re.compile('^>4\d+$') assert ff_re.match(rh_advice), "Bad first finger constraint" rh_advice = hart.advise(staff="upper", offset=10, first_digit=5, last_digit=5) short_advice_len = len(rh_advice) assert complete_rh_advice_len - 10 == short_advice_len, "Bad offset for advise() call" ff_re = re.compile('^>5\d+5$') assert ff_re.match(rh_advice), "Bad first and last finger constraints" lh_advice = hart.advise(staff="lower") left_re = re.compile('^<\d+$') assert left_re.match(lh_advice), "Bad left-hand, lower-staff advice" combo_advice = hart.advise(staff="both") clean_combo_advice = re.sub('[><&]', '', combo_advice) d_score = d_corpus.d_score_by_index(index=0) gold_fingering = d_score.abcdf(index=0) clean_gold_fingering = re.sub('[><&]', '', gold_fingering) combo_re = re.compile('^>\d+@<\d+$') assert combo_re.match(combo_advice), "Bad combined advice" hamming_evaluations = hart.evaluate_strike_distance(method="hamming", staff="both") # for he in hamming_evaluations: # print(he) assert hamming_evaluations[0] > 0, "Undetected Hamming costs" assert hamming_evaluations[1] == 0, "Bad fish in Hamming barrel" natural_evaluations = hart.evaluate_strike_distance(method="natural", staff="both") # for he in natural_evaluations: # print(he) assert natural_evaluations[0] > 0, "Undetected natural costs" assert natural_evaluations[1] == 0, "Bad fish in natural barrel" pivot_evaluations = hart.evaluate_strike_distance(method="pivot", staff="both") # for he in pivot_evaluations: # print(he) assert pivot_evaluations[0] > 0, "Undetected pivot costs" assert pivot_evaluations[1] == 0, "Bad fish in pivot barrel"
def test_append_dir(): d_corpus = DCorpus() d_corpus.append_dir(corpus_dir=TestConstant.BERINGER2_ANNOTATED_ARPEGGIO_DIR) # d_corpus.append_dir(corpus_dir=TestConstant.BERINGER2_ANNOTATED_SCALE_DIR) d_corpus.append_dir(corpus_dir=TestConstant.BERINGER2_ANNOTATED_BROKEN_CHORD_DIR) score_count = d_corpus.score_count() assert score_count > 48, "Bad score count" for i in range(score_count): d_score = d_corpus.d_score_by_index(i) assert d_score.title() is not None, "Missing title at {0}".format(i) assert d_score.is_fully_annotated(indices=[0]), "Missing annotation in {}".format(d_score.title())
def test_abc2xml_2part_chords(): p01_path = TestConstant.WTC_CORPUS_DIR + '/prelude01.abc' p09_path = TestConstant.WTC_CORPUS_DIR + '/prelude09.abc' d_corpus = DCorpus(corpus_path=p01_path, as_xml=True) score_count = d_corpus.score_count() assert score_count == 1, "Bad score count" d_corpus.append(corpus_path=p09_path, as_xml=True) assert d_corpus.score_count() == 2, "Bad append" titles = d_corpus.titles() assert len(titles) == 2, "Bad title count" d_score = d_corpus.d_score_by_index(0) assert d_score.title() == 'Prelude 1 (BWV 846)', "Bad title retrieval" part_count = d_score.part_count() assert part_count == 2, "Bad part count" d_part = d_score.combined_d_part() assert d_part is not None, "Bad DPart retrieval" assert d_part.is_monophonic() is False, "Polyphony not detected" d_upper = d_score.upper_d_part() assert d_upper, "Bad upper DPart" assert d_upper.is_monophonic() is False, "Polyphonic upper part not detected" d_lower = d_score.lower_d_part() assert d_lower, "Bad lower DPart" assert d_lower.is_monophonic() is False, "Polyphonic lower part in Prelude 1 not detected" assert d_lower.is_orderly() is False, "Lower part in Prelude 1 is not orderly" orderly_stream = d_lower.orderly_note_stream() # orderly_stream.show('text') orderly_d_part = DPart(music21_stream=orderly_stream) assert orderly_d_part.is_orderly() is True, "orderly_note_stream() or is_orderly() is broken" # Need to check what happens to tied notes d_score = d_corpus.d_score_by_index(1) d_upper = d_score.upper_d_part() disorderly_stream = d_upper.stream() disorderly_d_part = DPart(music21_stream=disorderly_stream) assert disorderly_d_part.is_orderly() is False, "orderly_note_stream() or is_orderly() is broken" disorderly_stream.show('text') orderly_stream = d_upper.orderly_note_stream() orderly_d_part = DPart(music21_stream=orderly_stream) assert orderly_d_part.is_orderly() is True, "orderly_note_stream() or is_orderly() is broken"