def test_duration_indexer_4(self):
     # Soprano part of bwv77.mxl which is a part with no ties
     expected = TestDurationIndexer.make_series(TestDurationIndexer.bwv77_soprano)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     ip._analyses['part_streams'] = ip._get_part_streams()
     actual = ip.get_data('duration').iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))
 def test_ngrams_1(self):
     """Integration test for ngrams."""
     expected = AllVoiceIntervalNGrams.series_maker(
         AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({
         ('ngram.NGramIndexer', 'Soprano,Bass Alto,Bass Tenor,Bass : Bass'):
         expected
     })
     v_setts = {
         'quality': False,
         'simple or compound': 'compound',
         'directed': True
     }
     h_setts = {
         'quality': False,
         'horiz_attach_later': True,
         'simple or compound': False,
         'directed': True
     }
     n_setts = {
         'n': 2,
         'horizontal': [('Bass', )],
         'brackets': True,
         'continuer': '1',
         'vertical': [('Soprano,Bass', 'Alto,Bass', 'Tenor,Bass')]
     }
     ind_piece = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
     vt = ind_piece.get_data('vertical_interval', settings=v_setts)
     hz = ind_piece.get_data('horizontal_interval', settings=h_setts)
     actual = ind_piece.get_data('ngram', data=(vt, hz), settings=n_setts)
     self.assertTrue(actual.equals(expected))
Exemplo n.º 3
0
def melodic_pattern_rest_finder(music_score, ngrams=3):
    imported_score = Importer(music_score)
    pattern_dict = {}
    horizontal_settings = {
        'quality': 'diatonic with quality',
        'simple or compound': 'compound',
        'directed': True,
        'horiz_attach_later': True,
        'mp': False
    }
    ngram_settings = {'n': ngrams, 'vertical': 'all', 'brackets': False}

    horizontal_intervals = imported_score.get_data(
        'horizontal_interval', settings=horizontal_settings)
    n_grams = imported_score.get_data('ngram',
                                      data=[horizontal_intervals],
                                      settings=ngram_settings)
    ngrams_occurrences = imported_score.get_data('frequency', data=n_grams)

    for occurrence in ngrams_occurrences:
        for i, y in enumerate(occurrence.values):
            pattern = occurrence.index[i]
            num_pattern_occurrences = occurrences_sum(occurrence, i)
            pattern_dict[pattern] = num_pattern_occurrences
        for w in sorted(pattern_dict, key=pattern_dict.get, reverse=True):
            print(w, pattern_dict[w])
Exemplo n.º 4
0
def dissonance_count(
        music_score):  # Returns a dictionary of the most common dissonances
    """
    Dissonances are described as follows:
    ‘Q’: Dissonant third quarter (special type of accented passing
    tone)
    ‘D’: Descending passing tone
    ‘R’: Ascending (“rising”) passing tone
    ‘L’: Lower neighbour
    ‘U’: Upper neighbour
    ‘S’: Suspension
    ‘F’: Fake suspension
    ‘f’: Diminished fake suspension
    ‘A’: Anticipation
    ‘C’: Nota cambiata
    ‘H’: Chanson idiom
    ‘E’: Echappée (escape tone)
    ‘-‘: Either no dissonance, or the part in question is not
    considered to be the dissonant note of the dissonance it’s in.
    :param music_score: a music score in the following formats: MIDI, Humdrum, xml.
    :return: dictionary of most common dissonances in the music piece
    """
    imported_score = Importer(music_score)
    dissonance = imported_score.get_data('dissonance')
    offset_dissonance = imported_score.get_data('dissonance')
    print(offset_dissonance)
    dissonance_dict = {}
    for dissonance_list in dissonance.values:
        for dissonance in dissonance_list:
            if dissonance is not "-":
                if dissonance not in dissonance_dict.keys():
                    dissonance_dict[dissonance] = 1
                else:
                    dissonance_dict[dissonance] += 1
    print(dissonance_dict)
 def test_measure_indexer_4(self):
     # bwv77.mxl, which is a piece with a pick-up measure. All 4 parts have the same data.
     measure_data = pandas.Series(range(19), index=TestMeasureIndexer.bwv77_measure_index)
     expected = pandas.concat([measure_data]*4, axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     actual = ip._get_measure()
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
 def test_duration_indexer_5(self):
     # Alto part of bwv603.mxl which is a part with ties. Also test that data argument is passed 
     # correctly. Since the data argument is passed, these results should not be cached.
     expected = TestDurationIndexer.make_series(TestDurationIndexer.bwv603_alto)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get_data('duration', data=(ip.get_data('noterest'), ip._analyses['part_streams'])).iloc[:, 1].dropna()
     self.assertTrue(actual.equals(expected))
     self.assertTrue('duration' not in ip._analyses.keys())
 def test_measure_indexer_5(self):
     # A two-part test piece with no pick-up measure originally written to test fermata indexer.
     measure_data = pandas.Series([1, 2], index=[0.0, 4.0])
     expected = pandas.concat([measure_data]*2, axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/test_fermata_rest.xml'))
     actual = ip.get_data('measure')
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
Exemplo n.º 8
0
 def test_dynamic_offset_method(self):
     # integration test for dynamic offset method call and execution
     expected = os.path.join(VIS_PATH, 'tests', 'expecteds', 'bwv77', 'dynamic_offset_method_test')
     expected = pandas.read_pickle(expected)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv77.mxl'))
     nr = ip.get_data('noterest')
     actual = ip.get_data('offset', data=nr, settings={'quarterLength': 'dynamic'})
     self.assertTrue(actual.equals(expected))
Exemplo n.º 9
0
 def test_duration_indexer_4(self):
     # Soprano part of bwv77.mxl which is a part with no ties
     expected = TestDurationIndexer.make_series(
         TestDurationIndexer.bwv77_soprano)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     ip._analyses['part_streams'] = ip._get_part_streams()
     actual = ip.get_data('duration').iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))
 def test_note_beat_strength_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([TestNoteBeatStrengthIndexer.make_series(bwv603_soprano),
                              TestNoteBeatStrengthIndexer.make_series(bwv603_bass)], axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip._get_beat_strength()['meter.NoteBeatStrengthIndexer'].iloc[:, [0, 3]].dropna(how='all')
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
 def test_duration_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([TestDurationIndexer.make_series(TestDurationIndexer.bwv603_soprano),
                               TestDurationIndexer.make_series(TestDurationIndexer.bwv603_bass)], axis=1)
     expected.columns = pandas.MultiIndex.from_product([('meter.DurationIndexer',), ('Soprano', 'Bass')])
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get_data('duration').iloc[:, [0, 3]].dropna(how='all')
     self.assertTrue(actual.equals(expected))
Exemplo n.º 12
0
 def test_multistop_indexer_2(self):
     # Integration test of a whole piece, the string quarted in the test corpus.
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'sqOp76-4-i.midi'))
     actual = ip._get_multistop()
     # Until we figure out why pickling isn't working:
     self.assertTrue(10 == len(actual.columns))
     self.assertTrue(3286 == len(actual.index))
     self.assertSequenceEqual([val for val in actual.count().values],
                              [2098, 41, 4, 1818, 131, 1, 1621, 15, 1232, 2])
