示例#1
0
class UserComponent(ActionWithSettingsComponent):
    __subject_events__ = (SubjectEvent(name='mode',
                                       doc=' Called when the mode changes '),
                          SubjectEvent(name='before_mode_sent',
                                       doc=' Called before the mode is sent'),
                          SubjectEvent(name='after_mode_sent',
                                       doc=' Called after the mode is sent '))
    settings_layer = forward_property('_settings')('layer')
    settings = forward_property('_settings')('settings')

    def __init__(self, value_control=None, *a, **k):
        super(UserComponent, self).__init__(*a, **k)
        raise value_control != None or AssertionError
        self._settings = self.register_component(UserSettingsComponent())
        self._settings.set_enabled(False)
        self._value_control = value_control
        self._on_value.subject = self._value_control
        self._selected_mode = Sysex.LIVE_MODE

    def show_settings(self):
        self._settings.set_enabled(True)
        return True

    def hide_settings(self):
        self._settings.set_enabled(False)

    def set_settings_info_text(self, text):
        self._settings.set_info_text(text)

    def post_trigger_action(self):
        self.mode = Sysex.LIVE_MODE if self.mode == Sysex.USER_MODE else Sysex.USER_MODE

    @subject_slot('value')
    def _on_value(self, value):
        mode = value[0]
        self._selected_mode = mode
        self.notify_mode(mode)

    def _get_mode(self):
        return self._selected_mode

    def _set_mode(self, mode):
        if mode != self._selected_mode:
            self._selected_mode = mode
            if self.is_enabled():
                self._apply_mode(self._selected_mode)

    mode = property(_get_mode, _set_mode)

    def update(self):
        super(UserComponent, self).update()
        if self.is_enabled():
            self._apply_mode(self._selected_mode)

    def _apply_mode(self, mode):
        self.notify_before_mode_sent(mode)
        self._value_control.send_value((mode, ))
        self.notify_after_mode_sent(mode)
示例#2
0
class MonoBridgeElement(NotifyingControlElement):
    __module__ = __name__
    __doc__ = ' Class representing a 2-dimensional set of buttons '

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, script, *a, **k):
        super(MonoBridgeElement, self).__init__(*a, **k)
        self._script = script

    def refresh_state(self, *a, **k):
        #self._script.schedule_message(2, self._script.update)
        #self._script.log_message('refresh_state')
        self._script.refresh_state()

    def _send(self, args1=None, args2=None, args3=None, args4=None):
        #self._button_value(args1, args2, args3, args4)
        self.notify_value(args1, args2, args3)

    def script_wants_forwarding(self):
        return True

    def reset(self):
        pass
class Setting(Subject):
    """
    Setting interface for writing to the preferences and all
    information for changing and displaying it.
    """
    __subject_events__ = (SubjectEvent(
        name='value',
        doc=
        ' Called when the value of the\n                                                 setting changes '
    ), )

    def __init__(self,
                 name='',
                 values=None,
                 default_value=None,
                 preferences=None,
                 *a,
                 **k):
        super(Setting, self).__init__(*a, **k)
        self.name = name
        if not values:
            self.values = []
            self._preferences = preferences if preferences != None else {}
            default_value = name in self._preferences and self._preferences[
                name] in values and self._preferences[name]
        self._preferences[name] = None
        self.value = default_value

    def __str__(self):
        return self.value_to_string(self.value)

    def _set_value(self, value):
        if not value in self.values:
            raise AssertionError
            self._preferences[
                self.name] = self._preferences[self.name] != value and value
            self.on_value_changed(value)
            self.notify_value(self.value)

    def _get_value(self):
        return self._preferences[self.name]

    value = property(_get_value, _set_value)

    def on_value_changed(self, value):
        pass

    def change_relative(self, value):
        """ Given a value between -1.0 and 1.0, this will decide on a new value. """
        raise NotImplementedError

    def value_to_string(self, value):
        raise NotImplementedError
示例#4
0
class MonoBridgeElement(NotifyingControlElement):
	__module__ = __name__
	__doc__ = ' Class representing a 2-dimensional set of buttons '
	__subject_events__ = (SubjectEvent(name='value', signal=InputSignal, override=True),)
	_input_signal_listener_count = 0
	


	def __init__(self, script, *a, **k):
		super(MonoBridgeElement, self).__init__()
		self._script = script
	

	def refresh_state(self, *a, **k):
		#self._script.schedule_message(2, self._script.update)
		#self._script.log_message('refresh_state')
		self._script.refresh_state()
	

	def _send(self, args1 = None, args2 = None, args3 = None, args4 = None):
		self.notify_value(args1, args2, args3)
	

	def script_wants_forwarding(self):
		return True
	

	def reset(self):
		pass
	

	def notification_to_bridge(self, name = None, value = None, sender = None):
		if hasattr(sender, 'name'):
			self._send(sender.name, 'lcd_name', str(self.generate_strip_string(name)))
			self._send(sender.name, 'lcd_value', str(self.generate_strip_string(value)))
		else:
			self._send(name, 'lcd_name', str(self.generate_strip_string(name)))
			self._send(name, 'lcd_value', str(self.generate_strip_string(value)))
	

	def generate_strip_string(self, display_string):
		NUM_CHARS_PER_DISPLAY_STRIP = 12
		if (not display_string):
			return (' ' * NUM_CHARS_PER_DISPLAY_STRIP)
		else:
			display_string = str(display_string)
		if ((len(display_string.strip()) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.endswith('dB') and (display_string.find('.') != -1))):
			display_string = display_string[:-2]
		if (len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)):
			for um in [' ',
			 'i',
			 'o',
			 'u',
			 'e',
			 'a']:
				while ((len(display_string) > (NUM_CHARS_PER_DISPLAY_STRIP - 1)) and (display_string.rfind(um, 1) != -1)):
					um_pos = display_string.rfind(um, 1)
					display_string = (display_string[:um_pos] + display_string[(um_pos + 1):])
		else:
			display_string = display_string.center((NUM_CHARS_PER_DISPLAY_STRIP - 1))
		ret = u''
		for i in range((NUM_CHARS_PER_DISPLAY_STRIP - 1)):
			if ((ord(display_string[i]) > 127) or (ord(display_string[i]) < 0)):
				ret += ' '
			else:
				ret += display_string[i]

		ret += ' '
		ret = ret.replace(' ', '_')
		assert (len(ret) == NUM_CHARS_PER_DISPLAY_STRIP)
		return ret
