Exemplo n.º 1
0
def sound_negative_duration_play_failure():
    s = Sound(TEST_SOUND_LONG)
    try:
        s.play(duration=-1)
    except ValueError:
        return True
    return False
Exemplo n.º 2
0
def sound_playing_before_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(0.5)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 3
0
def sound_playing_before_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 - 0.5)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 4
0
def sound_not_playing_after_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 + 0.5)
    playing = s.is_playing()
    s.stop()
    return not playing
Exemplo n.º 5
0
def sound_not_playing_after_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    time.sleep(2.5)
    playing = s.is_playing()
    s.stop()
    return not playing
Exemplo n.º 6
0
def sound_playing_before_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(0.5)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 7
0
def sound_chaining_test_timed():
    # Same as sound_chaining_test(), but time it.  Does not include Sound()
    # time, as it may take a while to load an uncached sound.
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait().play(duration=0.1).wait().play().stop()
    return verify_duration(start, TEST_SOUND_LENGTH + 0.1)
Exemplo n.º 8
0
def sound_not_playing_after_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    time.sleep(2.5)
    playing = s.is_playing()
    s.stop()
    return not playing
Exemplo n.º 9
0
def sound_negative_duration_play_failure():
    s = Sound(TEST_SOUND_LONG)
    try:
        s.play(duration=-1)
    except ValueError:
        return True
    return False
Exemplo n.º 10
0
def sound_chaining_test_timed():
    # Same as sound_chaining_test(), but time it.  Does not include Sound()
    # time, as it may take a while to load an uncached sound.
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait().play(duration=0.1).wait().play().stop()
    return verify_duration(start, TEST_SOUND_LENGTH + 0.1)
Exemplo n.º 11
0
def sound_not_playing_after_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 + 0.5)
    playing = s.is_playing()
    s.stop()
    return not playing
Exemplo n.º 12
0
def sound_playing_before_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 - 0.5)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 13
0
def sound_not_is_playing_after_play():
    s = Sound(TEST_SOUND)
    print("before play")
    s.play()
    print("after play")
    time.sleep(TEST_SOUND_LENGTH + 0.5)
    print("after wait: ", s.is_playing())
    return not s.is_playing()
Exemplo n.º 14
0
def sound_play_test_sound_and_note_mixed():
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    n.stop()
    return True
Exemplo n.º 15
0
def sound_not_is_playing_after_play():
    s = Sound(TEST_SOUND)
    print("before play")
    s.play()
    print("after play")
    time.sleep(TEST_SOUND_LENGTH + 0.5)
    print("after wait: ", s.is_playing())
    return not s.is_playing()
Exemplo n.º 16
0
def sound_play_test_sound_and_note_mixed():
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    n.stop()
    return True
Exemplo n.º 17
0
def sound_sound_volume():
    '''The long test sound will play for 10 second with increasing volume.  '''
    master_volume(100)
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=10)
    for i in range(20):
        s.volume += 15
        time.sleep(0.5)
    s.wait()
Exemplo n.º 18
0
def sound_short_latency():
    s = Sound(TEST_SOUND)
    s.stop()
    start = time.time()
    s.play()
    s.wait()
    duration = time.time() - start
    latency = duration - TEST_SOUND_LENGTH
    print("Latency: ", latency)
    return latency > 0 and latency < 0.050
Exemplo n.º 19
0
def sound_get_set_volume():
    # Verify Sound volume attribute can be get/set.
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=0.5)
    for i in range(10):
        s.volume += 10
        time.sleep(0.05)
    s.wait()
    return s.volume == 100
Exemplo n.º 20
0
def sound_short_latency():
    s = Sound(TEST_SOUND)
    s.stop()
    start = time.time()
    s.play()
    s.wait()
    duration = time.time() - start
    latency = duration - TEST_SOUND_LENGTH
    print("Latency: ", latency)
    return latency > 0 and latency < 0.050
Exemplo n.º 21
0
def sound_get_set_volume():
    # Verify Sound volume attribute can be get/set.
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=0.5)
    for i in range(10):
        s.volume += 10
        time.sleep(0.05)
    s.wait()
    return s.volume == 100