Exemplo n.º 13
0
def run_analysis(filename):
    s = Importer(filename)
    nr = s.get_data('noterest')
    lines = [' '.join(l.split()) for l in nr.to_string().split('\n')]
    for line in lines[2:]:
        ind, b, t, a, s = line.split(' ')
        print('{}:{}, {}, {}, {}, {}'.format(
            int(float(ind) / 3) + 1,
            float(ind) % 3, b, t, a, s))
 def test_fermata_indexer_2(self):
     """rest fermatas; no WorkflowManager"""
     # Create expected.
     temp = [pandas.Series(['Fermata'], index=[6]), pandas.Series(['Fermata'], index=[6])]
     expected = pandas.concat(temp, axis=1).reindex(pandas.Index([0,1,2,3,4,6]))
     # Test.
     ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'test_fermata_rest.xml'))
     expected.columns = ind_piece.metadata('parts')
     actual = ind_piece._get_fermata()
     self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
Exemplo n.º 15
0
 def test_dynamic_offset_method(self):
     # integration test for dynamic offset method call and execution
     expected = os.path.join(VIS_PATH, 'tests', 'expecteds', 'bwv77',
                             'dynamic_offset_method_test')
     expected = pandas.read_pickle(expected)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv77.mxl'))
     nr = ip.get_data('noterest')
     actual = ip.get_data('offset',
                          data=nr,
                          settings={'quarterLength': 'dynamic'})
     self.assertTrue(actual.equals(expected))
 def test_ngrams_1(self):
     """Ngram integration test."""
     expected = AllVoiceIntervalNGrams.series_maker(AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({('ngram.NGramIndexer', 'Soprano,Bass Alto,Bass Tenor,Bass : Bass'): expected})
     ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml'))
     setts = {'quality': False, 'simple': False, 'horiz_attach_later': True}
     horiz_ints = ind_piece.get_data('horizontal_interval', settings=setts)
     vert_ints = ind_piece.get_data('vertical_interval', settings=setts)
     setts = {'n': 2, 'continuer': '1', 'horizontal': 'lowest',
              'vertical': [('Soprano,Bass', 'Alto,Bass', 'Tenor,Bass')], 'brackets': True,}
     actual = ind_piece.get_data('ngram', data=(vert_ints, horiz_ints), settings=setts)
     self.assertTrue(actual.equals(expected))
Exemplo n.º 17
0
 def test_duration_indexer_5(self):
     # Alto part of bwv603.mxl which is a part with ties. Also test that data argument is passed
     # correctly. Since the data argument is passed, these results should not be cached.
     expected = TestDurationIndexer.make_series(
         TestDurationIndexer.bwv603_alto)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get_data(
         'duration',
         data=(ip.get_data('noterest'),
               ip._analyses['part_streams'])).iloc[:, 1].dropna()
     self.assertTrue(actual.equals(expected))
     self.assertTrue('duration' not in ip._analyses.keys())
Exemplo n.º 18
0
 def test_ngrams_3(self):
     """Integration test for ngrams."""
     expected = AllVoiceIntervalNGrams.series_maker(AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({('ngram.NGramIndexer', '0,3 1,3 2,3 : 3'): expected})
     v_setts = {'quality': False, 'simple or compound': 'compound', 'directed': True}
     h_setts = {'quality': False, 'horiz_attach_later': True, 'simple or compound': False, 'directed': True}
     n_setts = {'n': 2, 'horizontal': [('3',)], 'vertical': [('0,3', '1,3', '2,3')], 'brackets': True, 'continuer': '1'}
     ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
     vt = ind_piece.get_data('vertical_interval', settings=v_setts)
     hz = ind_piece.get_data('horizontal_interval', settings=h_setts)
     actual = ind_piece.get_data('ngram', data=(vt, hz), settings=n_setts)
     self.assertTrue(actual.equals(expected))
 def test_note_beat_strength_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([
         TestNoteBeatStrengthIndexer.make_series(bwv603_soprano),
         TestNoteBeatStrengthIndexer.make_series(bwv603_bass)
     ],
                              axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip._get_beat_strength(
     )['meter.NoteBeatStrengthIndexer'].iloc[:, [0, 3]].dropna(how='all')
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
Exemplo n.º 20
0
 def test_noterest_indexer_4(self):
     # Combine three previous tests to avoid re-importing the same piece multiple times.
     # Soprano part of bwv77.mxl
     expected = TestNoteRestIndexer.make_series(TestNoteRestIndexer.bwv77_soprano)
     expected.name = 'Soprano'
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     actual = ip._get_noterest()['noterest.NoteRestIndexer'].iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))
     
     # Reset analysis dictionary and make the score just the bass part and do the same test.
     expected = TestNoteRestIndexer.make_series(TestNoteRestIndexer.bwv77_bass)
     expected.name = 'Bass'
     actual = ip._get_noterest()['noterest.NoteRestIndexer'].iloc[:, 3].dropna()
     self.assertTrue(actual.equals(expected))
Exemplo n.º 21
0
 def test_duration_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([
         TestDurationIndexer.make_series(
             TestDurationIndexer.bwv603_soprano),
         TestDurationIndexer.make_series(TestDurationIndexer.bwv603_bass)
     ],
                              axis=1)
     expected.columns = pandas.MultiIndex.from_product([
         ('meter.DurationIndexer', ), ('Soprano', 'Bass')
     ])
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get_data('duration').iloc[:, [0, 3]].dropna(how='all')
     self.assertTrue(actual.equals(expected))
Exemplo n.º 22
0
def run_analysis(filename):
    s = Importer(filename)
    v = s.get_data('vertical_interval', vert_setts)
    h = s.get_data('horizontal_interval', horiz_setts)
    parts = [x for x in s._metadata['parts']]
    # Assuming parts come from higher to lower and reversing
    parts = list(reversed(parts))
    combinations = get_part_combinations(parts)
    for vertical, horizontal in combinations:
        ngram_setts['vertical'] = vertical
        ngram_setts['horizontal'] = horizontal
        ngram = s.get_data('ngram', data=[v, h], settings=ngram_setts)
        for k1, v1 in ngram.to_dict().items():
            for k2, v2 in v1.items():
                print('{}: {}'.format(k2, v2))
Exemplo n.º 23
0
 def test_fermata_indexer_2(self):
     """rest fermatas; no WorkflowManager"""
     # Create expected.
     temp = [
         pandas.Series(['Fermata'], index=[6]),
         pandas.Series(['Fermata'], index=[6])
     ]
     expected = pandas.concat(temp, axis=1).reindex(
         pandas.Index([0, 1, 2, 3, 4, 6]))
     # Test.
     ind_piece = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'test_fermata_rest.xml'))
     expected.columns = ind_piece.metadata('parts')
     actual = ind_piece._get_fermata()
     self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
