示例#1
0
class TestIndexedPieceB(TestCase):
    def setUp(self):
        self._pathname = u'test_path'
        self.ind_piece = IndexedPiece(self._pathname)

    def test_import_score_1(self):
        # That _import_score() raises an OpusWarning when it imports an Opus but "expect_opus" is
        # False
        with patch(u'vis.models.indexed_piece.converter.parse') as mock_parse:
            mock_parse.return_value = music21.stream.Opus()
            self.assertRaises(OpusWarning, self.ind_piece._import_score, known_opus=False)

    def test_import_score_2(self):
        # That _import_score() returns multiple IndexedPiece objects when it imports an Opus and
        # "expect_opus" is True
        with patch(u'vis.models.indexed_piece.converter.parse') as mock_parse:
            mock_parse.return_value = music21.stream.Opus()
            for _ in xrange(5):
                mock_parse.return_value.insert(music21.stream.Score())
            actual = self.ind_piece._import_score(known_opus=True)
            self.assertEqual(5, len(actual))
            for i, piece in enumerate(actual):
                self.assertTrue(isinstance(piece, IndexedPiece))
                self.assertEqual(i, piece._opus_id)

    def test_import_score_3(self):
        # That _import_score() raises an OpusWarning when "expect_opus" is True, but it doesn't
        # import an Opus
        with patch(u'vis.models.indexed_piece.converter.parse') as mock_parse:
            mock_parse.return_value = music21.stream.Score()
            self.assertRaises(OpusWarning, self.ind_piece._import_score, known_opus=True)

    def test_import_score_4(self):
        # That _import_score() returns the right Score object when it imports an Opus
        with patch(u'vis.models.indexed_piece.converter.parse') as mock_parse:
            mock_parse.return_value = music21.stream.Opus()
            for i in xrange(5):
                mock_parse.return_value.insert(music21.stream.Score())
                mock_parse.return_value[i].priority = 42 + i
            actual = self.ind_piece._import_score(known_opus=True)
            self.assertEqual(5, len(actual))
            for i, piece in enumerate(actual):
                self.assertEqual(42 + i, piece._import_score().priority)
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()
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()
示例#4
0
    # '/home/amor/Code/vis-framework/vis/scripts/M_corpus/15 In nets of golden wyers.xml',
    # '/home/amor/Code/vis-framework/vis/scripts/M_corpus/17 O thou that art so cruell.xml',
    # '/home/amor/Code/vis-framework/vis/scripts/M_corpus/19 I should for griefe and anguish.xml',
    ]
ccr_s, ni_s = [], []
v_setts = {'quality': True, 'simple or compound': 'simple'}
h_setts = {'quality': False, 'simple or compound': 'compound'}
h_setts2 = {'quality': True, 'simple or compound': 'compound', 'horiz_attach_later': True}
n_setts = {'n': 3, 'continuer': 'P1', 'horizontal': 'lowest', 'vertical': 'all',
           'terminator': ['Rest'], 'open-ended': False, 'brackets': False}
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 = []