def _init_device_component(self, device_controls, bank_controls, global_channel, macro_map_mode): is_momentary = True DeviceButton = partial(ButtonElement, is_momentary, MIDI_CC_TYPE) def make_bank_button(control, name, is_momentary=True): return DeviceButton(global_channel, bank_controls[control], name=name) if device_controls: device = DeviceComponent(device_selection_follows_track_selection=True, name='Device_Component') layer_specs = {} if bank_controls: if has_specification_for('NEXTBANK', bank_controls): layer_specs['bank_next_button'] = make_bank_button('NEXTBANK', 'Device_Next_Bank_Button') if has_specification_for('PREVBANK', bank_controls): layer_specs['bank_prev_button'] = make_bank_button('PREVBANK', 'Device_Previous_Bank_Button') if has_specification_for('TOGGLELOCK', bank_controls): layer_specs['lock_button'] = make_bank_button('TOGGLELOCK', 'Device_Lock_Button') bank_buttons_raw = [] for index in xrange(8): key = 'BANK' + str(index + 1) if key in bank_controls.keys(): control_info = bank_controls[key] channel = global_channel cc = control_info if isinstance(control_info, (tuple, list)): cc = control_info[0] if is_valid_midi_channel(control_info[1]): channel = control_info[1] if is_valid_midi_identifier(cc) and is_valid_midi_channel(channel): name = 'Device_Bank_' + str(index) + '_Button' bank_buttons_raw.append(DeviceButton(channel, cc, name=name)) if len(bank_buttons_raw) > 0: layer_specs['bank_buttons'] = ButtonMatrixElement(rows=[ bank_buttons_raw]) parameter_encoders_raw = [] for index, control_info in enumerate(device_controls): channel = global_channel cc = control_info if isinstance(control_info, (tuple, list)): cc = control_info[0] if is_valid_midi_channel(control_info[1]): channel = control_info[1] if is_valid_midi_identifier(cc) and is_valid_midi_channel(channel): name = 'Device_Parameter_%d_Control' % index parameter_encoders_raw.append(EncoderElement(MIDI_CC_TYPE, channel, cc, macro_map_mode, name=name)) if len(parameter_encoders_raw) > 0: layer_specs['parameter_controls'] = ButtonMatrixElement(rows=[ parameter_encoders_raw]) device.layer = Layer(**layer_specs) self.set_device_component(device)