Exemplo n.º 1
0
	def _setup_monobridge(self):
		self._monobridge = MonoBridgeElement(self)
		self._monobridge.name = 'MonoBridge'
Exemplo n.º 2
0
class LividControlSurface(ControlSurface):


	_rgb = 0
	_color_type = 'OhmRGB'
	_timer = 0
	_touched = 0
	flash_status = 1
	_connected = False
	_sysex_id = 0
	_model_name = 'Livid Control Surface'
	_version_check = 'Mod_Disabled'

	def __init__(self, *a, **k):
		self.log_message = logger.info
		super(LividControlSurface, self).__init__(*a, **k)
		with self.component_guard():
			self._setup_monobridge()
			self._livid_settings = LividSettings(model = self._sysex_id, control_surface = self)
		self.schedule_message(1, self._open_log)
		#self._connection_routine = self._tasks.add(task.sequence(task.wait(10), task.run(self._check_connection)))
		#self._connection_routine.restart()
		self.schedule_message(2, self._check_connection)
	

	def _open_log(self):
		self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log opened =>>>>>>>>>>>>>>>>>>>") 
		self.show_message(str(self._model_name) + ' Control Surface Loaded')
	

	def _close_log(self):
		self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log closed =>>>>>>>>>>>>>>>>>>>") 
	

	def _setup_monobridge(self):
		self._monobridge = MonoBridgeElement(self)
		self._monobridge.name = 'MonoBridge'
	

	def port_settings_changed(self):
		debug('port settings changed!')
		self._connected = False
		self._check_connection()
	

	def _check_connection(self):
		if not self._connected:
			#debug(self._model_name, '_check_connection')
			self._livid_settings.query_surface()
			#self._connection_routine.restart()
			self.schedule_message(5, self._check_connection)
	

	def _initialize_hardware(self):
		debug(self._model_name, 'initialize_hardware()')
	

	def _initialize_script(self):
		self.refresh_state()
		debug(self._model_name, 'initialize_script()')
	

	def set_appointed_device(self, device):
		self.song.appointed_device = device
	

	def flash(self):
		if(self.flash_status > 0):
			for control in self.controls:
				if isinstance(control, MonoButtonElement):
					control.flash(self._timer)
	

	def update_display(self):
		super(LividControlSurface, self).update_display()
		self._timer = (self._timer + 1) % 256
		self.flash()
	

	def touched(self):
		if self._touched is 0:
			self._monobridge._send('touch', 'on')
			self.schedule_message(2, self.check_touch)
		self._touched +=1
	

	def check_touch(self):
		if self._touched > 5:
			self._touched = 5
		elif self._touched > 0:
			self._touched -= 1
		if self._touched is 0:
			self._monobridge._send('touch', 'off')
		else:
			self.schedule_message(2, self.check_touch)
		
	

	def process_midi_bytes(self, midi_bytes, midi_processor):
		if midi.is_sysex(midi_bytes):
			result = self.get_registry_entry_for_sysex_midi_message(midi_bytes)
			if result is not None:
				identifier, recipient = result
				midi_processor(recipient, midi_bytes[len(identifier):-1])
			else:
				try:
					self.handle_sysex(midi_bytes)
				except:
					pass
		else:
			recipient = self.get_recipient_for_nonsysex_midi_message(midi_bytes)
			if recipient is not None:
				midi_processor(recipient, midi.extract_value(midi_bytes))
			else:
				logger.warning('Got unknown message: ' + midi.pretty_print_bytes(midi_bytes))
	

	def handle_sysex(self, midi_bytes):
		#debug('sysex: ', str(midi_bytes))
		#debug('matching:', midi_bytes[3:11], 'to', tuple([6, 2, 0, 1, 97, 1, 0]  + [self._sysex_id]))
		if midi_bytes[3:11] == tuple([6, 2, 0, 1, 97, 1, 0]  + [self._sysex_id]):
			if not self._connected:
				debug('connecting from sysex...')
				#self._connection_routine.kill()
				self._connected = True
				#self._livid_settings.set_model(midi_bytes[11])
				self._initialize_hardware()
				self._initialize_script()
	

	def disconnect(self):
		super(LividControlSurface, self).disconnect()
		self._close_log()
