from ableton.v2.control_surface.elements.sysex_element import SysexElement

def devmode_command(cmd, *a):
	"Return a MIDI SysEx message for the given DevMode command and arguments"
	return (0xF0, 0x00, 0x21, 0x7E, 0x7F, cmd) + a + (0xF7,)

class DevMode(SysexElement):
	"An Element that sets up the Developer Mode of the Exquis"

	"Turn off the Developer Mode"
	MASK_NONE = 0
	"Developer Mode controls all buttons except Settings and Sound"
	MASK_OTHER_BUTTONS = 0x20
	"Developer Mode controls everything (pads,etc.) except the Settings and Sound buttons"
	MASK_ALL_BUT_SETTINGS_SOUND = 0x2F
	"Developer Mode controls everything"
	MASK_ALL = 0x7F
	"Developer Mode only controls what's necessary to show in the Settings menu"
	MASK_IN_SETTINGS = 0x4
	"Developer Mode only controls what's necessary to show in the Sound menu"
	MASK_IN_SOUND = 0x5

	CMD_SETUP = 0
	CMD_USE_CUSTOM_SCALES_IN_SETTINGS = 1
	CMD_PALETTE = 2
	CMD_REFRESH = 3
	CMD_LED_COLOR_FX = 4
	CMD_TEMPO = 5
	CMD_ROOT_NOTE = 6
	CMD_SCALE_INDEX = 7
	CMD_SCALE_CUSTOM = 8
	CMD_SNAPSHOT = 9
	CMD_ENCODERS_CCS_SNAPSHOT = 0x0A 

	def __init__(self, *a, **k):
		super(DevMode, self).__init__(
			sysex_identifier=devmode_command(DevMode.CMD_SETUP)[0:-1],
			send_message_generator=lambda v: devmode_command(DevMode.CMD_SETUP, v),
			name="DevMode",
			*a, **k)

	def disconnect(self):
		self.send_value(DevMode.MASK_NONE)
		super(DevMode, self).disconnect()
