def setup_launchpad(): mode = None if launchpad.LaunchpadPro().Check(0): lp = launchpad.LaunchpadPro() if lp.Open(0): lpName = "Launchpad Pro" mode = "Pro" elif launchpad.LaunchpadProMk3().Check(0): lp = launchpad.LaunchpadProMk3() if lp.Open(0): lpName = "Launchpad Pro Mk3" mode = "ProMk3" elif launchpad.LaunchpadMiniMk3().Check(1): lp = launchpad.LaunchpadMiniMk3() if lp.Open(1): lpName = "Launchpad Mini Mk3" mode = "MiniMk3" elif launchpad.LaunchpadLPX().Check(1): lp = launchpad.LaunchpadLPX() if lp.Open(1): lpName = "Launchpad X" mode = "LPX" elif launchpad.LaunchpadMk2().Check(0): lp = launchpad.LaunchpadMk2() if lp.Open(0): lpName = "Launchpad Mk2" mode = "Mk2" elif launchpad.Dicer().Check(0): lp = launchpad.Dicer() if lp.Open(0): lpName = "Dicer" mode = "Dcr" elif launchpad.MidiFighter64().Check(0): lp = launchpad.MidiFighter64() if lp.Open(0): lpName = "Midi Fighter 64" mode = "F64" elif launchpad.Launchpad().Check(0): lp = launchpad.Launchpad() if lp.Open(0): lpName = "Launchpad Mk1/S/Mini" mode = "Mk1" if mode == None: return None return lp, mode, lpName
def box_init(): # create an instance global lp lp = launchpad.Launchpad() # check what we have here and override lp if necessary if lp.Check(0, "pro"): lp = launchpad.LaunchpadPro() if lp.Open(0, "pro"): print("Launchpad Pro") mode = "Pro" elif lp.Check(0, "mk2"): lp = launchpad.LaunchpadMk2() if lp.Open(0, "mk2"): print("Launchpad Mk2") mode = "Mk2" elif lp.Check(0, "control xl"): lp = launchpad.LaunchControlXL() if lp.Open(0, "control xl"): print("Launch Control XL") mode = "XL" elif lp.Check(0, "launchkey"): lp = launchpad.LaunchKeyMini() if lp.Open(0, "launchkey"): print("LaunchKey (Mini)") mode = "LKM" elif lp.Check(0, "dicer"): lp = launchpad.Dicer() if lp.Open(0, "dicer"): print("Dicer") mode = "Dcr" else: if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return lp.Reset()
def main(): mode = None # create an instance lp = launchpad.Launchpad() # check what we have here and override lp if necessary if lp.Check(0, "pad pro"): lp = launchpad.LaunchpadPro() if lp.Open(0, "pad pro"): print("Launchpad Pro") mode = "Pro" # experimental MK3 implementation # The MK3 has two MIDI instances per device; we need the 2nd one. # If you have two MK3s attached, its "1" for the first and "3" for the 2nd device elif lp.Check(1, "minimk3"): lp = launchpad.LaunchpadMiniMk3() if lp.Open(1, "minimk3"): print("Launchpad Mini Mk3") mode = "Pro" # experimental LPX implementation # Like the Mk3, the LPX also has two MIDI instances per device; we need the 2nd one. # If you have two LPXs attached, its "1" for the first and "3" for the 2nd device elif lp.Check(1, "lpx"): lp = launchpad.LaunchpadLPX() if lp.Open(1, "lpx"): print("Launchpad X") mode = "Pro" elif lp.Check(0, "mk2"): lp = launchpad.LaunchpadMk2() if lp.Open(0, "mk2"): print("Launchpad Mk2") mode = "Mk2" elif lp.Check(0, "control xl"): lp = launchpad.LaunchControlXL() if lp.Open(0, "control xl"): print("Launch Control XL") mode = "XL" elif lp.Check(0, "launchkey"): lp = launchpad.LaunchKeyMini() if lp.Open(0, "launchkey"): print("LaunchKey (Mini)") mode = "LKM" elif lp.Check(0, "dicer"): lp = launchpad.Dicer() if lp.Open(0, "dicer"): print("Dicer") mode = "Dcr" else: if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return # scroll "HELLO" from right to left if mode == "Mk1": lp.LedCtrlString("HELLO ", 0, 3, -1) # for all others except the XL and the LaunchKey elif mode != "XL" and mode != "LKM" and mode != "Dcr": lp.LedCtrlString("HELLO ", 0, 63, 0, -1) # random output if mode == "LKM": print( "The LaunchKey(Mini) does not (yet) support LED activation, but you" ) print("can push some buttons or rotate some knobes now...") print("Auto exit if first number reaches 0") else: print( "---\nRandom madness. Create some events. Stops after reaching 0 (first number)" ) print( "Notice that sometimes, old Mk1 units don't recognize any button") print("events before you press one of the (top) automap buttons") print("(or power-cycle the unit...).") # Clear the buffer because the Launchpad remembers everything :-) lp.ButtonFlush() # Lightshow if mode == "XL" or mode == "LKM": butHit = 100 elif mode == "Dcr": butHit = 30 else: butHit = 10 while 1: if mode == "Mk1" or mode == "XL": lp.LedCtrlRaw(random.randint(0, 127), random.randint(0, 3), random.randint(0, 3)) elif mode == "Dcr": lp.LedCtrlRaw(random.randint(0, 130), random.randint(0, 7), random.randint(0, 15)) elif mode != "LKM": lp.LedCtrlRaw(random.randint(0, 127), random.randint(0, 63), random.randint(0, 63), random.randint(0, 63)) time.wait(5) if mode == "XL" or mode == "LKM": but = lp.InputStateRaw() else: but = lp.ButtonStateRaw() if but != []: butHit -= 1 if butHit < 1: break print(butHit, " event: ", but) # now quit... print( "Quitting might raise a 'Bad Pointer' error (~almost~ nothing to worry about...:).\n\n" ) lp.Reset() # turn all LEDs off lp.Close( ) # close the Launchpad (will quit with an error due to a PyGame bug)
def main(): mode = None if launchpad.LaunchpadPro().Check( 0 ): lp = launchpad.LaunchpadPro() if lp.Open( 0 ): print("Launchpad Pro") mode = "Pro" elif launchpad.LaunchpadProMk3().Check( 0 ): lp = launchpad.LaunchpadProMk3() if lp.Open( 0 ): print("Launchpad Pro Mk3") mode = "ProMk3" elif launchpad.LaunchpadMiniMk3().Check( 1 ): lp = launchpad.LaunchpadMiniMk3() if lp.Open( 1 ): print("Launchpad Mini Mk3") mode = "Pro" elif launchpad.LaunchpadLPX().Check( 1 ): lp = launchpad.LaunchpadLPX() if lp.Open( 1 ): print("Launchpad X") mode = "Pro" elif launchpad.LaunchpadMk2().Check( 0 ): lp = launchpad.LaunchpadMk2() if lp.Open( 0 ): print("Launchpad Mk2") mode = "Mk2" # elif launchpad.LaunchControlXL().Check( 0 ): # lp = launchpad.LaunchControlXL() # if lp.Open( 0 ): # print("Launch Control XL") # mode = "XL" # elif launchpad.LaunchKeyMini().Check( 0 ): # lp = launchpad.LaunchKeyMini() # if lp.Open( 0 ): # print("LaunchKey (Mini)") # mode = "LKM" elif launchpad.Dicer().Check( 0 ): lp = launchpad.Dicer() if lp.Open( 0 ): print("Dicer") mode = "Dcr" elif launchpad.MidiFighter64().Check( 0 ): lp = launchpad.MidiFighter64() if lp.Open( 0 ): print("Midi Fighter 64") mode = "F64" else: lp = launchpad.Launchpad() if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return print("\nQUIT: Push one single button ten times in a row.\n") butLast = -1 butCount = 0 while True: buts = lp.ButtonStateRaw() if buts != []: print( buts[0], buts[1]) # shall we quit? if buts[0] != butLast: butLast = buts[0] butCount = 1 continue else: # counts pressed and release events butCount += 1 if butCount >= 20: break print("bye ...") lp.Reset() # turn all LEDs off lp.Close() # close the Launchpad (will quit with an error due to a PyGame bug)
def main(): mode = None # create an instance lp = launchpad.Launchpad() # check what we have here and override lp if necessary if lp.Check(0, "pro"): lp = launchpad.LaunchpadPro() if lp.Open(0, "pro"): print("Launchpad Pro") mode = "Pro" elif lp.Check(0, "mk2"): lp = launchpad.LaunchpadMk2() if lp.Open(0, "mk2"): print("Launchpad Mk2") mode = "Mk2" elif lp.Check(0, "control xl"): lp = launchpad.LaunchControlXL() if lp.Open(0, "control xl"): print("Launch Control XL") mode = "XL" elif lp.Check(0, "launchkey"): lp = launchpad.LaunchKeyMini() if lp.Open(0, "launchkey"): print("LaunchKey (Mini)") mode = "LKM" elif lp.Check(0, "dicer"): lp = launchpad.Dicer() if lp.Open(0, "dicer"): print("Dicer") mode = "Dcr" else: if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return # scroll "HELLO" from right to left ''' if mode == "Mk1": lp.LedCtrlString( "HELLO ", 0, 3, -1 ) # for all others except the XL and the LaunchKey elif mode != "XL" and mode != "LKM" and mode != "Dcr": lp.LedCtrlString( "HELLO ", 0, 63, 0, -1 ) ''' # Clear the buffer because the Launchpad remembers everything :-) lp.ButtonFlush() lp.LedAllOn() lp.Reset() #if mode == "Mk1" or mode == "XL": # lp.LedCtrlRaw( random.randint(0,127), random.randint(0,3), random.randint(0,3) ) #while True: # lp.LedCtrlXY(7,7,1,0) #time.wait(10) app_done = False butHit = 10 while 1: #time.wait( 5 ) but = lp.ButtonStateRaw() lp.LedCtrlRaw(22, 3, 3) lp.LedCtrlRaw(0, 3, 0) lp.LedCtrlXY(3, 3, 0, 3) ''' LED functions LedGetColor( red, green ) LedCtrlRaw( number, red, green ) LedCtrlXY( x, y, red, green ) LedCtrlRawRapid( allLeds ) LedCtrlRawRapidHome() LedCtrlAutomap( number, red, green ) LedAllOn() LedCtrlChar( char, red, green, offsx = 0, offsy = 0 ) LedCtrlString( str, red, green, dir = 0 ) Button functions ButtonChanged() ButtonStateRaw() ButtonStateXY() ButtonFlush() ''' #butHit = 10 if but != []: butHit -= 1 if butHit < 1: break print(butHit, " event: ", but) #print( butHit, " event: ", but ) if (but == ([0, True])): print("button appuye 0,0") break #lp.Reset() # turn all LEDs off #lp.Close() # close the Launchpad (will quit with an error due to a PyGame bug) #exit() lp.ButtonFlush() lp.Reset() # turn all LEDs off lp.Close( ) # close the Launchpad (will quit with an error due to a PyGame bug) print("penis")
def main(): mode = None # create an instance lp = launchpad.Launchpad(); # check what we have here and override lp if necessary if lp.Check( 0, "pro" ): lp = launchpad.LaunchpadPro() if lp.Open(0,"pro"): print("Launchpad Pro") mode = "Pro" elif lp.Check( 0, "mk2" ): lp = launchpad.LaunchpadMk2() if lp.Open( 0, "mk2" ): print("Launchpad Mk2") mode = "Mk2" elif lp.Check( 0, "control xl" ): lp = launchpad.LaunchControlXL() if lp.Open( 0, "control xl" ): print("Launch Control XL") mode = "XL" elif lp.Check( 0, "launchkey" ): lp = launchpad.LaunchKeyMini() if lp.Open( 0, "launchkey" ): print("LaunchKey (Mini)") mode = "LKM" elif lp.Check( 0, "dicer" ): lp = launchpad.Dicer() if lp.Open( 0, "dicer" ): print("Dicer") mode = "Dcr" else: if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return # scroll "HELLO" from right to left ''' if mode == "Mk1": lp.LedCtrlString( "HELLO ", 0, 3, -1 ) # for all others except the XL and the LaunchKey elif mode != "XL" and mode != "LKM" and mode != "Dcr": lp.LedCtrlString( "HELLO ", 0, 63, 0, -1 ) ''' # random output if mode == "LKM": print("The LaunchKey(Mini) does not (yet) support LED activation, but you") print("can push some buttons or rotate some knobes now...") print("Auto exit if first number reaches 0") else: print("---\nRandom madness. Create some events. Stops after reaching 0 (first number)") print("Notice that sometimes, old Mk1 units don't recognize any button") print("events before you press one of the (top) automap buttons") print("(or power-cycle the unit...).") # Clear the buffer because the Launchpad remembers everything :-) lp.ButtonFlush() lp.LedAllOn() lp.Reset() #if mode == "Mk1" or mode == "XL": # lp.LedCtrlRaw( random.randint(0,127), random.randint(0,3), random.randint(0,3) ) #while True: # lp.LedCtrlXY(7,7,1,0) #time.wait(10) for i in range(1000): lp.LedCtrlRaw(22, 2, 0) lp.LedCtrlXY(3,3,0,3) print('blah') time.wait(5) print('after wait') butHit = 10 but = lp.ButtonStateRaw() if but != []: butHit -= 1 #if butHit < 1: # break print( butHit, " event: ", but ) print( butHit, " event: ", but ) time.wait(5) lp.Reset() # turn all LEDs off lp.Close() # close the Launchpad (will quit with an error due to a PyGame bug)
def main(): mode = None # create an instance lp = launchpad.Launchpad() # check what we have here and override lp if necessary if lp.Check(0, "pro"): lp = launchpad.LaunchpadPro() if lp.Open(0, "pro"): print("Launchpad Pro") mode = "Pro" elif lp.Check(0, "mk2"): lp = launchpad.LaunchpadMk2() if lp.Open(0, "mk2"): print("Launchpad Mk2") mode = "Mk2" elif lp.Check(0, "control xl"): lp = launchpad.LaunchControlXL() if lp.Open(0, "control xl"): print("Launch Control XL") mode = "XL" elif lp.Check(0, "launchkey"): lp = launchpad.LaunchKeyMini() if lp.Open(0, "launchkey"): print("LaunchKey (Mini)") mode = "LKM" elif lp.Check(0, "dicer"): lp = launchpad.Dicer() if lp.Open(0, "dicer"): print("Dicer") mode = "Dcr" else: if lp.Open(): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return # scroll "HELLO" from right to left if mode == "Mk1": lp.LedCtrlString("HELLO ", 0, 3, -1) # for all others except the XL and the LaunchKey elif mode != "XL" and mode != "LKM" and mode != "Dcr": lp.LedCtrlString("HELLO ", 0, 63, 0, -1) # random output if mode == "LKM": print( "The LaunchKey(Mini) does not (yet) support LED activation, but you" ) print("can push some buttons or rotate some knobes now...") print("Auto exit if first number reaches 0") else: print( "---\nRandom madness. Create some events. Stops after reaching 0 (first number)" ) print( "Notice that sometimes, old Mk1 units don't recognize any button") print("events before you press one of the (top) automap buttons") print("(or power-cycle the unit...).") # Clear the buffer because the Launchpad remembers everything :-) lp.ButtonFlush() # Lightshow if mode == "XL" or mode == "LKM": butHit = 100 elif mode == "Dcr": butHit = 30 else: butHit = 10 while 1: if mode == "Mk1" or mode == "XL": lp.LedCtrlRaw(random.randint(0, 127), random.randint(0, 3), random.randint(0, 3)) elif mode == "Dcr": lp.LedCtrlRaw(random.randint(0, 130), random.randint(0, 7), random.randint(0, 15)) elif mode != "LKM": lp.LedCtrlRaw(random.randint(0, 127), random.randint(0, 63), random.randint(0, 63), random.randint(0, 63)) time.wait(5) if mode == "XL" or mode == "LKM": but = lp.InputStateRaw() else: but = lp.ButtonStateRaw() if but != []: butHit -= 1 if butHit < 1: break print(butHit, " event: ", but) # now crash it :-) print("\nNow let's crash PyGame...") print( "Don't worry, that's just a bug in PyGame's MIDI implementation.\n\n\n" ) lp.Reset() # turn all LEDs off lp.Close( ) # close the Launchpad (will quit with an error due to a PyGame bug)
def __init__(self, settings): """ :param settings = dict { "id" : "pro/mk2/control xl/launchkey/dicer/mk1 or mini or S", "assignments":dict, buttons and their assignment } """ keys = ['id', 'assignments'] for key in keys: if key not in settings: print( "Incorrect controller settings. Assure {} keys are present." .format(keys)) sys.exit(0) self.lp = launchpad.Launchpad() self.mode = None self.board = np.zeros((9, 9)) self.colours = { "red_dim": { 'r': 1, 'g': 0 }, "red_bright": { 'r': 1, 'g': 0 }, "green_dim": { 'r': 0, 'g': 1 }, "green_bright": { 'r': 0, 'g': 3 }, "orange_dim": { 'r': 1, 'g': 1 }, "orange_bright": { 'r': 3, 'g': 3 }, } self.assignments = {} self.assignment_functions = {} for key, value in settings['assignments'].items(): if len(value) != 4: print("Incorrect assignment values.") sys.exit(0) else: self.addAssignment(key, [value[0], value[1]], value[2], value[3]) # check what we have here and override lp if necessary id = settings['id'] if id != 'mk1' and id != "S" and id != "mini": if id == 'pro': if self.lp.Check(0, "pro"): self.lp = launchpad.LaunchpadPro() if self.lp.Open(0, "pro"): print("Launchpad Pro") self.mode = "Pro" elif id == 'mk2': if self.lp.Check(0, "mk2"): self.lp = launchpad.LaunchpadMk2() if self.lp.Open(0, "mk2"): print("Launchpad Mk2") self.mode = "Mk2" elif id == 'control xl': if self.lp.Check(0, "control xl"): self.lp = launchpad.LaunchControlXL() if self.lp.Open(0, "control xl"): print("Launch Control XL") self.mode = "XL" elif id == 'launchkey': if self.lp.Check(0, "launchkey"): self.lp = launchpad.LaunchKeyMini() if self.lp.Open(0, "launchkey"): print("LaunchKey (Mini)") self.mode = "LKM" elif id == 'dicer': if self.lp.Check(0, "dicer"): self.lp = launchpad.Dicer() if self.lp.Open(0, "dicer"): print("Dicer") self.mode = "Dcr" else: if self.lp.Open(): print("Launchpad Mk1/S/Mini") self.mode = "Mk1" if self.mode is None: print( "Could not intialize controller. Assure proper ID is being used and that the controller is properly plugged in." ) sys.exit(0) self.lp.Reset()
def main(): mode = None if launchpad.LaunchpadPro().Check(0): lp = launchpad.LaunchpadPro() if lp.Open(0): print("Launchpad Pro") mode = "Pro" elif launchpad.LaunchpadProMk3().Check(0): lp = launchpad.LaunchpadProMk3() if lp.Open(0): print("Launchpad Pro Mk3") mode = "ProMk3" elif launchpad.LaunchpadMiniMk3().Check(1): lp = launchpad.LaunchpadMiniMk3() if lp.Open(1): print("Launchpad Mini Mk3") mode = "MiniMk3" elif launchpad.LaunchpadLPX().Check(1): lp = launchpad.LaunchpadLPX() if lp.Open(1): print("Launchpad X") mode = "LPX" elif launchpad.LaunchpadMk2().Check(0): lp = launchpad.LaunchpadMk2() if lp.Open(0): print("Launchpad Mk2") mode = "Mk2" # elif launchpad.LaunchControlXL().Check( 0 ): # lp = launchpad.LaunchControlXL() # if lp.Open( 0 ): # print("Launch Control XL") # mode = "XL" # elif launchpad.LaunchKeyMini().Check( 0 ): # lp = launchpad.LaunchKeyMini() # if lp.Open( 0 ): # print("LaunchKey (Mini)") # mode = "LKM" elif launchpad.Dicer().Check(0): lp = launchpad.Dicer() if lp.Open(0): print("Dicer") mode = "Dcr" elif launchpad.MidiFighter64().Check(0): lp = launchpad.MidiFighter64() if lp.Open(0): print("Midi Fighter 64") mode = "F64" elif launchpad.Launchpad().Check(0): lp = launchpad.Launchpad() if lp.Open(0): print("Launchpad Mk1/S/Mini") mode = "Mk1" if mode is None: print("Did not find any Launchpads, meh...") return print("QUIT: Push a single button for longer than 3s and release it.") lastBut = (-99, -99) tStart = time.time() while True: if mode == 'Pro' or mode == 'ProMk3': buts = lp.ButtonStateXY(mode='pro') else: buts = lp.ButtonStateXY() if buts != []: print(buts[0], buts[1], buts[2]) # quit? if buts[2] > 0: lastBut = (buts[0], buts[1]) tStart = time.time() else: if lastBut == (buts[0], buts[1]) and (time.time() - tStart) > 2: break print("bye ...") lp.Reset() # turn all LEDs off lp.Close( ) # close the Launchpad (will quit with an error due to a PyGame bug)