import sys, ntpath, pygame, pygame.mixer, launchpad
from PyQt4 import QtCore, QtGui

class Sampler():
	def __init__(self):
		self.changeLabel("Edit")
		#Poll for MIDI input
		while True:
			pad = LP.ButtonStateRaw()
			if pad != []:
				self.padnumber = pad[0]
				self.velocity = pad[1]
				if self.padnumber == 200:
					self.Trigger(ex.btn_a1.samplePath, 0, ex.btn_a1)
				if self.padnumber == 201:
					self.Trigger(ex.btn_a2.samplePath, 1, ex.btn_a2)
				if self.padnumber == 202:
					self.Trigger(ex.btn_a3.samplePath, 2, ex.btn_a3)
				if self.padnumber == 203:
					self.Trigger(ex.btn_a4.samplePath, 3, ex.btn_a4)
				if self.padnumber == 204:
					self.Trigger(ex.btn_a5.samplePath, 4, ex.btn_a5)
				if self.padnumber == 205:
					self.Trigger(ex.btn_a6.samplePath, 5, ex.btn_a6)
				if self.padnumber == 206:
					self.Trigger(ex.btn_a7.samplePath, 6, ex.btn_a7)
				if self.padnumber == 207:
					self.Trigger(ex.btn_a8.samplePath, 7, ex.btn_a8)
				if self.padnumber == 0:
					self.Trigger(ex.btn_b1.samplePath, 0, ex.btn_b1)
				if self.padnumber == 1:
					self.Trigger(ex.btn_b2.samplePath, 1, ex.btn_b2)
				if self.padnumber == 2:
					self.Trigger(ex.btn_b3.samplePath, 2, ex.btn_b3)
				if self.padnumber == 3:
					self.Trigger(ex.btn_b4.samplePath, 3, ex.btn_b4)
				if self.padnumber == 4:
					self.Trigger(ex.btn_b5.samplePath, 4, ex.btn_b5)
				if self.padnumber == 5:
					self.Trigger(ex.btn_b6.samplePath, 5, ex.btn_b6)
				if self.padnumber == 6:
					self.Trigger(ex.btn_b7.samplePath, 6, ex.btn_b7)
				if self.padnumber == 7:
					self.Trigger(ex.btn_b8.samplePath, 7, ex.btn_b8)
				if self.padnumber == 8:
					self.Trigger(ex.btn_b9.samplePath, 8, ex.btn_b9)
				if self.padnumber == 16:
					self.Trigger(ex.btn_c1.samplePath, 16, ex.btn_c1)
				if self.padnumber == 17:
					self.Trigger(ex.btn_c2.samplePath, 17, ex.btn_c2)
				if self.padnumber == 18:
					self.Trigger(ex.btn_c3.samplePath, 18, ex.btn_c3)
				if self.padnumber == 19:
					self.Trigger(ex.btn_c4.samplePath, 19, ex.btn_c4)
				if self.padnumber == 20:
					self.Trigger(ex.btn_c5.samplePath, 20, ex.btn_c5)
				if self.padnumber == 21:
					self.Trigger(ex.btn_c6.samplePath, 21, ex.btn_c6)
				if self.padnumber == 22:
					self.Trigger(ex.btn_c7.samplePath, 22, ex.btn_c7)
				if self.padnumber == 23:
					self.Trigger(ex.btn_c8.samplePath, 23, ex.btn_c8)
				if self.padnumber == 24:
					self.Trigger(ex.btn_c9.samplePath, 24, ex.btn_c9)
				if self.padnumber == 32:
					self.Trigger(ex.btn_d1.samplePath, 32, ex.btn_d1)
				if self.padnumber == 33:
					self.Trigger(ex.btn_d2.samplePath, 33, ex.btn_d2)
				if self.padnumber == 34:
					self.Trigger(ex.btn_d3.samplePath, 34, ex.btn_d3)
				if self.padnumber == 35:
					self.Trigger(ex.btn_d4.samplePath, 35, ex.btn_d4)
				if self.padnumber == 36:
					self.Trigger(ex.btn_d5.samplePath, 36, ex.btn_d5)
				if self.padnumber == 37:
					self.Trigger(ex.btn_d6.samplePath, 37, ex.btn_d6)
				if self.padnumber == 38:
					self.Trigger(ex.btn_d7.samplePath, 38, ex.btn_d7)
				if self.padnumber == 39:
					self.Trigger(ex.btn_d8.samplePath, 39, ex.btn_d8)
				if self.padnumber == 40:
					self.Trigger(ex.btn_d9.samplePath, 40, ex.btn_d9)
				if self.padnumber == 48:
					self.Trigger(ex.btn_e1.samplePath, 48, ex.btn_e1)
				if self.padnumber == 49:
					self.Trigger(ex.btn_e2.samplePath, 49, ex.btn_e2)
				if self.padnumber == 50:
					self.Trigger(ex.btn_e3.samplePath, 50, ex.btn_e3)
				if self.padnumber == 51:
					self.Trigger(ex.btn_e4.samplePath, 51, ex.btn_e4)
				if self.padnumber == 52:
					self.Trigger(ex.btn_e5.samplePath, 52, ex.btn_e5)
				if self.padnumber == 53:
					self.Trigger(ex.btn_e6.samplePath, 53, ex.btn_e6)
				if self.padnumber == 54:
					self.Trigger(ex.btn_e7.samplePath, 54, ex.btn_e7)
				if self.padnumber == 55:
					self.Trigger(ex.btn_e8.samplePath, 55, ex.btn_e8)
				if self.padnumber == 56:
					self.Trigger(ex.btn_e9.samplePath, 56, ex.btn_e9)
				if self.padnumber == 64:
					self.Trigger(ex.btn_f1.samplePath, 64, ex.btn_f1)
				if self.padnumber == 65:
					self.Trigger(ex.btn_f2.samplePath, 65, ex.btn_f2)
				if self.padnumber == 66:
					self.Trigger(ex.btn_f3.samplePath, 66, ex.btn_f3)
				if self.padnumber == 67:
					self.Trigger(ex.btn_f4.samplePath, 67, ex.btn_f4)
				if self.padnumber == 68:
					self.Trigger(ex.btn_f5.samplePath, 68, ex.btn_f5)
				if self.padnumber == 69:
					self.Trigger(ex.btn_f6.samplePath, 69, ex.btn_f6)
				if self.padnumber == 70:
					self.Trigger(ex.btn_f7.samplePath, 70, ex.btn_f7)
				if self.padnumber == 71:
					self.Trigger(ex.btn_f8.samplePath, 71, ex.btn_f8)
				if self.padnumber == 72:
					self.Trigger(ex.btn_f9.samplePath, 72, ex.btn_f9)
				if self.padnumber == 80:
					self.Trigger(ex.btn_g1.samplePath, 80, ex.btn_g1)
				if self.padnumber == 81:
					self.Trigger(ex.btn_g2.samplePath, 81, ex.btn_g2)
				if self.padnumber == 82:
					self.Trigger(ex.btn_g3.samplePath, 82, ex.btn_g3)
				if self.padnumber == 83:
					self.Trigger(ex.btn_g4.samplePath, 83, ex.btn_g4)
				if self.padnumber == 84:
					self.Trigger(ex.btn_g5.samplePath, 84, ex.btn_g5)
				if self.padnumber == 85:
					self.Trigger(ex.btn_g6.samplePath, 85, ex.btn_g6)
				if self.padnumber == 86:
					self.Trigger(ex.btn_g7.samplePath, 86, ex.btn_g7)
				if self.padnumber == 87:
					self.Trigger(ex.btn_g8.samplePath, 87, ex.btn_g8)
				if self.padnumber == 88:
					self.Trigger(ex.btn_g9.samplePath, 88, ex.btn_g9)
				if self.padnumber == 96:
					self.Trigger(ex.btn_h1.samplePath, 96, ex.btn_h1)
				if self.padnumber == 97:
					self.Trigger(ex.btn_h2.samplePath, 97, ex.btn_h2)
				if self.padnumber == 98:
					self.Trigger(ex.btn_h3.samplePath, 98, ex.btn_h3)
				if self.padnumber == 99:
					self.Trigger(ex.btn_h4.samplePath, 99, ex.btn_h4)
				if self.padnumber == 100:
					self.Trigger(ex.btn_h5.samplePath, 100, ex.btn_h5)
				if self.padnumber == 101:
					self.Trigger(ex.btn_h6.samplePath, 101, ex.btn_h6)
				if self.padnumber == 102:
					self.Trigger(ex.btn_h7.samplePath, 102, ex.btn_h7)
				if self.padnumber == 103:
					self.Trigger(ex.btn_h8.samplePath, 103, ex.btn_h8)
				if self.padnumber == 104:
					self.Trigger(ex.btn_h9.samplePath, 104, ex.btn_h9)
				if self.padnumber == 112:
					self.Trigger(ex.btn_i1.samplePath, 112, ex.btn_i1)
				if self.padnumber == 113:
					self.Trigger(ex.btn_i2.samplePath, 113, ex.btn_i2)
				if self.padnumber == 114:
					self.Trigger(ex.btn_i3.samplePath, 114, ex.btn_i3)
				if self.padnumber == 115:
					self.Trigger(ex.btn_i4.samplePath, 115, ex.btn_i4)
				if self.padnumber == 116:
					self.Trigger(ex.btn_i5.samplePath, 116, ex.btn_i5)
				if self.padnumber == 117:
					self.Trigger(ex.btn_i6.samplePath, 117, ex.btn_i6)
				if self.padnumber == 118:
					self.Trigger(ex.btn_i7.samplePath, 118, ex.btn_i7)
				if self.padnumber == 119:
					self.Trigger(ex.btn_i8.samplePath, 119, ex.btn_i8)									
				if self.padnumber == 120:
					self.changeLabel("Play")
					break

