def __init__(self, name=DEFAULT_NAME, topic=None, message_type=None, sub_topic=None, sub_message_type=None,
                 queue_size=10, **kwargs):
        Adapter.__init__(self, name, **kwargs)

        msg_type_class = utils.attempt_import(message_type, _myvars=vars())
        self._js_publisher = ROSPublisher(name=name, topic=topic, message_type=msg_type_class, queue_size=queue_size,
                                          **kwargs)

        if sub_topic is not None and sub_message_type is not None:
            sub_msg_type_class = utils.attempt_import(sub_message_type, _myvars=vars())
            self._js_subscriber = rospy.Subscriber(sub_topic, sub_msg_type_class,
                                                   self.callback) if sub_topic is not None else None
        self._js = None
        self._new_js = JointState()
Exemple #2
0
 def _setup_board_config(self, serial=None, controls=None, **kwargs):# pylint: disable=unused-argument
     self._serial = serial
     LOGGER.info('Configuring VirtualMIDI: %s', serial)
     for control_type in controls.get('types', []):
         control_params = control_type.copy()
         control_type_class = utils.attempt_import(control_params['type'], _myvars=vars())
         del control_params['type']
         for control in controls.get(control_type['name']):
             this_control_params = control_params.copy()
             this_control_params.update(control)
             ctrl = Control.create_control(control_type_class, **this_control_params)
             self.add_control(ctrl)
Exemple #3
0
    def _setup_config(self, config=None, name=None, adapters=None, controls=None, **kwargs):# pylint: disable=unused-argument
        self._user_config_description = name
        if isinstance(config, str):
            config = utils.load_from_file(config)
        if not isinstance(config, dict):
            raise TypeError('MIDI board config file not specified.')
        self._setup_board_config(**config)
        for adapter_type in adapters:
            adapter_params = adapter_type.copy()
            adapter_type_class = utils.attempt_import(adapter_params['type'], _myvars=vars())
            del adapter_params['type']
            adapter = Adapter.create_adapter(adapter_type_class, **adapter_params)
            self.add_adapter(adapter)

        for control_type in controls:
            for control in controls.get(control_type):
                try:
                    self._configure_control(control)
                except KeyError as key_err:
                    LOGGER.warning('VirtualMIDI::_setup_user_config() -- Malformed control; requires key: %s', key_err)
                except AttributeError as att_err:
                    LOGGER.warning('VirtualMIDI::_setup_user_config() -- Unknown callback: %s', att_err)
Exemple #4
0
    def _configure_control(self, control_data):
        control = self._controls.get(control_data['identifier'], None)
        if not control:
            control_type = control_data['type']
            control_type_class = utils.attempt_import(control_type, _myvars=vars())
            control = Control.create_control(control_type_class, **control_data)
            self.add_control(control)
            LOGGER.warning('VirtualMIDI::_configure_control() -- Control.identifier %s not found. '
                           'This control is created virtually..', control_data['identifier'])

        for key in control.properties:
            try:
                old_key = getattr(control, key)
                setattr(control, key, control_data[key])
                if old_key in self._control_map[key]:
                    del self._control_map[key][old_key]
                self._control_map[key][control_data[key]] = control
            except KeyError:
                pass
        for signal_name in control_data['signals']:
            signal = control_data['signals'][signal_name]
            self._configure_control_signal(control, signal_name, signal)
        return True
Exemple #5
0
 def create_adapter(adapter_type, **kwargs):
     """Create an adapter from kwargs."""
     adapter_type = attempt_import(adapter_type)
     adapter = adapter_type(**kwargs)
     return adapter
Exemple #6
0
 def create_control(control_type, **kwargs):
     """Create a control from a dict of kwargs."""
     control_type = attempt_import(control_type)
     return control_type(**kwargs)