当前位置: 首页>>代码示例>>Python>>正文


Python mido.open_output方法代码示例

本文整理汇总了Python中mido.open_output方法的典型用法代码示例。如果您正苦于以下问题:Python mido.open_output方法的具体用法?Python mido.open_output怎么用?Python mido.open_output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mido的用法示例。


在下文中一共展示了mido.open_output方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def __init__(self):
        self.pending_queue = []
    
        ports = mido.get_input_names()
        try:
            for port in ports:
                if "Through" not in port and "RPi" not in port and "RtMidOut" not in port and "USB-USB" not in port:
                    self.inport =  mido.open_input(port)
                    print("Inport set to "+port)
        except:
            print ("no input port")
        try:            
            for port in ports:
                if "Through" not in port and "RPi" not in port and "RtMidOut" not in port and "USB-USB" not in port:
                    self.playport =  mido.open_output(port)
                    print("playport set to "+port)
        except:
            print("no playback port")
            
        self.portname = "inport" 
开发者ID:onlaj,项目名称:Piano-LED-Visualizer,代码行数:22,代码来源:visualizer.py

示例2: change_port

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def change_port(self, port, portname):
        try:
            if(port == "inport"):                
                self.inport =  mido.open_input(portname)
            elif(port == "playport"):
                self.playport =  mido.open_output(portname)
            menu.render_message("Changing "+port+" to:", portname, 1500)
        except:
            menu.render_message("Can't change "+port+" to:", portname, 1500) 
开发者ID:onlaj,项目名称:Piano-LED-Visualizer,代码行数:11,代码来源:visualizer.py

示例3: configure_midi_out

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def configure_midi_out(self):
        if self.midi_out_port is None:
            port_name_to_use = None
            for port_name in mido.get_output_names():
                if is_push_midi_out_port_name(port_name, use_user_port=self.use_user_midi_port):
                    port_name_to_use = port_name
                    break
                    
            if port_name_to_use is None:
                raise Push2MIDIeviceNotFound
            
            try:
                self.midi_out_port = mido.open_output(port_name_to_use)
            except OSError as e:
                raise Push2MIDIeviceNotFound 
开发者ID:ffont,项目名称:push2-python,代码行数:17,代码来源:__init__.py

示例4: __init__

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def __init__(self, device, deviceid):
        self.log = get_logger("midi_to_obs_device")
        self._id = deviceid
        self._devicename = device["devicename"]
        self._port_in = 0
        self._port_out = 0

        try:
            self.log.debug("Attempting to open midi port `%s`" % self._devicename)
            # a device can be input, output or ioport. in the latter case it can also be the other two
            # so we first check if we can use it as an ioport
            if self._devicename in mido.get_ioport_names():
                self._port_in = mido.open_ioport(name=self._devicename, callback=self.callback, autoreset=True)
                self._port_out = self._port_in
            # otherwise we try to use it separately as input and output
            else:
                if self._devicename in mido.get_input_names():
                    self._port_in = mido.open_input(name=self._devicename, callback=self.callback)
                if self._devicename in mido.get_output_names():
                    self._port_out = mido.open_output(name=self._devicename, callback=self.callback, autoreset=True)
        except:
            self.log.critical("\nCould not open device `%s`" % self._devicename)
            self.log.critical("The midi device might be used by another application/not plugged in/have a different name.")
            self.log.critical("Please close the device in the other application/plug it in/select the rename option in the device management menu and restart this script.")
            self.log.critical("Currently connected devices:")
            for name in mido.get_input_names():
                self.log.critical("  - %s" % name)
            # EIO 5 (Input/output error)
            exit(5) 
开发者ID:lebaston100,项目名称:MIDItoOBS,代码行数:31,代码来源:main.py