Exemplo n.º 24
0
def intervals_counter(music_score):
    imported_score = Importer(music_score)
    intervals_dict = {}
    hor_int_settings = {
        'quality': 'diatonic with quality',
        'simple or compound': 'compound',
        'directed': False
    }
    horizontal_intervals = imported_score.get_data('horizontal_interval',
                                                   settings=hor_int_settings)
    freqs = imported_score.get_data('frequency', data=horizontal_intervals)
    for interval_type in freqs:
        for i, num_occurrences in enumerate(interval_type.index):
            intervals_dict[num_occurrences] = occurrences_sum(interval_type, i)
        for w in sorted(intervals_dict, key=intervals_dict.get, reverse=True):
            print(w, intervals_dict[w])
Exemplo n.º 25
0
 def test_diss_indexer_run_2(self):
     """
     Test the dissonance indexer on an entire real piece that has most of the dissonance types 
     and covers almost all of the logic, namely the "Kyrie" in the test corpus. NB: perhaps 
     this test should get moved to the integration tests file.
     """
     expected = pd.read_pickle(os.path.join(VIS_PATH, 'tests', 'expecteds', 'test_dissonance_thorough.pickle'))
     # Detection of Z's and O's was removed and so this old ground-truth is updated in this test with the two 
     # following lines. If the dissonance indexer gets re-written, it would be good to go back to this old 
     # ground truth without needing these two replace() calls.
     expected.replace('Z', '-', inplace=True)
     expected.replace('O', '-', inplace=True)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'Kyrie.krn'))
     actual = ip.get_data('dissonance')
     assert_frame_equal(actual, expected)
     self.assertTrue(actual.equals(expected))
    def test_fermata_indexer_1(self):
        """all-voice fermatas; no WorkflowManager"""
        # Create expected.
        parts = [pandas.Series(['Fermata']*4, index=[10,19,31,46]),
                 pandas.Series(), pandas.Series(),
                 pandas.Series(['Fermata']*4, index=[10,19,31,46])]        
        expected = pandas.concat(parts, axis=1)
        indx = pandas.Index(range(47))
        expected = expected.reindex(index=indx)
        expected.drop([11, 12, 20, 32], inplace=True)

        # Test.
        ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
        expected.columns = ind_piece.metadata('parts')
        actual = ind_piece._get_fermata()
        self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
