def __init__(self): self.labels = {} self.queue = WorkQueue(5) threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start()
def __init__(self, beat): self.queue = WorkQueue(1) self.beat = beat self.beat_cooldown = time.time() threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start()
def __init__(self, plot, line): self.plot = plot self.line = line self.queue = WorkQueue(1) threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start()
class LabelHandler(threading.Thread): """ Thread responsible for updating labels. Each time new data is added to the LabelHandler's queue, the LabelHandler will check which label the data belongs to, and update the appropriate UI variable to display the latest value. """ def __init__(self): self.labels = {} self.queue = WorkQueue(5) threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start() def add_label(self, variable, key): """ Add a label for the thread to update. """ self.labels[key] = variable def run(self): while True: data = self.queue.get() if data[0] == 'note': self.labels['cents'].set(data[1]['cents_off']) self.labels['note'].set(data[1]['note']) elif data[0] == 'bands': for key, value in data[1].items(): self.labels[key].set("{0:.2f}".format(value)) elif data[0] == 'pitch': self.labels[data[0]].set("{0:.2f}".format(data[1])) else: self.labels[data[0]].set(data[1])
class SignalPlotter(threading.Thread): """ Retrieves signal data, downsamples and sets new Y data and limits. """ def __init__(self, plot, line): self.plot = plot self.line = line self.queue = WorkQueue(1) threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start() def run(self): graph_length = len(self.line.get_ydata()) signal = zeros(graph_length * SIGNAL_COUNT) min_power = 8000 while True: new_data = self.queue.get() signal = append(signal, new_data) signal = signal[len(new_data):] # Pad Y maximum/minimum so line doesn't hit top of graph. signal_max = max(abs(signal)) * (1 + GY_PADDING) # If mainly noise in signal use min_power as graph max/min. y_max = signal_max if signal_max > min_power else min_power self.plot.set_ylim([-y_max, y_max]) # Resample signal to graph's length, to reduce processing time. self.line.set_ydata(resample(signal, graph_length))
def __init__(self, config: dict = None, channel_id: int = None, queue_length: int = 1): threading.Thread.__init__(self, args=(), kwargs=None) self.queue = WorkQueue(queue_length) self.config = config self.channel_id = channel_id self.setDaemon(True) self.reset_attributes() self.start()
class SpectrumPlotter(threading.Thread): """ Retrieves signal data, downsamples and sets new Y data and limits. """ def __init__(self, plot, line): self.plot = plot self.line = line self.queue = WorkQueue(1) threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start() def run(self): graph_length = len(self.line.get_ydata()) while True: spectrum = real(self.queue.get()) # Resample spectrum to graph's length, to reduce processing time. downsampled_spectrum = resample(spectrum, graph_length) self.plot.set_ylim([0, max(downsampled_spectrum) * (1 + GY_PADDING)]) # Discard imaginary part to avoid numpy warning self.line.set_ydata(downsampled_spectrum)
class Exporter(threading.Thread): """ Exporter responsible for creating an output file that users can use for future spectrogram data. Attributes: - queue (WorkQueue): Queue for incoming spectrograms data - spectrumCollection (list): Stores received spectrograms for export """ def __init__(self, queue_length: int = 1): threading.Thread.__init__(self, args=(), kwargs=None) self.queue = WorkQueue(queue_length) self.setDaemon(True) self.start() self.spectrumCollection = [] def run(self): while True: spectrumData = self.queue.get() self.spectrumCollection.append(spectrumData) with open(os.path.join(os.path.dirname(__file__), '../CNN/save.p'), "wb") as output_file: pickle.dump(self.spectrumCollection, output_file)
class SpectrogramCompression(threading.Thread): """ Compresses the data in the spectrogram, making plotting faster. """ def __init__(self): self.queue = WorkQueue(1) threading.Thread.__init__(self, args=(), kwargs=None) self.compressed_data = [zeros(64), zeros(64), zeros([64, 64])] self.setDaemon(True) self.start() def run(self): while True: data = self.queue.get() compr_length = len(data[0]) // SPECTROGRAM_DOWNSAMPLE color_resample = resample(resample(data[2], compr_length), compr_length, axis=1) x_resample = resample(data[0], compr_length) y_resample = resample(data[1], compr_length) self.compressed_data = [x_resample, y_resample, color_resample] def get_spectro_data(self): """ As we can't update the data through a matplotlib method remotely, The UI grabs the latest data from this thread, every two seconds. """ return self.compressed_data
class BeatHandler(threading.Thread): """ Thread responsible for updating the beat label. Each time new data is added to the BeatHandlers's queue, the BeatHandler will check whether a beat has occured. If a beat has occured the beat label will be updated to display this, then after 0.1 seconds the beat label wil return to it's default value. """ def __init__(self, beat): self.queue = WorkQueue(1) self.beat = beat self.beat_cooldown = time.time() threading.Thread.__init__(self, args=(), kwargs=None) self.setDaemon(True) self.start() def run(self): while True: beat = self.queue.get() if beat: self.beat_cooldown = time.time() + 0.1 self.beat.set('[O]') if self.beat_cooldown - time.time() <= 0: self.beat.set('[X]')
def __init__(self, queue_length: int = 1): threading.Thread.__init__(self, args=(), kwargs=None) self.queue = WorkQueue(queue_length) self.setDaemon(True) self.start() self.spectrumCollection = []
def __init__(self): self.queue = WorkQueue(1) threading.Thread.__init__(self, args=(), kwargs=None) self.compressed_data = [zeros(64), zeros(64), zeros([64, 64])] self.setDaemon(True) self.start()