class SwitchboardElement(NotifyingControlElement):
    __module__ = __name__
    __doc__ = ' Class that connects and disconnects monomodular clients'

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, host, clients, *a, **k):
        super(SwitchboardElement, self).__init__(host, clients, *a, **k)
        self._host = host
        self._devices = []
        self.client_0 = clients[0]
        self.client_1 = clients[1]
        self.client_2 = clients[2]
        self.client_3 = clients[3]
        self.client_4 = clients[4]
        self.client_5 = clients[5]
        self._client = clients

    def disconnect(self):
        for client in self._client:
            client = None
        self._client = []
        NotifyingControlElement.disconnect(self)

    def _send(self, args1=None, args2=None, args3=None, args4=None):
        self.notify_value(args1, args2, args3, args4)
        #self._host.log_message('switchboard send' + str(self._host._in_build_midi_map) + str(self._host._enabled) + str(args1) + str(args2) + str(args3) + str(args4))
        """for entry in self._value_notifications:
			callback = entry['Callback']
			try:
				callback(args1, args2, args3, args4)
			except:
				self._host.log_message('failed callback ' + str(callback) + ' removing')
				self.remove_value_listener(callback)"""

    def reset(self):
        pass

    def request_connection(self, device, version, inLive=0):
        #self._host.log_message('request_connection ' + str(device))
        if version == self._host._version_check:
            client_num = 6
            for client in self._client:
                if client.device == device:
                    client._disconnect_client()
            for client in self._client:
                if client._connected is False:
                    client._connect_to(device)
                    client_num = client._number
                    break
        else:
            client_num = self._host._version_check
        return client_num

    def force_connection(self, device, client_number, version):
        #self._host.log_message('force ' + str(device) + ' ' + str(client_number) + ' build ' + str(self._host._in_build_midi_map))
        if version == self._host._version_check:
            for client in self._client:
                if client.device == device:
                    client._disconnect_client()
            self._client[client_number]._disconnect_client(True)
            self._client[client_number]._connect_to(device)
        else:
            client_number = self._host._version_check
        return client_number

    def set_client_enabled(self, client_num, enabled):
        self._client[client_num].set_enabled(enabled)
class TouchEncoderElement(EncoderElement, SlotManager):
    """ Class representing an encoder that is touch sensitive """
    __subject_events__ = (SubjectEvent(name='double_tap'), )

    def __init__(self,
                 msg_type,
                 channel,
                 identifier,
                 map_mode,
                 undo_step_handler=None,
                 delete_handler=None,
                 touch_button=None,
                 *a,
                 **k):
        super(TouchEncoderElement,
              self).__init__(msg_type, channel, identifier, map_mode, *a, **k)
        self._trigger_undo_step = False
        self._undo_step_open = False
        self._undo_step_handler = undo_step_handler
        self._delete_handler = delete_handler
        self._tap_count = 0
        self._tap_task = self._tasks.add(
            Task.sequence(Task.wait(consts.TAPPING_DELAY),
                          Task.run(self._reset_tapping)))
        self._tap_task.kill()
        self.set_touch_button(touch_button)
        self.set_observer(None)

    def is_pressed(self):
        button = self._on_touch_button.subject
        return button and button.is_pressed()

    def set_touch_button(self, touch_button):
        self._on_touch_button.subject = touch_button

    def set_observer(self, observer):
        self._observer = observer or TouchEncoderObserver()

    def _delete_clip_automation(self):
        mapped_parameter = self.mapped_parameter()
        if mapped_parameter:
            selected_track = self._undo_step_handler.view.selected_track
            playing_slot_index = selected_track.playing_slot_index
            if playing_slot_index >= 0:
                playing_clip = selected_track.clip_slots[
                    playing_slot_index].clip
                if playing_clip:
                    playing_clip.clear_envelope(mapped_parameter)

    @subject_slot('value')
    def _on_touch_button(self, value):
        self._trigger_undo_step = value
        if value:
            param = self.mapped_parameter()
            if self._delete_handler and self._delete_handler.is_deleting and param:
                self._delete_handler.delete_clip_envelope(param)
            else:
                self.begin_gesture()
                self._observer.on_encoder_touch(self)
        else:
            if self._undo_step_open:
                self._undo_step_handler.end_undo_step()
            self._observer.on_encoder_touch(self)
            self.end_gesture()
            self._tap_count += 1
            if self._tap_count > 1:
                self.notify_double_tap()
                self._reset_tapping()
            else:
                self._tap_task.restart()

    def _reset_tapping(self):
        self._tap_count = 0

    def connect_to(self, parameter):
        if parameter != self.mapped_parameter():
            super(TouchEncoderElement, self).connect_to(parameter)
            self._observer.on_encoder_parameter(self)

    def release_parameter(self):
        if self.mapped_parameter() != None:
            super(TouchEncoderElement, self).release_parameter()
            self._observer.on_encoder_parameter(self)

    def receive_value(self, value):
        self._reset_tapping()
        if self._trigger_undo_step:
            self._undo_step_handler.begin_undo_step()
            self._trigger_undo_step = False
            self._undo_step_open = True
        super(TouchEncoderElement, self).receive_value(value)