Exemplo n.º 27
0
 def test_part_ranges(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     score = Importer(path)._score
     expected_range = [('E4', 'E5'), ('E3', 'B4'), ('F#3', 'A4'),
                       ('A2', 'C4')]
     actual_range = _find_part_ranges(score)
     self.assertEqual(expected_range, actual_range)
Exemplo n.º 28
0
def rhythmic_pattern(music_score, ngrams=5):
    imported_score = Importer(music_score)
    pattern_dict = {}
    ngram_settings = {'n': ngrams, 'vertical': 'all', 'brackets': False}

    duration = imported_score.get_data('duration')
    n_grams = imported_score.get_data('ngram',
                                      data=[duration],
                                      settings=ngram_settings)
    ngrams_occurrences = imported_score.get_data('frequency', data=n_grams)
    for occurrence in ngrams_occurrences:
        for i, y in enumerate(occurrence.values):
            pattern = occurrence.index[i]
            num_pattern_occurrences = occurrences_sum(occurrence, i)
            pattern_dict[pattern] = num_pattern_occurrences
        for w in sorted(pattern_dict, key=pattern_dict.get, reverse=True):
            print(w, pattern_dict[w])
Exemplo n.º 29
0
 def test_bwv2(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     expected_title = 'bwv2'
     expected_parts = ['Soprano', 'Alto', 'Tenor', 'Bass']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
Exemplo n.º 30
0
 def test_diss_indexer_run_2(self):
     """
     Test the dissonance indexer on an entire real piece that has most of the dissonance types 
     and covers almost all of the logic, namely the "Kyrie" in the test corpus. NB: perhaps 
     this test should get moved to the integration tests file.
     """
     expected = pd.read_pickle(
         os.path.join(VIS_PATH, 'tests', 'expecteds',
                      'test_dissonance_thorough.pickle'))
     # Detection of Z's and O's was removed and so this old ground-truth is updated in this test with the two
     # following lines. If the dissonance indexer gets re-written, it would be good to go back to this old
     # ground truth without needing these two replace() calls.
     expected.replace('Z', '-', inplace=True)
     expected.replace('O', '-', inplace=True)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'Kyrie.krn'))
     actual = ip.get_data('dissonance')
     expected.columns = actual.columns  # the pickle file has old-style column names.
     assert_frame_equal(actual, expected)
