Ejemplo n.º 1
0
 def reset_output_buffers(self):
     """
     Clears the output buffers
     """
     self._buffer_a = BufferUtils.create_buffer()
     self._buffer_b = BufferUtils.create_buffer()
     self._output_buffer = BufferUtils.create_buffer()
Ejemplo n.º 2
0
    def __init__(self, app, name):
        super(Layer, self).__init__()
        self._app = app
        self._mixer = app.mixer
        self._enable_profiling = self._app.args.profile
        self.name = name
        self._playlist = None
        self._scene = app.scene
        self._main_buffer = None
        self._secondary_buffer = None
        self._in_transition = False
        self._transition = None
        self.transition_progress = 0.0
        self._start_transition = False
        self._transition_list = []
        self._transition_duration = self._app.settings.get(
            'mixer')['transition-duration']
        self._transition_slop = self._app.settings.get(
            'mixer')['transition-slop']
        self._elapsed = 0
        self._duration = self._app.settings.get('mixer')['preset-duration']

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            pass
        else:
            self._main_buffer = BufferUtils.create_buffer()
            self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 3
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._tick_timer = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._max_fixtures = 0
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._random_transition = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0
        self._global_speed = 1.0
        self._render_in_progress = False

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            log.warn("No scene assigned to mixer.  Preset rendering and transitions are disabled.")
            self._transition_duration = 0.0
            self._enable_rendering = False
        else:
            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()
            for strand in fh:
                self._strand_keys.append(strand)

            (maxs, maxf, maxp) = self._scene.get_matrix_extents()

            self._main_buffer = BufferUtils.create_buffer(self._app)
            self._secondary_buffer = BufferUtils.create_buffer(self._app)
            self._max_fixtures = maxf
            self._max_pixels = maxp

            log.info("Warming up BufferUtils cache...")
            BufferUtils.warmup(self._app)
            log.info("Completed BufferUtils cache warmup")
Ejemplo n.º 4
0
    def __init__(self, app, name):
        super(Layer, self).__init__()
        self._app = app
        self._mixer = app.mixer
        self._enable_profiling = self._app.args.profile
        self.name = name
        self._playlist = None
        self._scene = app.scene
        self._main_buffer = None
        self._secondary_buffer = None
        self._in_transition = False
        self._transition = None
        self.transition_progress = 0.0
        self._start_transition = False
        self._transition_list = []
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._elapsed = 0
        self._duration = self._app.settings.get('mixer')['preset-duration']

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            pass
        else:
            self._main_buffer = BufferUtils.create_buffer()
            self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 5
0
 def setup(self):
     self.add_parameter(StringParameter('first-preset', ""))
     self.add_parameter(StringParameter('second-preset', ""))
     self.add_parameter(FloatParameter('transition-progress', 0.5))
     self.add_parameter(FloatParameter('audio-transition', 0.0))
     self.add_parameter(StringParameter('transition-mode', "Additive Blend"))
     self._preset1_buffer = BufferUtils.create_buffer()
     self._preset2_buffer = BufferUtils.create_buffer()
Ejemplo n.º 6
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._tick_timer = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._max_fixtures = 0
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = False
        self._frozen = False
        self._random_transition = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        if not self._scene:
            log.warn("No scene assigned to mixer.  Preset rendering and transitions are disabled.")
            self._transition_duration = 0.0
            self._enable_rendering = False
        else:
            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()
            for strand in fh:
                self._strand_keys.append(strand)

            (maxs, maxf, maxp) = self._scene.get_matrix_extents()

            self._main_buffer = BufferUtils.create_buffer(self._app)
            self._secondary_buffer = BufferUtils.create_buffer(self._app)
            self._max_fixtures = maxf
            self._max_pixels = maxp

            log.info("Warming up BufferUtils cache...")
            BufferUtils.warmup(self._app)
            log.info("Completed BufferUtils cache warmup")