class ScrollableListComponent(ControlSurfaceComponent):
    """
    Component for handling a list of options with a limtied set of
    buttons and display segments.
    """
    __subject_events__ = (
        SubjectEvent(name='change_option',
                     doc=' Event signaled when the selected option changes '),
        SubjectEvent(
            name='press_option',
            signal=short_circuit_signal,
            doc=
            '\n       Event signaled when an option is pressed getting the option as\n       parameter.  The ScrollableListComponent is connected to it, if\n       you want to override selection behaviour, connect to the front\n       and return True from your handler.\n       '
        ))
    num_segments = 8
    display_line = 3
    jump_size = 3
    ARROW_LEFT = '   <<   '
    ARROW_RIGHT = '   >>   '

    def __init__(self, *a, **k):
        super(ScrollableListComponent, self).__init__(*a, **k)
        self._data_sources = [
            DisplayDataSource() for _ in range(self.num_segments)
        ]
        self._selected_option = None
        self._offset_index = 0
        self._option_names = []
        self._select_buttons = []
        self._select_button_slots = self.register_slot_manager()
        self.register_slot(self, self._set_selected_option, 'press_option')

    def set_display_line(self, line):
        if line:
            sources = self._data_sources
            line.set_num_segments(len(sources))
            for segment in xrange(len(sources)):
                line.segment(segment).set_data_source(sources[segment])

    def set_select_buttons(self, buttons):
        self._select_button_slots.disconnect()
        self._select_buttons = buttons or []
        for b in self._select_buttons:
            if b:
                b.set_on_off_values('Option.Selected', 'Option.Unselected')
            self._select_button_slots.register_slot(
                b,
                self._on_select_value,
                'value',
                extra_kws=dict(identify_sender=True))

        self.update()

    @property
    def offset_index(self):
        return self._offset_index

    def scroll_right(self):
        return self._scroll(1)

    def scroll_left(self):
        return self._scroll(-self.jump_size)

    def _get_option_names(self):
        return self._option_names

    def _set_option_names(self, names):
        self._option_names = names
        self._normalize_offset()
        self.update()

    option_names = property(_get_option_names,
                            lambda self, x: self._set_option_names(x))

    def _get_selected_option(self):
        return self._selected_option

    def _set_selected_option(self, selected_option):
        if not (selected_option != self._selected_option and
                (selected_option == None
                 or in_range(selected_option, 0, self._option_names))):
            raise AssertionError
            self._selected_option = selected_option
            self.notify_change_option(selected_option)
            self.update()

    selected_option = property(_get_selected_option, _set_selected_option)

    def _has_select_button(self, index):
        return len(
            self._select_buttons
        ) == self.num_segments and self._select_buttons[index] != None

    def _maximal_offset(self):
        if len(self._option_names) > self.num_segments:
            return len(self._option_names) - self.num_segments + 1
        else:
            return 0

    def _normalize_offset(self):
        quantized_offset = self._offset_index - self._offset_index % -self.jump_size
        self._offset_index = max(0,
                                 min(self._maximal_offset(), quantized_offset))

    def _scroll(self, delta):
        old_offset = self._offset_index
        self._offset_index += delta
        self._normalize_offset()
        if self._offset_index != old_offset:
            self.update()
            return True
        return False

    def _on_select_value(self, value, sender):
        if not self.is_enabled() or not value:
            return
        index = list(self._select_buttons).index(sender)
        if index == 0 and self._offset_index != 0:
            self.scroll_left()
        elif index == self.num_segments - 1 and self._offset_index < self._maximal_offset(
        ):
            self.scroll_right()
        elif self._offset_index == 0:
            self.notify_press_option(
                index if index < len(self._option_names) else None)
        else:
            self.notify_press_option(index + self._offset_index - 1)

    def _get_display_string(self, option_index):
        if option_index < len(self._option_names):
            decorator = consts.CHAR_SELECT if option_index == self.selected_option else ''
            return decorator + self._option_names[option_index]
        else:
            return ''

    def update(self):
        super(ScrollableListComponent, self).update()
        if not self.is_enabled():
            return
        first_segment, max_segment = 0, self.num_segments
        if self._offset_index > 0:
            self._data_sources[0].set_display_string(self.ARROW_LEFT)
            if self._has_select_button(0):
                self._select_buttons[0].set_light('List.ScrollerOn')
            first_segment = 1
        if self._offset_index < self._maximal_offset():
            self._data_sources[-1].set_display_string(self.ARROW_RIGHT)
            if self._has_select_button(-1):
                self._select_buttons[-1].set_light('List.ScrollerOn')
            max_segment -= 1
        for i, j in zip(
                xrange(first_segment, max_segment),
                xrange(self._offset_index,
                       self._offset_index + self.num_segments)):
            self._data_sources[i].set_display_string(
                self._get_display_string(j))
            if self._has_select_button(i):
                if i < len(self.option_names):
                    if j == self.selected_option:
                        self._select_buttons[i].turn_on()
                    else:
                        self._select_buttons[i].turn_off()
                else:
                    self._select_buttons[i].set_light('Option.Unused')