Exemplo n.º 22
0
def sound_sound_volume():
    '''The long test sound will play for 10 second with increasing volume.  '''
    master_volume(100)
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=10)
    for i in range(20):
        s.volume += 15
        time.sleep(0.5)
    s.wait()
Exemplo n.º 23
0
def sound_stop_time():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
Exemplo n.º 24
0
def sound_stop_time():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
Exemplo n.º 25
0
def sound_manual_play_test_sound_and_note_mixed():
    '''The sound match1.wav will play TWO TIMES on the speaker, mixed with an
    'A' note.
    '''
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    s.play()
    s.wait()
    n.stop()
Exemplo n.º 26
0
def sound_stop_time():
    #s = Sound(TEST_SOUND_LONG)
    s = Sound('/opt/sonic-pi/etc/samples/loop_garzul.wav')
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
Exemplo n.º 27
0
def sound_manual_play_test_sound_and_note_mixed():
    '''The sound match1.wav will play TWO TIMES on the speaker, mixed with an
    'A' note.
    '''
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    s.play()
    s.wait()
    n.stop()
Exemplo n.º 28
0
def sound_play_then_replay():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(0.5)
    playing_firsttime = s.is_playing()
    s.play(duration=1.0)
    time.sleep(0.5)
    playing_secondtime_before_end = s.is_playing()
    time.sleep(1.0)
    playing_secondtime_after_end = s.is_playing()
    s.stop()
    print('playing_firsttime: ', playing_firsttime)
    print('playing_secondtime_before_end: ', playing_secondtime_before_end)
    print('playing_secondtime_after_end: ', playing_secondtime_after_end)
    return playing_firsttime and playing_secondtime_before_end and not playing_secondtime_after_end
Exemplo n.º 29
0
def sound_play_then_replay():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(0.5)
    playing_firsttime = s.is_playing()
    s.play(duration=1.0)
    time.sleep(0.5)
    playing_secondtime_before_end = s.is_playing()
    time.sleep(1.0)
    playing_secondtime_after_end = s.is_playing()
    s.stop()
    print('playing_firsttime: ', playing_firsttime)
    print('playing_secondtime_before_end: ', playing_secondtime_before_end)
    print('playing_secondtime_after_end: ', playing_secondtime_after_end)
    return playing_firsttime and playing_secondtime_before_end and not playing_secondtime_after_end
Exemplo n.º 30
0
def sound_stop():
    s = Sound(TEST_SOUND)
    s.play()
    s.stop()
    return not s.is_playing()
Exemplo n.º 31
0
def sound_playing_before_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 32
0
def sound_stop():
    s = Sound(TEST_SOUND)
    s.play()
    s.stop()
    return not s.is_playing()
Exemplo n.º 33
0
def sound_is_playing_at_play_start():
    s = Sound(TEST_SOUND)
    s.play()
    return s.is_playing()
Exemplo n.º 34
0
def sound_play_test_sound_loop_2():
    '''The sound match1.wav will play TWO TIMES on the speaker (about 0.5 seconds each).'''
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    s.wait()
Exemplo n.º 35
0
def sound_is_playing_at_play_start():
    s = Sound(TEST_SOUND)
    s.play()
    return s.is_playing()
Exemplo n.º 36
0
def sound_play_test_sound():
    '''The sound match1.wav will play on the speaker (about 0.5 seconds).'''
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
Exemplo n.º 37
0
def sound_wait_verify_duration_with_duration_and_loops():
    s = Sound(TEST_SOUND_LONG)
    start = time.time()
    s.play(duration=1, loops=3).wait()
    return verify_duration(start, 3)
Exemplo n.º 38
0
def sound_wait_verify_duration():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait()
    return verify_duration(start, TEST_SOUND_LENGTH)
Exemplo n.º 39
0
def sound_wait_verify_duration_with_duration_and_loops():
    s = Sound(TEST_SOUND_LONG)
    start = time.time()
    s.play(duration=1, loops=3).wait()
    return verify_duration(start, 3)
