예제 #1
0
def main_control_loop(player: ManagedAudioPlayer, loop_try_delay: int) -> None:
    """Main playback loop for the controls.
    Blocks forever."""
    rotor_enc.when_rotated_clockwise = partial(rotor_clockwise, player)
    rotor_enc.when_rotated_counter_clockwise = partial(rotor_counter_clock,
                                                       player)
    prev_but.when_pressed = partial(previous_button, player)
    next_but.when_pressed = partial(next_button, player)
    play_but.when_pressed = partial(play_button, player)
    rotor_but.when_pressed = partial(rotor_button, player)
    mod_but.when_pressed = mod_led.on

    mod_but.when_released = mod_led.off
    play_but.when_released = play_led.off
    next_but.when_released = next_led.off
    prev_but.when_released = prev_led.off
    rotor_but.when_released = leds_off

    try:
        while True:
            song_finished = player.play_current_song(
            )  # Will block during playback
            if song_finished:
                player.next_song()
            sleep(loop_try_delay)
    finally:
        leds_off()
예제 #2
0
def controlless_play_loop(player: ManagedAudioPlayer):
    """Simply plays songs as they're received."""
    while True:
        song_finished = player.play_current_song()  # Will block during playback
        if song_finished:
            player.next_song()
        sleep(SONG_BREAK_DELAY_SECS)
예제 #3
0
def rotor_button(player: ManagedAudioPlayer) -> None:
    """Callback to control mute/pitch reset features associated with the rotary encoder button."""
    if mod_but.is_pressed:
        player_logger.info("Reset Pitch")
        player.set_pitch(0)
    else:
        player_logger.info("Mute")
        player.toggle_mute()
    mod_led.on()
    prev_led.on()
    play_led.on()
    next_led.on()
예제 #4
0
def rotor_counter_clock(player: ManagedAudioPlayer) -> None:
    """Callback for volume/pitch control associated with the counter-clockwise rotation of the rotary encoder"""
    if mod_but.is_pressed:
        player_logger.info("Song Pitch Down 1%")
        player.adjust_pitch(-PITCH_STEP)
    else:
        player_logger.info("Volume Down 5%")
        player.adjust_volume(-VOLUME_STEP)
    next_led.blink(0.025, 0, 1, background=False)
    play_led.blink(0.025, 0, 1, background=False)
    prev_led.blink(0.025, 0, 1, background=False)
    mod_led.blink(0.025, 0, 1, background=False)
예제 #5
0
def main(use_controls: bool = True) -> None:
    with ManagedAudioPlayer() as player:
        if use_controls:
            import controls
            controls.main_control_loop(player, SONG_BREAK_DELAY_SECS)
        else:
            controlless_play_loop(player)
예제 #6
0
def next_button(player: ManagedAudioPlayer) -> None:
    """Callback to control the next song/seek forwards features associated with the next button."""
    if mod_but.is_pressed:
        player_logger.info("Seek Forwards")
        player.seek_by(SEEK_STEP)
    else:
        player_logger.info("Next Song")
        player.next_song()
        player.stop()
    next_led.on()
예제 #7
0
def previous_button(player: ManagedAudioPlayer) -> None:
    """Callback to control the previous song/seek back features associated with the previous button  """
    if mod_but.is_pressed:
        player_logger.info("Seek Back")
        player.seek_by(-SEEK_STEP)
    else:
        player_logger.info("Previous Song")
        player.previous_song()
        player.stop()
    prev_led.on()
예제 #8
0
def play_button(player: ManagedAudioPlayer) -> None:
    """Callback to control play/pause features associated with the play button."""
    player_logger.info("Toggle Pause")
    player.toggle_pause()
    play_led.on()