Exemple #1
0
  def _create_midi_element(self, ctrl, ch = 0, is_cc = True):
    """
    Returns a new MIDI element (either CC or note), e.g., for controlling lights
    on a MIDI device. Typical usage:

    e = self._create_midi_element(60, 0, is_cc = False)  # MIDI note 60, ch 0.
    e.send_value(127, force = True)

    Note that you don't have to set force = True if the element was returned by
    _register_slider or _register_trigger.
    """
    return InputControlElement(
        MIDI_CC_TYPE if is_cc else MIDI_NOTE_TYPE, ch, ctrl)
 def register_midi_control(self, name, status, number):
     message = (status, number)
     if not (isinstance(status, int) and status & 240 in (144, 176, 224)
             and isinstance(number, int) and 0 <= number <= 127):
         raise RuntimeError(
             'register_midi_control requires parameters: name, status byte, note/CC number\n    name:\n        as used for grab/release\n    status byte:\n        0x9n for note-on/off\n        0xBn for control change\n        0xEn for pitch bend\n        where n is the channel in range 0x0..0xF\n    note/CC number:\n        0...127 (ignored for pitch bend)\n'
         )
     if name in self._registered_control_names:
         raise RuntimeError(
             "a control called '%s' has already been registered" % name)
     if message in self._registered_messages:
         raise RuntimeError(
             'a control with status %d and note/CC number %d has already been registered'
             % message)
     with self.component_guard():
         element = InputControlElement(msg_type=STATUS_TO_TYPE[(status
                                                                & 240)],
                                       channel=status & 15,
                                       identifier=number,
                                       name=name)
         self._registered_control_names.append(name)
         self._registered_messages.append(message)
     return element