Example #1
0
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 main():

	mode = None

	if launchpad.LaunchpadProMk3().Check( 0 ):
		lp = launchpad.LaunchpadProMk3()
		if lp.Open( 0 ):
			mode = "promk3"
	elif launchpad.LaunchpadPro().Check( 0 ):
		lp = launchpad.LaunchpadPro()
		if lp.Open( 0 ):
			mode = "pro"
	elif launchpad.LaunchpadLPX().Check ( 1 ):
		lp = launchpad.LaunchpadLPX()
		if lp.Open( 1 ):
			mode = "lpx"

	if mode is None:
		print("no compatible Launchpad found ...")	
		return

	while(True):
		# enable the "pressure" feature by calling ButtonStateXY with
		# "returnPressure" set to True
		events = lp.ButtonStateXY( returnPressure = True )
		if events != []:
			# x and y button codes of >=255 indicate that this is a pressure value
			if events[0] >= 255 and events[1] >= 255:
				# The pressure events are different for the Pro and X:
				# PRO:
				#   The pressure value is not related to a specific button. It always returns
				#   a fake coordinate of "255", so that the pressure events can be distinguished
				#   from the standard button-press events.
				#   If two or more buttons are hold at the same time, the biggest value will be returned.
				#   Because this is the XY methods, X and Y contain 255.
				# LPX:
				#   Returns a per-button pressure event.
				#   To distinguish pressure events from button events, "255" is added to the X/Y coordinates.
				if mode == "pro" or mode == "promk3":
					print(" PRESSURE: " + str(events[2]) )
				else:
					print(" PRESSURE: " + str(events[0]-255) + " " + str(events[1]-255) + " " + str(events[2]) )

			else:
				# the standard button events
				if events[2] > 0:
					print(" PRESSED:  ", end='')
				else:
					print(" RELEASED: ", end='')
				# TODO
				print( str(events[0]) + " " + str(events[1]) + " " + str(events[2]) )
Example #3
0
def init_lp():
    """
    initialize the launchpad
    :return: launchpad object
    """
    # create launchpad instance
    lp = launchpad.Launchpad()
    mode = check_type(lp)
    success = False
    # check for the correct launchpad
    if mode == "Pro":
        lp = launchpad.LaunchpadPro()
        if lp.Open(0, "pro"):
            success = True

    elif mode == "Mk2":
        lp = launchpad.LaunchpadMk2()
        if lp.Open(0, "mk2"):
            success = True

    else:
        if lp.Open():
            success = True

    lp.LedCtrlXY(0, 0, 10, 30, 64)  # speed play and pause
    lp.LedCtrlXY(1, 0, 10, 30, 64)
    lp.LedCtrlXY(2, 0, 64, 30, 0)
    lp.LedCtrlXY(3, 0, 0, 64, 0)
    lp.LedCtrlXY(7, 0, 64, 0, 0)

    if not success:
        exit(1)
    else:
        return lp
def main():

	# create an instance
	lp = launchpad.Launchpad();

	# try the first Mk2
	if lp.Check( 0, "mk2" ):
		lp = launchpad.LaunchpadMk2()
		if lp.Open( 0, "mk2" ):
			print( " - Launchpad Mk2: OK" )
		else:
			print( " - Launchpad Mk2: ERROR")
			return
		
	# try the first Mk3
	elif lp.Check( 1, "mk3" ):
		lp = launchpad.LaunchpadMk3()
		if lp.Open( 1, "mk3" ):
			print( " - Launchpad Mk3: OK" )
		else:
			print( " - Launchpad Mk3: ERROR")
			return

	# try the first Pro
	elif lp.Check( 0, "pro" ):
		lp = launchpad.LaunchpadPro()
		if lp.Open( 0, "pro" ):
			print( " - Launchpad Pro: OK" )
		else:
			print( " - Launchpad Pro: ERROR")
			return
		
	else:
		print( " - No Launchpad available" )
		return


	lp.ButtonFlush()

	for i in [ 5, 21, 79, 3]:
		lp.LedAllOn( i )
		time.wait(500)
	lp.LedAllOn( 0 )

	colors = [ [63,0,0],[0,63,0],[0,0,63],[63,63,0],[63,0,63],[0,63,63],[63,63,63] ]
	for i in range(4):
		for y in range( i + 1, 8 - i + 1 ):
			for x in range( i, 8 - i ):
				lp.LedCtrlXY( x, y, colors[i][0], colors[i][1], colors[i][2])
		time.wait(500)

	# turn all LEDs off
	lp.Reset()

	# close this instance
	lp.Close()
