def __init__(self, led, vis_list=None, steps_per_vis=None, bins=64, max_freq=4000, log_scale=True, auto_gain=False, gain=3): super(Spectrum, self).__init__(led) self.source = EQ(bins=bins, max_freq=max_freq, log_scale=log_scale, auto_gain=auto_gain, gain=gain) self.draw_obj = None self.steps_per_vis = steps_per_vis self.vis_dict = {} for v in DEFAULT_VIS_LIST: self.vis_dict[v.__name__] = v(self) self.vis_list = vis_list if not self.vis_list: self.vis_list = [v.__name__ for v in DEFAULT_VIS_LIST] self.cur_vis = len(self.vis_list) self.next_draw_obj()
class Spectrum(BaseMatrixAnim): def __init__(self, led, vis_list=None, steps_per_vis=None, bins=64, max_freq=4000, log_scale=True, auto_gain=False, gain=3): super(Spectrum, self).__init__(led) self.source = EQ(bins=bins, max_freq=max_freq, log_scale=log_scale, auto_gain=auto_gain, gain=gain) self.draw_obj = None self.steps_per_vis = steps_per_vis self.vis_dict = {} for v in DEFAULT_VIS_LIST: self.vis_dict[v.__name__] = v(self) self.vis_list = vis_list if not self.vis_list: self.vis_list = [v.__name__ for v in DEFAULT_VIS_LIST] self.cur_vis = len(self.vis_list) self.next_draw_obj() def preRun(self, amt=1): self.source.start() def _exit(self, type, value, traceback): self.source.stop() def next_draw_obj(self): self.cur_vis += 1 if self.cur_vis >= len(self.vis_list): self.cur_vis = 0 if self.draw_obj: del self.draw_obj name = self.vis_list[self.cur_vis] log.info("Loading {}".format(name)) self.draw_obj = self.vis_dict[name] def step(self, amt=1): assert self.draw_obj, "No loaded visualizers!" self._led.all_off() data = self.source.get_audio_data() self.draw_obj.draw(data, amt) if self.steps_per_vis: self._step += 1 if self._step % self.steps_per_vis == 0: self.next_draw_obj()