Exemplo n.º 40
0
def sound_wait_verify_duration_with_loops():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play(loops=3).wait()
    return verify_duration(start, 3*TEST_SOUND_LENGTH)
Exemplo n.º 41
0
def sound_wait_verify_duration():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait()
    return verify_duration(start, TEST_SOUND_LENGTH)
Exemplo n.º 42
0
def sound_wait():
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
    return not s.is_playing()
Exemplo n.º 43
0
def sound_is_playing_at_play_middle():
    s = Sound(TEST_SOUND)
    s.play()
    time.sleep(TEST_SOUND_LENGTH/2)
    return s.is_playing()
Exemplo n.º 44
0
def sound_wait_verify_duration_with_loops():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play(loops=3).wait()
    return verify_duration(start, 3 * TEST_SOUND_LENGTH)
Exemplo n.º 45
0
def sound_play_test_sound():
    '''The sound match1.wav will play on the speaker (about 0.5 seconds).'''
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
Exemplo n.º 46
0
def sound_wait():
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
    return not s.is_playing()
Exemplo n.º 47
0
def sound_not_playing_after_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(1.5)
    return not s.is_playing()
Exemplo n.º 48
0
def sound_is_playing_at_play_middle():
    s = Sound(TEST_SOUND)
    s.play()
    time.sleep(TEST_SOUND_LENGTH / 2)
    return s.is_playing()
Exemplo n.º 49
0
def sound_playing_before_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    playing = s.is_playing()
    s.stop()
    return playing
Exemplo n.º 50
0
def sound_play_test_sound_loop_2():
    '''The sound match1.wav will play TWO TIMES on the speaker (about 0.5 seconds each).'''
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    s.wait()
Exemplo n.º 51
0
def sound_not_playing_after_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(1.5)
    return not s.is_playing()
Exemplo n.º 52
0
 
     # ########################################
     # Change the World
     # ########################################
 
     if missile_x >= 0 and now - missile_start_time > MISSILE_STEP_TIME:
         # Missile already launched - move it up
         missile_y += 1
         if missile_y >= fb.height:
             missile_x, missile_y = -1, -1
         missile_start_time = now
     elif presses:
         # Button was pressed - launch missile
         missile_x, missile_y = (round(spaceship_position), 1)
         missile_start_time = now
         fire_sound.play()
 
     # Move spaceship
     if x_force > TILT_FORCE:
         spaceship_position -= SPACESHIP_STEP
     elif x_force < -TILT_FORCE:
         spaceship_position += SPACESHIP_STEP
     spaceship_position = max(0, min(fb.width - 1, spaceship_position))
 
     # Move alien
     if now - alien_start_time > ALIENS_STEP_TIME / alien_speed:
         for note in notes:
             note.stop()
         next(notes_cycle).play(duration=0.20)
         alien_at_right_side = alien_direction > 0 and max(alien_columns) == fb.width - 1
         alien_at_left_side = alien_direction < 0 and min(alien_columns) == 0
Exemplo n.º 53
0
        # ########################################
        # Change the World
        # ########################################

        if missile_x >= 0 and now - missile_start_time > MISSILE_STEP_TIME:
            # Missile already launched - move it up
            missile_y += 1
            if missile_y >= fb.height:
                missile_x, missile_y = -1, -1
            missile_start_time = now
        elif presses:
            # Button was pressed - launch missile
            missile_x, missile_y = (round(spaceship_position), 1)
            missile_start_time = now
            fire_sound.play()

        # Move spaceship
        if x_force > TILT_FORCE:
            spaceship_position -= SPACESHIP_STEP
        elif x_force < -TILT_FORCE:
            spaceship_position += SPACESHIP_STEP
        spaceship_position = max(0, min(fb.width - 1, spaceship_position))

        # Move alien
        if now - alien_start_time > ALIENS_STEP_TIME / alien_speed:
            for note in notes:
                note.stop()
            next(notes_cycle).play(duration=0.20)
            alien_at_right_side = alien_direction > 0 and max(
                alien_columns) == fb.width - 1