Exemplo n.º 3
0
class MonoBlocks(ControlSurface):


	_rgb = 0
	_color_type = 'Push'
	_timer = 0
	_touched = 0
	flash_status = False
	_model_name = 'MonoBlocks'
	_host_name = 'MonoBlocks'
	_version_check = 'b996'
	monomodular = None
	device_provider_class = ModDeviceProvider

	def __init__(self, *a, **k):
		super(MonoBlocks, self).__init__(*a, **k)
		self.log_message = logger.info
		self._skin = Skin(MonoBlocksColors)
		with self.component_guard():
			self._setup_monobridge()
			self._setup_controls()
			#self._setup_device()
			self._setup_mod()
			#self._setup_modes()
			self._setup_modswitcher()
		self._on_device_changed.subject = self._device_provider
		self.schedule_message(1, self._open_log)


	def _open_log(self):
		#self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log opened =>>>>>>>>>>>>>>>>>>>")
		self.show_message(str(self._model_name) + ' Control Surface Loaded')


	def _close_log(self):
		#self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log closed =>>>>>>>>>>>>>>>>>>>")
		pass


	def _setup_controls(self):
		is_momentary = True
		optimized = True
		resource = PrioritizedResource
		#self._pads_raw = [ ButtonElement(True, MIDI_NOTE_TYPE, 0, identifier, name=u'Pad_{}'.format(identifier), skin=skin) for identifier in xrange(100) ]
		self._pad = [MonoButtonElement(is_momentary = is_momentary, msg_type = MIDI_NOTE_TYPE, channel = CHANNEL, identifier = BLOCKS_PADS[index], name = 'Pad_' + str(index), script = self, monobridge = self._monobridge, skin = self._skin, color_map = COLOR_MAP, optimized_send_midi = optimized, resource_type = resource) for index in range(64)]
		for button in self._pad:
			button.set_color_map(tuple(range(128)))
		self._matrix = ButtonMatrixElement(name = 'Matrix', rows = [self._pad[(index*8):(index*8)+8] for index in range(8)])


	#def _setup_device(self):
	#	self._device_selection_follows_track_selection = True
	#	self._device = DeviceComponent(name = 'Device_Component', device_bank_registry = DeviceBankRegistry(), device_provider = self._device_provider)
	#	self._device.set_enabled(True)


	def _setup_monobridge(self):
		self._monobridge = MonoBridgeElement(self)
		self._monobridge.name = 'MonoBridge'


	def _setup_mod(self):

		def get_monomodular(host):
				if isinstance(__builtins__, dict):
					if not 'monomodular' in __builtins__.keys() or not isinstance(__builtins__['monomodular'], ModRouter):
						__builtins__['monomodular'] = ModRouter(song = self.song, register_component = self._register_component)
				else:
					if not hasattr(__builtins__, 'monomodular') or not isinstance(__builtins__['monomodular'], ModRouter):
						setattr(__builtins__, 'monomodular', ModRouter(song = self.song, register_component = self._register_component))
				monomodular = __builtins__['monomodular']
				if not monomodular.has_host():
					monomodular.set_host(host)
				return monomodular


		self.monomodular = get_monomodular(self)
		self.monomodular.name = 'monomodular_switcher'
		with inject(register_component = const(self._register_component), song = const(self.song)).everywhere():
			self.modhandler = MonoBlocksModHandler(self) ## song = self.song, register_component = self._register_component)
		self.modhandler.name = 'ModHandler'
		self.modhandler.layer = Layer( priority = 6, grid = self._matrix)
		self.modhandler.alt_shift_layer = AddLayerMode( self.modhandler, Layer())
		#																	Shift_button = self.elements.shift_button,
		#																	Alt_button = self.elements.select_button))
		self.modhandler.legacy_shift_layer = AddLayerMode( self.modhandler, Layer(priority = 7,
																			device_selector_matrix = self._matrix.submatrix[:, :1],
																			channel_buttons = self._matrix.submatrix[:, 1:2],
																			nav_matrix = self._matrix.submatrix[4:8, 2:6],
																			))
		self.modhandler.shift_layer = AddLayerMode( self.modhandler, Layer( priority = 7,
																			device_selector_matrix = self._matrix.submatrix[:, :1],
																			))
																			#lock_button = self.elements.master_select_button,
																			#))
		self.modhandler.alt_layer = AddLayerMode( self.modhandler, Layer( priority = 7,
																			))
																			#key_buttons = self.elements.select_buttons))
																			#key_buttons = self.elements.track_state_buttons))
		self._device_provider.restart_mod()


	def _setup_modswitcher(self):
		self._modswitcher = ModesComponent(name = 'ModSwitcher')
		self._modswitcher.add_mode('mod', [self.modhandler])
		self._modswitcher.selected_mode = 'mod'
		self._modswitcher.set_enabled(True)


	def flash(self):
		if(self.flash_status > 0):
			for control in self.controls:
				if isinstance(control, MonoButtonElement):
					control.flash(self._timer)


	def update_display(self):
		super(ControlSurface, self).update_display()
		self._timer = (self._timer + 1) % 256
		self.flash()


	def touched(self):
		if self._touched is 0:
			self._monobridge._send('touch', 'on')
			self.schedule_message(2, self.check_touch)
		self._touched +=1


	def check_touch(self):
		if self._touched > 5:
			self._touched = 5
		elif self._touched > 0:
			self._touched -= 1
		if self._touched is 0:
			self._monobridge._send('touch', 'off')
		else:
			self.schedule_message(2, self.check_touch)


	@listens('device')
	def _on_device_changed(self):
		#self.schedule_message(1, self._update_modswitcher)
		debug('base on_device_changed')
		#self._update_modswitcher()


	def _on_selected_track_changed(self):
		super(MonoBlocks, self)._on_selected_track_changed()
		if not len(self.song.view.selected_track.devices):
			self._update_modswitcher()
		#self.schedule_message(1, self._update_modswitcher)


	def disconnect(self):
		super(MonoBlocks, self).disconnect()
		self._close_log()


	def restart_monomodular(self):
		#self.log_message('restart monomodular')
		self.modhandler.disconnect()
		with self.component_guard():
			self._setup_mod()


	def process_midi_bytes(self, midi_bytes, midi_processor):
		u"""
		Finds the right recipient for the MIDI message and translates it into the
		expected format. The result is forwarded to the midi_processor.
		"""
		if midi.is_sysex(midi_bytes):
			result = self.get_registry_entry_for_sysex_midi_message(midi_bytes)
			if result is not None:
				identifier, recipient = result
				midi_processor(recipient, midi_bytes[len(identifier):-1])
			#elif self.received_midi_listener_count() == 0:
			#	logger.warning(u'Got unknown sysex message: ' + midi.pretty_print_bytes(midi_bytes))
		else:
			recipient = self.get_recipient_for_nonsysex_midi_message(midi_bytes)
			if recipient is not None:
				midi_processor(recipient, midi.extract_value(midi_bytes))