class SwitchboardElement(NotifyingControlElement):
    __module__ = __name__
    __doc__ = ' Class that connects and disconnects monomodular clients'

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, host, clients, *a, **k):
        super(SwitchboardElement, self).__init__(host, clients, *a, **k)
        self._host = host
        self._devices = []
        for index in range(len(clients)):
            setattr(self, 'client_' + str(index), clients[index])
        self._client = clients

    def disconnect(self):
        for client in self._client:
            client = None
        self._client = []
        super(SwitchboardElement, self).disconnect()

    def send_swing(self, client, val):
        self._host._client[client].receive_swing(val)

    def receive_swing(self, client, val):
        self._send('receive_swing', client, val)

    def disconnect_client(self, device):
        for client in self._client:
            if client.device == device:
                client._disconnect_client()

    def reset(self):
        pass

    def _send(self, args1=None, args2=None, args3=None, args4=None):
        self.notify_value(args1, args2, args3, args4)

    def reset_callbacks(self):
        pass

    def request_connection(self, device, version, inLive=0):
        #self._host.log_message('request_connection ' + str(device))
        if version == self._host._version_check:
            client_num = len(self._client)
            for client in self._client:
                if client.device == device:
                    client._disconnect_client()
            for client in self._client:
                if client._connected is False:
                    client._connect_to(device)
                    client_num = client._number
                    break
        else:
            client_num = self._host._version_check
        return client_num

    def force_connection(self, device, client_number, version):
        #self._host.log_message('force ' + str(device) + ' ' + str(client_number) + ' build ' + str(self._host._in_build_midi_map))
        if version == self._host._version_check:
            for client in self._client:
                if client.device == device:
                    client._disconnect_client()
            self._client[client_number]._disconnect_client(True)
            self._client[client_number]._connect_to(device)
        else:
            client_number = self._host._version_check
        return client_number

    def editor_connection(self, device, version):
        #self._host.log_message('editor_connection ' + str(device) + ' ' + ' build ' + str(self._host._in_build_midi_map))
        if version == self._host._version_check:
            client_num = len(self._client)
            for client in self._client:
                if client._connected is False:
                    client._connect_to(device)
                    client_num = client._number
                    break
        else:
            client_num = self._host._version_check
        return client_num

    def set_client_enabled(self, client_num, enabled):
        self._client[client_num].set_enabled(enabled)
