led_plot.addItem(g_curve)
        led_plot.addItem(b_curve)
        # Frequency range label
        freq_label = pg.LabelItem('')

        # Frequency slider
        def freq_slider_change(tick):
            minf = freq_slider.tickValue(0)**2.0 * (config.MIC_RATE / 2.0)
            maxf = freq_slider.tickValue(1)**2.0 * (config.MIC_RATE / 2.0)
            t = 'Frequency range: {:.0f} - {:.0f} Hz'.format(minf, maxf)
            freq_label.setText(t)
            config.MIN_FREQUENCY = minf
            config.MAX_FREQUENCY = maxf
            dsp.create_mel_bank()

        freq_slider = pg.TickSliderItem(orientation='bottom', allowAdd=False)
        freq_slider.addTick(
            (config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.addTick(
            (config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.tickMoveFinished = freq_slider_change
        freq_label.setText('Frequency range: {} - {} Hz'.format(
            config.MIN_FREQUENCY, config.MAX_FREQUENCY))
        # Effect selection
        active_color = '#16dbeb'
        inactive_color = '#FFFFFF'

        def energy_click(x):
            global visualization_effect
            visualization_effect = visualize_energy
            energy_label.setText('Energy', color=active_color)
def main():
    print("Mode = "+config.VISUAL_EFFECT)

    if config.USE_GUI:
        import pyqtgraph as pg
        from pyqtgraph.Qt import QtGui, QtCore
        # Create GUI window
        app = QtGui.QApplication([])
        view = pg.GraphicsView()
        layout = pg.GraphicsLayout(border=(100,100,100))
        view.setCentralItem(layout)
        view.show()
        view.setWindowTitle('Visualization')
        view.resize(800,600)
        # Mel filterbank plot
        fft_plot = layout.addPlot(title='Filterbank Output', colspan=3)
        fft_plot.setRange(yRange=[-0.1, 1.2])
        fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        x_data = np.array(range(1, config.N_FFT_BINS + 1))
        mel_curve = pg.PlotCurveItem()
        mel_curve.setData(x=x_data, y=x_data*0)
        fft_plot.addItem(mel_curve)
        # Visualization plot
        layout.nextRow()
        led_plot = layout.addPlot(title='Visualization Output', colspan=3)
        led_plot.setRange(yRange=[-5, 260])
        led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        # Pen for each of the color channel curves
        r_pen = pg.mkPen((255, 30, 30, 200), width=4)
        g_pen = pg.mkPen((30, 255, 30, 200), width=4)
        b_pen = pg.mkPen((30, 30, 255, 200), width=4)
        # Color channel curves
        r_curve = pg.PlotCurveItem(pen=r_pen)
        g_curve = pg.PlotCurveItem(pen=g_pen)
        b_curve = pg.PlotCurveItem(pen=b_pen)
        # Define x data
        x_data = np.array(range(1, config.N_PIXELS + 1))
        r_curve.setData(x=x_data, y=x_data*0)
        g_curve.setData(x=x_data, y=x_data*0)
        b_curve.setData(x=x_data, y=x_data*0)
        # Add curves to plot
        led_plot.addItem(r_curve)
        led_plot.addItem(g_curve)
        led_plot.addItem(b_curve)
        # Frequency range label
        freq_label = pg.LabelItem('')
        # Frequency slider
        def freq_slider_change(tick):
            minf = freq_slider.tickValue(0)**2.0 * (config.MIC_RATE / 2.0)
            maxf = freq_slider.tickValue(1)**2.0 * (config.MIC_RATE / 2.0)
            t = 'Frequency range: {:.0f} - {:.0f} Hz'.format(minf, maxf)
            freq_label.setText(t)
            config.MIN_FREQUENCY = minf
            config.MAX_FREQUENCY = maxf
            dsp.create_mel_bank()
        freq_slider = pg.TickSliderItem(orientation='bottom', allowAdd=False)
        freq_slider.addTick((config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.addTick((config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.tickMoveFinished = freq_slider_change
        freq_label.setText('Frequency range: {} - {} Hz'.format(
            config.MIN_FREQUENCY,
            config.MAX_FREQUENCY))
        # Effect selection
        active_color = '#16dbeb'
        inactive_color = '#FFFFFF'
        def energy_click(x):
            global visualization_effect
            visualization_effect = visualize_energy
            energy_label.setText('Energy', color=active_color)
            scroll_label.setText('Scroll', color=inactive_color)
            spectrum_label.setText('Spectrum', color=inactive_color)
        def scroll_click(x):
            global visualization_effect
            visualization_effect = visualize_scroll
            energy_label.setText('Energy', color=inactive_color)
            scroll_label.setText('Scroll', color=active_color)
            spectrum_label.setText('Spectrum', color=inactive_color)
        def spectrum_click(x):
            global visualization_effect
            visualization_effect = visualize_spectrum
            energy_label.setText('Energy', color=inactive_color)
            scroll_label.setText('Scroll', color=inactive_color)
            spectrum_label.setText('Spectrum', color=active_color)
        # Create effect "buttons" (labels with click event)
        energy_label = pg.LabelItem('Energy')
        scroll_label = pg.LabelItem('Scroll')
        spectrum_label = pg.LabelItem('Spectrum')
        energy_label.mousePressEvent = energy_click
        scroll_label.mousePressEvent = scroll_click
        spectrum_label.mousePressEvent = spectrum_click
        energy_click(0)
        # Layout
        layout.nextRow()
        layout.addItem(freq_label, colspan=3)
        layout.nextRow()
        layout.addItem(freq_slider, colspan=3)
        layout.nextRow()
        layout.addItem(energy_label)
        layout.addItem(scroll_label)
        layout.addItem(spectrum_label)
    # Initialize LEDs
    led.update()
    # Start listening to live audio stream
    microphone.start_stream(microphone_update)
Ejemplo n.º 3
0
    def make_gui(self):
        # Create GUI window
        app = QtGui.QApplication([])
        view = pg.GraphicsView()
        layout = pg.GraphicsLayout(border=(100,100,100))
        view.setCentralItem(layout)
        view.show()
        view.setWindowTitle('Visualization')
        view.resize(800,600)
        # Mel filterbank plot
        fft_plot = layout.addPlot(title='Filterbank Output', colspan=3)
        fft_plot.setRange(yRange=[-0.1, 1.2])
        fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        x_data = np.array(range(1, self.config['N_FFT_BINS'] + 1))
        mel_curve = pg.PlotCurveItem()
        mel_curve.setData(x=x_data, y=x_data*0)
        fft_plot.addItem(mel_curve)

        def add_led_plot(o):
            # Visualization plot
            layout.nextRow()
            led_plot = layout.addPlot(title='LED: ' + o['NAME'], colspan=3)
            led_plot.setRange(yRange=[-5, 260])
            led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
            # Pen for each of the color channel curves
            r_pen = pg.mkPen((255, 30, 30, 200), width=4)
            g_pen = pg.mkPen((30, 255, 30, 200), width=4)
            b_pen = pg.mkPen((30, 30, 255, 200), width=4)
            # Color channel curves
            r_curve = pg.PlotCurveItem(pen=r_pen)
            g_curve = pg.PlotCurveItem(pen=g_pen)
            b_curve = pg.PlotCurveItem(pen=b_pen)
            # Define x data
            x_data = np.array(range(1, o['N_PIXELS'] + 1))
            r_curve.setData(x=x_data, y=x_data*0)
            g_curve.setData(x=x_data, y=x_data*0)
            b_curve.setData(x=x_data, y=x_data*0)
            # Add curves to plot
            led_plot.addItem(r_curve)
            led_plot.addItem(g_curve)
            led_plot.addItem(b_curve)

            self.led_plots[o['NAME']] = (led_plot, r_curve, g_curve, b_curve)

        for o in self.config.get('OUTPUTS') or []:
            # TODO: better way to figure this out
            if o.get('DEVICE', '').endswith('Strip'):
                add_led_plot(o)

        # Frequency range label
        freq_label = pg.LabelItem('')
        # Frequency slider
        def freq_slider_change(tick):
            minf = freq_slider.tickValue(0)**2.0 * (self.config['MIC_RATE'] / 2.0)
            maxf = freq_slider.tickValue(1)**2.0 * (self.config['MIC_RATE'] / 2.0)
            t = 'Frequency range: {:.0f} - {:.0f} Hz'.format(minf, maxf)
            freq_label.setText(t)
            self.config['MIN_FREQUENCY'] = minf
            self.config['MAX_FREQUENCY'] = maxf
            return
            dsp.create_mel_bank()
        freq_slider = pg.TickSliderItem(orientation='bottom', allowAdd=False)
        freq_slider.addTick((self.config['MIN_FREQUENCY'] / (self.config['MIC_RATE'] / 2.0))**0.5)
        freq_slider.addTick((self.config['MAX_FREQUENCY'] / (self.config['MIC_RATE'] / 2.0))**0.5)
        freq_slider.tickMoveFinished = freq_slider_change
        freq_label.setText('Frequency range: {} - {} Hz'.format(
            self.config['MIN_FREQUENCY'],
            self.config['MAX_FREQUENCY']))
        # # Effect selection
        # active_color = '#16dbeb'
        # inactive_color = '#FFFFFF'
        # def energy_click(x):
        #     global visualization_effect
        #     visualization_effect = visualize_energy
        #     energy_label.setText('Energy', color=active_color)
        #     scroll_label.setText('Scroll', color=inactive_color)
        #     spectrum_label.setText('Spectrum', color=inactive_color)
        # def scroll_click(x):
        #     global visualization_effect
        #     visualization_effect = visualize_scroll
        #     energy_label.setText('Energy', color=inactive_color)
        #     scroll_label.setText('Scroll', color=active_color)
        #     spectrum_label.setText('Spectrum', color=inactive_color)
        # def spectrum_click(x):
        #     global visualization_effect
        #     visualization_effect = visualize_spectrum
        #     energy_label.setText('Energy', color=inactive_color)
        #     scroll_label.setText('Scroll', color=inactive_color)
        #     spectrum_label.setText('Spectrum', color=active_color)
        # # Create effect "buttons" (labels with click event)
        # energy_label = pg.LabelItem('Energy')
        # scroll_label = pg.LabelItem('Scroll')
        # spectrum_label = pg.LabelItem('Spectrum')
        # energy_label.mousePressEvent = energy_click
        # scroll_label.mousePressEvent = scroll_click
        # spectrum_label.mousePressEvent = spectrum_click
        # energy_click(0)
        # Layout
        layout.nextRow()
        layout.addItem(freq_label, colspan=3)
        layout.nextRow()
        layout.addItem(freq_slider, colspan=3)
        layout.nextRow()
        # layout.addItem(energy_label)
        # layout.addItem(scroll_label)
        # layout.addItem(spectrum_label)

        self.app = app
        self.view = view
        self.layout = layout
        self.mel_curve = mel_curve
Ejemplo n.º 4
0
    def drawGraph(self):
        self.graphView = pg.GraphicsView(self.wave_widget)
        self.graphLayout = pg.GraphicsLayout(border=(100, 100, 100))
        self.graphView.setCentralItem(self.graphLayout)
        self.graphView.show()
        self.graphView.setWindowTitle('Visualization')
        self.graphView.resize(764, 528)
        # Mel filterbank plot
        fft_plot = self.graphLayout.addPlot(title='Filterbank Output',
                                            colspan=3)
        fft_plot.setRange(yRange=[-0.1, 1.2])
        fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        x_data = np.array(range(1, config.N_FFT_BINS + 1))
        self.mel_curve = pg.PlotCurveItem()
        self.mel_curve.setData(x=x_data, y=x_data * 0)
        fft_plot.addItem(self.mel_curve)
        # Visualization plot
        self.graphLayout.nextRow()
        led_plot = self.graphLayout.addPlot(title='Visualization Output',
                                            colspan=3)
        led_plot.setRange(yRange=[-5, 260])
        led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        # Pen for each of the color channel curves
        r_pen = pg.mkPen((255, 30, 30, 200), width=4)
        g_pen = pg.mkPen((30, 255, 30, 200), width=4)
        b_pen = pg.mkPen((30, 30, 255, 200), width=4)
        # Color channel curves
        self.r_curve = pg.PlotCurveItem(pen=r_pen)
        self.g_curve = pg.PlotCurveItem(pen=g_pen)
        self.b_curve = pg.PlotCurveItem(pen=b_pen)
        # Define x data
        x_data = np.array(range(1, config.N_PIXELS + 1))
        self.r_curve.setData(x=x_data, y=x_data * 0)
        self.g_curve.setData(x=x_data, y=x_data * 0)
        self.b_curve.setData(x=x_data, y=x_data * 0)
        # Add curves to plot
        led_plot.addItem(self.r_curve)
        led_plot.addItem(self.g_curve)
        led_plot.addItem(self.b_curve)
        # Frequency range label
        self.freq_label = pg.LabelItem('')

        self.freq_slider = pg.TickSliderItem(orientation='bottom',
                                             allowAdd=False)
        self.freq_slider.addTick(
            (config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        self.freq_slider.addTick(
            (config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        self.freq_slider.tickMoveFinished = self.freq_slider_change
        self.freq_label.setText('Frequency range: {} - {} Hz'.format(
            config.MIN_FREQUENCY, config.MAX_FREQUENCY))

        #Create effect "buttons" (labels with click event)
        self.energy_label = pg.LabelItem('Energy')
        self.scroll_label = pg.LabelItem('Scroll')
        self.spectrum_label = pg.LabelItem('Spectrum')
        self.energy_label.mousePressEvent = self.energy_click
        self.scroll_label.mousePressEvent = self.scroll_click
        self.spectrum_label.mousePressEvent = self.spectrum_click
        self.energy_click(0)
        # Layout
        self.graphLayout.nextRow()
        self.graphLayout.addItem(self.freq_label, colspan=3)
        self.graphLayout.nextRow()
        self.graphLayout.addItem(self.freq_slider, colspan=3)
        self.graphLayout.nextRow()
        self.graphLayout.addItem(self.energy_label)
        self.graphLayout.addItem(self.scroll_label)
        self.graphLayout.addItem(self.spectrum_label)
        self.verticalLayout_5.addWidget(self.graphView)
Ejemplo n.º 5
0
 def __init__(self, app_parent, layout_parent):
     self.parent = app_parent
     self.layout = layout_parent
     # Mel filterbank plot
     self.fft_plot = self.layout.addPlot(title='Filterbank Output',
                                         colspan=3)
     self.fft_plot.setRange(yRange=[-0.1, 1.2])
     self.fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
     self.x_data = np.array(range(1, config.N_FFT_BINS + 1))
     self.mel_curve = pg.PlotCurveItem()
     self.mel_curve.setData(x=self.x_data, y=self.x_data * 0)
     self.fft_plot.addItem(self.mel_curve)
     # Visualization plot
     self.layout.nextRow()
     self.led_plot = self.layout.addPlot(title='Visualization Output',
                                         colspan=3)
     self.led_plot.setRange(yRange=[-5, 260])
     self.led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
     # Pen for each of the color channel curves
     self.r_pen = pg.mkPen((255, 30, 30, 200), width=4)
     self.g_pen = pg.mkPen((30, 255, 30, 200), width=4)
     self.b_pen = pg.mkPen((30, 30, 255, 200), width=4)
     # Color channel curves
     self.r_curve = pg.PlotCurveItem(pen=self.r_pen)
     self.g_curve = pg.PlotCurveItem(pen=self.g_pen)
     self.b_curve = pg.PlotCurveItem(pen=self.b_pen)
     # Define x data
     self.x_data = np.array(range(1, config.N_PIXELS + 1))
     self.r_curve.setData(x=self.x_data, y=self.x_data * 0)
     self.g_curve.setData(x=self.x_data, y=self.x_data * 0)
     self.b_curve.setData(x=self.x_data, y=self.x_data * 0)
     # Add curves to plot
     self.led_plot.addItem(self.r_curve)
     self.led_plot.addItem(self.g_curve)
     self.led_plot.addItem(self.b_curve)
     # Frequency range label
     self.freq_label = pg.LabelItem('')
     # Frequency slider
     self.freq_slider = pg.TickSliderItem(orientation='bottom',
                                          allowAdd=False)
     self.freq_slider.addTick(
         (config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
     self.freq_slider.addTick(
         (config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
     self.freq_slider.tickMoveFinished = self.freq_slider_change
     self.freq_label.setText('Frequency range: {} - {} Hz'.format(
         config.MIN_FREQUENCY, config.MAX_FREQUENCY))
     # Create effect "buttons" (labels with click event)
     self.energy_label = pg.LabelItem('Energy')
     self.scroll_label = pg.LabelItem('Scroll')
     self.spectrum_label = pg.LabelItem('Spectrum')
     self.energy_label.mousePressEvent = self.energy_click
     self.scroll_label.mousePressEvent = self.scroll_click
     self.spectrum_label.mousePressEvent = self.spectrum_click
     self.energy_click(0)
     # Layout
     self.layout.nextRow()
     self.layout.addItem(self.freq_label, colspan=3)
     self.layout.nextRow()
     self.layout.addItem(self.freq_slider, colspan=3)
     self.layout.nextRow()
     self.layout.addItem(self.energy_label)
     self.layout.addItem(self.scroll_label)
     self.layout.addItem(self.spectrum_label)
Ejemplo n.º 6
0
##We need to keep track of two things:
# - The time series data
# - The indices of selected points
data = np.empty(100)
bad = []

#Set up plot components
s1 = pg.ScatterPlotItem(brush=(255, 0, 0), pen='w', symbol='o')
l1 = pg.PlotCurveItem()

#Add components to plot object.
p1.addItem(s1)
p1.addItem(l1)

#Add tickslider
ts = pg.TickSliderItem(title='smooth level')
for i in range(1, 11):
    ts.addTick(i)
win.nextRow()
win.addItem(ts)

#Stream data
ptr = 0


def newdata():
    global data, ptr
    data[ptr] = np.random.normal()
    ptr += 1
    #Double length of array as needed to hold new data.
    if ptr >= data.shape[0]:
Ejemplo n.º 7
0
def init_gui():
    def microphone_update(audio_samples):
        global y_roll, prev_rms, prev_exp, prev_fps_update
        # Normalize samples between 0 and 1
        y = audio_samples / 2.0 ** 15
        # Construct a rolling window of audio samples
        y_roll[:-1] = y_roll[1:]
        y_roll[-1, :] = np.copy(y)
        y_data = np.concatenate(y_roll, axis=0).astype(np.float32)

        vol = np.max(np.abs(y_data))
        if vol < config.MIN_VOLUME_THRESHOLD:
            print('No audio input. Volume below threshold. Volume:', vol)
            led.pixels = np.tile(0, (3, config.N_PIXELS))
            led.update()
        else:
            # Transform audio input into the frequency domain
            N = len(y_data)
            N_zeros = 2 ** int(np.ceil(np.log2(N))) - N
            # Pad with zeros until the next power of two
            y_data *= fft_window
            y_padded = np.pad(y_data, (0, N_zeros), mode='constant')
            YS = np.abs(np.fft.rfft(y_padded)[:N // 2])
            # Construct a Mel filterbank from the FFT data
            mel = np.atleast_2d(YS).T * dsp.mel_y.T
            # Scale data to values more suitable for visualization
            # mel = np.sum(mel, axis=0)
            mel = np.sum(mel, axis=0)
            mel = mel ** 2.0
            # Gain normalization
            mel_gain.update(np.max(gaussian_filter1d(mel, sigma=1.0)))
            mel /= mel_gain.value
            mel = mel_smoothing.update(mel)
            # Map filterbank output onto LED strip
            output = visualization_effect(mel)
            led.pixels = output
            led.update()
            if config.USE_GUI:
                # Plot filterbank output
                x = np.linspace(config.MIN_FREQUENCY, config.MAX_FREQUENCY, len(mel))
                mel_curve.setData(x=x, y=fft_plot_filter.update(mel))
                # Plot the color channels
                r_curve.setData(y=led.pixels[0])
                g_curve.setData(y=led.pixels[1])
                b_curve.setData(y=led.pixels[2])
        if config.USE_GUI:
            app.processEvents()

        if config.DISPLAY_FPS:
            fps = frames_per_second()
            if time.time() - 0.5 > prev_fps_update:
                prev_fps_update = time.time()
                print('FPS {:.0f} / {:.0f}'.format(fps, config.FPS))

    if config.USE_GUI:
        import pyqtgraph as pg
        from pyqtgraph.Qt import QtGui, QtCore
        # Create GUI window
        app = QtGui.QApplication([])
        view = pg.GraphicsView()
        layout = pg.GraphicsLayout(border=(100,100,100))
        view.setCentralItem(layout)
        view.show()
        view.setWindowTitle('Visualization')
        view.resize(800,600)
        # Mel filterbank plot
        fft_plot = layout.addPlot(title='Filterbank Output', colspan=3)
        fft_plot.setRange(yRange=[-0.1, 1.2])
        fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        x_data = np.array(range(1, config.N_FFT_BINS + 1))
        mel_curve = pg.PlotCurveItem()
        mel_curve.setData(x=x_data, y=x_data*0)
        fft_plot.addItem(mel_curve)
        # Visualization plot
        layout.nextRow()
        led_plot = layout.addPlot(title='Visualization Output', colspan=3)
        led_plot.setRange(yRange=[-5, 260])
        led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        # Pen for each of the color channel curves
        r_pen = pg.mkPen((255, 30, 30, 200), width=4)
        g_pen = pg.mkPen((30, 255, 30, 200), width=4)
        b_pen = pg.mkPen((30, 30, 255, 200), width=4)
        # Color channel curves
        r_curve = pg.PlotCurveItem(pen=r_pen)
        g_curve = pg.PlotCurveItem(pen=g_pen)
        b_curve = pg.PlotCurveItem(pen=b_pen)
        # Define x data
        x_data = np.array(range(1, config.N_PIXELS + 1))
        r_curve.setData(x=x_data, y=x_data*0)
        g_curve.setData(x=x_data, y=x_data*0)
        b_curve.setData(x=x_data, y=x_data*0)
        # Add curves to plot
        led_plot.addItem(r_curve)
        led_plot.addItem(g_curve)
        led_plot.addItem(b_curve)
        # Frequency range label
        freq_label = pg.LabelItem('')
        # Frequency slider
        def freq_slider_change(tick):
            minf = freq_slider.tickValue(0)**2.0 * (config.MIC_RATE / 2.0)
            maxf = freq_slider.tickValue(1)**2.0 * (config.MIC_RATE / 2.0)
            t = 'Frequency range: {:.0f} - {:.0f} Hz'.format(minf, maxf)
            freq_label.setText(t)
            config.MIN_FREQUENCY = minf
            config.MAX_FREQUENCY = maxf
            dsp.create_mel_bank()
        freq_slider = pg.TickSliderItem(orientation='bottom', allowAdd=False)
        freq_slider.addTick((config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.addTick((config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        freq_slider.tickMoveFinished = freq_slider_change
        freq_label.setText('Frequency range: {} - {} Hz'.format(
            config.MIN_FREQUENCY,
            config.MAX_FREQUENCY))
        # Effect selection
        active_color = '#16dbeb'
        inactive_color = '#FFFFFF'
        def energy_click(x):
            global visualization_effect
            visualization_effect = visualize_energy
            energy_label.setText('Energy', color=active_color)
            scroll_label.setText('Scroll', color=inactive_color)
            spectrum_label.setText('Spectrum', color=inactive_color)
        def scroll_click(x):
            global visualization_effect
            visualization_effect = visualize_scroll
            energy_label.setText('Energy', color=inactive_color)
            scroll_label.setText('Scroll', color=active_color)
            spectrum_label.setText('Spectrum', color=inactive_color)
        def spectrum_click(x):
            global visualization_effect
            visualization_effect = visualize_spectrum
            energy_label.setText('Energy', color=inactive_color)
            scroll_label.setText('Scroll', color=inactive_color)
            spectrum_label.setText('Spectrum', color=active_color)
        # Create effect "buttons" (labels with click event)
        energy_label = pg.LabelItem('Energy')
        scroll_label = pg.LabelItem('Scroll')
        spectrum_label = pg.LabelItem('Spectrum')
        energy_label.mousePressEvent = energy_click
        scroll_label.mousePressEvent = scroll_click
        spectrum_label.mousePressEvent = spectrum_click
        energy_click(0)
        # Layout
        layout.nextRow()
        layout.addItem(freq_label, colspan=3)
        layout.nextRow()
        layout.addItem(freq_slider, colspan=3)
        layout.nextRow()
        layout.addItem(energy_label)
        layout.addItem(scroll_label)
        layout.addItem(spectrum_label)
    # Initialize LEDs
    led.update()
Ejemplo n.º 8
0
lr.setZValue(-10)
p8.addItem(lr)

p9 = win.addPlot(title="Zoom on selected region")
p9.plot(data2)


def updatePlot():
    p9.setXRange(*lr.getRegion(), padding=0)


def updateRegion():
    lr.setRegion(p9.getViewBox().viewRange()[0])


lr.sigRegionChanged.connect(updatePlot)
p9.sigXRangeChanged.connect(updateRegion)
updatePlot()

win.nextRow()
p10 = win.addPlot(title='test')
sl = pg.TickSliderItem()
sl.addTick(2)
p10.addItem(sl)

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
Ejemplo n.º 9
0
    def setupUi(self, MainWindow):

        super().setupUi(MainWindow)
        ####
        self.visualizerGView = pg.GraphicsView(self.visualizerTab)
        self.visualizerGView.setObjectName(_fromUtf8("visualizerGView"))
        self.visualizerVLayout.addWidget(self.visualizerGView)
        self.layout = pg.GraphicsLayout(border=(100, 100, 100))
        self.visualizerGView.setCentralItem(self.layout)
        ####
        # Mel filterbank plot
        self.fft_plot = self.layout.addPlot(title='Filterbank Output',
                                            colspan=3)
        self.fft_plot.setRange(yRange=[-0.1, 1.2])
        self.fft_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        self.x_data = np.array(range(1, config.N_FFT_BINS + 1))
        self.mel_curve = pg.PlotCurveItem()
        self.mel_curve.setData(x=self.x_data, y=self.x_data * 0)
        self.fft_plot.addItem(self.mel_curve)
        # Visualization plot
        self.layout.nextRow()
        self.led_plot = self.layout.addPlot(title='Visualization Output',
                                            colspan=3)
        self.led_plot.setRange(yRange=[-5, 260])
        self.led_plot.disableAutoRange(axis=pg.ViewBox.YAxis)
        # Pen for each of the color channel curves
        self.r_pen = pg.mkPen((255, 30, 30, 200), width=4)
        self.g_pen = pg.mkPen((30, 255, 30, 200), width=4)
        self.b_pen = pg.mkPen((30, 30, 255, 200), width=4)
        # Color channel curves
        self.r_curve = pg.PlotCurveItem(pen=self.r_pen)
        self.g_curve = pg.PlotCurveItem(pen=self.g_pen)
        self.b_curve = pg.PlotCurveItem(pen=self.b_pen)
        # Define x data
        self.x_data = np.array(range(1, config.N_PIXELS + 1))
        self.r_curve.setData(x=self.x_data, y=self.x_data * 0)
        self.g_curve.setData(x=self.x_data, y=self.x_data * 0)
        self.b_curve.setData(x=self.x_data, y=self.x_data * 0)
        # Add curves to plot
        self.led_plot.addItem(self.r_curve)
        self.led_plot.addItem(self.g_curve)
        self.led_plot.addItem(self.b_curve)
        # Frequency range label
        self.freq_label = pg.LabelItem('')
        # Frequency slider
        self.freq_slider = pg.TickSliderItem(orientation='bottom',
                                             allowAdd=False)
        self.freq_slider.addTick(
            (config.MIN_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        self.freq_slider.addTick(
            (config.MAX_FREQUENCY / (config.MIC_RATE / 2.0))**0.5)
        self.freq_slider.tickMoveFinished = self.freq_slider_change
        self.freq_label.setText('Frequency range: {} - {} Hz'.format(
            config.MIN_FREQUENCY, config.MAX_FREQUENCY))
        # Create effect "buttons" (labels with click event)
        self.energy_label = pg.LabelItem('Energy')
        self.scroll_label = pg.LabelItem('Scroll')
        self.spectrum_label = pg.LabelItem('Spectrum')
        self.energy_label.mousePressEvent = self.energy_click
        self.scroll_label.mousePressEvent = self.scroll_click
        self.spectrum_label.mousePressEvent = self.spectrum_click
        self.energy_click(0)
        # Layout
        self.layout.nextRow()
        self.layout.addItem(self.freq_label, colspan=3)
        self.layout.nextRow()
        self.layout.addItem(self.freq_slider, colspan=3)
        self.layout.nextRow()
        self.layout.addItem(self.energy_label)
        self.layout.addItem(self.scroll_label)
        self.layout.addItem(self.spectrum_label)

        # Fix secondTab
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.visualizerTab),
                                  _translate("MainWindow", "Visualizer", None))
        #SIGNALS AND CONNECTORS
        self.visualizerStartBtn.clicked.connect(self.start_visualizer_click)
        self.visualizerStopBtn.clicked.connect(self.stop_visualizer_click)
        self.parent_app.aboutToQuit.connect(self.closeEvent)
        # AUDIO INPUT DEVICES
        self.getaudiodevices()
        self.soundDeviceSelectBox.currentIndexChanged.connect(
            self.inputDeviceChanged)
Ejemplo n.º 10
0
    # gui.add_curve(plot_index=0)
    # gui.win.nextRow()
    # Cos plot
    # gui.add_plot(title='Cos Plot')
    # gui.add_curve(plot_index=1)
    #
    inactive_color = '#FFFFFF'
    R_label = pg.LabelItem('')
    def freq_slider_changeR(tick):
        value = freq_sliderR.tickValue(0) +1
        R_label.setText(f"valor Red: {str(value)}",color=inactive_color)
        print(value)
        config.R_MULTIPLIER = value

    R_label.setText(f"valor Red: ",color=inactive_color)
    freq_sliderR = pg.TickSliderItem(orientation='left', allowAdd=False)
    freq_sliderR.addTick(0)
    freq_sliderR.addTick(255)
    # print(config.R_MULTIPLIER)
    freq_sliderR.tickMoveFinished = freq_slider_changeR
        
    gui.win.nextRow()
    gui.win.addItem(freq_sliderR,colspan=3)
    # while True:
    #     t = time.time()
    #     x = np.linspace(t, 2 * np.pi + t, N)
    #     gui.curve[0][0].setData(x=x, y=np.sin(x))
    #     gui.curve[1][0].setData(x=x, y=np.cos(x))
    #     gui.app.processEvents()
    #     time.sleep(1.0 / 30.0)