Example #5
0
    def __init__(self):

        # remember the Launchpad type to adjust the mapping of the buttons
        self.mode = None

        # create an instance
        lp = launchpad.Launchpad()

        # try the first Mk2
        if lp.Check(0, "mk2"):
            lp = launchpad.LaunchpadMk2()
            if lp.Open(0, "mk2"):
                print(" - Launchpad Mk2: OK")
                self.mode = "mk2"
            else:
                print(" - Launchpad Mk2: ERROR")
                return

        # try the first Mini Mk3
        elif lp.Check(1, "minimk3"):
            lp = launchpad.LaunchpadMiniMk3()
            if lp.Open(1, "minimk3"):
                print(" - Launchpad Mini Mk3: OK")
                self.mode = "mk3"
            else:
                print(" - Launchpad Mini Mk3: ERROR")
                return

        # try the first X
        elif lp.Check(1, "x"):
            lp = launchpad.LaunchpadLPX()
            if lp.Open(1, "x"):
                print(" - Launchpad X: OK")
                self.mode = "x"
            else:
                print(" - Launchpad X: ERROR")
                return

        # try the first Pro
        elif lp.Check(0, "pad pro"):
            lp = launchpad.LaunchpadPro()
            if lp.Open(0, "pad pro"):
                print(" - Launchpad Pro: OK")
                self.mode = "pro"
            else:
                print(" - Launchpad Pro: ERROR")
                return

        # nope
        else:
            raise Exception(
                "No compatible Launchpad found. Only for Mk2, Mk3, X, Pro")

        self.lp = lp
def setup():
    global lp
    # create launchpad instance
    lp = launchpad.Launchpad()
    global mode
    # Launchpad model set to none before scanning, to recognize the launchpad
    mode = None

    # try the first Mk2
    if lp.Check(0, "mk2"):
        lp = launchpad.LaunchpadMk2()
        if lp.Open(0, "mk2"):
            mode = "Mk2"

        else:
            pass

    # try the first Pro
    elif lp.Check(0, "Pro"):
        lp = launchpad.LaunchpadPro()
        if lp.Open(0, "Pro"):
            mode = "Pro"

        else:
            pass

    # try the pro with cfw
    elif lp.Check(1, "Open"):
        lp = launchpad.LaunchpadPro()
        if lp.Open(1, "Open"):
            mode = "Pro"

    # experimental LPX implementation
    elif lp.Check(1, "lpx"):
        lp = launchpad.LaunchpadLPX()
        if lp.Open(1, "lpx"):
            mode = "X"

    else:
        pass
Example #7
0
def get_launchpad():
    lp = launchpad.Launchpad()

    if lp.Check(0, MK2_NAME):
        return launchpad.LaunchpadMk2()
    if lp.Check(0, PRO_NAME):
        return launchpad.LaunchpadPro()

    # unsupported pads
    if lp.Check(0, CTRL_XL_NAME) or lp.Check(0, LAUNCHKEY_NAME) or lp.Check(0, DICER_NAME):
        return -1

    if lp.Check():
        return lp

    return None
Example #8
0
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()
Example #9
0
def get_launchpad():
    lp = launchpad.Launchpad()

    if lp.Check(0, MK2_NAME):
        return launchpad.LaunchpadMk2()
    # the MK3 has two midi devices, we need the second one
    if lp.Check(1, MK3MINI_NAME):
        return launchpad.LaunchpadMiniMk3()
    if lp.Check(0, PRO_NAME):
        return launchpad.LaunchpadPro()
    if lp.Check(1, LPX_NAME):
        return launchpad.LaunchpadLPX()

    # unsupported pads
    if lp.Check(0, CTRL_XL_NAME) or lp.Check(0, LAUNCHKEY_NAME) or lp.Check(
            0, DICER_NAME):
        return -1

    if lp.Check():
        return lp

    return None
Example #10
0
except ImportError:
    try:
        import launchpad
    except ImportError:
        sys.exit("[LPHK] Error loading launchpad.py")

lp = launchpad.Launchpad()

if lp.Check(0, "mk2"):
    lp = launchpad.LaunchpadMk2()
    if lp.Open(0, "mk2"):
        print('Connected to MkII! Yay!')
    else:
        raise Exception('MkII detected, but connection failed!')