示例#9
0
class MonoClient(NotifyingControlElement):
    __module__ = __name__
    __doc__ = ' Class representing a single mod in a Monomodular hosted environment '

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, script, number, *a, **k):
        super(MonoClient, self).__init__(script, number, *a, **k)
        self._host = script
        self._is_monolink = False
        self._active_host = []
        self._number = number
        self._channel = 0
        self._connected = False
        self._enabled = True
        self.device = None
        self._device_parent = None
        self._device_component = None
        self._swing = 0
        self._mute = 0
        self._autoselect_enabled = 0
        self._offset = [0, 0]
        self._color_maps = []
        self._report_offset = False
        self._local_ring_control = 1
        self._c_local_ring_control = 1
        self._controls = [{}, {}]
        self._create_grid()
        self._create_keys()
        self._create_wheels()
        self._create_c_grid()
        self._create_c_keys()
        self._create_c_wheels()
        self._create_c_knobs()
        self._absolute_mode = 1
        self._c_absolute_mode = 1
        self._parameters = []
        self._mod_dial = None
        self._mod_vol = 127
        self._mod_color = 0
        self._device_component = MonoDeviceComponent(self)
        self._banner_state = 0
        self._monomodular = 0

    def is_active(self):
        return (len(self._active_host) > 0)

    def set_enabled(self, val):
        self._enabled = val != 0

    def _banner(self):
        if not self.is_connected() and len(self._active_host) > 0:
            if self._banner_state < 54:
                self.receive_grid_all(0)
                for index in range(16):
                    for y in range(len(LOGO[self._banner_state + index])):
                        self.receive_grid(
                            index, LOGO[self._banner_state + index][y][0],
                            LOGO[self._banner_state + index][y][1])
                self._banner_state += 1
                self._host.schedule_message(1, self._banner)
            else:
                self._banner_state = 0

    def is_connected(self):
        return self._connected

    def disconnect(self):
        #self._device_component.disconnect()
        self._active_host = []
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        super(MonoClient, self).disconnect()
        self._enabled = True
        self._c_local_ring_control = 1
        self._local_ring_control = 1
        self._c_absolute_mode = 1
        self._absolute_mode = 1

    def reset(self):
        pass

    def _connect_to(self, device):
        #self._host.log_message('client ' + str(self._number) + ' connect_to'  + str(device.name))
        self._connected = True
        self.device = device
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        self._device_parent = device.canonical_parent
        if not self._device_parent.devices_has_listener(self._device_listener):
            self._device_parent.add_devices_listener(self._device_listener)
        self._mute = 0
        self._send('toggle_mute', self._mute)
        for host in self._active_host:
            host.update()

    def _disconnect_client(self, reconnect=False):
        #self._host.log_message('disconnect client ' + str(self._number))
        self._create_grid()
        self._create_keys()
        self._create_wheels()
        self._create_c_grid()
        self._create_c_keys()
        self._create_c_wheels()
        self._create_c_knobs()
        self.set_local_ring_control(1)
        self.set_absolute_mode(1)
        self.set_c_local_ring_control(1)
        self.set_c_absolute_mode(1)
        self._mod_vol = 127
        self._mod_color = 0
        self._monomodular = 0
        self._swing = 0
        self._report_offset = False
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        if reconnect == True:
            self._send('reconnect')
        if not self._device_component is None:
            self._device_component.disconnect_client()
        self._connected = False
        self.device = None
        for host in self._active_host:
            host.update()
            if not host.is_enabled() and 'display_mod_colors' in dir(host):
                host.display_mod_colors()

    def _device_listener(self):
        #self._host.log_message('device_listener' + str(self.device))
        if self.device == None:
            self._disconnect_client()

    def linked_device(self):
        return self.device

    """initiation methods"""

    def _create_grid(self):
        self._grid = [None for index in range(16)]
        for column in range(16):
            self._grid[column] = [None for index in range(16)]
            for row in range(16):
                self._grid[column][row] = 0

    def _create_keys(self):
        self._key = [None for index in range(8)]
        for index in range(8):
            self._key[index] = 0

    def _create_wheels(self):
        self._wheel = [[] for index in range(9)]
        for column in range(9):
            self._wheel[column] = [[] for index in range(5)]
            for row in range(5):
                self._wheel[column][row] = {
                    'log': 0,
                    'value': 0,
                    'mode': 0,
                    'white': 0,
                    'green': 0,
                    'custom': '00000000',
                    'pn': ' ',
                    'pv': '0'
                }

    """send methods (to m4l from host)"""

    def _send(self, args1=None, args2=None, args3=None, args4=None):
        if self._enabled is True:
            self.notify_value(args1, args2, args3, args4)

    def _send_key(self, index, value):
        self._send('key', index, value)

    def _send_grid(self, column, row, value):
        self._send('grid', column, row, value)

    def _send_offset(self, x, y):
        self._offset = [x, y]
        if (self._report_offset is True):
            self._send('offset', x, y)

    """receive methods (from m4l)"""

    def receive_key(self, index, value=0):
        if self._key[index] != value:
            self._key[index] = value
            for host in self._active_host:
                host._send_key(index, value)

    def receive_grid(self, column, row, value=0):
        if self._grid[column][row] != value:
            self._grid[column][row] = value
            for host in self._active_host:
                host._send_grid(column, row, value)

    def receive_grid_row(self, row, value=0):
        g_len = len(self._grid)
        for column in xrange(g_len):
            self._grid[column][row] = value
        for host in self._active_host:
            for column in xrange(g_len):
                host._send_grid(column, row, value)

    def receive_grid_column(self, column, value=0):
        g_len = len(self._grid[column])
        for row in xrange(g_len):
            self._grid[column][row] = value
        for host in self._active_host:
            for row in xrange(g_len):
                host._send_grid(column, row, value)

    def receive_grid_all(self, value=0):
        for column in xrange(len(self._grid)):
            for row in xrange(len(self._grid[column])):
                self._grid[column][row] = value
                #if self.is_active():
                for host in self._active_host:
                    #for column in range(len(self._grid)):
                    #for row in range(len(self._grid[column])):
                    host._send_grid(column, row, value)

    def receive_mask_key(self, num, value=-1):
        #if self.is_active():
        if value > -1:
            for host in self._active_host:
                host._send_key(num, value)
        else:
            for host in self._active_host:
                host._send_key(num, int(self._key[num]))

    def receive_mask_grid(self, column, row, value=-1):
        if value > -1:
            for host in self._active_host:
                host._send_grid(column, row, value)
        else:
            for host in self._active_host:
                host._send_grid(column, row, int(self._grid[column][row]))

    def receive_mask_column(self, column, value=-1):
        if value > -1:
            for host in self._active_host:
                for index in xrange(16):
                    host._send_grid(column, index, value)
        else:
            for host in self._active_host:
                for index in xrange(16):
                    host._send_grid(column, index, self._grid[column][index])

    def receive_mask_row(self, row, value=-1):
        hosts = self._active_host
        if value > -1:
            for index in xrange(16):
                for host in hosts:
                    host._send_grid(index, row, value)
        else:
            for host in self._active_host:
                for index in xrange(16):
                    host._send_grid(index, row, self._grid[index][row])

    def receive_mask_all(self, value=-1):
        if value > -1:
            for host in self._active_host:
                for column in xrange(16):
                    for row in xrange(16):
                        host._send_grid(column, row, value)
        else:
            for host in self._active_host:
                for column in xrange(16):
                    for row in xrange(16):
                        host._send_grid(column, row, self._grid[index][row])

    def receive_hotline(self, client, func=None, arguments=None):
        #self._host.log_message(str(client) + ' ' + str(func) + ' ' + str(arguments))
        if (client == 'all') and (func != None):
            for index in xrange(16):
                self._host._client[index]._send('hotline', func, arguments)
        elif (client in xrange(16)) and (func != None):
            self._host._client[client]._send('hotline', func, arguments)

    def receive_autoselect_enabled(self, val=0):
        self._autoselect_enabled = val

    def receive_swing(self, swing=0):
        self._swing = swing
        self._send('swing', swing)

    def report_swing(self, swing=0):
        self._send('report_swing', swing)

    def toggle_mute(self):
        self._mute = abs(self._mute - 1)
        self._send('toggle_mute', self._mute)

    def set_mute(self, val=0):
        self._mute = val

    def receive_channel(self, channel=0):
        if channel in range(16):
            self._channel = channel

    def autoselect_enabled(self=0):
        return self._autoselect_enabled > 0

    def _autoselect(self):
        if self.autoselect_enabled():
            if self.device != None:
                for host in self._active_host:
                    host.set_appointed_device(self.device)

    def _set_channel(self, channel):
        self._send('channel', channel)
        self._channel = channel

    def set_report_offset(self, val=0):
        self._report_offset = (val == 1)
        self._send_offset(self._offset[0], self._offset[1])

    def set_monomodular(self, val=0):
        self._monomodular = val

    def set_color_map(self, color_type, color_map):
        for host in self._host._hosts:
            #self._host.log_message(str(host._host_name) + str(host_name))
            if str(host._script._color_type) == str(color_type):
                #new_map = [color_map[i] for i in range(len(color_map))]
                #self._host.log_message('mapping ' + str(host_name) + ' to ' + str(self._number))
                new_map = color_map.split('*')
                for index in xrange(len(new_map)):
                    new_map[index] = int(new_map[index])
                #self._host.log_message(str(host_name) + str(new_map))
                host._color_maps[self._number] = new_map
                if host._active_client is self:
                    host._select_client(self._number)
                #self._host.log_message(str(host_name) + ' ' + str(color_map.split('*')))

    def linked_device(self):
        return self.device

    """CNTRL:R specific methods"""

    def _create_c_grid(self):
        self._c_grid = [None for index in range(4)]
        for column in range(4):
            self._c_grid[column] = [None for index in range(4)]
            for row in range(4):
                self._c_grid[column][row] = 0

    def _create_c_keys(self):
        self._c_key = [None for index in range(32)]
        for index in range(32):
            self._c_key[index] = 0

    def _create_c_knobs(self):
        self._knob = [None for index in range(24)]
        for index in range(24):
            self._knob[index] = 0

    def _create_c_wheels(self):
        self._c_wheel = [[] for index in range(4)]
        for column in range(4):
            self._c_wheel[column] = [[] for index in range(3)]
            for row in range(3):
                self._c_wheel[column][row] = {
                    'log': 0,
                    'value': 0,
                    'mode': 0,
                    'white': 0,
                    'green': 0,
                    'custom': '00000000',
                    'pn': ' ',
                    'pv': '0'
                }

    def _send_c_knob(self, index, value=0):
        self._send('c_knob', index, value)

    def _send_c_key(self, index, value=0):
        self._send('c_key', index, value)

    def _send_c_grid(self, column, row, value=0):
        self._send('c_grid', column, row, value)

    def _send_c_dial(self, column, row, value=0):
        self._send('c_dial', column, row, value)

    def _send_c_dial_button(self, column, row, value=0):
        if row > 0:
            self._send('c_dial_button', column, row - 1, value)

    def receive_c_key(self, index, value=0):
        if self._c_key[index] != value:
            self._c_key[index] = value
            for host in self._active_host:
                host._send_c_key(index, value)

    def receive_c_grid(self, column, row, value=0):
        if self._c_grid[column][row] != value:
            self._c_grid[column][row] = value
            for host in self._active_host:
                host._send_c_grid(column, row, value)

    def receive_c_grid_row(self, row, value=0):
        g_len = len(self._c_grid)
        for column in xrange(g_len):
            self._c_grid[column][row] = value
        for host in self._active_host:
            for column in xrange(g_len):
                host._send_c_grid(column, row, value)

    def receive_c_grid_column(self, column, value=0):
        g_len = len(self._c_grid[0])
        for row in xrange(g_len):
            self._c_grid[column][row] = value
        for host in self._active_host:
            for row in xrange(g_len):
                host._send_c_grid(column, row, value)

    def receive_c_grid_all(self, value=0):
        g_len = len(self._c_grid)
        g_ht = len(self._c_grid[0])
        for column in xrange(g_len):
            for row in xrange(g_ht):
                self._c_grid[column][row] = value
        for host in self._active_host:
            for column in xrange(g_len):
                for row in xrange(g_ht):
                    host._send_c_grid(column, row, value)

    def receive_mask_c_key(self, num, value=-1):
        if value > -1:
            for host in self._active_host:
                host._send_c_key(num, value)
        else:
            for host in self._active_host:
                host._send_c_key(num, int(self._c_key[num]))

    def receive_mask_c_grid(self, column, row, value=-1):
        if value > -1:
            for host in self._active_host:
                host._send_c_grid(column, row, value)
        else:
            for host in self._active_host:
                host._send_c_grid(column, row, int(self._c_grid[column][row]))

    def receive_mask_c_column(self, column, value=-1):
        if value > -1:
            for host in self._active_host:
                for index in xrange(4):
                    host._send_c_grid(column, index, value)
        else:
            for host in self._active_host:
                for index in xrange(4):
                    host._send_c_grid(column, index,
                                      self._c_grid[column][index])

    def receive_mask_c_row(self, row, value=-1):
        if value > -1:
            for host in self._active_host:
                for index in xrange(4):
                    host._send_c_grid(index, row, value)
        else:
            for host in self._active_host:
                for index in xrange(4):
                    host._send_c_grid(index, row, self._c_grid[index][row])

    def receive_mask_c_all(self, value=-1):
        if value > -1:
            for host in self._active_host:
                for column in xrange(4):
                    for row in xrange(4):
                        host._send_c_grid(column, row, value)
        else:
            for host in self._active_host:
                for column in xrange(4):
                    for row in xrange(4):
                        host._send_c_grid(column, row,
                                          self._c_grid[index][row])

    def receive_c_wheel(self, number, parameter, value):
        column = number % 4
        row = int(number / 4)
        if self._c_wheel[column]:
            if self._c_wheel[column][row]:
                wheel = self._c_wheel[column][row]
                wheel[parameter] = value
                if parameter != 'white':
                    for host in self._active_host:
                        host._send_c_wheel(column, row, wheel, parameter)
                elif row > 0:
                    for host in self._active_host:
                        host._send_c_wheel(column, row, wheel, parameter)

    def _send_c_dial(self, column, row, value):
        self._send('c_dial', column, row, value)

    def _send_c_dial_button(self, column, row, value):
        if row > 0:
            self._send('c_dial_button', column, row - 1, value)

    def set_c_absolute_mode(self, val=1):
        #self._host.log_message('client set absolute mode ' + str(val))
        self._c_absolute_mode = val
        if self._enabled:
            for host in self._active_host:
                if 'set_c_absolute_mode' in dir(host):
                    host.set_c_absolute_mode(self._c_absolute_mode)

    def set_c_local_ring_control(self, val=0):
        self._c_local_ring_control = val
        if self._enabled:
            for host in self._active_host:
                if 'set_c_local_ring_control' in dir(host):
                    host.set_c_local_ring_control(self._c_local_ring_control)

    def receive_mod_color(self, val=0):
        #self._host.log_message('mod color' + str(val))
        if val != 1:
            self._mod_color = val
            for host in self._active_host:
                if '_display_mod_colors' in dir(host):
                    host._display_mod_colors()

    def _mod_dial_parameter(self):
        param = None
        if not self.device == None:
            for parameter in self.device.parameters:
                if (parameter.original_name == 'moddial'):
                    param = parameter
                    break
        return param

    def send_midi(self, Type, num, val):
        self._host.send_midi(Type, num, val)

    """Codec specific methods"""

    def _send_dial(self, column, row, value=0):
        self._send('dial', column, row, value)

    def _send_dial_button(self, column, row, value=0):
        if column < 8 and row < 4:
            self._send('dial_button', column, row, value)
        elif row is 4:
            self._send('column_button', column, value)
        else:
            self._send('row_button', row, value)

    def receive_wheel(self, number, parameter, value):
        column = number % 9
        row = int(number / 9)
        if self._wheel[column]:
            if self._wheel[column][row]:
                self._wheel[column][row][parameter] = value
                #if self.is_active():
                if parameter != 'white':
                    for host in self._active_host:
                        host._send_wheel(column, row, self._wheel[column][row],
                                         parameter)
                elif row > -1:
                    for host in self._active_host:
                        host._send_wheel(column, row, self._wheel[column][row],
                                         parameter)

    def set_local_ring_control(self, val=1):
        #self._host.log_message('client set local ring ' + str(val))
        self._local_ring_control = val
        if self._enabled:
            for host in self._active_host:
                if 'set_local_ring_control' in dir(host):
                    host.set_local_ring_control(self._local_ring_control)

    def set_absolute_mode(self, val=1):
        #self._host.log_message('client set absolute mode ' + str(val))
        self._absolute_mode = val
        if self._enabled:
            for host in self._active_host:
                if 'set_absolute_mode' in dir(host):
                    host.set_absolute_mode(self._absolute_mode)

    """MonoDevice integration"""

    def receive_device(self, command, args0=None, args1=None, args2=None):
        if command in dir(self._device_component):
            getattr(self._device_component, command)(args0, args1, args2)