Exemplo n.º 4
0
class Aum256(ControlSurface):

    _rgb = 0
    _color_type = 'Push'
    _timer = 0
    _touched = 0
    flash_status = False
    _model_name = 'Aum256'
    _host_name = 'Aum256'
    _version_check = 'b996'
    monomodular = None
    device_provider_class = ModDeviceProvider

    def __init__(self, *a, **k):
        super(Aum256, self).__init__(*a, **k)
        self.log_message = logger.info
        self._skin = Skin(Aum256Colors)
        with self.component_guard():
            self._setup_monobridge()
            self._setup_controls()
            #self._setup_device()
            self._setup_mod()
            #self._setup_modes()
            self._setup_modswitcher()
        self._on_device_changed.subject = self._device_provider
        self.schedule_message(1, self._open_log)

    def _open_log(self):
        #self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log opened =>>>>>>>>>>>>>>>>>>>")
        self.show_message(str(self._model_name) + ' Control Surface Loaded')

    def _close_log(self):
        #self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log closed =>>>>>>>>>>>>>>>>>>>")
        pass

    @listenable_property
    def pipe(self):
        return None

    def _send(self, **a):
        notify_pipe(a)

    def _setup_controls(self):
        is_momentary = True
        optimized = True
        resource = PrioritizedResource
        #self._pads_raw = [ ButtonElement(True, MIDI_NOTE_TYPE, 0, identifier, name=u'Pad_{}'.format(identifier), skin=skin) for identifier in xrange(100) ]
        self._pad = [
            SpecialMonoButtonElement(is_momentary=is_momentary,
                                     msg_type=MIDI_NOTE_TYPE,
                                     channel=int(math.floor(index / 128)),
                                     identifier=index % 128,
                                     name='Pad_' + str(index),
                                     script=self,
                                     monobridge=self._monobridge,
                                     skin=self._skin,
                                     color_map=COLOR_MAP,
                                     optimized_send_midi=optimized,
                                     resource_type=resource)
            for index in range(256)
        ]
        for button in self._pad:
            button.set_color_map(tuple(range(128)))
        self._matrix = ButtonMatrixElement(
            name='Matrix',
            rows=[
                self._pad[(index * 16):(index * 16) + 16]
                for index in range(16)
            ])
        self._key = [
            SpecialMonoButtonElement(is_momentary=is_momentary,
                                     msg_type=MIDI_NOTE_TYPE,
                                     channel=2,
                                     identifier=index,
                                     name='Key_' + str(index),
                                     script=self,
                                     monobridge=self._monobridge,
                                     skin=self._skin,
                                     color_map=COLOR_MAP,
                                     optimized_send_midi=optimized,
                                     resource_type=resource)
            for index in range(8)
        ]
        for button in self._pad:
            button.set_color_map(tuple(range(128)))
        self._key_matrix = ButtonMatrixElement(name='KeyMatrix',
                                               rows=[self._key])

        self._shift = SpecialMonoButtonElement(is_momentary=is_momentary,
                                               msg_type=MIDI_NOTE_TYPE,
                                               channel=2,
                                               identifier=8,
                                               name='Shift',
                                               script=self,
                                               monobridge=self._monobridge,
                                               skin=self._skin,
                                               color_map=COLOR_MAP,
                                               optimized_send_midi=optimized,
                                               resource_type=resource)
        self._shift.set_color_map(tuple(range(128)))
        self._alt = SpecialMonoButtonElement(is_momentary=is_momentary,
                                             msg_type=MIDI_NOTE_TYPE,
                                             channel=2,
                                             identifier=9,
                                             name='Alt',
                                             script=self,
                                             monobridge=self._monobridge,
                                             skin=self._skin,
                                             color_map=COLOR_MAP,
                                             optimized_send_midi=optimized,
                                             resource_type=resource)
        self._alt.set_color_map(tuple(range(128)))
        self._lock = SpecialMonoButtonElement(is_momentary=is_momentary,
                                              msg_type=MIDI_NOTE_TYPE,
                                              channel=2,
                                              identifier=10,
                                              name='Lock',
                                              script=self,
                                              monobridge=self._monobridge,
                                              skin=self._skin,
                                              color_map=COLOR_MAP,
                                              optimized_send_midi=optimized,
                                              resource_type=resource)
        self._lock.set_color_map(tuple(range(128)))

    #def _setup_device(self):
    #	self._device_selection_follows_track_selection = True
    #	self._device = DeviceComponent(name = 'Device_Component', device_bank_registry = DeviceBankRegistry(), device_provider = self._device_provider)
    #	self._device.set_enabled(True)

    def _setup_monobridge(self):
        self._monobridge = MonoBridgeElement(self)
        self._monobridge.name = 'MonoBridge'

    def _setup_mod(self):
        def get_monomodular(host):
            if isinstance(__builtins__, dict):
                if not 'monomodular' in list(
                        __builtins__.keys()) or not isinstance(
                            __builtins__['monomodular'], ModRouter):
                    __builtins__['monomodular'] = ModRouter(
                        song=self.song,
                        register_component=self._register_component)
            else:
                if not hasattr(__builtins__, 'monomodular') or not isinstance(
                        __builtins__['monomodular'], ModRouter):
                    setattr(
                        __builtins__, 'monomodular',
                        ModRouter(song=self.song,
                                  register_component=self._register_component))
            monomodular = __builtins__['monomodular']
            if not monomodular.has_host():
                monomodular.set_host(host)
            return monomodular

        self.monomodular = get_monomodular(self)
        self.monomodular.name = 'monomodular_switcher'
        # with inject(register_component = const(self._register_component), song = const(self.song)).everywhere():
        self.modhandler = Aum256ModHandler(
            self
        )  ## song = self.song, register_component = self._register_component)
        self.modhandler.name = 'ModHandler'
        self.modhandler.layer = Layer(priority=6,
                                      grid=self._matrix,
                                      Shift_button=self._shift,
                                      Alt_button=self._alt,
                                      key_buttons=self._key_matrix)
        self.modhandler.alt_shift_layer = AddLayerMode(self.modhandler,
                                                       Layer())
        self.modhandler.legacy_shift_layer = AddLayerMode(
            self.modhandler,
            Layer(
                priority=7,
                device_selector_matrix=self._matrix.submatrix[:, :1],
                channel_buttons=self._matrix.submatrix[:, 1:2],
            ))
        #nav_matrix = self._matrix.submatrix[4:8, 2:6],
        #))
        self.modhandler.shift_layer = AddLayerMode(
            self.modhandler,
            Layer(
                priority=7,
                device_selector_matrix=self._matrix.submatrix[:, :1],
            ))
        #lock_button = self.elements.master_select_button,
        #))
        self.modhandler.alt_layer = AddLayerMode(self.modhandler,
                                                 Layer(priority=7, ))
        #key_buttons = self.elements.select_buttons))
        #key_buttons = self.elements.track_state_buttons))
        self._device_provider.restart_mod()
        self._modHandle = ModControl(modscript=self,
                                     monomodular=self.monomodular,
                                     name='ModHandle')

    def _setup_modswitcher(self):
        self._modswitcher = ModesComponent(name='ModSwitcher')
        self._modswitcher.add_mode('mod', [self.modhandler])
        self._modswitcher.selected_mode = 'mod'
        self._modswitcher.set_enabled(True)

    def flash(self):
        if (self.flash_status > 0):
            for control in self.controls:
                if isinstance(control, MonoButtonElement):
                    control.flash(self._timer)

    def update_display(self):
        super(ControlSurface, self).update_display()
        self._timer = (self._timer + 1) % 256
        self.flash()

    def touched(self):
        if self._touched is 0:
            self._monobridge._send('touch', 'on')
            self.schedule_message(2, self.check_touch)
        self._touched += 1

    def check_touch(self):
        if self._touched > 5:
            self._touched = 5
        elif self._touched > 0:
            self._touched -= 1
        if self._touched is 0:
            self._monobridge._send('touch', 'off')
        else:
            self.schedule_message(2, self.check_touch)

    @listens('device')
    def _on_device_changed(self):
        #self.schedule_message(1, self._update_modswitcher)
        debug('Aum256 on_device_changed')
        #self._update_modswitcher()

    def _on_selected_track_changed(self):
        super(Aum256, self)._on_selected_track_changed()
        if not len(self.song.view.selected_track.devices):
            self._update_modswitcher()
        #self.schedule_message(1, self._update_modswitcher)

    def disconnect(self):
        for script in self._connected_scripts:
            if hasattr(script, '_disconnect_mod'):
                script._disconnect_mod()
        super(Aum256, self).disconnect()
        self._close_log()

    def restart_monomodular(self):
        #self.log_message('restart monomodular')
        self.modhandler.disconnect()
        with self.component_guard():
            self._setup_mod()

    def _do_send_midi(self, midi_event_bytes):
        super(Aum256, self)._do_send_midi(midi_event_bytes)
        bytes = list(midi_event_bytes)
        self.notify_pipe('midi', *bytes)

    def receive_note(self, num, val, chan=0):
        # debug('receive_note', num, val)
        self.receive_midi(tuple([144 + chan, num, val]))

    def receive_cc(self, num, val, chan=0):
        # debug('receive_cc', num, val)
        self.receive_midi(tuple([176 + chan, num, val]))

    def process_midi_bytes(self, midi_bytes, midi_processor):
        """
		Finds the right recipient for the MIDI message and translates it into the
		expected format. The result is forwarded to the midi_processor.
		"""
        if midi.is_sysex(midi_bytes):
            result = self.get_registry_entry_for_sysex_midi_message(midi_bytes)
            if result is not None:
                identifier, recipient = result
                midi_processor(recipient, midi_bytes[len(identifier):-1])
            #elif self.received_midi_listener_count() == 0:
            #	logger.warning(u'Got unknown sysex message: ' + midi.pretty_print_bytes(midi_bytes))
        else:
            recipient = self.get_recipient_for_nonsysex_midi_message(
                midi_bytes)
            if recipient is not None:
                midi_processor(recipient, midi.extract_value(midi_bytes))
            #elif self.received_midi_listener_count() == 0:
            #	logger.warning(u'Got unknown message: ' + midi.pretty_print_bytes(midi_bytes))

    def connect_script_instances(self, instanciated_scripts):
        debug('connect_script_instances', instanciated_scripts)
        self._connected_scripts = []
        for script in instanciated_scripts:
            # debug(script)
            if isinstance(script, Launchpad_MK2):
                self._connected_scripts.append(script)
                self._on_lp2_mode_changed.subject = script._modes
                if not hasattr(script, '_modified') or (hasattr(
                        script, '_modified') and not script._modified):
                    script.setup_mod = _Launchpad_MK2_setup_mod
                    script.schedule_message(1, script.setup_mod,
                                            [script, self])
            elif isinstance(script, Launchpad_Pro):
                self._connected_scripts.append(script)
                self._on_lppro_mode_changed.subject = script._note_modes
                if not hasattr(script, '_modified') or (hasattr(
                        script, '_modified') and not script._modified):
                    script.setup_mod = _Launchpad_Pro_setup_mod
                    script.schedule_message(1, script.setup_mod,
                                            [script, self])
            elif isinstance(script, Launchpad):
                self._connected_scripts.append(script)
                # self._on_lppro_mode_changed.subject = script._note_modes
                if not hasattr(script, '_modified') or (hasattr(
                        script, '_modified') and not script._modified):
                    script.setup_mod = _Launchpad_setup_mod
                    script.schedule_message(1, script.setup_mod,
                                            [script, self])
        debug('connected_scripts:', self._connected_scripts)

    @listens('selected_mode')
    def _on_lp2_mode_changed(self, mode):
        debug('_on_lp2_mode_changed', mode)

    @listens('selected_mode')
    def _on_lppro_mode_changed(self, mode):
        debug('_on_lppro_mode_changed', mode)
	def _setup_monobridge(self):
		self._monobridge = MonoBridgeElement(self)
		self._monobridge.name = 'MonoBridge'