elif lp.Check(0, "pro"):
    lp = launchpad.LaunchpadPro()
    if lp.Open(0, "pro"):
        print('Connected to Pro! Yay!')
    else:
        raise Exception('Pro detected, but connection failed!')
elif lp.Check(0, "control xl") or lp.Check(0, "launchkey") or lp.Check(
        0, "dicer"):
    raise Exception('Unsupported device detected!')
elif lp.Check():
    if lp.Open():
        print('Connected to Classic/Mini/S! Yay!')
    else:
        raise Exception('Classic/Mini/S detected, but connection failed!')
else:
    raise Exception('Launchpad appears to be unplugged!')
Example #11
0
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"

    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":
        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
    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 != "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 ):

		# remember the Launchpad type to adjust the mapping of the buttons
		self.mode = None

		# create an instance
		lp = launchpad.Launchpad()

		# try the first Mk2
		if lp.Check( 0, "mk2" ):
			lp = launchpad.LaunchpadMk2()
			if lp.Open( 0, "mk2" ):
				print( " - Launchpad Mk2: OK" )
				self.mode = "mk2"
			else:
				print( " - Launchpad Mk2: ERROR")
				return
			
		# try the first Mini Mk3
		elif lp.Check( 1, "minimk3" ):
			lp = launchpad.LaunchpadMiniMk3()
			if lp.Open( 1, "minimk3" ):
				print( " - Launchpad Mini Mk3: OK" )
				self.mode = "mk3"
			else:
				print( " - Launchpad Mini Mk3: ERROR")
				return

		# try the first Pro
		elif lp.Check( 0, "pad pro" ):
			lp = launchpad.LaunchpadPro()
			if lp.Open( 0, "pad pro" ):
				print( " - Launchpad Pro: OK" )
				self.mode = "pro"
			else:
				print( " - Launchpad Pro: ERROR")
				return

		# try the first Pro Mk3
		elif lp.Check( 0, "mk3" ):
			lp = launchpad.LaunchpadProMk3()
			if lp.Open( 0 ):
				print( " - Launchpad Pro Mk3: OK" )
				self.mode = "promk3"
			else:
				print( " - Launchpad Pro Mk3: ERROR")
				return

		# try the first X
		# Notice that this is already built-in in the LPX class' methods Check() and Open,
		# but we're using the one from above!
		elif lp.Check( 1, "Launchpad X") or lp.Check( 1, "LPX" ):
			lp = launchpad.LaunchpadLPX()
			# Open() includes looking for "LPX" and "Launchpad X"
			if lp.Open( 1 ):
				print( " - Launchpad X: OK" )
				self.mode = "lpx"
			else:
				print( " - Launchpad X: ERROR")
				return

		# nope
		else:
			raise Exception("No compatible Launchpad found. Only for Mk2, Mk3, Pro")

		self.lp = lp
Example #13
0
from pygame import time
import launchpad_py as launchpad 
import threading
import json
from playsound import playsound

DetectMidi = True
GetFile = None
PathProj = None
mode = None
lp = None	

if launchpad.LaunchpadPro().Check(0):
	lp = launchpad.LaunchpadPro()
	lp.Open(0)
elif launchpad.LaunchpadMk2().Check(0):
	lp = launchpad.LaunchpadMk2()
	lp.Open(0)
else:
	print("Lanchpad not connected")
	input()
	exit(0)

LedValue = [5,9,13,21,37,45,49,0]
sleep = 20
sleep2 = [30, 50, 30, 30, 30, 30, 30, 30]

Page = 0

ButtonClick = {}
ButtonSound = {}
Example #14
0
import launchpad_py
import time

lp = launchpad_py.LaunchpadPro()


def lpProStartup():
    lp.Open()
    lp.LedAllOn(13)
    time.sleep(0.3)
    lp.LedAllOn(57)
    time.sleep(0.3)
    lp.LedAllOn(37)
    time.sleep(1)
    lp.LedAllOn(0)
    time.sleep(0.5)
    lp.Reset()
    def __init__( self, name ):

        self.lp = launchpad.LaunchpadPro();

        if not self.lp.Open( 0, name ):
            raise Exception("No Launchpad Pro was found")
