예제 #1
0
 def _get_dissonance(self):
     """Used internally by get() to cache and retrieve results from the
     dissonance.DissonanceIndexer. This method automatically supplies the input dataframes from
     the indexed_piece that is the self argument. If you want to call this with indexer results
     other than those associated with self, you can call the indexer directly."""
     if 'dissonance' not in self._analyses:
         h_setts = {
             'quality': False,
             'simple or compound': 'compound',
             'horiz_attach_later': False
         }
         v_setts = setts = {
             'quality': True,
             'simple or compound': 'simple',
             'directed': True
         }
         in_dfs = [
             self._get_beat_strength(),
             self._get_duration(),
             self._get_horizontal_interval(h_setts),
             self._get_vertical_interval(v_setts)
         ]
         self._analyses['dissonance'] = dissonance.DissonanceIndexer(
             in_dfs).run()
     return self._analyses['dissonance']
예제 #2
0
 def test_diss_indexer_is_passing_1b(self):
     """
     Check that (False,) is returned when previous_event is not in dissonance._consonances.
     """
     in_dfs = [qh_b_df, qh_dur_df, qh_h_df, asc_q_v_df]
     expected = (False, )
     init = dissonance.DissonanceIndexer(in_dfs)
     actual = init._is_passing_or_neigh(1, '0,1', 'M2', 'm2')
     self.assertSequenceEqual(expected, actual)
예제 #3
0
 def test_diss_indexer_is_passing_1a(self):
     """
     Check that (False,) is returned whenprevious_event is None.
     """
     in_dfs = [qh_b_df, qh_dur_df, qh_h_df, asc_q_v_df]
     expected = (False, )
     init = dissonance.DissonanceIndexer(in_dfs)
     actual = init._is_passing_or_neigh('dummy', 'dummy', 'dummy', None)
     self.assertSequenceEqual(expected, actual)
예제 #4
0
 def test_diss_indexer_run_1a(self):
     """
     Detection of two rising passing tones in a mini-piece.
     """
     in_dfs = [qh_b_df, qh_dur_df, qh_h_df, asc_q_v_df]
     expected = empty_df.copy()
     expected.iat[1, 0] = 'R'
     expected.iat[3, 0] = 'R'
     actual = dissonance.DissonanceIndexer(in_dfs).run()
     assert_frame_equal(expected, actual)
예제 #5
0
 def test_diss_indexer_is_passing_2b(self):
     """
     Detection of rising passing tone in quarter notes.
     """
     in_dfs = [hq_b_df, hq_dur_df, hdescq_h_df, asc_q_v_df]
     expected = (True, '0', dissonance._no_diss_label, '1',
                 dissonance._pass_dp_label)
     init = dissonance.DissonanceIndexer(in_dfs)
     actual = init._is_passing_or_neigh(1, '0,1', 'M2', 'P1')
     self.assertSequenceEqual(expected, actual)
예제 #6
0
 def test_diss_indexer_run_1b(self):
     """
     Detection of two descending passing tones in a mini-piece. NB: the int size increases even 
     though the passing tones are descending because the passing tones are in the lower voice
     """
     in_dfs = [hq_b_df, hq_dur_df, hdescq_h_df, asc_q_v_df]
     expected = empty_df.copy()
     expected.iat[1, 1] = 'D'
     expected.iat[3, 1] = 'D'
     actual = dissonance.DissonanceIndexer(in_dfs).run()
     assert_frame_equal(expected, actual)
def main():
    piece_path = "/home/amor/Code/vizitka/vis/tests/corpus/Kyrie.krn"
    # piece_path = "/home/amor/Code/vizitka/vis/tests/corpus/bach.xml"
    # piece_path = "/home/amor/Code/vizitka/vis/tests/corpus/bwv603.xml"
    # piece_path = '/home/amor/Code/vizitka/vis/tests/corpus/Reimenschnieder/1-026900B_.xml'
    #piece_path = '/home/amor/Code/vizitka/vis/tests/corpus/Jos2308.mei'
    # piece_path = '/home/amor/Code/vizitka/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()
예제 #8
0
w = 6  # w is for window
ends = []

for number, piece_path in enumerate(pieces):
    ind_piece = IndexedPiece(piece_path)
    piece = ind_piece._import_score()
    parts = piece.parts
    nr = noterest.NoteRestIndexer(parts).run()
    dr = meter.DurationIndexer(parts).run()
    ms = meter.MeasureIndexer(parts).run()
    bs = meter.NoteBeatStrengthIndexer(parts).run()
    hz = interval.HorizontalIntervalIndexer(nr, h_setts).run()
    hz2 = interval.HorizontalIntervalIndexer(nr, h_setts2).run()
    vt = interval.IntervalIndexer(nr, v_setts).run()
    # ng = new_ngram.NewNGramIndexer((vt, hz2), n_setts).run()
    ds = dissonance.DissonanceIndexer([bs, dr, hz, vt]).run()
    av = active_voices.ActiveVoicesIndexer(nr).run()
    av_sa = active_voices.ActiveVoicesIndexer(nr, {'show_all': True}).run()

    voice_dr_means = []
    # Attack-density analysis each voice. The whole-piece analysis is probably what matters most though.
    for x in range(len(nr.columns)):
        mask = nr.iloc[:, x].dropna()
        # The durations of just the notes
        ndr = dr.iloc[:, x].dropna()[mask != 'Rest']
        mean_roll = ndr.rolling(window=w).mean()
        voice_dr_means.append(mean_roll)

    vdm = pandas.concat(voice_dr_means, axis=1)

    # Attack-density analysis for whole piece.