#Change text for the mode button and colour of corresponding Launchpad Pad
	def changeLabel(self, currentMode):
		if currentMode == "Play":
			ex.lab_i9.setText(QtGui.QApplication.translate("Form", "<html><head/><body><p align=\"center\"><span style=\" color:#ffffff;\">Edit</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
			QtGui.QApplication.processEvents()
			LP.LedCtrlRaw(120, 0, 3)
			return
		if currentMode == "Edit":
			ex.lab_i9.setText(QtGui.QApplication.translate("Form", "<html><head/><body><p align=\"center\"><span style=\" color:#ffffff;\">Play</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
			QtGui.QApplication.processEvents()
			LP.LedCtrlRaw(120, 3, 0)
			return

#Determine if pad has a sample assigned. If so then play it, if not then ignore. Change pad LEDs and GUI icons for visual feedback.	
	def Trigger(self, sample, padnumber, button):
		self.samplePath = sample
		if self.samplePath == None:
			pass
		else:
			if self.velocity < 1: 
				LP.LedCtrlRaw(padnumber, 0, 3)
				button.icon.addPixmap(QtGui.QPixmap(button.iconPathAssigned), QtGui.QIcon.Normal, QtGui.QIcon.Off)
				button.setIcon(button.icon)
				QtGui.QApplication.processEvents()
			else:
				LP.LedCtrlRaw(padnumber, 3, 0)
				button.icon.addPixmap(QtGui.QPixmap(button.iconPathPlaying), QtGui.QIcon.Normal, QtGui.QIcon.Off)
				button.setIcon(button.icon)
				QtGui.QApplication.processEvents()
				sample = pygame.mixer.Sound(self.samplePath)
				pygame.mixer.Sound.play(sample)

#Create the GUI. Inherits from the QT QWidget class.		
class Ui_Form(QtGui.QWidget):
	def __init__(self):
		QtGui.QWidget.__init__(self)
		self.setupUi(self)

#Properly shut the Launchpad process and turn off all LEDs.		
	def closeEvent(self, event):
		LP.Reset()
		LP.Close()

#Create the buttons, labels and background. Define properties.		
	def setupUi(self, Form):
		Form.setObjectName("Form")
		Form.resize(591, 591)
		
		self.Background = QtGui.QLabel(Form)
		self.Background.setGeometry(QtCore.QRect(0, 0, 631, 591))
		self.Background.setPixmap(QtGui.QPixmap("Python/LP_Proj/LP_Background.png"))
		self.Background.setObjectName("Background")
		
		self.lab_a1 = Label("Unassigned", 20, 76, 61, 16, "lab_a1", self)
		self.lab_a2 = Label("Unassigned", 80, 76, 61, 16, "lab_a2", self)
		self.lab_a3 = Label("Unassigned", 140, 76, 61, 16, "lab_a3", self)
		self.lab_a4 = Label("Unassigned", 200, 76, 61, 16, "lab_a4", self)
		self.lab_a5 = Label("Unassigned", 260, 76, 61, 16, "lab_a5", self)
		self.lab_a6 = Label("Unassigned", 320, 76, 61, 16, "lab_a6", self)
		self.lab_a7 = Label("Unassigned", 380, 76, 61, 16, "lab_a7", self)
		self.lab_a8 = Label("Unassigned", 440, 76, 61, 16, "lab_a8", self)
		
		self.lab_b1 = Label("Unassigned", 20, 136, 61, 16, "lab_b1", self)
		self.lab_b2 = Label("Unassigned", 80, 136, 61, 16, "lab_b2", self)
		self.lab_b3 = Label("Unassigned", 140, 136, 61, 16, "lab_b3", self)
		self.lab_b4 = Label("Unassigned", 200, 136, 61, 16, "lab_b4", self)
		self.lab_b5 = Label("Unassigned", 260, 136, 61, 16, "lab_b5", self)
		self.lab_b6 = Label("Unassigned", 320, 136, 61, 16, "lab_b6", self)
		self.lab_b7 = Label("Unassigned", 380, 136, 61, 16, "lab_b7", self)
		self.lab_b8 = Label("Unassigned", 440, 136, 61, 16, "lab_b8", self)
		self.lab_b9 = Label("Unassigned", 500, 136, 61, 16, "lab_b9", self)
		
		self.lab_c1 = Label("Unassigned", 20, 196, 61, 16, "lab_c1", self)
		self.lab_c2 = Label("Unassigned", 80, 196, 61, 16, "lab_c2", self)
		self.lab_c3 = Label("Unassigned", 140, 196, 61, 16, "lab_c3", self)
		self.lab_c4 = Label("Unassigned", 200, 196, 61, 16, "lab_c4", self)
		self.lab_c5 = Label("Unassigned", 260, 196, 61, 16, "lab_c5", self)
		self.lab_c6 = Label("Unassigned", 320, 196, 61, 16, "lab_c6", self)
		self.lab_c7 = Label("Unassigned", 380, 196, 61, 16, "lab_c7", self)
		self.lab_c8 = Label("Unassigned", 440, 196, 61, 16, "lab_c8", self)
		self.lab_c9 = Label("Unassigned", 500, 196, 61, 16, "lab_c9", self)
		
		self.lab_d1 = Label("Unassigned", 20, 256, 61, 16, "lab_d1", self)
		self.lab_d2 = Label("Unassigned", 80, 256, 61, 16, "lab_d2", self)
		self.lab_d3 = Label("Unassigned", 140, 256, 61, 16, "lab_d3", self)
		self.lab_d4 = Label("Unassigned", 200, 256, 61, 16, "lab_d4", self)
		self.lab_d5 = Label("Unassigned", 260, 256, 61, 16, "lab_d5", self)
		self.lab_d6 = Label("Unassigned", 320, 256, 61, 16, "lab_d6", self)
		self.lab_d7 = Label("Unassigned", 380, 256, 61, 16, "lab_d7", self)
		self.lab_d8 = Label("Unassigned", 440, 256, 61, 16, "lab_d8", self)
		self.lab_d9 = Label("Unassigned", 500, 256, 61, 16, "lab_d9", self)
		
		self.lab_e1 = Label("Unassigned", 20, 316, 61, 16, "lab_e1", self)
		self.lab_e2 = Label("Unassigned", 80, 316, 61, 16, "lab_e2", self)
		self.lab_e3 = Label("Unassigned", 140, 316, 61, 16, "lab_e3", self)
		self.lab_e4 = Label("Unassigned", 200, 316, 61, 16, "lab_e4", self)
		self.lab_e5 = Label("Unassigned", 260, 316, 61, 16, "lab_e5", self)
		self.lab_e6 = Label("Unassigned", 320, 316, 61, 16, "lab_e6", self)
		self.lab_e7 = Label("Unassigned", 380, 316, 61, 16, "lab_e7", self)
		self.lab_e8 = Label("Unassigned", 440, 316, 61, 16, "lab_e8", self)
		self.lab_e9 = Label("Unassigned", 500, 316, 61, 16, "lab_e9", self)
		
		self.lab_f1 = Label("Unassigned", 20, 376, 61, 16, "lab_f1", self)
		self.lab_f2 = Label("Unassigned", 80, 376, 61, 16, "lab_f2", self)
		self.lab_f3 = Label("Unassigned", 140, 376, 61, 16, "lab_f3", self)
		self.lab_f4 = Label("Unassigned", 200, 376, 61, 16, "lab_f4", self)
		self.lab_f5 = Label("Unassigned", 260, 376, 61, 16, "lab_f5", self)
		self.lab_f6 = Label("Unassigned", 320, 376, 61, 16, "lab_f6", self)
		self.lab_f7 = Label("Unassigned", 380, 376, 61, 16, "lab_f7", self)
		self.lab_f8 = Label("Unassigned", 440, 376, 61, 16, "lab_f8", self)
		self.lab_f9 = Label("Unassigned", 500, 376, 61, 16, "lab_f9", self)
		
		self.lab_g1 = Label("Unassigned", 20, 436, 61, 16, "lab_g1", self)
		self.lab_g2 = Label("Unassigned", 80, 436, 61, 16, "lab_g2", self)
		self.lab_g3 = Label("Unassigned", 140, 436, 61, 16, "lab_g3", self)
		self.lab_g4 = Label("Unassigned", 200, 436, 61, 16, "lab_g4", self)
		self.lab_g5 = Label("Unassigned", 260, 436, 61, 16, "lab_g5", self)
		self.lab_g6 = Label("Unassigned", 320, 436, 61, 16, "lab_g6", self)
		self.lab_g7 = Label("Unassigned", 380, 436, 61, 16, "lab_g7", self)
		self.lab_g8 = Label("Unassigned", 440, 436, 61, 16, "lab_g8", self)
		self.lab_g9 = Label("Unassigned", 500, 436, 61, 16, "lab_g9", self)
		
		self.lab_h1 = Label("Unassigned", 20, 496, 61, 16, "lab_h1", self)
		self.lab_h2 = Label("Unassigned", 80, 496, 61, 16, "lab_h2", self)
		self.lab_h3 = Label("Unassigned", 140, 496, 61, 16, "lab_h3", self)
		self.lab_h4 = Label("Unassigned", 200, 496, 61, 16, "lab_h4", self)
		self.lab_h5 = Label("Unassigned", 260, 496, 61, 16, "lab_h5", self)
		self.lab_h6 = Label("Unassigned", 320, 496, 61, 16, "lab_h6", self)
		self.lab_h7 = Label("Unassigned", 380, 496, 61, 16, "lab_h7", self)
		self.lab_h8 = Label("Unassigned", 440, 496, 61, 16, "lab_h8", self)
		self.lab_h9 = Label("Unassigned", 500, 496, 61, 16, "lab_h9", self)
		
		self.lab_i1 = Label("Unassigned", 20, 556, 61, 16, "lab_i1", self)
		self.lab_i2 = Label("Unassigned", 80, 556, 61, 16, "lab_i2", self)
		self.lab_i3 = Label("Unassigned", 140, 556, 61, 16, "lab_i3", self)
		self.lab_i4 = Label("Unassigned", 200, 556, 61, 16, "lab_i4", self)
		self.lab_i5 = Label("Unassigned", 260, 556, 61, 16, "lab_i5", self)
		self.lab_i6 = Label("Unassigned", 320, 556, 61, 16, "lab_i6", self)
		self.lab_i7 = Label("Unassigned", 380, 556, 61, 16, "lab_i7", self)
		self.lab_i8 = Label("Unassigned", 440, 556, 61, 16, "lab_i8", self)
		self.lab_i9 = Label("Edit", 500, 556, 61, 16, "lab_i9", self)
		
		self.btn_a1 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 30, 38, 41, 41, "btn_a1", self.lab_a1, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 200, self)
		self.btn_a2 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 90, 38, 41, 41, "btn_a2", self.lab_a2, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 201, self)
		self.btn_a3 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 150, 38, 41, 41, "btn_a3", self.lab_a3, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 202, self)
		self.btn_a4 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 210, 38, 41, 41, "btn_a4", self.lab_a4, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 203, self)
		self.btn_a5 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 270, 38, 41, 41, "btn_a5", self.lab_a5, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 204, self)
		self.btn_a6 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 330, 38, 41, 41, "btn_a6", self.lab_a6, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 205, self)
		self.btn_a7 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 390, 38, 41, 41, "btn_a7", self.lab_a7, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 206, self)
		self.btn_a8 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 450, 38, 41, 41, "btn_a8", self.lab_a8, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 207, self)
		
		self.btn_b1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 90, 61, 51, "btn_b1", self.lab_b1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 0, self)
		self.btn_b2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 90, 61, 51, "btn_b2", self.lab_b2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 1, self)
		self.btn_b3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 90, 61, 51, "btn_b3", self.lab_b3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 2, self)
		self.btn_b4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 90, 61, 51, "btn_b4", self.lab_b4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 3, self)
		self.btn_b5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 90, 61, 51, "btn_b5", self.lab_b5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 4, self)
		self.btn_b6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 90, 61, 51, "btn_b6", self.lab_b6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 5, self)
		self.btn_b7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 90, 61, 51, "btn_b7", self.lab_b7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 6, self)
		self.btn_b8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 90, 61, 51, "btn_b8", self.lab_b8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 7, self)
		self.btn_b9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 95, 41, 41, "btn_b9", self.lab_b9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 8, self)
		
		self.btn_c1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 150, 61, 51, "btn_c1", self.lab_c1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 16, self)
		self.btn_c2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 150, 61, 51, "btn_c2", self.lab_c2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 17, self)
		self.btn_c3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 150, 61, 51, "btn_c3", self.lab_c3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 18, self)
		self.btn_c4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 150, 61, 51, "btn_c4", self.lab_c4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 19, self)
		self.btn_c5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 150, 61, 51, "btn_c5", self.lab_c5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 20, self)
		self.btn_c6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 150, 61, 51, "btn_c6", self.lab_c6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 21, self)
		self.btn_c7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 150, 61, 51, "btn_c7", self.lab_c7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 22, self)
		self.btn_c8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 150, 61, 51, "btn_c8", self.lab_c8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 23, self)
		self.btn_c9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 155, 41, 41, "btn_c9", self.lab_c9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 24, self)
		
		self.btn_d1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 210, 61, 51, "btn_d1", self.lab_d1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 32, self)
		self.btn_d2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 210, 61, 51, "btn_d2", self.lab_d2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 33, self)
		self.btn_d3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 210, 61, 51, "btn_d3", self.lab_d3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 34, self)
		self.btn_d4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 210, 61, 51, "btn_d4", self.lab_d4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 35, self)
		self.btn_d5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 210, 61, 51, "btn_d5", self.lab_d5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 36, self)
		self.btn_d6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 210, 61, 51, "btn_d6", self.lab_d6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 37, self)
		self.btn_d7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 210, 61, 51, "btn_d7", self.lab_d7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 38, self)
		self.btn_d8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 210, 61, 51, "btn_d8", self.lab_d8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 39, self)
		self.btn_d9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 215, 41, 41, "btn_d9", self.lab_d9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 40, self)
		
		self.btn_e1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 270, 61, 51, "btn_e1", self.lab_e1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 48, self)
		self.btn_e2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 270, 61, 51, "btn_e2", self.lab_e2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 49, self)
		self.btn_e3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 270, 61, 51, "btn_e3", self.lab_e3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 50, self)
		self.btn_e4 = Button("Python/LP_Proj/LP_MidTL_Off.png", 55, 55, 200, 270, 61, 51, "btn_e4", self.lab_e4, "Python/LP_Proj/LP_MidTL_Green.png", "Python/LP_Proj/LP_MidTL_Red.png", 51, self)
		self.btn_e5 = Button("Python/LP_Proj/LP_MidTR_Off.png", 55, 55, 260, 270, 61, 51, "btn_e5", self.lab_e5, "Python/LP_Proj/LP_MidTR_Green.png", "Python/LP_Proj/LP_MidTR_Red.png", 52, self)
		self.btn_e6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 270, 61, 51, "btn_e6", self.lab_e6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 53, self)
		self.btn_e7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 270, 61, 51, "btn_e7", self.lab_e7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 54, self)
		self.btn_e8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 270, 61, 51, "btn_e8", self.lab_e8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 55, self)
		self.btn_e9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 275, 41, 41, "btn_e9", self.lab_e9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 56, self)
		
		self.btn_f1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 330, 61, 51, "btn_f1", self.lab_f1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 64, self)
		self.btn_f2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 330, 61, 51, "btn_f2", self.lab_f2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 65, self)
		self.btn_f3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 330, 61, 51, "btn_f3", self.lab_f3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 66, self)
		self.btn_f4 = Button("Python/LP_Proj/LP_MidBL_Off.png", 55, 55, 200, 330, 61, 51, "btn_f4", self.lab_f4, "Python/LP_Proj/LP_MidBL_Green.png", "Python/LP_Proj/LP_MidBL_Red.png", 67, self)
		self.btn_f5 = Button("Python/LP_Proj/LP_MidBR_Off.png", 55, 55, 260, 330, 61, 51, "btn_f5", self.lab_f5, "Python/LP_Proj/LP_MidBR_Green.png", "Python/LP_Proj/LP_MidBR_Red.png", 68, self)
		self.btn_f6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 330, 61, 51, "btn_f6", self.lab_f6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 69, self)
		self.btn_f7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 330, 61, 51, "btn_f7", self.lab_f7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 70, self)
		self.btn_f8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 330, 61, 51, "btn_f8", self.lab_f8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 71, self)
		self.btn_f9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 335, 41, 41, "btn_f9", self.lab_f9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 72, self)
		
		self.btn_g1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 390, 61, 51, "btn_g1", self.lab_g1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 80, self)
		self.btn_g2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 390, 61, 51, "btn_g2", self.lab_g2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 81, self)
		self.btn_g3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 390, 61, 51, "btn_g3", self.lab_g3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 82, self)
		self.btn_g4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 390, 61, 51, "btn_g4", self.lab_g4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 83, self)
		self.btn_g5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 390, 61, 51, "btn_g5", self.lab_g5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 84, self)
		self.btn_g6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 390, 61, 51, "btn_g6", self.lab_g6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 85, self)
		self.btn_g7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 390, 61, 51, "btn_g7", self.lab_g7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 86, self)
		self.btn_g8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 390, 61, 51, "btn_g8", self.lab_g8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 87, self)
		self.btn_g9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 395, 41, 41, "btn_g9", self.lab_g9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 88, self)
		
		self.btn_h1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 450, 61, 51, "btn_h1", self.lab_h1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 96, self)
		self.btn_h2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 450, 61, 51, "btn_h2", self.lab_h2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 97, self)
		self.btn_h3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 450, 61, 51, "btn_h3", self.lab_h3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 98, self)
		self.btn_h4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 450, 61, 51, "btn_h4", self.lab_h4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 99, self)
		self.btn_h5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 450, 61, 51, "btn_h5", self.lab_h5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 100, self)
		self.btn_h6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 450, 61, 51, "btn_h6", self.lab_h6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 101, self)
		self.btn_h7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 450, 61, 51, "btn_h7", self.lab_h7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 102, self)
		self.btn_h8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 450, 61, 51, "btn_h8", self.lab_h8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 103, self)
		self.btn_h9 = Button("Python/LP_Proj/LP_Circle_Off.png", 49, 49, 510, 455, 41, 41, "btn_h9", self.lab_h9, "Python/LP_Proj/LP_Circle_Green.png", "Python/LP_Proj/LP_Circle_Red.png", 104, self)
		
		self.btn_i1 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 20, 510, 61, 51, "btn_i1", self.lab_i1, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 112, self)
		self.btn_i2 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 80, 510, 61, 51, "btn_i2", self.lab_i2, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 113, self)
		self.btn_i3 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 140, 510, 61, 51, "btn_i3", self.lab_i3, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 114, self)
		self.btn_i4 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 200, 510, 61, 51, "btn_i4", self.lab_i4, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 115, self)
		self.btn_i5 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 260, 510, 61, 51, "btn_i5", self.lab_i5, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 116, self)
		self.btn_i6 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 320, 510, 61, 51, "btn_i6", self.lab_i6, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 117, self)
		self.btn_i7 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 380, 510, 61, 51, "btn_i7", self.lab_i7, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 118, self)
		self.btn_i8 = Button("Python/LP_Proj/LP_Square_Off.png", 55, 55, 440, 510, 61, 51, "btn_i8", self.lab_i8, "Python/LP_Proj/LP_Square_Green.png", "Python/LP_Proj/LP_Square_Red.png", 119, self)
		self.btn_i9 = ModeButton("Python/LP_Proj/LP_Circle_Mode.png", 49, 49, 510, 515, 41, 41, "btn_i9", self)

		self.retranslateUi(Form)
		QtCore.QMetaObject.connectSlotsByName(Form)

