經過千言萬語洗禮,將知一小段派生互動︰
pi@raspberrypi:~ $ python3 Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import jack >>> client = jack.Client("thru_client") >>> @client.set_process_callback ... def process(frames): ... assert len(client.inports) == len(client.outports) ... assert frames == client.blocksize ... for i, o in zip(client.inports, client.outports): ... o.get_buffer()[:] = i.get_buffer() ... >>> process == None True >>> for number in 1, 2: ... client.inports.register('input_{0}'.format(number)) ... client.outports.register('output_{0}'.format(number)) ... jack.OwnPort('thru_client:input_1') jack.OwnPort('thru_client:output_1') jack.OwnPort('thru_client:input_2') jack.OwnPort('thru_client:output_2') >>> client.activate() >>>
幾行 JACK Client for Python 原始碼摘要︰
def set_process_callback(self, callback): @self._callback('JackProcessCallback', error=_FAILURE) def callback_wrapper(frames, _): try: callback(frames) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_process_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting process callback') def _callback(self, cdecl, **kwargs): """Wrapper for ffi.callback() that keeps callback alive.""" def callback_decorator(python_callable): function_ptr = _ffi.callback(cdecl, python_callable, **kwargs) self._keepalive.append(function_ptr) return function_ptr return callback_decorator _keepalive = {} def _check(error_code, msg): """Check error code and raise JackError if non-zero.""" if error_code: raise JackError('{0} ({1})'.format(msg, error_code))
簡單兩個連線動作︰
實現打招呼程式耶!當明使用裝飾子之理乎?