Beispiel #1
0
 def _get_duration(self, data=None):
     """Used internally by get_data() to cache and retrieve results from the 
     meter.DurationIndexer. The `data` argument should be a 2-tuple where the first element is 
     a dataframe of results with one column per voice (like the noterest indexer) and the second 
     element is a list of the part streams, one per part."""
     if data is not None:
         return meter.DurationIndexer(data[0], data[1]).run()
     elif 'duration' not in self._analyses:
         self._analyses['duration'] = meter.DurationIndexer(self._get_noterest(), self._get_part_streams()).run()
     return self._analyses['duration']
Beispiel #2
0
 def test_duration_indexer_1(self):
     # When the parts are empty
     expected = pandas.DataFrame({
         '0': pandas.Series(),
         '1': pandas.Series()
     })
     expected.columns = pandas.MultiIndex.from_product([
         ('meter.DurationIndexer', ), ['0', '1']
     ])
     test_parts = [stream.Part(), stream.Part()]
     dur_indexer = meter.DurationIndexer(expected, test_parts)
     actual = dur_indexer.run()
     self.assertTrue(actual.equals(expected))
Beispiel #3
0
 def test_duration_indexer_2(self):
     # When the part has no Note or Rest objects in it
     expected = pandas.DataFrame({'0': pandas.Series()})
     expected.columns = pandas.MultiIndex.from_product([
         ('meter.DurationIndexer', ), ('0', )
     ])
     test_part = stream.Part()
     # add stuff to the test_part
     for i in range(10):
         add_me = clef.BassClef()
         add_me.offset = i
         test_part.append(add_me)
         add_me = bar.Barline()
         add_me.offset = i
         test_part.append(add_me)
     test_part = [test_part]  # finished adding stuff to the test_part
     dur_indexer = meter.DurationIndexer(expected, test_part)
     actual = dur_indexer.run()
     self.assertTrue(actual.equals(expected))
def main():
    piece_path = "/home/amor/Code/vis-framework/vis/tests/corpus/Kyrie.krn"
    # piece_path = "/home/amor/Code/vis-framework/vis/tests/corpus/bach.xml"
    # piece_path = "/home/amor/Code/vis-framework/vis/tests/corpus/bwv603.xml"
    # piece_path = '/home/amor/Code/vis-framework/vis/tests/corpus/Reimenschnieder/1-026900B_.xml'
    #piece_path = '/home/amor/Code/vis-framework/vis/tests/corpus/Jos2308.mei'
    # piece_path = '/home/amor/Code/vis-framework/vis/tests/corpus/Sanctus.krn'
    ind_piece = IndexedPiece(piece_path)
    test_piece = ind_piece._import_score()
    test_parts = test_piece.parts

    # bwv603 = converter.parse(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
    # test_part = [bwv603.parts[0], bwv603.parts[1], bwv603.parts[2], bwv603.parts[3]]

    setts = {'quality': True, 'simple or compound': 'simple'}
    horiz_setts = {'quality': False, 'simple or compound': 'compound'}

    t0 = time.time()
    actual = noterest.NoteRestIndexer(test_parts).run()

    # filter_setts = {'quarterLength': 2.0, 'method':None}
    # filtered_results = offset.FilterByOffsetIndexer(actual, filter_setts).run()
    # pdb.set_trace()
    dur_ind = meter.DurationIndexer(test_parts).run()
    bs_ind = meter.NoteBeatStrengthIndexer(test_parts).run()
    horiz = interval.HorizontalIntervalIndexer(actual, horiz_setts).run()
    # ind_piece._analyses['noterest'] = actual
    # h_df = ind_piece._get_h_ints(settings=horiz_setts)
    vert_ints = interval.IntervalIndexer(actual, setts).run()
    dissonances = dissonance.DissonanceIndexer(
        [bs_ind, dur_ind, horiz, vert_ints]).run()

    t1 = time.time()
    print('Time taken to run all indexers: ')
    print(t1 - t0)

    pdb.set_trace()
Beispiel #5
0
av_setts = {'show_all': True}
v_setts = {'quality': True, 'simple or compound': 'simple', 'directed': True, 'mp': False}
h_setts = {'quality': False, 'horiz_attach_later': False, 'simple or compound': 'simple', 'directed': True, 'mp': False}
n_setts = {'n': 5, 'continuer': 'P1', 'horizontal': 'lowest', 'vertical': [('0,4',)],
           'terminator': ['Rest'], 'open-ended': False, 'brackets': False}
n_setts_2 = {'n': 5, 'continuer': 'P1', 'vertical': 'all',
           'terminator': ['Rest'], 'open-ended': False, 'brackets': False}
n_setts_3 = {'n': 2, 'continuer': 'P1', 'vertical': [('0,4',)],
           'terminator': [], 'open-ended': False, 'brackets': False}

# pieces = (IndexedPiece(piece_path2), ind_piece)
# corpus = AggregatedPieces(pieces)
pdb.set_trace()

nr = noterest.NoteRestIndexer(parts).run()
dr = meter.DurationIndexer(parts).run()
ms = meter.MeasureIndexer(parts).run()
bs = meter.NoteBeatStrengthIndexer(parts).run()
t0 = time.time()
hz = interval.HorizontalIntervalIndexer(nr, h_setts).run()
hz.columns.set_levels(('Horiz_nsd',), level=0, inplace=True)
av = active_voices.ActiveVoicesIndexer(nr, av_setts).run()
av = pandas.concat([av]*5, axis=1, ignore_index=True)
av.columns=[('av', '0'), ('av', '1'), ('av', '2'), ('av', '3'), ('av', '4')]
t1 = time.time()
print(str(t1-t0))
vt = interval.IntervalIndexer(nr, v_setts).run()

ng = new_ngram.NewNGramIndexer((vt, hz), n_setts).run()
ng_2 = new_ngram.NewNGramIndexer((hz,), n_setts_2).run()
# ng_3 = new_ngram.NewNGramIndexer((dr,), n_setts_3).run()