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


Python midi.init函数代码示例

本文整理汇总了Python中pygame.midi.init函数的典型用法代码示例。如果您正苦于以下问题:Python init函数的具体用法?Python init怎么用?Python init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get_device

def get_device(device_id):
    midi.init()
    
    keys = ['interface', 'name', 'is_input', 'is_output', 'opened']
    info = dict(zip(keys, midi.get_device_info(device_id)))
    info['device_id'] = device_id
    return info
开发者ID:rbinkys,项目名称:mido,代码行数:7,代码来源:mido_pygame.py

示例2: main

def main():
    """Initiates program and loop."""
    pygame.init()
    midi.init()

    print "Number of MIDI devices:", midi.get_count()
    if midi.get_count() == 0:
        print "No MIDI devices detected :P"
        return
    
    out_device = midi.get_default_output_id()
    if out_device == -1:
        print "No MIDI output device detected :P"
        return
    
    print "Uses device no:", out_device
    try:
        output = midi.Output( out_device )
        output.set_instrument( instrument )
        keyboard = init_keyboard(53)
        
        screen = pygame.display.set_mode([250,80])
        screen.fill((0,0,0))
        pygame.display.set_caption("MIDI Keyboard")
        pygame.display.flip()
        
        io_loop(keyboard, output, instrument)
        
    finally:
        del output
        midi.quit()
开发者ID:introprogramming,项目名称:exercises,代码行数:31,代码来源:midi.py

示例3: __init__

    def __init__(self, device, latency=0, buffer_size=1024):
        """Create a MIDI output.

        Parameters
        ----------
        device : int or str
            id or name of the MIDI device
        latency : int, optional
            delay in ms applied to timestamp (default=0)
        buffer_size : int, optional
            number of events to be buffered (default=1024)

        """

        if not isinstance(_midi,ModuleType):
            raise ImportError("""Sorry, MIDI output is not supported on this computer.""")

        if not _internals.active_exp.is_initialized:
            raise RuntimeError(
                "Cannot create MidiOut before expyriment.initialize()!")
        _midi.init()
        Output.__init__(self)
        self._id = device
        self._buffer_size = buffer_size
        self._latency = latency
        self.output = _midi.Output(device, latency, buffer_size)
开发者ID:MichaelUM,项目名称:expyriment-stash,代码行数:26,代码来源:_midiout.py

示例4: _open

    def _open(self):
        midi.init()

        self.device = None

        opening_input = (self.__class__ is Input)

        if self.name is None:
            self.device = self._get_default_device(opening_input)
            self.name = self.device['name']
        else:
            self.device = self._get_named_device(self.name, opening_input)

        if self.device['opened']:
            if opening_input:
                devtype = 'input'
            else:
                devtype = 'output'
            raise IOError('{} port {!r} is already open'.format(devtype,
                                                                self.name))

        if opening_input:
            self._port = midi.Input(self.device['device_id'])
        else:
            self._port = midi.Output(self.device['device_id'])

        atexit.register(self.close)
开发者ID:rbinkys,项目名称:mido,代码行数:27,代码来源:mido_pygame.py

示例5: __init__

    def __init__(self, device, buffer_size=None):
        """Create a MIDI input.

        Parameters
        ----------
        device : int or str
            id or name of the MIDI device
        buffer_size : int, optional
            number of events to be buffered

        """

        import types
        if type(_midi) is not types.ModuleType:
            raise ImportError("""Sorry, MIDI input is not supported on this computer.""")

        if not expyriment._active_exp.is_initialized:
            raise RuntimeError(
                "Cannot create MidiIn before expyriment.initialize()!")
        _midi.init()
        Input.__init__(self)
        self._id = device
        if buffer_size is None:
            buffer_size = defaults.midiin_buffer_size
        self._buffer_size = buffer_size
        self.input = _midi.Input(device, buffer_size)
开发者ID:fnielsen,项目名称:expyriment,代码行数:26,代码来源:_midiin.py

示例6: _open

    def _open(self, **kwargs):
        if 'virtual' in kwargs:
            raise IOError(
                "virtual ports are not supported by the Pygame backend")

        midi.init()

        opening_input = hasattr(self, 'receive')

        if self.name is None:
            device = _get_default_device(opening_input)
            self.name = device['name']
        else:
            device = _get_named_device(self.name, opening_input)

        if device['opened']:
            if opening_input:
                devtype = 'input'
            else:
                devtype = 'output'
            raise IOError('{} port {!r} is already open'.format(devtype,
                                                                self.name))
        if opening_input:
            self._port = midi.Input(device['id'])
        else:
            self._port = midi.Output(device['id'])

        self._device_type = 'Pygame/{}'.format(device['interface'])
开发者ID:ViktorNova,项目名称:musikernel,代码行数:28,代码来源:pygame.py

示例7: _open

    def _open(self, **kwargs):
        if kwargs.get('virtual'):
            raise ValueError('virtual ports are not supported'
                             ' by the Pygame backend')
        elif kwargs.get('callback'):
            raise ValueError('callbacks are not supported'
                             ' by the Pygame backend')

        midi.init()

        if self.name is None:
            device = _get_default_device(self.is_input)
            self.name = device['name']
        else:
            device = _get_named_device(self.name, self.is_input)

        if device['opened']:
            if self.is_input:
                devtype = 'input'
            else:
                devtype = 'output'
            raise IOError('{} port {!r} is already open'.format(devtype,
                                                                self.name))
        if self.is_input:
            self._port = midi.Input(device['id'])
        else:
            self._port = midi.Output(device['id'])

        self._device_type = 'Pygame/{}'.format(device['interface'])