Ejemplo n.º 7
0
 def setup(self):
     self.add_parameter(StringParameter('first-preset', ""))
     self.add_parameter(StringParameter('second-preset', ""))
     self.add_parameter(FloatParameter('transition-progress', 0.5))
     self.add_parameter(StringParameter('transition-mode', "Additive Blend"))
     self.add_parameter(StringParameter('layer', 'default'))
     self.parameter_changed(None)
     self._preset1_buffer = BufferUtils.create_buffer()
     self._preset2_buffer = BufferUtils.create_buffer()
Ejemplo n.º 8
0
 def setup(self):
     self.add_parameter(StringParameter('first-preset', ""))
     self.add_parameter(StringParameter('second-preset', ""))
     self.add_parameter(FloatParameter('transition-progress', 0.5))
     self.add_parameter(StringParameter('transition-mode',
                                        "Additive Blend"))
     self.add_parameter(StringParameter('layer', 'default'))
     self.parameter_changed(None)
     self._preset1_buffer = BufferUtils.create_buffer()
     self._preset2_buffer = BufferUtils.create_buffer()
Ejemplo n.º 9
0
 def init_pixels(self):
     """
     Sets up the pixel array
     """
     (self._max_strand, self._max_fixture,
      self._max_pixel) = self.scene().get_matrix_extents()
     self._pixel_buffer = BufferUtils.create_buffer()
Ejemplo n.º 10
0
    def tick(self):
        self._num_frames += 1
        if len(self._playlist) > 0:

            self._playlist.get_active_preset().clear_commands()
            self._playlist.get_active_preset().tick()
            transition_progress = 0.0

            # Handle transition by rendering both the active and the next preset, and blending them together
            if self._in_transition:
                if self._start_transition:
                    self._start_transition = False
                    if self._random_transition:
                        self.get_next_transition()
                    if self._transition:
                        self._transition.reset()
                    self._playlist.get_next_preset()._reset()
                    self._secondary_buffer = BufferUtils.create_buffer(self._app)
                if self._transition_duration > 0.0 and self._transition is not None:
                    transition_progress = self._elapsed / self._transition_duration
                else:
                    transition_progress = 1.0
                self._playlist.get_next_preset().clear_commands()
                self._playlist.get_next_preset().tick()

                # Exit from transition state after the transition duration has elapsed
                if transition_progress >= 1.0:
                    self._in_transition = False
                    # Reset the elapsed time counter so the preset runs for the full duration after the transition
                    self._elapsed = 0.0
                    self._playlist.advance()

            # If the scene tree is available, we can do efficient mixing of presets.
            # If not, a tree would need to be constructed on-the-fly.
            # TODO: Support mixing without a scene tree available
            if self._enable_rendering:
                if self._in_transition:
                    self.render_presets(self._playlist.get_active_index(), self._playlist.get_next_index(), transition_progress)
                else:
                    self.render_presets(self._playlist.get_active_index())
            else:
                if self._net is not None:
                    self._net.write(self._playlist.get_active_preset().get_commands_packed())

            if not self._paused and (self._elapsed >= self._duration) and self._playlist.get_active_preset().can_transition() and not self._in_transition:
                if (self._elapsed >= (self._duration + self._transition_slop)) or self._onset:
                    if len(self._playlist) > 1:
                        self.start_transition()
                    self._elapsed = 0.0

            if self._reset_onset:
                self._onset = False
                self._reset_onset = False

        if self._enable_profiling:
            tick_time = (time.time() - self._last_frame_time)
            self._last_frame_time = time.time()
            if tick_time > 0.0:
                index = int((1.0 / tick_time))
                self._tick_time_data[index] = self._tick_time_data.get(index, 0) + 1
Ejemplo n.º 11
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._tick_timer = None
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0
        self._global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = time.time()
        self._audio_emitters_by_group = {}
        self._layers = []
        self._leap_controller = Leap.Controller()
                
        
        if self._app.args.yappi and USE_YAPPI:
            yappi.start()

        if not self._scene:
            log.warn("No scene assigned to mixer.  Preset rendering and transitions are disabled.")
            self._enable_rendering = False
        else:
            log.info("Warming up BufferUtils cache...")
            BufferUtils.init()
            log.info("Completed BufferUtils cache warmup")

            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()

            self._main_buffer = BufferUtils.create_buffer()
