class Test(object): def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.x = 0 self.y = 0 self.color = GREEN self.phase = 1 self.timer = Timer(1 / 30.) self.wave_range = 1 self.wave_step = 1 self.amplitude = 4 self.offset = matrix_width / 2 self.freq = 1. / matrix_height * 8 self.controlled = True self.mc = MidiController() def generate(self): self.graphics.fill(BLACK) if self.timer.valid(): self.phase += 1 for i in range(0, self.wave_range, self.wave_step): for self.y in range(0, matrix_height): if self.controlled: self.freq = self.mc.getButton(0, 0) / 126. self.amplitude = self.mc.getButton(0, 1) self.timer.set_interval(self.mc.getButton(0, 2) / 126.) self.x = math.sin(self.y * self.freq + self.phase ) * self.amplitude + self.offset + i b = translate(i, 0, matrix_width, 0, 50) g = translate(self.y, 0, matrix_height, 0, 80) r = translate(self.x, 0, 12, 0, 24) self.color = (255, 0, 0) self.graphics.drawPixel(self.x, self.y, self.color) return self.graphics.getSurface()
class SegmentCounter(object): def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.timer = Timer(1 / 30.) self.number = 0 self.segmentdisp = SegmentDisplay(self.graphics) def generate(self): self.graphics.fill(BLACK) if self.timer.valid(): self.number += 1 self.segmentdisp.drawnumbers(0, 0, self.number, 4) return self.graphics.getSurface()
def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.x = 0 self.y = 0 self.color = GREEN self.phase = 1 self.timer = Timer(1 / 30.) self.wave_range = 1 self.wave_step = 1 self.amplitude = 4 self.offset = matrix_width / 2 self.freq = 1. / matrix_height * 8 self.controlled = True self.mc = MidiController()
class DrawSegmentNumber(object): def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.letter_width = 4 self.letter_height = 7 self.timer = Timer(1 / 2.) self.number = 0 def generate(self): self.graphics.fill(BLACK) if self.timer.valid(): self.number += 1 if self.number > 9: self.number = 0 for x, row in enumerate(numbers[self.number]): for y, pixel in enumerate(row): color = (0, 0, 0xff * pixel) self.graphics.drawPixel(6 - x, y, color) return self.graphics.getSurface()
def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.graphics.fill(BLUE) self.color = BLUE self.timer = Timer(0.1) self.levels = [] self.chunk = 1024 self.scale = 1 self.exponent = 1 self.samplerate = 44100 self.audio_params = (pyaudio.paInt16, 1, self.samplerate, True, self.chunk) self.p = pyaudio.PyAudio() self.stream = self.p.open(format=self.audio_params[0], channels=self.audio_params[1], rate=self.audio_params[2], input=self.audio_params[3], frames_per_buffer=self.audio_params[4]) self.data = self.stream.read(self.chunk) self.mc = MidiController() self.points = []
def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.timer = Timer(1 / 30.) self.number = 0 self.segmentdisp = SegmentDisplay(self.graphics)
def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.letter_width = 4 self.letter_height = 7 self.timer = Timer(1 / 2.) self.number = 0
class VisualizerMc(object): """ testing with this is cool: https://www.youtube.com/watch?v=82Q6DRqf9H4 https://youtu.be/XzjmPo6qr_0?list=RD05IZxpCWSao https://youtu.be/UUIQox072QA?list=RD05IZxpCWSao https://youtu.be/JTNXgzSpiTU?list=RD05IZxpCWSao https://youtu.be/S5xOj3JGU0c?list=RD05IZxpCWSao https://youtu.be/7Ul7uBoewdM?list=RD05IZxpCWSao https://youtu.be/B1DDpyt8qyg?list=RD05IZxpCWSao https://youtu.be/VwME67reIYk?list=RD05IZxpCWSao https://youtu.be/hn_T2rMPL4c?list=RD05IZxpCWSao https://youtu.be/U20HZoCnRGA https://youtu.be/eRE0dfOfVYE """ def __init__(self): self.graphics = Graphics(matrix_width, matrix_height) self.graphics.fill(BLUE) self.color = BLUE self.timer = Timer(0.1) self.levels = [] self.chunk = 1024 self.scale = 1 self.exponent = 1 self.samplerate = 44100 self.audio_params = (pyaudio.paInt16, 1, self.samplerate, True, self.chunk) self.p = pyaudio.PyAudio() self.stream = self.p.open(format=self.audio_params[0], channels=self.audio_params[1], rate=self.audio_params[2], input=self.audio_params[3], frames_per_buffer=self.audio_params[4]) self.data = self.stream.read(self.chunk) self.mc = MidiController() self.points = [] def calculate_levels(self, data, chunk, samplerate, points=6, maxi=0): # Use FFT to calculate volume for each frequency MAX=maxi # Convert raw sound data to Numpy array fmt = "%dH"%(len(data)/2) data2 = struct.unpack(fmt, data) data2 = numpy.array(data2, dtype='h') # Apply FFT fourier = numpy.fft.fft(data2) ffty = numpy.abs(fourier[0:len(fourier)/2])/1000 ffty1=ffty[:len(ffty)/2] ffty2=ffty[len(ffty)/2::]+2 ffty2=ffty2[::-1] ffty=ffty1+ffty2 ffty=numpy.log(ffty)-2 fourier = list(ffty)[4:-4] fourier = fourier[:len(fourier)/2] size = len(fourier) # Add up for x poinst amount of lights levels = [sum(fourier[i:(i+size/points)]) for i in xrange(0, size, size/points)][:points] return levels def getaudio(self): try: raw = self.stream.read(self.audio_params[5]) except IOError as e: if e[1] != pyaudio.paInputOverflowed: raise else: print("Warning: audio input buffer overflow") raw = '\x00' * self.audio_params[5] return np.array(np.frombuffer(raw, np.int16), dtype=np.float64) def generate(self): self.graphics.fill(BLACK) if self.timer.valid(): # print(self.exponent, self.scale) pass if self.stream.get_read_available(): self.data = self.stream.read(self.chunk) self.levels = self.calculate_levels(self.data, self.chunk, self.samplerate, matrix_height) if len(self.levels): for i, level in enumerate(self.levels): # self.color = color_convert(interp_color(level/max(self.levels))) self.color = (255, 0, 0) level = max(min(level/self.scale*((self.mc.getButton(0, 3)/126.)*1/(0.5**(i*(self.mc.getButton(0, 4)/126.)))), 1.0), 0.0) level = level**self.exponent level = int(level*10*matrix_width) self.points.append(level) for i in range(0, len(self.points)-1): self.graphics.drawLine(self.points[i], i, self.points[i+1], i+1, self.color) return self.graphics.getSurface() def __del__(self): print("Closing Stream") self.stream.close() self.p.terminate()