Example #16
0
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")
Example #17
0
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)
Example #18
0
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

    # 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(1, "mk3"):
        lp = launchpad.LaunchpadMk3()
        if lp.Open(1, "mk3"):
            print("Launchpad Mk3")
            mode = "Mk3"

    if mode is None:
        print("Did not find any compatible Launchpads, meh...")
        return

    # set flashing/pulsing frequency to 240bpm
    lp.LedCtrlBpm(240)

    # stupid lightshow from here on...
    for y in range(8):
        for x in range(8):
            lp.LedCtrlXYByCode(7 - x, 8 - y, 5 if y < 4 else 13)
            lp.LedCtrlXYByCode(x, y + 1, 21 if y < 4 else 13)
            time.wait(50)

    time.wait(1000)

    for y in range(8):
        for x in range(8):
            lp.LedCtrlFlashXYByCode(x, y + 1, 0)

    time.wait(3000)

    for y in range(8):
        for x in range(8):
            lp.LedCtrlPulseXYByCode(x, y + 1, 53)

    time.wait(3000)

    for x in range(4):
        for y in range(8):
            lp.LedCtrlXYByCode(7 - x, 8 - y, random.randint(0, 127))
            lp.LedCtrlFlashXYByCode(7 - x, 8 - y, random.randint(0, 127))
            lp.LedCtrlXYByCode(x, y + 1, random.randint(0, 127))
            lp.LedCtrlFlashXYByCode(x, y + 1, random.randint(0, 127))
            time.wait(250)

    time.wait(3000)

    lp.Reset()  # turn all LEDs off
    lp.Close(
    )  # close the Launchpad (will quit with an error due to a PyGame bug)
Example #20
0
    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()
Example #21
0
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)
Example #22
0
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)
Example #23
0
def main():

	# some basic info
	print( "\nRunning..." )
	print( " - Python " + str( sys.version.split()[0] ) )
	print( " - PyGame " + str( pygame.ver ) )

	# create an instance
	lp = launchpad.Launchpad()

	# try the first Mk2
	if lp.Check( 0, "mk2" ):
		lp = launchpad.LaunchpadMk2()
		if lp.Open( 0, "mk2" ):
			print( " - Launchpad Mk2: OK" )
		else:
			print( " - Launchpad Mk2: ERROR")
			return
		
	# try the first Mini Mk3
	elif lp.Check( 1, "minimk3" ):
		lp = launchpad.LaunchpadMiniMk3()
		if lp.Open( 1, "minimk3" ):
			print( " - Launchpad Mini Mk3: OK" )
		else:
			print( " - Launchpad Mini Mk3: ERROR")
			return

	# try the first Pro
	elif lp.Check( 0, "pad pro" ):
		lp = launchpad.LaunchpadPro()
		if lp.Open( 0, "pad pro" ):
			print( " - Launchpad Pro: OK" )
		else:
			print( " - Launchpad Pro: ERROR")
			return

	# try the first Pro Mk3
	elif lp.Check( 0, "promk3" ):
		lp = launchpad.LaunchpadProMk3()
		if lp.Open( 0 ):
			print( " - Launchpad Pro Mk3: OK" )
		else:
			print( " - Launchpad Pro Mk3: ERROR")
			return

	# try the first X
	# Notice that this is already built-in in the LPX class' methods Check() and Open,
	# but we're using the one from above!
	elif lp.Check( 1, "Launchpad X") or lp.Check( 1, "LPX" ):
		lp = launchpad.LaunchpadLPX()
		# Open() includes looking for "LPX" and "Launchpad X"
		if lp.Open( 1 ):
			print( " - Launchpad X: OK" )
		else:
			print( " - Launchpad X: ERROR")
			return

	# nope
	else:
		print( " - No Launchpad available" )
		return

	# Clear the buffer because the Launchpad remembers everything
	lp.ButtonFlush()

	# List the class's methods
	print( " - Available methods:" )
	for mName in sorted( dir( lp ) ):
		if mName.find( "__") >= 0:
			continue
		if callable( getattr( lp, mName ) ):
			print( "     " + str( mName ) + "()" )

	# LedAllOn() test
	print( " - Testing LedAllOn()" )
	for i in [ 5, 21, 79, 3]:
		lp.LedAllOn( i )
		time.wait(500)
	lp.LedAllOn( 0 )

	# LedCtrlXY() test
	# -> LedCtrlRaw()
	#    -> midi.RawWriteSysEx()
	#       -> devOut.write_sys_ex()
	print( " - Testing LedCtrlXY()" )
	colors = [ [63,0,0],[0,63,0],[0,0,63],[63,63,0],[63,0,63],[0,63,63],[63,63,63] ]
	for i in range(4):
		for y in range( i + 1, 8 - i + 1 ):
			for x in range( i, 8 - i ):
				lp.LedCtrlXY( x, y, colors[i][0], colors[i][1], colors[i][2])
		time.wait(500)

	# turn all LEDs off
	print( " - Testing Reset()" )
	lp.Reset()

	# close this instance
	print( " - More to come, goodbye...\n" )
	lp.Close()