Exemplo n.º 31
0
 def test_sinfony(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'sinfony.md')
     expected_title = 'Messiah'
     expected_parts = ['Violino I', 'Violino II', 'Viola', 'Bassi']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
Exemplo n.º 32
0
 def test_jos2308_krn(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'Jos2308.krn')
     expected_title = 'Jos2308'
     expected_parts = ['spine_3', 'spine_2', 'spine_1', 'spine_0']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
Exemplo n.º 33
0
 def test_opus76(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'sqOp76-4-i.midi')
     expected_title = 'sqOp76-4-i'
     expected_parts = ['Part 1', 'Part 2', 'Part 3', 'Part 4']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
Exemplo n.º 34
0
 def test_get_data_3(self):
     """integration test with a nested called to get_data, an ind_analyzer and a 
     combined_experimenter"""
     expected = pandas.Series([4.0,2.0,2.0,2.0,2.0,2.0,2.0,4.0],
                              index=['C3','C4','D4','E4','F4','G2','G4','Rest'])
     pieces = [Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'test_fermata_rest.xml'))]*2
     aps = AggregatedPieces(pieces=pieces)
     actual = aps.get_data(combined_experimenter='aggregator',
                           data=aps.get_data(ind_analyzer='noterest', combined_experimenter='frequency'))
     self.assertTrue(actual.iloc[:,0].equals(expected))
