Ejemplo n.º 1
0
    def test_simple_beam(self):
        note = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        beam = Beam([note])
        print(beam)
        assert beam.cardinality() == 1
        assert beam.get_all_notes()[0].diatonic_pitch == DiatonicPitch(4, 'c')

        notes = beam.get_all_notes()
        assert len(notes) == 1
        TestBeam.print_all_notes(notes)
Ejemplo n.º 2
0
    def test_multi_notes(self):
        note0 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        note1 = Note(DiatonicPitch(4, 'd'), Duration(1, 8), 1)
        note2 = Note(DiatonicPitch(4, 'e'), Duration(1, 16))
        beam = Beam([note0, note1, note2])
        print(beam)
        assert beam.cardinality() == 3
        notes = beam.get_all_notes()
        assert notes[0].diatonic_pitch == DiatonicPitch(4, 'c')
        assert notes[1].diatonic_pitch == DiatonicPitch(4, 'd')
        assert notes[2].diatonic_pitch == DiatonicPitch(4, 'e')
        assert beam.duration == Duration(3, 8)
        assert notes[0].relative_position == Offset(0)
        assert notes[1].relative_position == Offset(1, 8)
        assert notes[2].relative_position == Offset(5, 16)

        assert len(notes) == 3
        TestBeam.print_all_notes(notes)
Ejemplo n.º 3
0
    def test_single_voice(self):
        print('test single voice')
        note0 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
        note1 = Note(DiatonicPitch(4, 'd'), Duration(1, 8), 1)
        note2 = Note(DiatonicPitch(4, 'e'), Duration(1, 16))
        beam = Beam([note0, note1, note2])
        print(beam)
        assert beam.cardinality() == 3

        line = Line(beam)

        assert line.length() == Duration(3, 8)

        c = InstrumentCatalog.instance()

        violin = c.get_instrument("violin")

        voice = Voice(violin)
        voice.pin(line, Offset(3, 4))

        coverage = voice.coverage()
        print('Coverage = {0}'.format(coverage))
        assert coverage.lower == Position(3, 4)
        assert coverage.upper == Position(9, 8)

        assert voice.length() == Duration(9, 8)

        interval = Interval(Position(15, 16), Position(9, 8))
        notes = voice.get_notes_by_interval(interval)
        print(', '.join([str(n) for n in notes]))
        for n in notes:
            intvl = TestVoice.compute_note_interval(n)
            print('{0} intersect {1} = {2}'.format(
                intvl, interval, intvl.intersection(interval)))

        assert len(notes) == 2
        print(notes[0].get_absolute_position(),
              notes[1].get_absolute_position())
        assert TestVoice.has_pitch(notes, DiatonicPitch.parse('D:4'))
        assert TestVoice.has_pitch(notes, DiatonicPitch.parse('E:4'))