Ejemplo n.º 12
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._tick_timer = None
        self._running = False
        self._enable_rendering = True
        self._main_buffer = None
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self._global_dimmer = 1.0
        self._global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = time.time()
        self._audio_emitters_by_group = {}
        self._layers = []

        if self._app.args.yappi and USE_YAPPI:
            yappi.start()

        if not self._scene:
            log.warn(
                "No scene assigned to mixer.  Preset rendering and transitions are disabled."
            )
            self._enable_rendering = False
        else:
            log.info("Warming up BufferUtils cache...")
            BufferUtils.init()
            log.info("Completed BufferUtils cache warmup")

            log.info("Initializing preset rendering buffer")
            fh = self._scene.fixture_hierarchy()

            self._main_buffer = BufferUtils.create_buffer()
Ejemplo n.º 13
0
 def reset(self):
     self.frame = BufferUtils.create_buffer()
     pixel_locations = np.asarray(
         self._app.scene.get_all_pixel_locations()).T
     self.scaled_pixel_xs = 0.01 * pixel_locations[0]
     self.scaled_pixel_ys = 0.01 * pixel_locations[1]
Ejemplo n.º 14
0
    def tick(self, dt):
        self._num_frames += 1

        dt *= self.global_speed

        if len(self.playlist) > 0:

            active_preset = self.playlist.get_active_preset()
            next_preset = self.playlist.get_next_preset()

            if active_preset is None:
                return

            try:
                active_preset.tick(dt)
            except:
                log.error("Exception raised in preset %s" %
                          active_preset.name())
                self.playlist.disable_presets_by_class(
                    active_preset.__class__.__name__)
                raise

            # Handle transition by rendering both the active and the next
            # preset, and blending them together
            if self._in_transition and next_preset and (next_preset !=
                                                        active_preset):
                if self._start_transition:
                    self._start_transition = False
                    if self._app.settings.get(
                            'mixer')['transition'] == "Random":
                        self.get_next_transition()
                    if self._transition:
                        self._transition.reset()
                    next_preset._reset()
                    self._buffer_b = BufferUtils.create_buffer()

                if self._transition_duration > 0.0 and self._transition is not None:
                    if not self._paused and not self._transition_scrubbing:
                        self.transition_progress = clip(
                            0.0, self._elapsed / self._transition_duration,
                            1.0)
                else:
                    if not self._transition_scrubbing:
                        self.transition_progress = 1.0

                next_preset.tick(dt)

            # If the scene tree is available, we can do efficient mixing of presets.
            # If not, a tree would need to be constructed on-the-fly.
            # TODO: Support mixing without a scene tree available

            if self._in_transition:
                mixed_buffer = self.render_presets(
                    active_preset,
                    self._buffer_a,
                    next_preset,
                    self._buffer_b,
                    self._in_transition,
                    self._transition,
                    self.transition_progress,
                    check_for_nan=self._enable_profiling)
            else:
                mixed_buffer = self.render_presets(
                    active_preset,
                    self._buffer_a,
                    check_for_nan=self._enable_profiling)

            # render_presets writes all the desired pixels to
            # self._main_buffer.

            #else:
            # Global gamma correction.
            # TODO(jon): This should be a setting
            #mixed_buffer.T[1] = np.power(mixed_buffer.T[1], 4)

            # Mod hue by 1 (to allow wrap-around) and clamp lightness and
            # saturation to [0, 1].
            mixed_buffer.T[0] = np.mod(mixed_buffer.T[0], 1.0)
            np.clip(mixed_buffer.T[1], 0.0, 1.0, mixed_buffer.T[1])
            np.clip(mixed_buffer.T[2], 0.0, 1.0, mixed_buffer.T[2])

            # Write this buffer to enabled clients.
            if self._net is not None:
                self._net.write_buffer(mixed_buffer)

            if (not self._paused and (self._elapsed >= self._duration)
                    and active_preset.can_transition()
                    and not self._in_transition):

                if (self._elapsed >=
                    (self._duration + self._transition_slop)) or self._onset:
                    if len(self.playlist) > 1:
                        self.start_transition()
                    self._elapsed = 0.0

            elif self._in_transition:
                if not self._transition_scrubbing and (self.transition_progress
                                                       >= 1.0):
                    self._in_transition = False
                    # Reset the elapsed time counter so the preset runs for the
                    # full duration after the transition
                    self._elapsed = 0.0
                    self.playlist.advance()

        if self._reset_onset:
            self._onset = False
            self._reset_onset = False

        if self._enable_profiling:
            tick_time = (time.time() - self._last_frame_time)
            self._last_frame_time = time.time()
            if tick_time > 0.0:
                index = int((1.0 / tick_time))
                self._tick_time_data[index] = self._tick_time_data.get(
                    index, 0) + 1