示例5: __init__

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def __init__(self, input_midi_ports, output_midi_ports, texture_type,
               passthrough=True, playback_channel=0, playback_offset=0.0):
    self._texture_type = texture_type
    self._passthrough = passthrough
    self._playback_channel = playback_channel
    self._playback_offset = playback_offset
    # When `passthrough` is True, this is the set of open MIDI note pitches.
    self._open_notes = set()
    # This lock is used by the serialized decorator.
    self._lock = threading.RLock()
    # A dictionary mapping a compiled MidiSignal regex to a condition variable
    # that will be notified when a matching messsage is received.
    self._signals = {}
    # A dictionary mapping a compiled MidiSignal regex to a list of functions
    # that will be called with the triggering message in individual threads when
    # a matching message is received.
    self._callbacks = collections.defaultdict(list)
    # A dictionary mapping integer control numbers to most recently-received
    # integer value.
    self._control_values = {}
    # Threads actively being used to capture incoming messages.
    self._captors = []
    # Potentially active player threads.
    self._players = []
    self._metronome = None

    # Open MIDI ports.

    inports = []
    if input_midi_ports:
      for port in input_midi_ports:
        if isinstance(port, mido.ports.BaseInput):
          inport = port
        else:
          virtual = port not in get_available_input_ports()
          if virtual:
            tf.logging.info(
                "Opening '%s' as a virtual MIDI port for input.", port)
          inport = mido.open_input(port, virtual=virtual)
        # Start processing incoming messages.
        inport.callback = self._timestamp_and_handle_message
        inports.append(inport)
      # Keep references to input ports to prevent deletion.
      self._inports = inports
    else:
      tf.logging.warn('No input port specified. Capture disabled.')
      self._inports = None

    outports = []
    for port in output_midi_ports:
      if isinstance(port, mido.ports.BaseOutput):
        outports.append(port)
      else:
        virtual = port not in get_available_output_ports()
        if virtual:
          tf.logging.info(
              "Opening '%s' as a virtual MIDI port for output.", port)
        outports.append(mido.open_output(port, virtual=virtual))
    self._outport = mido.ports.MultiPort(outports) 
开发者ID:magenta,项目名称:magenta,代码行数:61,代码来源:midi_hub.py

示例6: _start

# 需要导入模块: import mido [as 别名]
# 或者: from mido import open_output [as 别名]
def _start():
    """Start the module
    This uses the global variables from setup and adds a set of global variables
    """
    global parser, args, config, r, response, patch, name
    global monitor, debug, mididevice, outputport, lock, trigger, port, channel, previous_val, previous_port_val

    # this can be used to show parameters that have changed
    monitor = EEGsynth.monitor(name=name, debug=patch.getint('general', 'debug'))

    # get the options from the configuration file
    debug = patch.getint('general', 'debug')
    mididevice = patch.getstring('midi', 'device')
    mididevice = EEGsynth.trimquotes(mididevice)
    mididevice = process.extractOne(mididevice, mido.get_output_names())[0]  # select the closest match

    # this is only for debugging, check which MIDI devices are accessible
    monitor.info('------ OUTPUT ------')
    for port in mido.get_output_names():
        monitor.info(port)
    monitor.info('-------------------------')

    try:
        outputport = mido.open_output(mididevice)
        monitor.success('Connected to MIDI output')
    except:
        raise RuntimeError("cannot connect to MIDI output")

    # this is to prevent two messages from being sent at the same time
    lock = threading.Lock()

    # each of the gates that can be triggered is mapped onto a different message
    trigger = []
    for channel in range(0, 16):

        # channels are one-offset in the ini file, zero-offset in the code
        name = 'channel{}'.format(channel + 1)
        if config.has_option('gate', name):

            # start the background thread that deals with this channel
            this = TriggerThread(patch.getstring('gate', name), channel)
            trigger.append(this)
            monitor.debug(name + ' trigger configured')

    # start the thread for each of the notes
    for thread in trigger:
        thread.start()

    # control values are only relevant when different from the previous value
    previous_val = {}
    previous_port_val = {}
    for channel in range(0, 16):
        name = 'channel{}'.format(channel + 1)
        previous_val[name] = None
        previous_port_val[name] = None

    # there should not be any local variables in this function, they should all be global
    if len(locals()):
        print("LOCALS: " + ", ".join(locals().keys())) 
开发者ID:eegsynth,项目名称:eegsynth,代码行数:61,代码来源:endorphines.py


注:本文中的mido.open_output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。