#Allow buttons to function upon being clicked.
	def retranslateUi(self, Form):
		Form.setWindowTitle(QtGui.QApplication.translate("Form", "Launchpad Control", None, QtGui.QApplication.UnicodeUTF8))
		
		self.btn_a1.clicked.connect(self.btn_a1.playSample)
		self.btn_a2.clicked.connect(self.btn_a2.playSample)
		self.btn_a3.clicked.connect(self.btn_a1.playSample)
		self.btn_a4.clicked.connect(self.btn_a2.playSample)
		self.btn_a5.clicked.connect(self.btn_a1.playSample)
		self.btn_a6.clicked.connect(self.btn_a2.playSample)
		self.btn_a7.clicked.connect(self.btn_a1.playSample)
		self.btn_a8.clicked.connect(self.btn_a2.playSample)
		
		self.btn_b1.clicked.connect(self.btn_b1.playSample)
		self.btn_b2.clicked.connect(self.btn_b2.playSample)
		self.btn_b3.clicked.connect(self.btn_b3.playSample)
		self.btn_b4.clicked.connect(self.btn_b4.playSample)
		self.btn_b5.clicked.connect(self.btn_b5.playSample)
		self.btn_b6.clicked.connect(self.btn_b6.playSample)
		self.btn_b7.clicked.connect(self.btn_b7.playSample)
		self.btn_b8.clicked.connect(self.btn_b8.playSample)
		self.btn_b9.clicked.connect(self.btn_b9.playSample)
		
		self.btn_c1.clicked.connect(self.btn_c1.playSample)
		self.btn_c2.clicked.connect(self.btn_c2.playSample)
		self.btn_c3.clicked.connect(self.btn_c3.playSample)
		self.btn_c4.clicked.connect(self.btn_c4.playSample)
		self.btn_c5.clicked.connect(self.btn_c5.playSample)
		self.btn_c6.clicked.connect(self.btn_c6.playSample)
		self.btn_c7.clicked.connect(self.btn_c7.playSample)
		self.btn_c8.clicked.connect(self.btn_c8.playSample)
		self.btn_c9.clicked.connect(self.btn_c9.playSample)
		
		self.btn_d1.clicked.connect(self.btn_d1.playSample)
		self.btn_d2.clicked.connect(self.btn_d2.playSample)
		self.btn_d3.clicked.connect(self.btn_d3.playSample)
		self.btn_d4.clicked.connect(self.btn_d4.playSample)
		self.btn_d5.clicked.connect(self.btn_d5.playSample)
		self.btn_d6.clicked.connect(self.btn_d6.playSample)
		self.btn_d7.clicked.connect(self.btn_d7.playSample)
		self.btn_d8.clicked.connect(self.btn_d8.playSample)
		self.btn_d9.clicked.connect(self.btn_d9.playSample)
		
		self.btn_e1.clicked.connect(self.btn_e1.playSample)
		self.btn_e2.clicked.connect(self.btn_e2.playSample)
		self.btn_e3.clicked.connect(self.btn_e3.playSample)
		self.btn_e4.clicked.connect(self.btn_e4.playSample)
		self.btn_e5.clicked.connect(self.btn_e5.playSample)
		self.btn_e6.clicked.connect(self.btn_e6.playSample)
		self.btn_e7.clicked.connect(self.btn_e7.playSample)
		self.btn_e8.clicked.connect(self.btn_e8.playSample)
		self.btn_e9.clicked.connect(self.btn_e9.playSample)
		
		self.btn_f1.clicked.connect(self.btn_f1.playSample)
		self.btn_f2.clicked.connect(self.btn_f2.playSample)
		self.btn_f3.clicked.connect(self.btn_f3.playSample)
		self.btn_f4.clicked.connect(self.btn_f4.playSample)
		self.btn_f5.clicked.connect(self.btn_f5.playSample)
		self.btn_f6.clicked.connect(self.btn_f6.playSample)
		self.btn_f7.clicked.connect(self.btn_f7.playSample)
		self.btn_f8.clicked.connect(self.btn_f8.playSample)
		self.btn_f9.clicked.connect(self.btn_f9.playSample)
		
		self.btn_g1.clicked.connect(self.btn_g1.playSample)
		self.btn_g2.clicked.connect(self.btn_g2.playSample)
		self.btn_g3.clicked.connect(self.btn_g3.playSample)
		self.btn_g4.clicked.connect(self.btn_g4.playSample)
		self.btn_g5.clicked.connect(self.btn_g5.playSample)
		self.btn_g6.clicked.connect(self.btn_g6.playSample)
		self.btn_g7.clicked.connect(self.btn_g7.playSample)
		self.btn_g8.clicked.connect(self.btn_g8.playSample)
		self.btn_g9.clicked.connect(self.btn_g9.playSample)
		
		self.btn_h1.clicked.connect(self.btn_h1.playSample)
		self.btn_h2.clicked.connect(self.btn_h2.playSample)
		self.btn_h3.clicked.connect(self.btn_h3.playSample)
		self.btn_h4.clicked.connect(self.btn_h4.playSample)
		self.btn_h5.clicked.connect(self.btn_h5.playSample)
		self.btn_h6.clicked.connect(self.btn_h6.playSample)
		self.btn_h7.clicked.connect(self.btn_h7.playSample)
		self.btn_h8.clicked.connect(self.btn_h8.playSample)
		self.btn_h9.clicked.connect(self.btn_h9.playSample)
		
		self.btn_i1.clicked.connect(self.btn_i1.playSample)
		self.btn_i2.clicked.connect(self.btn_i2.playSample)
		self.btn_i3.clicked.connect(self.btn_i3.playSample)
		self.btn_i4.clicked.connect(self.btn_i4.playSample)
		self.btn_i5.clicked.connect(self.btn_i5.playSample)
		self.btn_i6.clicked.connect(self.btn_i6.playSample)
		self.btn_i7.clicked.connect(self.btn_i7.playSample)
		self.btn_i8.clicked.connect(self.btn_i8.playSample)
		self.btn_i9.clicked.connect(launchSampler)

