def test_nested_tuplet(self): note1 = Note(DiatonicPitch(4, 'c'), Duration(1, 8)) note2 = Note(DiatonicPitch(4, 'd'), Duration(1, 8)) sub_tuplet = Tuplet(Duration(1, 8), 2, [ Note(DiatonicPitch(3, 'c'), Duration(1, 8)), Note(DiatonicPitch(3, 'd'), Duration(1, 8)), Note(DiatonicPitch(3, 'e'), Duration(1, 8)) ]) tuplet = Tuplet(Duration(1, 8), 2, [note1, sub_tuplet, note2]) print(tuplet) AbstractNote.print_structure(tuplet) notes = tuplet.get_all_notes() assert len(notes) == 5 assert notes[0].duration == Duration(1, 16) assert notes[1].duration == Duration(1, 24) assert notes[2].duration == Duration(1, 24) assert notes[3].duration == Duration(1, 24) assert notes[4].duration == Duration(1, 16) assert notes[0].relative_position == Offset(0) assert notes[1].relative_position == Offset(0) assert notes[2].relative_position == Offset(1, 24) assert notes[3].relative_position == Offset(1, 12) assert notes[4].relative_position == Offset(3, 16) assert tuplet.sub_notes[1].duration == Duration(1, 8) assert tuplet.sub_notes[1].relative_position == Offset(1, 16) sub_tuplet_prime = sub_tuplet.clone() notes = sub_tuplet_prime.get_all_notes() AbstractNote.print_structure(sub_tuplet_prime) assert notes[0].duration == Duration(1, 12) assert str(notes[0].diatonic_pitch) == 'C:3' tuplet_prime = tuplet.clone() notes = tuplet_prime.get_all_notes() AbstractNote.print_structure(tuplet_prime) assert notes[0].duration == Duration(1, 16) assert str(notes[0].diatonic_pitch) == 'C:4' assert notes[1].duration == Duration(1, 24)
def test_tuplet_with_nested_beam(self): note1 = Note(DiatonicPitch(4, 'c'), Duration(1, 8)) note2 = Note(DiatonicPitch(4, 'd'), Duration(1, 8)) n_list = [ Note(DiatonicPitch(3, 'c'), Duration(1, 8)), Note(DiatonicPitch(3, 'd'), Duration(1, 8)) ] add_beam = Beam(n_list) tuplet = Tuplet(Duration(1, 8), 2, [note1, add_beam, note2]) print(tuplet) AbstractNote.print_structure(tuplet) notes = tuplet.get_all_notes() assert len(notes) == 4 assert tuplet.sub_notes[0].duration == Duration(1, 16) assert tuplet.sub_notes[0].relative_position == Offset(0) assert tuplet.sub_notes[1].duration == Duration(1, 8) assert tuplet.sub_notes[1].relative_position == Offset(1, 16) assert tuplet.sub_notes[2].duration == Duration(1, 16) assert tuplet.sub_notes[2].relative_position == Offset(3, 16) assert notes[1].duration == Duration(1, 16) assert notes[1].relative_position == Offset(0) assert notes[2].duration == Duration(1, 16) assert notes[2].relative_position == Offset(1, 16) add_beam_prime = add_beam.clone() notes = add_beam_prime.get_all_notes() AbstractNote.print_structure(add_beam_prime) assert notes[0].duration == Duration(1, 8) assert str(notes[0].diatonic_pitch) == 'C:3' tuplet_prime = tuplet.clone() notes = tuplet_prime.get_all_notes() AbstractNote.print_structure(tuplet_prime) assert notes[0].duration == Duration(1, 16) assert str(notes[0].diatonic_pitch) == 'C:4' assert notes[1].duration == Duration(1, 16)