def test_book_example(self): print('----- book_example -----') voice_line = Line() melody_line = Line() melody_1 = Line( [Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'aceg']) melody_2 = Line( [Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'cadg']) base_line = Line( [Note(DiatonicPitch(4, y), Duration(1, 4)) for y in 'dddddddd']) melody_line.pin(melody_1, Offset(1, 8)) melody_line.pin(melody_2, Offset(1, 4)) voice_line.pin(melody_line) voice_line.pin(base_line) print(voice_line) all_notes = voice_line.get_all_notes() print('... pinned notes ...') for n in all_notes: print('({0}) : {1}'.format(n.get_absolute_position(), n.diatonic_pitch)) print('... end pinned notes ...') print('End test_pin')
def test_pin(self): print('----- test_pin -----') l1_notes = [Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'abcd'] l2_notes = [Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'efgab'] line = Line() line.pin(Line(l1_notes), Offset(1, 8)) line.pin(Line(l2_notes), Offset(1, 4)) all_notes = line.get_all_notes() print('... pinned notes ...') for n in all_notes: print('({0}) : {1}'.format(n.get_absolute_position(), n.diatonic_pitch)) print('... end pinned notes ...') print('End test_pin')
def test_richer_structure(self): line = Line() s = Beam() s.append(Note(DiatonicPitch.parse('C:4'), Duration(1, 8))) s.append(Note(DiatonicPitch.parse('D:4'), Duration(1, 8))) line.pin(s) q1 = Note(DiatonicPitch.parse('E:4'), Duration(1, 4)) line.pin(q1, Offset(1, 4)) q2 = Note(DiatonicPitch.parse('F#:4'), Duration(1, 4)) line.pin(q2, Offset(1, 2)) cs = Beam() first_note = Note(DiatonicPitch.parse('C:3'), Duration(1, 8)) cs.append(first_note) cs.append(Note(DiatonicPitch.parse('D:3'), Duration(1, 8))) line.pin(cs, Offset(2)) cq1 = Note(DiatonicPitch.parse('E:3'), Duration(1, 4)) line.pin(cq1, Offset(9, 4)) cq2 = Note(DiatonicPitch.parse('F#:3'), Duration(1, 4)) line.pin(cq2, Offset(5, 2)) notes = line.get_all_notes() c = [ EqualPitchConstraint([notes[0], notes[2]]), NotEqualPitchConstraint([notes[1], notes[3]]) ] m = Motif([s, q1, q2], c, 'A') print(m) actors = m.actors assert 'A' == m.name assert len(actors) == 4 cc = m.constraints assert len(cc) == len(c) assert isinstance(cc[0], EqualPitchConstraint) cc_a = cc[0].actors assert len(cc_a) == 2 assert cc_a[0] == actors[0] assert cc_a[1] == actors[2] assert isinstance(cc[1], NotEqualPitchConstraint) cc_b = cc[1].actors assert len(cc_a) == 2 assert cc_b[0] == actors[1] assert cc_b[1] == actors[3] assert 'F#:4' == str(actors[3].diatonic_pitch) c_motif = m.copy_to(first_note) assert c_motif is not None c_actors = c_motif.actors assert 'A' == c_motif.name assert len(c_actors) == 4 ccc = c_motif.constraints assert len(ccc) == len(c) assert isinstance(ccc[0], EqualPitchConstraint) ccc_a = ccc[0].actors assert len(ccc_a) == 2 assert ccc_a[0] == c_actors[0] assert ccc_a[1] == c_actors[2] assert isinstance(ccc[1], NotEqualPitchConstraint) ccc_b = ccc[1].actors assert len(ccc_a) == 2 assert ccc_b[0] == c_actors[1] assert ccc_b[1] == c_actors[3] assert 'F#:3' == str(c_actors[3].diatonic_pitch) print(c_motif)