示例#10
0
class ModClient(NotifyingControlElement):

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, parent, device, name, *a, **k):
        super(ModClient, self).__init__(*a, **k)
        self.name = name
        self.device = device
        self._device_parent = None
        self._parent = parent
        self.log_message = parent.log_message
        self._active_handlers = []
        #self._addresses = {'grid':Grid(self.active_handlers, 'grid', 16, 16)}
        self._addresses = {}
        self._translations = {}
        self._translation_groups = {}
        self._color_maps = {}
        self.legacy = False
        for handler in self._parent._handlers:
            handler._register_addresses(self)
        self._param_component = MonoDeviceComponent(self, MOD_BANK_DICT,
                                                    MOD_TYPES)

    def addresses(self):
        return self._addresses

    def translations(self):
        return self._translations

    def active_handlers(self):
        return self._active_handlers

    def receive(self, address_name, method='value', values=0, *a, **k):
        if address_name in self._addresses.keys():
            address = self._addresses[address_name]
            value_list = unpack_items(values)
            #self.log_message('address: ' + str(address) + ' value_list: ' + str(value_list))
            try:
                #with self._parent._host.component_guard():
                getattr(address, method)(*value_list)
            except:
                if debug():
                    self.log_message(
                        'receive method exception %(a)s %(m)s %(vl)s' % {
                            'a': address_name,
                            'm': method,
                            'vl': values
                        })

    def distribute(self, function_name, values=0, *a, **k):
        if hasattr(self, function_name):
            value_list = unpack_items(values)
            #self.log_message('distribute: ' + str(function_name) + ' ' + str(values) + ' ' + str(value_list))
            try:
                getattr(self, function_name)(*value_list)
            except:
                if debug():
                    self.log_message(
                        'distribute method exception %(fn)s %(vl)s' % {
                            'fn': function_name,
                            'vl': value_list
                        })

    def receive_translation(self, translation_name, method='value', *values):
        #value_list = unpack_items(values)
        #self.log_message('receive_translation: ' + str(translation_name) + ' ' + str(method) + ' ' + str(values))
        try:
            self._translations[translation_name].receive(method, *values)
        except:
            if debug():
                self.log_message(
                    'receive_translation method exception %(n)s %(m)s %(vl)s' %
                    {
                        'n': translation_name,
                        'm': method,
                        'vl': values
                    })

    def trans(self, translation_name, method='value', *values):
        #value_list = unpack_items(values)
        #self.log_message('receive_translation: ' + str(translation_name) + 'is avail: ' + str(translation_name in self._translations.keys()) + ' ' + str(method) + ' ' + str(values))# + ' ' + str(value_list))
        try:
            self._translations[translation_name].receive(method, *values)
        except:
            if debug():
                self.log_message(
                    'receive_translation method exception %(n)s %(m)s %(vl)s' %
                    {
                        'n': translation_name,
                        'm': method,
                        'vl': values
                    })

    def send(self, control_name, *a):
        #with self._parent._host.component_guard():
        self.notify_value(control_name, *a)

    def is_active(self):
        return (len(self._active_host) > 0)

    def set_enabled(self, val):
        self._enabled = val != 0

    def is_connected(self):
        return self._connected

    def disconnect(self):
        self._active_handler = []
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        super(ModClient, self).disconnect()
        self._enabled = True

    def reset(self):
        pass

    def restore(self):
        for address_name, address in self._addresses.iteritems():
            address.restore()
        self._param_component.update()

    def _connect_to(self, device):
        self._connected = True
        self.device = device
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        self._device_parent = device.canonical_parent
        if not self._device_parent.devices_has_listener(self._device_listener):
            self._device_parent.add_devices_listener(self._device_listener)
        for handler in self._active_handler:
            handler.update()

    def _disconnect_client(self, reconnect=False):
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        self._connected = False
        self.device = None
        for handler in self._active_handler:
            handler.set_mod(None)

    def _device_listener(self):
        if self.device == None:
            self._disconnect_client()

    def linked_device(self):
        return self.device

    def script_wants_forwarding(self):
        return True

    def add_translation(self, name, target, group=None, *args, **k):
        #self.log_message('name: ' + str(name) + ' target: ' + str(target) + ' args: ' + str(args))
        if target in self._addresses.keys():
            if not name in self._translations.keys():
                self._translations[name] = ElementTranslation(name, self)
            #self.log_message('adding new target')
            self._translations[name].add_target(target,
                                                self._addresses[target], *args)
            if not group is None:
                if not group in self._translation_groups.keys():
                    self._translation_groups[group] = []
                self._translation_groups[group].append([name, target])
                #self.log_message('added to group ' + str(group) + ' : ' + str(self._translation_groups[group]))

    def enable_translation(self, name, target, enabled=True):
        if name in self._translations.keys():
            self._translations[name].set_enabled(target, enabled)

    def enable_translation_group(self, group, enabled=True):
        if group in self._translation_groups.keys():
            for pair in self._translation_groups[group]:
                #self.log_message('enabling for ' + str(pair))
                self.enable_translation(pair[0], pair[1], enabled)

    def receive_device(self, command, *args):
        #self.log_message('receive_device ' + str(command) +str(args))
        try:
            getattr(self._param_component, command)(*args)
        except:
            self.log_message('receive_device exception: %(c)s %(a)s' % {
                'c': command,
                'a': args
            })

    def update_device(self):
        for handler in self.active_handlers():
            handler.update_device()

    def set_legacy(self, value):
        #self.log_message('set_legacy: ' + str(value))
        self.legacy = value > 0

    def select_device_from_key(self, key):
        key = str(key)
        preset = None
        for track in self._parent.song().tracks:
            for device in enumerate_track_device(track):
                if (match(key, str(device.name)) != None):
                    preset = device
                    break
        for return_track in self._parent.song().return_tracks:
            for device in enumerate_track_device(return_track):
                if (match(key, str(device.name)) != None):
                    preset = device
                    break
        for device in enumerate_track_device(self._parent.song().master_track):
            if (match(key, str(device.name)) != None):
                preset = device
                break
        if preset != None:
            self._parent.song().view.select_device(preset)

    def set_color_map(self, color_type, color_map):
        #new_map = color_map.split('*')
        #for index in xrange(len(new_map)):
        #	new_map[index] = int(new_map[index])
        #self._color_maps[color_type] = new_map
        pass
