def setup_input(self): api_in = MidiIn() api_in.ignore_types(sysex=False) port_in = self.get_mixer_port(api_in) try: midi_in, port_name = open_midiinput(port_in, interactive=False) except InvalidPortError: return except NoDevicesError: return midi_in.ignore_types(sysex=False) midi_in.set_callback(self.listener) self.api_in = api_in self.input = midi_in return port_name
def get_ports(port_name: str, *, clock_source: bool = False) -> Tuple[MidiIn, MidiOut]: midi_in = MidiIn() midi_out = MidiOut() midi_in_ports = midi_in.get_ports() midi_out_ports = midi_out.get_ports() try: midi_in.open_port(midi_in_ports.index(port_name)) except ValueError: raise ValueError(port_name) from None if clock_source: midi_in.ignore_types(timing=False) try: midi_out.open_port(midi_out_ports.index(port_name)) except ValueError: raise ValueError(port_name) from None return midi_in, midi_out