Ejemplo n.º 15
0
 def init_pixels(self):
     """
     Sets up the pixel array
     """
     (self._max_strand, self._max_fixture, self._max_pixel) = self.scene().get_matrix_extents()
     self._pixel_buffer = BufferUtils.create_buffer(self._mixer._app)
Ejemplo n.º 16
0
 def reset(self):
     self._main_buffer = BufferUtils.create_buffer()
     self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 17
0
    def draw(self, dt):
        if len(self._playlist) == 0:
            self._main_buffer *= (0.0, 0.0, 0.0)
            return self._main_buffer

        self._elapsed += dt

        active_preset = self._playlist.get_active_preset()
        active_index = self._playlist.get_active_index()

        next_preset = self._playlist.get_next_preset()
        next_index = self._playlist.get_next_index()

        active_preset.clear_commands()
        active_preset.tick(dt)

        # Handle transition by rendering both the active and the next preset,
        # and blending them together.
        if self._in_transition:
            if self._start_transition:
                self._start_transition = False
                if self._app.settings.get('mixer')['transition'] == "Random":
                    self.get_next_transition()
                if self._transition:
                    self._transition.reset()
                next_preset._reset()
                self._secondary_buffer = BufferUtils.create_buffer()

            if self._transition_duration > 0.0 and self._transition is not None:
                if not self._mixer.is_paused():
                    self.transition_progress = self._elapsed / self._transition_duration
            else:
                self.transition_progress = 1.0

            next_preset.clear_commands()
            next_preset.tick(dt)

            # Exit from transition state after the transition duration has
            # elapsed
            if self.transition_progress >= 1.0:
                self._in_transition = False
                # Reset the elapsed time counter so the preset runs for the
                # full duration after the transition
                self._elapsed = 0.0
                self._playlist.advance()
                active_preset = next_preset
                active_index = next_index

        first_preset = self._playlist.get_preset_by_index(active_index)
        if self._in_transition:
            second_preset = self._playlist.get_preset_by_index(next_index)
            mixed_buffer = self.render_presets(
                first_preset,
                self._main_buffer,
                second_preset,
                self._secondary_buffer,
                self._in_transition,
                self._transition,
                self.transition_progress,
                check_for_nan=self._enable_profiling)
        else:
            mixed_buffer = self.render_presets(
                first_preset,
                self._main_buffer,
                check_for_nan=self._enable_profiling)

        if not self._mixer.is_paused() and (
                self._elapsed >= self._duration
        ) and active_preset.can_transition() and not self._in_transition:
            if (self._elapsed >=
                (self._duration +
                 self._transition_slop)) or self._mixer._onset:
                self.start_transition()
                self._elapsed = 0.0

        return mixed_buffer
Ejemplo n.º 18
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self.playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_scrubbing = False
        self._transition_duration = self._app.settings.get(
            'mixer')['transition-duration']
        self._transition_slop = self._app.settings.get(
            'mixer')['transition-slop']
        self._tick_timer = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self.running = False
        self._buffer_a = None
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self.global_dimmer = 1.0
        self.global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = 0.0
        self._fps_time = 0.0
        self._fps_frames = 0
        self._fps = 0.0
        self.last_time = time.time()
        self.transition_progress = 0.0
        self.audio = Audio(self)
        self._fft_data = None

        if self._app.args.yappi and USE_YAPPI:
            print "yappi start"
            yappi.start()

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        log.info("Warming up BufferUtils cache...")
        BufferUtils.init()
        log.info("Completed BufferUtils cache warmup")

        log.info("Initializing preset rendering buffer")
        fh = self._scene.fixture_hierarchy()
        for strand in fh:
            self._strand_keys.append(strand)

        (maxs, maxp) = self._scene.get_matrix_extents()

        self._buffer_a = BufferUtils.create_buffer()
        self._buffer_b = BufferUtils.create_buffer()
        self._max_pixels = maxp
