Beispiel #1
0
    def test_nested_notes(self):
        note1 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        note2 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
        note3 = Note(DiatonicPitch(4, 'e'), Duration(1, 16))
        sub_beam = Beam([note1, note2, note3])

        beam = Beam()
        beam.append(Note(DiatonicPitch(4, 'f'), Duration(1, 8)))
        beam.append(sub_beam)
        beam.append(Note(DiatonicPitch(4, 'g'), Duration(1, 8)))

        print(beam)

        notes = beam.get_all_notes()
        assert len(notes) == 5
        assert notes[0].diatonic_pitch == DiatonicPitch(4, 'f')
        assert notes[1].diatonic_pitch == DiatonicPitch(4, 'c')
        assert notes[2].diatonic_pitch == DiatonicPitch(4, 'd')
        assert notes[3].diatonic_pitch == DiatonicPitch(4, 'e')
        assert notes[4].diatonic_pitch == DiatonicPitch(4, 'g')

        assert notes[0].relative_position == Offset(0)
        assert notes[1].relative_position == Offset(0)
        assert notes[2].relative_position == Offset(1, 16)
        assert notes[3].relative_position == Offset(1, 8)
        assert notes[4].relative_position == Offset(9, 32)
        TestBeam.print_all_notes(notes)

        notes = sub_beam.get_all_notes()
        TestBeam.print_all_notes(notes)

        b = Beam()
        b.append(beam)

        notes = sub_beam.get_all_notes()
        TestBeam.print_all_notes(notes)
        assert notes[0].duration == Duration(1, 32)
        assert str(notes[0].diatonic_pitch) == 'C:4'

        sub_beam_prime = sub_beam.clone()
        notes = sub_beam_prime.get_all_notes()
        TestBeam.print_all_notes(notes)
        assert notes[0].duration == Duration(1, 8)
        assert str(notes[0].diatonic_pitch) == 'C:4'

        beam_prime = beam.clone()
        notes = beam_prime.get_all_notes()
        TestBeam.print_all_notes(notes)
        assert notes[0].duration == Duration(1, 8)
        assert str(notes[0].diatonic_pitch) == 'F:4'

        b_prime = b.clone()
        notes = b_prime.get_all_notes()
        TestBeam.print_all_notes(notes)
        assert notes[0].duration == Duration(1, 16)
        assert str(notes[0].diatonic_pitch) == 'F:4'
Beispiel #2
0
    def test_add_notes_to_tuplet(self):
        c = InstrumentCatalog.instance()
        violin = c.get_instrument("violin")

        note0 = Note(DiatonicPitch(4, 'a'), Duration(1, 8))
        note1 = Note(DiatonicPitch(4, 'b'), Duration(1, 8))
        note2 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        note3 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
        beam = Beam([note0, note1])

        line = Line()
        line.pin(beam, Offset(1, 2))

        voice = Voice(violin)
        voice.pin(line, Offset(0))

        tuplet = Tuplet(Duration(1, 8), 3, [note2, note3])
        beam.append(tuplet)

        notee0 = Note(DiatonicPitch(5, 'a'), Duration(1, 8))
        tuplet.append(notee0)

        print(voice)
        notes = voice.get_notes_starting_in_interval(
            Interval(Position(1, 2), Position(5, 4)))

        assert len(notes) == 5
        assert TestVoice.has_pitch(notes, DiatonicPitch.parse('A:5'))

        beam_prime = beam.clone()
        notes = beam_prime.get_all_notes()
        AbstractNote.print_structure(beam_prime)
        assert notes[0].duration == Duration(1, 8)
        assert str(notes[0].diatonic_pitch) == 'A:4'

        line_prime = line.clone()
        notes = line_prime.get_all_notes()
        AbstractNote.print_structure(line_prime)
        assert notes[0].duration == Duration(1, 8)
        assert str(notes[0].diatonic_pitch) == 'A:4'
        assert notes[2].duration == Duration(1, 8)
        assert str(notes[2].diatonic_pitch) == 'C:4'
Beispiel #3
0
    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)