class LividControlSurface(ControlSurface):


	_rgb = 0
	_color_type = 'OhmRGB'
	_timer = 0
	_touched = 0
	flash_status = 1
	_connected = False
	_sysex_id = 0
	_model_name = 'Livid Control Surface'
	_version_check = 'Mod_Disabled'

	def __init__(self, *a, **k):
		self.log_message = logger.info
		super(LividControlSurface, self).__init__(*a, **k)
		with self.component_guard():
			self._setup_monobridge()
			self._livid_settings = LividSettings(model = self._sysex_id, control_surface = self)
		self.schedule_message(1, self._open_log)
		#self._connection_routine = self._tasks.add(task.sequence(task.wait(10), task.run(self._check_connection)))
		#self._connection_routine.restart()
		self.schedule_message(2, self._check_connection)
	

	def _open_log(self):
		self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log opened =>>>>>>>>>>>>>>>>>>>") 
		self.show_message(str(self._model_name) + ' Control Surface Loaded')
	

	def _close_log(self):
		self.log_message("<<<<<<<<<<<<<<<<<<<<= " + str(self._model_name) + " " + str(self._version_check) + " log closed =>>>>>>>>>>>>>>>>>>>") 
	

	def _setup_monobridge(self):
		self._monobridge = MonoBridgeElement(self)
		self._monobridge.name = 'MonoBridge'
	

	def port_settings_changed(self):
		debug('port settings changed!')
		self._connected = False
		self._check_connection()
	

	def _check_connection(self):
		if not self._connected:
			debug(self._model_name, '_check_connection')
			self._livid_settings.query_surface()
			#self._connection_routine.restart()
			self.schedule_message(5, self._check_connection)
	

	def _initialize_hardware(self):
		debug(self._model_name, 'initialize_hardware()')
	

	def _initialize_script(self):
		self.refresh_state()
		debug(self._model_name, 'initialize_script()')
	

	def set_appointed_device(self, device):
		self.song.appointed_device = device
	

	def flash(self):
		if(self.flash_status > 0):
			for control in self.controls:
				if isinstance(control, MonoButtonElement):
					control.flash(self._timer)
	

	def update_display(self):
		super(LividControlSurface, self).update_display()
		self._timer = (self._timer + 1) % 256
		self.flash()
	

	def touched(self):
		if self._touched is 0:
			self._monobridge._send('touch', 'on')
			self.schedule_message(2, self.check_touch)
		self._touched +=1
	

	def check_touch(self):
		if self._touched > 5:
			self._touched = 5
		elif self._touched > 0:
			self._touched -= 1
		if self._touched is 0:
			self._monobridge._send('touch', 'off')
		else:
			self.schedule_message(2, self.check_touch)
		
	

	def process_midi_bytes(self, midi_bytes, midi_processor):
		if midi.is_sysex(midi_bytes):
			result = self.get_registry_entry_for_sysex_midi_message(midi_bytes)
			if result is not None:
				identifier, recipient = result
				midi_processor(recipient, midi_bytes[len(identifier):-1])
			else:
				try:
					self.handle_sysex(midi_bytes)
				except:
					pass
		else:
			recipient = self.get_recipient_for_nonsysex_midi_message(midi_bytes)
			if recipient is not None:
				midi_processor(recipient, midi.extract_value(midi_bytes))
			else:
				logger.warning('Got unknown message: ' + midi.pretty_print_bytes(midi_bytes))
	

	def handle_sysex(self, midi_bytes):
		#debug('sysex: ', str(midi_bytes))
		#debug('matching:', midi_bytes[3:11], 'to', tuple([6, 2, 0, 1, 97, 1, 0]  + [self._sysex_id]))
		if midi_bytes[3:11] == tuple([6, 2, 0, 1, 97, 1, 0]  + [self._sysex_id]):
			if not self._connected:
				debug('connecting from sysex...')
				#self._connection_routine.kill()
				self._connected = True
				#self._livid_settings.set_model(midi_bytes[11])
				self._initialize_hardware()
				self._initialize_script()
	

	def disconnect(self):
		super(LividControlSurface, self).disconnect()
		self._close_log()