def blendColor(color_a, color_b, amount): newred = (color_a.red() * (1.0 - amount)) + (color_b.red() * amount) newgreen = (color_a.green() * (1.0 - amount)) + (color_b.green() * amount) newblue = (color_a.blue() * (1.0 - amount)) + (color_b.blue() * amount) return leddriver.Color(newred, newgreen, newblue) # defaults to white.
def set_pitch_leds(self, mode): # Pitch input 0-1.0 neg | 1.0-4.0 pos pink = libDriver.Color(3037, 200, 3825) white = libDriver.Color(4095, 4095, 4095) red = libDriver.Color(4095, 0, 0) #octave 0 / record orange = libDriver.Color(4095, 1100, 0) #octave 1 (1V) yellow = libDriver.Color(4095, 3395, 0) #octave 2 (2V) blue = libDriver.Color(0, 0, 4095) #octave 3 (3V original pitch) green = libDriver.Color(0, 4095, 0) # octave 4 (4V) purple = libDriver.Color(511, 0, 4095) # octave 5 (5V) colororder = [white, orange, yellow, blue, green, purple] octaves = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] if mode == "normal" or mode == "puredata": original_pitch = 0.6 tolerance = 0.001 pitch_amt = round(self.controlhandler.getValue("pitch"), 4) # I don't like that I have to do this sector_total = pitch_amt / 0.2 sector_int = int(sector_total) sector_brightness = sector_total - sector_int if pitch_amt > original_pitch + tolerance: # handle blending up ward if pitch_amt > octaves[5]: scalar = (pitch_amt - octaves[5]) * 5.00 pos_color = self.blendColor(colororder[5], colororder[0], scalar) elif pitch_amt > octaves[4]: ## Blend green to purple scalar = (pitch_amt - octaves[4]) * 5.00 pos_color = self.blendColor(colororder[4], colororder[5], scalar) else: scalar = (pitch_amt - octaves[3]) * 5.00 pos_color = self.blendColor(colororder[3], colororder[4], scalar) neg_color = white #pitch_pos_bright = sector_brightness * 0.33 pitch_pos_bright = 0.33 pitch_neg_bright = 0.0 elif pitch_amt < original_pitch - tolerance: if pitch_amt < octaves[1]: scalar = (pitch_amt - octaves[0]) * 5.0 neg_color = self.blendColor(colororder[0], colororder[1], scalar) elif pitch_amt < octaves[2]: scalar = (pitch_amt - octaves[1]) * 5.0 neg_color = self.blendColor(colororder[1], colororder[2], scalar) elif pitch_amt < octaves[3]: scalar = (pitch_amt - octaves[2]) * 5.0 neg_color = self.blendColor(colororder[2], colororder[3], scalar) pos_color = white pitch_pos_bright = 0.0 pitch_neg_bright = 0.33 octaves = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] for idx, octave in enumerate(octaves): if pitch_amt >= octave - tolerance and pitch_amt <= octave + tolerance: if octave < 0.6: pitch_neg_bright = 1.0 neg_color = colororder[idx] elif octave > 0.6: pitch_pos_bright = 1.0 pos_color = colororder[idx] else: pitch_pos_bright = 1.0 pitch_neg_bright = 1.0 pos_color = colororder[idx] neg_color = colororder[idx] self.set_rgb("pitch_neg", neg_color.red(), neg_color.green(), neg_color.blue(), pitch_neg_bright) self.set_rgb("pitch_pos", pos_color.red(), pos_color.green(), pos_color.blue(), pitch_pos_bright) elif mode == "secondary controls": tempc = purple amt = round(self.controlhandler.getAltValue("pitch_alt"), 3) pos_bright = (amt - 0.5) * 2.0 neg_bright = ((1.0 - amt) - 0.5) * 2.0 if pos_bright < 0.0: pos_bright = 0.0 elif pos_bright > 1.0: pos_bright = 1.0 if neg_bright < 0.0: neg_bright = 0.0 elif neg_bright > 1.0: neg_bright = 1.0 blink = (self.now & 150) > 75 if amt < 0.001 and self.pitch_blink_anim_flag == True: if blink == True: neg_bright = 1.0 else: neg_bright = 0.0 if self.now - self.pitch_blink_timer > 450: self.pitch_blink_anim_flag = False if amt > 0.99 and self.pitch_blink_anim_flag == True: if blink == True: pos_bright = 1.0 else: pos_bright = 0.0 if self.now - self.pitch_blink_timer > 450: self.pitch_blink_anim_flag = False self.set_rgb("pitch_neg", tempc.red(), tempc.green(), tempc.blue(), neg_bright) self.set_rgb("pitch_pos", tempc.red(), tempc.green(), tempc.blue(), pos_bright) elif mode == "instr selector": tempc = libDriver.Color(0, 4095, 0) self.set_rgb("pitch_neg", tempc.red(), tempc.green(), tempc.blue(), 1.0) self.set_rgb("pitch_pos", tempc.red(), tempc.green(), tempc.blue(), 1.0) else: pass
import leddriver import time import sys def blendColor(color_a, color_b, amount): newred = (color_a.red() * (1.0 - amount)) + (color_b.red() * amount) newgreen = (color_a.green() * (1.0 - amount)) + (color_b.green() * amount) newblue = (color_a.blue() * (1.0 - amount)) + (color_b.blue() * amount) return leddriver.Color(newred, newgreen, newblue) # defaults to white. ledDriver = leddriver.LedDriver() pink = leddriver.Color(3037, 200, 3825) white = leddriver.Color(4095,4095,4095) red = leddriver.Color(4095, 0, 0) orange = leddriver.Color(4095, 1100, 0) yellow = leddriver.Color(4095, 3395, 0) blue = leddriver.Color(0,0,4095) green = leddriver.Color(0, 4095, 0) purple = leddriver.Color(511, 0, 4095) if len(sys.argv) > 1: arg = sys.argv[1] if arg == "booting": tempc = white elif arg == "loading": tempc = blue elif arg == "loadingusb": tempc = blendColor(blue, green, 0.5) elif arg == "updating": tempc = green elif arg == "error":
def set_speed_leds(self, mode): if mode == "normal" or mode == "puredata": pink = libDriver.Color(3037, 200, 3825) white = libDriver.Color(4095, 4095, 4095) red = libDriver.Color(4095, 0, 0) #octave 0 / record orange = libDriver.Color(4095, 1100, 0) #octave 1 (1V) yellow = libDriver.Color(4095, 3395, 0) #octave 2 (2V) blue = libDriver.Color(0, 0, 4095) #octave 3 (3V original pitch) green = libDriver.Color(0, 4095, 0) # octave 4 (4V) purple = libDriver.Color(511, 0, 4095) # octave 5 (5V) colororder = [white, orange, yellow, blue, green, purple] speed_amt = self.controlhandler.channeldict["speed"].curVal translated_speed = speed_amt * 8.0 - 4.0 factors = [0.125, 0.25, 0.5, 1.0, 2.0, 4.0] color_pos = white color_neg = white #speed_pos_bright = (speed_amt - 0.5) * 2.0 #speed_neg_bright = ((1.0 - speed_amt) - 0.5) * 2.0 if translated_speed > 0: speed_pos_bright = 1.0 speed_neg_bright = 0.0 else: speed_pos_bright = 0.0 speed_neg_bright = 1.0 speed_pos_bright *= 0.33 speed_neg_bright *= 0.33 blink = (self.now & 150) > 75 highest_factor = 0 abs_speed = abs(translated_speed) if abs_speed < factors[0]: highest_factor = 0 elif abs_speed < factors[1]: highest_factor = 1 elif abs_speed < factors[2]: highest_factor = 2 elif abs_speed < factors[3]: highest_factor = 3 elif abs_speed < factors[4]: highest_factor = 4 elif abs_speed < factors[5]: highest_factor = 5 if highest_factor < 1: scalar = (abs_speed / factors[0]) newcolor = colororder[0] color_pos = newcolor color_neg = newcolor if translated_speed < 0: speed_neg_bright = scalar * 0.33 else: speed_pos_bright = scalar * 0.33 else: scalarRange = factors[highest_factor] / 2.0 scalar = (abs_speed - factors[highest_factor - 1]) / scalarRange newcolor = self.blendColor(colororder[highest_factor - 1], colororder[highest_factor], scalar) color_pos = newcolor color_neg = newcolor for idx, factor in enumerate(factors): if (abs(translated_speed) > factor - 0.0075) and abs(translated_speed) < factor + 0.0075: if translated_speed > 0: color_pos = colororder[idx] speed_pos_bright = 1.0 else: color_neg = colororder[idx] speed_neg_bright = 1.0 if translated_speed == 0: speed_pos_bright = 0 speed_neg_bright = 0 if speed_pos_bright < 0: speed_pos_bright = 0 if speed_neg_bright < 0: speed_neg_bright = 0 if self.currentInstr == "a_granularlooper": if self.controlhandler.channeldict["record"].curVal == 1: color_neg = red color_pos = red speed_neg_bright = 1.0 speed_pos_bright = 1.0 self.set_rgb("speed_neg", color_neg.red(), color_neg.green(), color_neg.blue(), speed_neg_bright) self.set_rgb("speed_pos", color_pos.red(), color_pos.green(), color_pos.blue(), speed_pos_bright) elif mode == "secondary controls": speed_ticks = self.controlhandler.getAltValue("speed_alt") speed_amt = speed_ticks / 32.0 speed_pos_bright = (speed_amt - 0.5) * 2.0 speed_neg_bright = ((1.0 - speed_amt) - 0.5) * 2.0 if speed_pos_bright < 0: speed_pos_bright = 0 if speed_neg_bright < 0: speed_neg_bright = 0 if speed_ticks == 23: tempc = libDriver.Color(0, 4095, 0) else: tempc = libDriver.Color(3037, 200, 3825) self.set_rgb("speed_neg", tempc.red(), tempc.green(), tempc.blue(), speed_neg_bright) self.set_rgb("speed_pos", tempc.red(), tempc.green(), tempc.blue(), speed_pos_bright) elif mode == "instr selector": tempc = libDriver.Color(0, 4095, 0) if self.controlhandler.getInstrSelBank() == "factory": self.set_rgb("speed_neg", tempc.red(), tempc.green(), tempc.blue(), 1.0) self.set_rgb("speed_pos", tempc.red(), tempc.green(), tempc.blue(), 1.0) elif self.controlhandler.getInstrSelBank() == "user": self.set_rgb("speed_neg", tempc.red(), tempc.green(), tempc.blue(), 1.0) self.set_rgb("speed_pos", tempc.red(), tempc.green(), tempc.blue(), 0.0) elif self.controlhandler.getInstrSelBank() == "puredata": self.set_rgb("speed_neg", tempc.red(), tempc.green(), tempc.blue(), 0.0) self.set_rgb("speed_pos", tempc.red(), tempc.green(), tempc.blue(), 1.0) else: pass