示例#11
0
class ModClient(NotifyingControlElement):

    __subject_events__ = (SubjectEvent(name='value',
                                       signal=InputSignal,
                                       override=True), )
    _input_signal_listener_count = 0

    def __init__(self, parent, device, name, *a, **k):
        super(ModClient, self).__init__(*a, **k)
        self.name = name
        self.device = device
        self._device_parent = None
        self._parent = parent
        self.log_message = parent.log_message
        self._active_handlers = []
        self._addresses = {}
        self.log_message('making modclient')
        for handler in self._parent._handlers:
            handler._register_addresses(self)

    def addresses(self):
        return self._addresses

    def active_handlers(self):
        return self._active_handlers

    def receive(self, address_name, method='value', values=0, *a, **k):
        if address_name in self._addresses.keys():
            address = self._addresses[address_name]
            value_list = unpack_values(values)
            #self.log_message('address: ' + str(address) + ' value_list: ' + str(value_list))
            try:
                getattr(address, method)(*value_list)
            except:
                self.log_message('receive method exception')

    def send(self, control_name, *a):
        self.notify_value(control_name, *a)

    def is_active(self):
        return (len(self._active_host) > 0)

    def set_enabled(self, val):
        self._enabled = val != 0

    def is_connected(self):
        return self._connected

    def disconnect(self):
        self._active_handler = []
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        super(ModClient, self).disconnect()
        self._enabled = True

    def reset(self):
        pass

    def restore(self):
        for address_name, address in self._addresses.iteritems():
            address.restore()

    def _connect_to(self, device):
        self._connected = True
        self.device = device
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        self._device_parent = device.canonical_parent
        if not self._device_parent.devices_has_listener(self._device_listener):
            self._device_parent.add_devices_listener(self._device_listener)
        for handler in self._active_handler:
            handler.update()

    def _disconnect_client(self, reconnect=False):
        if self._device_parent != None:
            if self._device_parent.devices_has_listener(self._device_listener):
                self._device_parent.remove_devices_listener(
                    self._device_listener)
        self._connected = False
        self.device = None
        for handler in self._active_handler:
            handler.update()

    def _device_listener(self):
        if self.device == None:
            self._disconnect_client()

    def linked_device(self):
        return self.device

    def script_wants_forwarding(self):
        return True