#Custom label class, inheriting from QT QLabel.
class Label(QtGui.QLabel):
	def __init__(self, text, posX, posY, posA, posB, objName, parent=None):
		super(Label, self).__init__(parent=parent)
		
		self.setGeometry(QtCore.QRect(posX, posY, posA, posB))
		self.font = QtGui.QFont()
		self.font.setPointSize(10)
		self.setFont(self.font)
		self.setObjectName(objName)
		self.text = text
		self.setText(QtGui.QApplication.translate("Form", "<html><head/><body><p align=\"center\"><span style=\" color:#ffffff;\">"+ self.text +"</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))

#Custom button class without drag and drop functionality. 
class ModeButton(QtGui.QPushButton):
	def __init__(self, iconPathUnassigned, iconX, iconY, posX, posY, posA, posB, objName, parent=None):
		super(ModeButton, self).__init__(parent=parent) 

		self.icon = QtGui.QIcon()
		self.icon.addPixmap(QtGui.QPixmap(iconPathUnassigned), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setIcon(self.icon)
		self.setIconSize(QtCore.QSize(iconX, iconY))
		self.setGeometry(QtCore.QRect(posX, posY, posA, posB))
		self.setObjectName(objName)	
		LP.LedCtrlRaw(120, 0, 3)

#Custom button class with drag and drop functionality.
class Button(QtGui.QPushButton):
	def __init__(self, iconPathUnassigned, iconX, iconY, posX, posY, posA, posB, objName, labEdit, iconPathAssigned, iconPathPlaying, padnumber, parent=None):
		super(Button, self).__init__(parent=parent) 
		
		self.setAcceptDrops(True)
        
		self.iconPathAssigned = iconPathAssigned
		self.iconPathPlaying = iconPathPlaying
		self.icon = QtGui.QIcon()
		self.icon.addPixmap(QtGui.QPixmap(iconPathUnassigned), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setIcon(self.icon)
		self.setIconSize(QtCore.QSize(iconX, iconY))
		self.setGeometry(QtCore.QRect(posX, posY, posA, posB))
		self.setObjectName(objName)
		self.samplePath = None
		self.label = labEdit	
		self.padnumber = padnumber

#If dragged item has a filepath then accept it, otherwise do not (i.e if it were text that had been dragged straight onto the button)
	def dragEnterEvent(self, event):
		if event.mimeData().hasUrls():
			event.acceptProposedAction()
		else:
			super(Button, self).dragEnterEvent(event)

	def dragMoveEvent(self, event):
		super(Button, self).dragMoveEvent(event)

#If dragged item has a filepath then accept it, otherwise do not (i.e if it were text that had been dragged straight onto the button)
	def dropEvent(self, event):
		if event.mimeData().hasUrls():
			for url in event.mimeData().urls():
				self.samplePath = str(url.toLocalFile())
				self.editLabel()
				self.iconAssigned()
			event.acceptProposedAction()
		else:
			super(Button,self).dropEvent(event)
			
	def iconAssigned(self):
		self.icon.addPixmap(QtGui.QPixmap(self.iconPathAssigned), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setIcon(self.icon)
		LP.LedCtrlRaw(self.padnumber, 0, 3)
		
	def iconPlaying(self):
		self.icon.addPixmap(QtGui.QPixmap(self.iconPathPlaying), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.setIcon(self.icon)
	
	def playSample(self):
		if self.samplePath == None:
			self.sample = None
		else:
			self.sample = pygame.mixer.Sound(self.samplePath)
			pygame.mixer.Sound.play(self.sample)
			
	def editLabel(self):
		self.fileName = ntpath.basename(self.samplePath)
		self.label.setText(QtGui.QApplication.translate("Form", "<html><head/><body><p align=\"center\"><span style=\" color:#ffffff;\">"+ self.fileName +"</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))

def launchSampler():
	playmode = Sampler()
			
if __name__=='__main__':
	pygame.mixer.init(frequency=44100, size=-16, buffer=1024)
	pygame.init()
	app = QtGui.QApplication(sys.argv)
	LP = launchpad.Launchpad()
	LP.Open()
	LP.Reset()
	ex = Ui_Form()
	ex.show()
	sys.exit(app.exec_())