Example #24
0
def main():

    # some basic info
    print("\nRunning...")
    print(" - Python " + str(sys.version.split()[0]))

    # create an instance
    lp = launchpad.LaunchpadPro()

    # open the first Launchpad Pro
    if lp.Open(0, "pro"):
        print(" - Launchpad Pro: OK")
    else:
        print(" - Launchpad Pro: ERROR")
        return

    # Clear the buffer because the Launchpad remembers everything
    lp.ButtonFlush()

    # List the class's methods
    print(" - Available methods:")
    for mName in sorted(dir(lp)):
        if mName.find("__") >= 0:
            continue
        if callable(getattr(lp, mName)):
            print("     " + str(mName) + "()")

    # LedAllOn() test
    print(" - Testing LedAllOn()")
    for i in [5, 21, 79, 3]:
        lp.LedAllOn(i)
        time.sleep(0.001 * 500)

    # LedCtrlXY() test
    # -> LedCtrlRaw()
    #    -> midi.RawWriteSysEx()
    #       -> devOut.write_sys_ex()
    print(" - Testing LedCtrlXY(), Pro Mode")
    colors = [[63, 0, 0], [0, 63, 0], [0, 0, 63], [63, 63, 0], [63, 0, 63],
              [0, 63, 63], [63, 63, 63]]
    for i in range(5):
        for y in range(i, 10 - i):
            for x in range(i, 10 - i):
                lp.LedCtrlXY(x,
                             y,
                             colors[i][0],
                             colors[i][1],
                             colors[i][2],
                             mode="pro")
        time.sleep(0.001 * 500)

    print(" - Testing LedCtrlXY(), Classic Mode")
    for i in range(4, -1, -1):
        for y in range(i, 10 - i):
            for x in range(i, 10 - i):
                if x == 0:
                    x = 10
                lp.LedCtrlXY(x - 1, y, colors[3 - i + 2][0],
                             colors[4 - i + 2][1], colors[4 - i + 2][2])
        time.sleep(0.001 * 500)

    i = 1
    for y in range(i, 10 - i):
        for x in range(i, 10 - i):
            lp.LedCtrlXY(x, y, 0, 0, 0, mode="pro")
    time.sleep(0.001 * 100)

    # LedCtrlChar() test
    # -> LedCtrlRaw()
    #    -> midi.RawWriteSysEx()
    #       -> devOut.write_sys_ex()
    print(" - Testing LedCtrlChar()")
    for i in range(-7, 7, 1):
        lp.LedCtrlChar('A', 63, 0, 0, i, 0)
        if i == -6:
            print("   - left edge")
            time.sleep(0.001 * 2000)
        elif i == 6:
            print("   - right edge")
            time.sleep(0.001 * 2000)
        else:
            time.sleep(0.001 * 250)
    lp.LedAllOn(0)

    # LedCtrlRawByCode() test
    # -> midi.RawWrite()
    #    -> devOut.write_short()
    print(" - Testing LedCtrlRawByCode()")
    print("   - matrix")
    for y in range(10, 90, 10):
        for x in range(8):
            lp.LedCtrlRawByCode(y + x + 1, x + y)
            time.sleep(0.001 * 50)
    print("   - bottom")
    for i in range(1, 9, 1):
        lp.LedCtrlRawByCode(i, 5)
        time.sleep(0.001 * 200)
    print("   - right")
    for i in range(19, 99, 10):
        lp.LedCtrlRawByCode(i, 17)
        time.sleep(0.001 * 200)
    print("   - top")
    for i in range(98, 90, -1):
        lp.LedCtrlRawByCode(i, 79)
        time.sleep(0.001 * 200)
    print("   - left")
    for i in range(80, 0, -10):
        lp.LedCtrlRawByCode(i, 3)
        time.sleep(0.001 * 200)

    time.sleep(0.001 * 2000)

    # turn all LEDs off
    print(" - Testing Reset()")
    lp.Reset()

    # close this instance
    print(" - More to come, goodbye...\n")
    lp.Close()