Exemplo n.º 35
0
    def test_fermata_indexer_1(self):
        """all-voice fermatas; no WorkflowManager"""
        # Create expected.
        parts = [
            pandas.Series(['Fermata'] * 4, index=[10, 19, 31, 46]),
            pandas.Series(),
            pandas.Series(),
            pandas.Series(['Fermata'] * 4, index=[10, 19, 31, 46])
        ]
        expected = pandas.concat(parts, axis=1)
        indx = pandas.Index(range(47))
        expected = expected.reindex(index=indx)
        expected.drop([11, 12, 20, 32], inplace=True)

        # Test.
        ind_piece = Importer(
            os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
        expected.columns = ind_piece.metadata('parts')
        actual = ind_piece._get_fermata()
        self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
Exemplo n.º 36
0
 def test_Importer3(self):
     path = 'vis/tests/corpus/elvisdownload/'
     folder = os.listdir(path)
     if '.DS_Store' in folder:
         folder.remove('.DS_Store')
     folder.remove('meta')
     new_f = []
     for f in folder:
         new_f.append(path + f)
     agg = Importer(new_f)
     self.assertTrue(isinstance(agg, AggregatedPieces))
Exemplo n.º 37
0
def count_intervals():
    def get_ints(row, num_voices):
        return tuple(sorted(set(n for n in tuple((tuple(row))[1]) if n != 'Rest'), key = lambda n: abs(int(n)))[:num_voices-1])
    prog_counter = Counter()
    i = 0

    vert_settings = {
        'quality': 'chromatic',
        'simple or compound': 'simple',
        'directed': True
    }

    for m in [p for p in os.listdir('music_files/corpus/Palestrina/') if p[-3:] == 'xml']:
        print("processing " + m)
        num_voices = m.split('_')[-1][0]
        if num_voices.isdigit():
            num_voices = int(num_voices)
        else:
            print("skipping " + m)
            continue
        ip = Importer('music_files/corpus/Palestrina/' + m)
        df = ip.get_data('vertical_interval', settings=vert_settings).fillna(method="ffill")

        note_df = ip.get_data('noterest').fillna(method="ffill")

        #int_df = df['interval.IntervalIndexer']

        it = zip(df.iterrows(), islice(df.iterrows(), 1, None))
        for row in it:
            ints = tuple(get_ints(r, num_voices) for r in row)
            prog_counter.update((ints, ))

        if i % 100 == 0:
            with open('scripts/prog.pckl', 'wb') as f:
                pickle.dump(prog_counter, f)

    with open('scripts/prog.pckl', 'wb') as f:
        pickle.dump(prog_counter, f)

    return prog_counter, df
Exemplo n.º 38
0
def count_notes():
    def get_notes(row):
            return tuple(sorted(set([n[0] if n[1].isdigit() else n[0:2] for n in tuple((tuple(row))[1]) if n != 'Rest'])))

    prog_counter = Counter()
    i = 0

    for m in [p for p in os.listdir('music_files/corpus/Palestrina/') if p[-3:] == 'xml']:
        print("processing " + m)
        ip = Importer('music_files/corpus/Palestrina/' + m)
        df = ip.get_data('noterest').fillna(method="ffill")
        it = zip(df.iterrows(), islice(df.iterrows(), 1, None))
        for row in it:
            notes = tuple(map(get_notes, row))
            prog_counter.update((notes, ))

        if i % 100 == 0:
            with open('scripts/prog.pckl', 'wb') as f:
                pickle.dump(prog_counter, f)

    with open('scripts/prog.pckl', 'wb') as f:
        pickle.dump(prog_counter, f)
Exemplo n.º 39
0
 def test_ngrams_1(self):
     """Ngram integration test."""
     expected = AllVoiceIntervalNGrams.series_maker(
         AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({
         ('ngram.NGramIndexer', 'Soprano,Bass Alto,Bass Tenor,Bass : Bass'):
         expected
     })
     ind_piece = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml'))
     setts = {'quality': False, 'simple': False, 'horiz_attach_later': True}
     horiz_ints = ind_piece.get_data('horizontal_interval', settings=setts)
     vert_ints = ind_piece.get_data('vertical_interval', settings=setts)
     setts = {
         'n': 2,
         'continuer': '1',
         'horizontal': 'lowest',
         'vertical': [('Soprano,Bass', 'Alto,Bass', 'Tenor,Bass')],
         'brackets': True,
     }
     actual = ind_piece.get_data('ngram',
                                 data=(vert_ints, horiz_ints),
                                 settings=setts)
     self.assertTrue(actual.equals(expected))
Exemplo n.º 40
0
def runAnalysis(scorelist, output_json, output_tsv):	
    with open(scorelist) as f:
        pathnames = f.readlines()
        pathnames = [f.strip() for f in pathnames]
        for filename in pathnames:
            if not filename.endswith('.xml'):
                continue
            print(filename)
            s = Importer(filename)
            ### Workaround for getting the part names because the 'all' setting in vis-framework does not seem to be working for horizontal intervals
            parts = [x.id for x in s._analyses['part_streams']]
            parts = list(reversed(parts))
            parts = [tuple(parts)]
            ngram_setts['horizontal'] = parts
            ###################################
            hn, ngrams = analysisHalfNotesCutAtRestNoRepeats(s)
            ngramdict = ngrams.iloc[:,0].to_dict()
            reversengram = inverseNGramDict(ngramdict, filename)
            ngramsperscore[filename] = ngramdict

        with open(output_json, 'w') as o:
            o.write(json.dumps(ngramsperscore, sort_keys=True, indent=4))
       
        with open(output_tsv, 'w') as o:
            top20 = []
            header = 'Occurrences\tNGram\tComposer\tWork\tOffset (Minim)\n'
            o.write(header)
            for k,v in sorted(globalngrams.items(), reverse=True, key=lambda kv: len(kv[1])):
                o.write('{}\t{}\n'.format(len(v),k))
                composer_occurrences = Counter()
                for x in v:
                    offset = x[1]
                    f = x[0].split('/')
                    composer = f[2]
                    work = f[4]
                    o.write('\t\t{}\t{}\t{}\n'.format(composer,work,offset))
                    composer_occurrences[composer] += 1
                top20.append('{}, {}, {}'.format(len(v), k, composer_occurrences))
        print('Top 20')
        for x in top20[:20]:
            print('\t',x)
Exemplo n.º 41
0
def runAnalysis(scorelist, output_tsv):
    intervals = OrderedDict()
    total_intervals = OrderedDict()
    with open(scorelist) as f:
        pathnames = f.readlines()
        pathnames = [f.strip() for f in pathnames]
        for filename in pathnames:
            if not filename.endswith('.xml'):
                continue
            print(filename)
            s = Importer(filename)
            _, verts = analysisHalfNotesCutAtRestNoRepeats(s)
            verts_list = list(list(verts.to_dict().values())[0].values())
            composer = filename.split('/')[2]
            composer_intervals = intervals.get(composer, Counter())
            composer_total_intervals = total_intervals.get(composer, 0)
            composer_intervals.update(verts_list)
            composer_total_intervals += len(verts_list)
            intervals[composer] = composer_intervals
            total_intervals[composer] = composer_total_intervals
        with open(output_tsv, 'w') as o:
            header = "interval"
            for composer in intervals:
                header += '\t{0}\t{0} (percent)'.format(composer)
            header += '\n'
            o.write(header)
            all_intervals = []
            [all_intervals.extend(v.keys()) for c, v in intervals.items()]
            all_intervals = [int(n) for n in all_intervals if n != 'Rest']
            min_interval = min(all_intervals)
            max_interval = max(all_intervals)
            for n in range(min_interval, max_interval + 1):
                strn = str(n)
                row = '{}'.format(n)
                for composer in intervals:
                    count = intervals[composer][strn]
                    percent = count / total_intervals[composer]
                    row += '\t{}\t{}'.format(count, percent)
                row += '\n'
                o.write(row)
Exemplo n.º 42
0
 def test_piece_range(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     score = Importer(path)._score
     expected_range = ('A2', 'E5')
     actual_range = _find_piece_range(score)
     self.assertEqual(expected_range, actual_range)
 def test_multistop_indexer_3(self):
     # Integration test on a piece with multiple voices in each part
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'prelude28-20.mid'))
     actual = ip.get_data('multistop')
     self.assertTrue(8 == len(actual.columns))
 def test_note_beat_strength_indexer_5(self):
     # Alto part of bwv603.mxl which is a part with ties
     expected = TestNoteBeatStrengthIndexer.make_series(bwv603_alto)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip._get_beat_strength().iloc[:, 1].dropna()
     self.assertTrue(actual.equals(expected))
 def test_note_beat_strength_indexer_4(self):
     # Soprano part of bwv77.mxl which is a part with no ties
     expected = TestNoteBeatStrengthIndexer.make_series(bwv77_soprano)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     actual = ip._get_beat_strength().iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))
Exemplo n.º 46
0
from vis.models.indexed_piece import Importer
import vis
VIS_path = vis.__path__[0]

folder = VIS_path + '/tests/corpus/elvisdownload2'
dendro_setts = {
    'graph_settings': {
        'filename_and_type': 'Dendrogram_output.png'
    }
}
ap = Importer(folder)
intervals = ap.get_data('vertical_interval')
ap.get_data(combined_experimenter='dendrogram',
            data=[intervals],
            settings=dendro_setts)
from vis.models.indexed_piece import Importer
import vis
VIS_path = vis.__path__[0]

folder = VIS_path + '/tests/corpus/elvisdownload2'
dendro_setts = {'graph_settings': {'filename_and_type': 'Dendrogram_output.png'}}
ap = Importer(folder)
intervals = ap.get_data('vertical_interval')
ap.get_data(combined_experimenter='dendrogram', data=[intervals], settings=dendro_setts)
Exemplo n.º 48
0
 def test_Importer2(self):
     directory = 'vis/tests/corpus/elvisdownload2'
     agg = Importer(directory)
     self.assertTrue(isinstance(agg, AggregatedPieces))