Ejemplo n.º 19
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self.playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_scrubbing = False
        self._transition_duration = self._app.settings.get(
            'mixer')['transition-duration']
        self._transition_slop = self._app.settings.get(
            'mixer')['transition-slop']
        self._render_thread = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self.running = False
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self.global_dimmer = 1.0
        self.global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = 0.0
        self._fps_time = 0.0
        self._fps_frames = 0
        self._fps = 0.0
        self.last_time = time.time()
        self.transition_progress = 0.0
        self.useColorCorrections = True

        # TODO: bring back noaudio
        #if not self._app.args.noaudio:
        # TODO: harmonize on threading.Thread
        self._audio_thread = QtCore.QThread()
        self._audio_thread.start()
        self.aubio_connector = AubioConnector()
        self.audio = Audio(self)
        self.audio.onset.connect(self.onset_detected)
        self.aubio_connector.onset_detected.connect(self.audio.trigger_onset)
        self.aubio_connector.fft_data.connect(self.audio.fft_data_from_network)
        self.aubio_connector.pitch_data.connect(self.audio.update_pitch_data)
        self.aubio_connector.moveToThread(self._audio_thread)

        log.info("Warming up BufferUtils cache...")
        BufferUtils.init()
        log.info("Completed BufferUtils cache warmup")

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        log.info("Initializing preset rendering buffer")
        fh = self._scene.fixture_hierarchy()
        for strand in fh:
            self._strand_keys.append(strand)

        (maxs, maxp) = self._scene.get_matrix_extents()

        self._buffer_a = BufferUtils.create_buffer()
        self._buffer_b = BufferUtils.create_buffer()
        self._output_buffer = BufferUtils.create_buffer()
        self._max_pixels = maxp
Ejemplo n.º 20
0
 def reset(self):
     self.parameter_changed(None)
     self._buffer1 = BufferUtils.create_buffer()
     self._buffer2 = BufferUtils.create_buffer()
Ejemplo n.º 21
0
 def reset(self):
     self._buffer = BufferUtils.create_buffer()
