示例#1
0
    def test_add_note_at_lower_level(self):
        print('start test_add_note_at_lower_level')
        sub_beam = Beam([
            Note(DiatonicPitch(2, 'c'), Duration(1, 8)),
            Note(DiatonicPitch(2, 'd'), Duration(1, 8))
        ])
        beam = Beam([
            Note(DiatonicPitch(3, 'c'), Duration(1, 8)), sub_beam,
            Note(DiatonicPitch(3, 'd'), Duration(1, 8))
        ])

        AbstractNote.print_structure(beam)

        notes = beam.get_all_notes()
        assert len(notes) == 4

        assert beam.sub_notes[1].duration == Duration(1, 8)
        assert beam.sub_notes[1].relative_position == Offset(1, 8)
        assert beam.sub_notes[1].sub_notes[1].duration == Duration(1, 16)
        assert beam.sub_notes[1].sub_notes[1].relative_position == Offset(
            1, 16)

        sub_beam.add(Note(DiatonicPitch(2, 'c'), Duration(1, 8)), 1)
        AbstractNote.print_structure(beam)

        assert beam.sub_notes[1].duration == Duration(3, 16)
        assert beam.sub_notes[1].relative_position == Offset(1, 8)
        assert beam.sub_notes[1].sub_notes[1].duration == Duration(1, 16)
        assert beam.sub_notes[1].sub_notes[1].relative_position == Offset(
            1, 16)
示例#2
0
    def test_tie_break(self):
        print('test tie break')
        a = Note(DiatonicPitch(3, 'a'), Duration(1, 8))
        b = Note(DiatonicPitch(3, 'b'), Duration(1, 8))
        c = Note(DiatonicPitch(3, 'c'), Duration(1, 8))
        d = Note(DiatonicPitch(3, 'a'), Duration(1, 8))
        sub_beam = Beam([b, c])

        beam = Beam([a, d])
        a.tie()
        assert a.is_tied_to
        assert d.is_tied_from

        beam.add(sub_beam, 1)

        assert not a.is_tied_to
        assert not d.is_tied_from
示例#3
0
    def test_insert_notes(self):
        print('test_insert_notes')
        # same as test_nested_notes
        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)))

        AbstractNote.print_structure(beam)

        # add a beam
        n_list = [
            Note(DiatonicPitch(3, 'c'), Duration(1, 8)),
            Note(DiatonicPitch(3, 'd'), Duration(1, 8))
        ]
        add_beam = Beam(n_list)
        sub_beam.add(add_beam, 1)

        print(beam)
        AbstractNote.print_structure(beam)

        notes = beam.get_all_notes()
        assert len(notes) == 7
        TestBeam.print_all_notes(notes)
        assert notes[0].diatonic_pitch == DiatonicPitch(4, 'f')
        assert notes[1].diatonic_pitch == DiatonicPitch(4, 'c')
        assert notes[2].diatonic_pitch == DiatonicPitch(3, 'c')
        assert notes[3].diatonic_pitch == DiatonicPitch(3, 'd')
        assert notes[4].diatonic_pitch == DiatonicPitch(4, 'd')
        assert notes[5].diatonic_pitch == DiatonicPitch(4, 'e')
        assert notes[6].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(0)
        assert notes[3].relative_position == Offset(1, 32)
        assert notes[4].relative_position == Offset(1, 8)
        assert notes[5].relative_position == Offset(3, 16)
        assert notes[6].relative_position == Offset(11, 32)
示例#4
0
    def test_TBB_layers(self):
        print('start test_TBB_layers')
        sub_sub_beam = Beam([
            Note(DiatonicPitch(2, 'c'), Duration(1, 8)),
            Note(DiatonicPitch(2, 'd'), Duration(1, 8))
        ])
        sub_beam = Beam([
            Note(DiatonicPitch(3, 'c'), Duration(1, 8)), sub_sub_beam,
            Note(DiatonicPitch(3, 'd'), Duration(1, 8))
        ])

        AbstractNote.print_structure(sub_beam)

        note1 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        note2 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
        print('-----------')
        tuplet = Tuplet(Duration(1, 8), 2, [note1, sub_beam, note2])
        AbstractNote.print_structure(tuplet)

        notes = tuplet.get_all_notes()
        assert len(notes) == 6

        assert tuplet.sub_notes[1].duration == Duration(3, 20)
        assert tuplet.sub_notes[1].relative_position == Offset(1, 20)
        assert tuplet.sub_notes[1].sub_notes[1].duration == Duration(1, 20)
        assert tuplet.sub_notes[1].sub_notes[1].relative_position == Offset(
            1, 20)

        sub_sub_beam.add(Note(DiatonicPitch(2, 'c'), Duration(1, 8)), 1)
        AbstractNote.print_structure(tuplet)

        assert tuplet.sub_notes[1].duration == Duration(7, 44)
        assert tuplet.sub_notes[1].relative_position == Offset(1, 22)
        assert tuplet.sub_notes[1].sub_notes[1].duration == Duration(3, 44)
        assert tuplet.sub_notes[1].sub_notes[1].relative_position == Offset(
            1, 22)

        print('end test_TBB_layers')