コード例 #1
0
    def __init__(self, device_id, latency=0, buffer_size=4096):
        """Output(device_id)
        Output(device_id, latency = 0)
        Output(device_id, buffer_size = 4096)
        Output(device_id, latency, buffer_size)

        The buffer_size specifies the number of output events to be
        buffered waiting for output.  (In some cases -- see below --
        PortMidi does not buffer output at all and merely passes data
        to a lower-level API, in which case buffersize is ignored.)

        latency is the delay in milliseconds applied to timestamps to determine
        when the output should actually occur. (If latency is < 0, 0 is
        assumed.)

        If latency is zero, timestamps are ignored and all output is delivered
        immediately. If latency is greater than zero, output is delayed until
        the message timestamp plus the latency. (NOTE: time is measured
        relative to the time source indicated by time_proc. Timestamps are
        absolute, not relative delays or offsets.) In some cases, PortMidi
        can obtain better timing than your application by passing timestamps
        along to the device driver or hardware. Latency may also help you
        to synchronize midi data to audio data by matching midi latency to
        the audio buffer latency.
        """

        _check_init()
        self._aborted = 0

        if device_id == -1:
            raise MidiException("Device id is -1, not a valid output id."
                                "  -1 usually means there were no default "
                                "Output devices.")

        try:
            result = get_device_info(device_id)
        except TypeError:
            raise TypeError("an integer is required")
        except OverflowError:
            raise OverflowError("long int too large to convert to int")

        # and now some nasty looking error checking, to provide nice error
        #   messages to the kind, lovely, midi using people of wherever.
        if result:
            _, _, is_input, is_output, _ = result
            if is_output:
                try:
                    self._output = _pypm.Output(device_id, latency)
                except TypeError:
                    raise TypeError("an integer is required")
                self.device_id = device_id

            elif is_input:
                raise MidiException("Device id given is not a valid output "
                                    "id, it is an input id.")
            else:
                raise MidiException("Device id given is not a"
                                    " valid output id.")
        else:
            raise MidiException("Device id invalid, out of range.")
コード例 #2
0
    def connectOutput(self, device=None):
        """
        Connect output to send data to VMeter.
        If no device number is specified, attempts to connect
        to the first unopened output device with "VMeter" in the name.
        """
        if device is None:
            a = [
                i for (i, (_, name, inp, outp,
                           opened)) in enumerate(get_devices())
                if outp == 1 and opened == 0 and "VMeter" in name
            ]
            if len(a) > 0:
                device = a[0]
            else:
                raise Exception("No unopened VMeter output devices found!")

        return pypm.Output(device)
コード例 #3
0
def connect_midi():
    # connect MIDI input and output streams
    output_device = None
    input_device = None

    if len(sys.argv) > 2:
        output_device = int(sys.argv[1])
        input_device = int(sys.argv[2])
    else:
        print_devices(OUTPUT)
        output_device = int(raw_input("Type output number: "))

        print_devices(INPUT)
        input_device = int(raw_input("Type input number: "))

    out, in_ = (pypm.Output(output_device, 0), pypm.Input(input_device))

    print
    print "MIDI Connected."
    print

    return (out, in_)
コード例 #4
0
    def __init__(self, device_id, latency = 0, buffer_size = 4096):
        """
        The buffer_size specifies the number of output events to be 
        buffered waiting for output.  (In some cases -- see below -- 
        PortMidi does not buffer output at all and merely passes data 
        to a lower-level API, in which case buffersize is ignored.)

        latency is the delay in milliseconds applied to timestamps to determine
        when the output should actually occur. (If latency is < 0, 0 is 
        assumed.)

        If latency is zero, timestamps are ignored and all output is delivered
        immediately. If latency is greater than zero, output is delayed until
        the message timestamp plus the latency. (NOTE: time is measured 
        relative to the time source indicated by time_proc. Timestamps are 
        absolute, not relative delays or offsets.) In some cases, PortMidi 
        can obtain better timing than your application by passing timestamps 
        along to the device driver or hardware. Latency may also help you 
        to synchronize midi data to audio data by matching midi latency to 
        the audio buffer latency.
        """
        self._output = pypm.Output(device_id, latency)
        self.device_id = device_id