Ejemplo n.º 22
0
    def tick(self, dt):
        self._num_frames += 1

        dt *= self._global_speed

        if len(self.playlist) > 0:

            active_preset = self.playlist.get_active_preset()
            next_preset = self.playlist.get_next_preset()

            if active_preset is None:
                return

            try:
                active_preset.tick(dt)
            except:
                log.error("Exception raised in preset %s" % active_preset.name())
                self.playlist.disable_presets_by_class(active_preset.__class__.__name__)
                raise

            # Handle transition by rendering both the active and the next
            # preset, and blending them together
            if self._in_transition and next_preset:
                if self._start_transition:
                    self._start_transition = False
                    if self._app.settings.get('mixer')['transition'] == "Random":
                        self.get_next_transition()
                    if self._transition:
                        self._transition.reset()
                    next_preset._reset()
                    self._buffer_b = BufferUtils.create_buffer()

                if self._transition_duration > 0.0 and self._transition is not None:
                    if not self._paused:
                        self.transition_progress = self._elapsed / self._transition_duration
                else:
                    self.transition_progress = 1.0

                next_preset.tick(dt)

            # If the scene tree is available, we can do efficient mixing of presets.
            # If not, a tree would need to be constructed on-the-fly.
            # TODO: Support mixing without a scene tree available
            if self._enable_rendering:
                if self._in_transition:
                    mixed_buffer = self.render_presets(
                        active_preset, self._buffer_a,
                        next_preset, self._buffer_b,
                        self._in_transition, self._transition,
                        self.transition_progress,
                        check_for_nan=self._enable_profiling)
                else:
                    mixed_buffer = self.render_presets(
                        active_preset, self._buffer_a,
                        check_for_nan=self._enable_profiling)

                # render_presets writes all the desired pixels to
                # self._main_buffer.

                # Apply the global dimmer to _main_buffer.
                if self._global_dimmer < 1.0:
                    mixed_buffer.T[1] *= self._global_dimmer
                #else:
                    # Global gamma correction.
                    # TODO(jon): This should be a setting
                    #mixed_buffer.T[1] = np.power(mixed_buffer.T[1], 4)

                # Mod hue by 1 (to allow wrap-around) and clamp lightness and
                # saturation to [0, 1].
                mixed_buffer.T[0] = np.mod(mixed_buffer.T[0], 1.0)
                np.clip(mixed_buffer.T[1], 0.0, 1.0, mixed_buffer.T[1])
                np.clip(mixed_buffer.T[2], 0.0, 1.0, mixed_buffer.T[2])

                # Write this buffer to enabled clients.
                if self._net is not None:
                    self._net.write_buffer(mixed_buffer)
            else:
                if self._net is not None:
                    self._net.write_commands(active_preset.get_commands_packed())

            if (not self._paused and (self._elapsed >= self._duration)
                and active_preset.can_transition()
                and not self._in_transition):

                if (self._elapsed >= (self._duration + self._transition_slop)) or self._onset:
                    if len(self.playlist) > 1:
                        self.start_transition()
                    self._elapsed = 0.0

            elif self._in_transition:
                if self.transition_progress >= 1.0:
                    self._in_transition = False
                    # Reset the elapsed time counter so the preset runs for the
                    # full duration after the transition
                    self._elapsed = 0.0
                    self.playlist.advance()

        if self._reset_onset:
            self._onset = False
            self._reset_onset = False

        if self._enable_profiling:
            tick_time = (time.time() - self._last_frame_time)
            self._last_frame_time = time.time()
            if tick_time > 0.0:
                index = int((1.0 / tick_time))
                self._tick_time_data[index] = self._tick_time_data.get(index, 0) + 1
Ejemplo n.º 23
0
    def draw(self, dt):
        if len(self._playlist) == 0:
            self._main_buffer *= (0.0, 0.0, 0.0)
            return self._main_buffer

        self._elapsed += dt

        active_preset = self._playlist.get_active_preset()
        active_index = self._playlist.get_active_index()

        next_preset = self._playlist.get_next_preset()
        next_index = self._playlist.get_next_index()

        active_preset.clear_commands()
        active_preset.tick(dt)

        # Handle transition by rendering both the active and the next preset,
        # and blending them together.
        if self._in_transition:
            if self._start_transition:
                self._start_transition = False
                if self._app.settings.get('mixer')['transition'] == "Random":
                    self.get_next_transition()
                if self._transition:
                    self._transition.reset()
                next_preset._reset()
                self._secondary_buffer = BufferUtils.create_buffer()

            if self._transition_duration > 0.0 and self._transition is not None:
                if not self._mixer.is_paused():
                    self.transition_progress = self._elapsed / self._transition_duration
            else:
                self.transition_progress = 1.0

            next_preset.clear_commands()
            next_preset.tick(dt)

            # Exit from transition state after the transition duration has
            # elapsed
            if self.transition_progress >= 1.0:
                self._in_transition = False
                # Reset the elapsed time counter so the preset runs for the
                # full duration after the transition
                self._elapsed = 0.0
                self._playlist.advance()
                active_preset = next_preset
                active_index = next_index

        first_preset = self._playlist.get_preset_by_index(active_index)
        if self._in_transition:
            second_preset = self._playlist.get_preset_by_index(next_index)
            mixed_buffer = self.render_presets(
                first_preset, self._main_buffer,
                second_preset, self._secondary_buffer,
                self._in_transition, self._transition,
                self.transition_progress,
                check_for_nan=self._enable_profiling)
        else:
            mixed_buffer = self.render_presets(
                first_preset, self._main_buffer,
                check_for_nan=self._enable_profiling)

        if not self._mixer.is_paused() and (self._elapsed >= self._duration) and active_preset.can_transition() and not self._in_transition:
            if (self._elapsed >= (self._duration + self._transition_slop)) or self._mixer._onset:
                self.start_transition()
                self._elapsed = 0.0

        return mixed_buffer