开发者ID:olemb,项目名称:mido,代码行数:29,代码来源:pygame.py

示例8: __init__

 def __init__(self):
     self.b = []
     self.enumerate_devices()
     self.init_audio()
     self.reset_strip()
     self.history=collections.deque()
     self.lpf_audio=[0]*len(self.RANGES)
     self.dt=float(self.CHUNK)/self.RATE
     self.alpha=self.dt/(self.TAU_LPF+self.dt)
     self.hue=0.
     self.stepfns = [self.step]
     self.smooth_dict = {}
     self.mute_delta = 0
     self.mute = 1.0
     self.whiteout_delta = 0
     self.whiteout = 1.0
     midi.init()
     self.mi = None
     try:
         self.mi = midi.Input(3)
     except:
         traceback.print_exc()
         print "Can't find midi. Continuing..."
     self.mstat = {}
     self.hueoff = 0
     super(Visualizer, self).__init__()
开发者ID:gdkar,项目名称:beat-off,代码行数:26,代码来源:visualizer.py

示例9: main

def main():

    fin = open("workfile2.txt",'r')

    midi.init()
    p1 = midi.Output(2)
    instrument = 0
    count = 0
    while (count < 50):
        line = parse(fin)
        x = line[0]
        v = line[1]
        if (line[-1] == 'fist'):
            instrument = 41
        elif (line[-1] == 'wave_out'):
            instrument = 31
        elif (line[-1] == 'rest'):
            instrument = 1
        elif (line[-1] == 'wave_in'):
            instrument = 59
        else:
            intrument = 67

        p1.set_instrument(instrument)
        print line
        NOTE = 64.0 + 64.0*x
        VOLUME = 64.0 + 64.0*v
        p1.note_on(int(NOTE),int(VOLUME))
        time.sleep(0.25)
        p1.note_off(int(NOTE),int(VOLUME))
        count += 1
    del p1
    midi.quit()
    fin.close()
开发者ID:ekisu,项目名称:MyoMusicController,代码行数:34,代码来源:ryanMidi.py

示例10: __init__

    def __init__(self, device, latency=None, buffer_size=None):
        """Create a MIDI output.

        Parameters
        ----------
        device : int or str
            id or name of the MIDI device
        latency : int, optional
            delay in ms applied to timestamp
        buffer_size : int, optional
            number of events to be buffered

        """

        import types
        if type(_midi) is not types.ModuleType:
            raise ImportError("""Sorry, MIDI output is not supported on this computer.""")

        if not expyriment._active_exp.is_initialized:
            raise RuntimeError(
                "Cannot create MidiOut before expyriment.initialize()!")
        _midi.init()
        Output.__init__(self)
        self._id = device
        if buffer_size is None:
            buffer_size = defaults.midiout_buffer_size
        self._buffer_size = buffer_size
        if latency is None:
            latency = defaults.midiout_latency
        self._latency = latency
        self.output = _midi.Output(device, latency, buffer_size)
开发者ID:Dannnno,项目名称:expyriment,代码行数:31,代码来源:_midiout.py

示例11: main

def main():
    midi.init()
    pygame.init()

    app = QtWidgets.QApplication(sys.argv)
    form = QueryByLickMainWindow()
    form.show()
    app.exec_()
开发者ID:WillLynch,项目名称:query-by-lick,代码行数:8,代码来源:main.py

示例12: __enter__

 def __enter__(self):
     print "entering DeviceSource"
     print "  initializing MIDI interface"
     midi.init()
     print "  acquiring MIDI input"
     self.midi_input = midi.Input(self.midi_id)
     print "  acquiring video input"
     self.video_input = cv2.VideoCapture(self.video_id)
     return self
开发者ID:mkovacs,项目名称:clavius,代码行数:9,代码来源:input.py

示例13: play_chords

def play_chords(chords):
    midi.init()
    out = init_output_device()
    for ns in chords:
        print ns
        play_chord(out, ns)
    out.close()
    out.abort()
    try: midi.quit()
    except: pass
开发者ID:blacktaxi,项目名称:inversion,代码行数:10,代码来源:pygameplayer.py

示例14: __init__

	def __init__(self, name):
		super(MidiDevice, self).__init__()
		# Initialize the python midi module 
		midi.init()
		# Get the Midi device that we want to control
		self.outport = self.get_device(name)
		# True/False whether to play or now
		self.play = True
		# List of notes currently being played
		self.playing_notes = [] #Each element is of the form: [note, velocity, duration]
		self.playing_mutex = threading.Lock()
开发者ID:marcdjulien,项目名称:PhysCompFinal,代码行数:11,代码来源:MidiDevice.py

示例15: init

def init(text='HELO', device_index=1):
    '''Finds and initializes the device'''
    
    global softstep
    
    midi.init()
    softstep = _open_device('SSCOM MIDI 1', device_index)
    _standalone(False)
    
    display(text)
    reset_leds()
开发者ID:amiguet,项目名称:foococo,代码行数:11,代码来源:hardware.py


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