Пример #1
0
    def test_play_tetris():
        # Change me if you need this test to run faster or slower.
        SPEEDUP_FACTOR = 8

        tetris = 'E52 B41 C51 D52 C51 B41 A42 A41 C51 E52 D51 C51 B42 B41 C51 D52 E52 C52 A42 A42 R14 D51 F51 A52 G51 F51 E53 C51 E52 D51 C51 B42 B41 C51 D52 E52 C52 A42 A42'
        for note_info in tetris.split():
            pitch, octave, duration = note_info
            pitch = Note.Pitch[pitch]
            octave = int(octave)
            duration = int(duration)
            note = Note(duration / 8, pitch, octave, Note.Accidental.NATURAL)
            note.play()
Пример #2
0
    def test_play_all_notes():
        # Change me if you need this test to run faster or slower.:
        NOTE_DURATION = 0.05

        # Don't worry if this sounds a little strange.
        # Recall than an A9 is actually a higher pitch than a C9, since the
        # octave counts increment at C.
        for octave in range(OCTAVE_MIN, OCTAVE_MAX + 1):
            for pitch in Note.Pitch:
                for accidental in Note.Accidental:
                    note = Note(NOTE_DURATION, pitch, octave, accidental)
                    note.play()
Пример #3
0
def test_create_rest():
    note = Note.rest(1)
    assert note.pitch == Note.Pitch.R
    assert note.duration == 1
    assert note.is_rest()
    assert note.accidental == Note.Accidental.NATURAL
    assert note.octave == OCTAVE_MIN
Пример #4
0
def test_create_simple_note():
    note = Note(1, Note.Pitch.C, 4)
    assert note.duration == 1
    assert note.pitch == Note.Pitch.C
    assert note.octave == 4
    assert note.accidental == Note.Accidental.NATURAL
    assert note.repeat == False
Пример #5
0
    def test_play_ode_to_joy_from_lines():
        # Change me if you need this test to run faster or slower.
        SPEEDUP_FACTOR = 8

        # The zero-second rests force the note player to stop and start a new note.
        ode_to_joy = [
            '1 E 5 NATURAL false',
            '0 R 1 NATURAL false',
            '1 E 5 NATURAL false',
            '1 F 5 NATURAL false',
            '1 G 5 NATURAL false',
            '0 R 1 NATURAL false',
            '1 G 5 NATURAL false',
            '1 F 5 NATURAL false',
            '1 E 5 NATURAL false',
            '1 D 5 NATURAL false',
            '1 C 5 NATURAL false',
            '0 R 1 NATURAL false',
            '1 C 5 NATURAL false',
            '1 D 5 NATURAL false',
            '1 E 5 NATURAL false',
            '0 R 1 NATURAL false',
            '1 E 5 NATURAL false',
            '1 D 5 NATURAL false',
            '0 R 1 NATURAL false',
            '1 D 5 NATURAL false',
        ]
        for line in ode_to_joy:
            note = Note.from_line(line)
            note.duration /= SPEEDUP_FACTOR
            note.play()
Пример #6
0
def test_create_from_line():
    note = Note.from_line('1 C 4 NATURAL false')
    assert note.duration == 1
    assert note.pitch == Note.Pitch.C
    assert note.octave == 4
    assert note.accidental == Note.Accidental.NATURAL
    assert note.repeat == False
Пример #7
0
def test_change_rest_to_pitch():
    note = Note.rest(1)
    assert note.is_rest()
    print(note)
    print(note.octave)
    note.pitch = Note.Pitch.C
    print(note)
    assert note.pitch == Note.Pitch.C
    assert note.accidental == Note.Accidental.NATURAL
    assert note.octave == OCTAVE_MIN
Пример #8
0
def test_change_octave():
    note = Note(1, Note.Pitch.C, 4)
    assert note.octave == 4
    note.octave = OCTAVE_MIN
    assert note.octave == OCTAVE_MIN
Пример #9
0
def test_change_accidental():
    note = Note(1, Note.Pitch.C, 4, Note.Accidental.SHARP)
    assert note.accidental == Note.Accidental.SHARP
    note.accidental = Note.Accidental.FLAT
    assert note.accidental == Note.Accidental.FLAT
Пример #10
0
def test_change_pitch_to_rest():
    note = Note(1, Note.Pitch.C, 4)
    assert note.pitch == Note.Pitch.C
    note.pitch = Note.Pitch.R
    assert note.pitch == Note.Pitch.R
    assert note.is_rest()
Пример #11
0
def test_change_pitch():
    note = Note(1, Note.Pitch.C, 4)
    assert note.pitch == Note.Pitch.C
    note.pitch = Note.Pitch.G
    assert note.pitch == Note.Pitch.G
Пример #12
0
def test_lengthen_duration():
    note = Note(1, Note.Pitch.C, 4)
    assert note.duration == 1
    note.duration = 2
    assert note.duration == 2
Пример #13
0
def test_shorten_duration():
    note = Note(1, Note.Pitch.C, 4)
    assert note.duration == 1
    note.duration = 0.5
    assert note.duration == 0.5
Пример #14
0
def test_create_repeating_note():
    note = Note(1, Note.Pitch.C, 4, repeat=True)
    assert note.repeat == True
Пример #15
0
def test_create_nonnatural_notes():
    note = Note(1, Note.Pitch.C, 4, Note.Accidental.SHARP)
    assert note.accidental == Note.Accidental.SHARP
    note = Note(1, Note.Pitch.C, 4, Note.Accidental.FLAT)
    assert note.accidental == Note.Accidental.FLAT
Пример #16
0
 def test_play_single_note():
     note = Note(1, Note.Pitch.C, 4, Note.Accidental.NATURAL)
     note.play()