Ejemplo n.º 24
0
 def reset(self):
     self.parameter_changed(None)
     self._buffer1 = BufferUtils.create_buffer()
     self._buffer2 = BufferUtils.create_buffer()
Ejemplo n.º 25
0
 def reset(self):
     self._main_buffer = BufferUtils.create_buffer()
     self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 26
0
    def __init__(self, app):
        super(Mixer, self).__init__()
        self._app = app
        self._net = app.net
        self.playlist = None
        self._scene = app.scene
        self._tick_rate = self._app.settings.get('mixer')['tick-rate']
        self._in_transition = False
        self._start_transition = False
        self._transition_scrubbing = False
        self._transition_duration = self._app.settings.get('mixer')['transition-duration']
        self._transition_slop = self._app.settings.get('mixer')['transition-slop']
        self._tick_timer = None
        self._duration = self._app.settings.get('mixer')['preset-duration']
        self._elapsed = 0.0
        self.running = False
        self._buffer_a = None
        self._max_pixels = 0
        self._tick_time_data = dict()
        self._num_frames = 0
        self._last_frame_time = 0.0
        self._start_time = 0.0
        self._stop_time = 0.0
        self._strand_keys = list()
        self._enable_profiling = self._app.args.profile
        self._paused = self._app.settings.get('mixer').get('paused', False)
        self._frozen = False
        self._last_onset_time = 0.0
        self._onset_holdoff = self._app.settings.get('mixer')['onset-holdoff']
        self._onset = False
        self._reset_onset = False
        self.global_dimmer = 1.0
        self.global_speed = 1.0
        self._render_in_progress = False
        self._last_tick_time = 0.0
        self._fps_time = 0.0
        self._fps_frames = 0
        self._fps = 0.0
        self.last_time = time.time()
        self.transition_progress = 0.0
        self.audio = Audio(self)

        if self._app.args.yappi and USE_YAPPI:
            print "yappi start"
            yappi.start()

        log.info("Warming up BufferUtils cache...")
        BufferUtils.init()
        log.info("Completed BufferUtils cache warmup")

        # Load transitions
        self.set_transition_mode(self._app.settings.get('mixer')['transition'])

        log.info("Initializing preset rendering buffer")
        fh = self._scene.fixture_hierarchy()
        for strand in fh:
            self._strand_keys.append(strand)

        (maxs, maxp) = self._scene.get_matrix_extents()

        self._buffer_a = BufferUtils.create_buffer()
        self._buffer_b = BufferUtils.create_buffer()
        self._max_pixels = maxp
Ejemplo n.º 27
0
 def reset_output_buffer(self):
     """
     Clears the output buffer
     """
     self._buffer_a = BufferUtils.create_buffer()
     self._buffer_b = BufferUtils.create_buffer()
Ejemplo n.º 28
0
 def init_pixels(self):
     """
     Sets up the pixel array
     """
     self._pixel_buffer = BufferUtils.create_buffer()
Ejemplo n.º 29
0
 def reset_output_buffer(self):
     """
     Clears the output buffer
     """
     self._main_buffer = BufferUtils.create_buffer()
     self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 30
0
 def reset_output_buffer(self):
     """
     Clears the output buffer
     """
     self._main_buffer = BufferUtils.create_buffer()
     self._secondary_buffer = BufferUtils.create_buffer()
Ejemplo n.º 31
0
 def reset(self):
     self.frame = BufferUtils.create_buffer()
     pixel_locations = np.asarray(self._app.scene.get_all_pixel_locations()).T
     self.scaled_pixel_xs = 0.01 * pixel_locations[0]
     self.scaled_pixel_ys = 0.01 * pixel_locations[1]
Ejemplo n.º 32
0
 def init_pixels(self):
     """
     Sets up the pixel array
     """
     self._pixel_buffer = BufferUtils.create_buffer()