class MixerComponent(MixerComponentBase):
    selection_control = InputControl()
    mute_control = InputControl()
    solo_control = InputControl()

    def set_selected_track_volume_control(self, control):
        self._selected_strip.set_volume_control(control)

    def set_selected_track_pan_control(self, control):
        self._selected_strip.set_pan_control(control)

    def set_selected_track_type_display(self, control):
        self._selected_strip.track_type_display.set_control_element(control)

    def set_selected_track_muted_via_solo_display(self, control):
        self._selected_strip.track_muted_via_solo_display.set_control_element(
            control)

    def set_track_meter_display(self, display):
        for index, strip in enumerate(self._channel_strips):
            strip.set_meter_display_callback(
                partial(display.update_meter_display, index *
                        METERS_PER_SEGMENT) if display else None)

        return

    def set_track_arm_displays(self, displays):
        for strip, display in izip_longest(self._channel_strips, displays
                                           or []):
            strip.track_arm_display.set_control_element(display)

    @selection_control.value
    def selection_control(self, index, _):
        if index in xrange(self._provider.num_tracks):
            self._channel_strips[index].select_track()

    @mute_control.value
    def mute_control(self, index, _):
        if index in xrange(self._provider.num_tracks):
            self._channel_strips[index].mute_track()

    @solo_control.value
    def solo_control(self, index, _):
        if index in xrange(self._provider.num_tracks):
            self._channel_strips[index].solo_track()
예제 #2
0
class PingPongComponent(Component):
    pong = InputControl()

    def __init__(self, on_pong_callback=None, on_ping_timeout=None, *a, **k):
        super(PingPongComponent, self).__init__(*a, **k)
        assert on_pong_callback is not None
        assert on_ping_timeout is not None
        self._on_pong_callback = on_pong_callback
        self._on_ping_timeout = on_ping_timeout
        self._ping = None
        self._pong_received = False
        self._keepalive_task = self._tasks.add(
            task.sequence(task.run(self._send_ping), task.wait(PING_PERIOD),
                          task.run(self._check_pong_received)))
        self._keepalive_task.kill()
        self._keepalive_starter_task = self._tasks.add(
            task.run(self._keepalive_task.restart))
        self._keepalive_starter_task.kill()
        return

    @pong.value
    def pong(self, value, _):
        self._pong_received = True
        if not self._keepalive_task.is_running:
            self._keepalive_starter_task.restart()
        self._on_pong_callback(value)

    def set_ping(self, button):
        self._ping = button
        self._keepalive_starter_task.restart()

    def _send_ping(self):
        if self._ping and self.is_enabled():
            self._pong_received = False
            self._ping.send_value(0)

    def _check_pong_received(self):
        if not self._pong_received:
            self._keepalive_task.kill()
            self._on_ping_timeout()
        else:
            self._keepalive_starter_task.restart()