def connect(self, max_attempts=None): if max_attempts is None: max_attempts = self.connect_max_attempts tries = 0 while True: log.debug("Attempting to connect to JACK server...") status = jacklib.jack_status_t(0x0) self.client = jacklib.client_open(self.client_name, jacklib.JackNoStartServer, status) tries += 1 if status.value: err = get_jack_status_error_string(status) if status.value & jacklib.JackNameNotUnique: log.debug(err) elif status.value & jacklib.JackServerStarted: # Should not happen, since we use the JackNoStartServer option log.warning("Unexpected JACK status: %s", err) else: log.warning("JACK connection error (attempt %i): %s", tries, err) if self.client: break if max_attempts and tries >= max_attempts: log.error( "Maximum number (%i) of connection attempts reached. Aborting.", max_attempts) raise RuntimeError(err) log.debug("Waiting %.2f seconds to connect again...", self.connect_interval) sleep(self.connect_interval) name = jacklib.get_client_name(self.client) if name is not None: self.client_name = name.decode() else: raise RuntimeError("Could not get JACK client name.") jacklib.on_shutdown(self.client, self.shutdown_callback, None) log.debug( "Client connected, name: %s UUID: %s", self.client_name, jacklib.client_get_uuid(self.client), ) jacklib.set_port_registration_callback(self.client, self.port_reg_callback, None) jacklib.set_port_rename_callback(self.client, self.port_rename_callback, None) jacklib.set_property_change_callback(self.client, self.property_callback, None) jacklib.activate(self.client)
def set_registrations(self): if not self.jack_client: return jacklib.set_client_registration_callback( self.jack_client, self.jack_client_registration_callback, None) jacklib.set_port_registration_callback( self.jack_client, self.jack_port_registration_callback, None) jacklib.set_port_connect_callback(self.jack_client, self.jack_port_connect_callback, None) jacklib.set_port_rename_callback(self.jack_client, self.jack_port_rename_callback, None) jacklib.set_xrun_callback(self.jack_client, self.jack_xrun_callback, None) jacklib.set_buffer_size_callback(self.jack_client, self.jack_buffer_size_callback, None) jacklib.set_sample_rate_callback(self.jack_client, self.jack_sample_rate_callback, None) jacklib.set_property_change_callback( self.jack_client, self.jack_properties_change_callback, None) jacklib.on_shutdown(self.jack_client, self.jack_shutdown_callback, None) jacklib.activate(self.jack_client)
channels = int(chStr) # Init JACK client client = jacklib.client_open("cadence-aloop-daemon", jacklib.JackUseExactName, None) if not client: print("cadence-aloop-daemon is already running, delete \"/tmp/.cadence-aloop-daemon.x\" to close it") quit() if jacklib.JACK2: jacklib.set_client_registration_callback(client, client_registration_callback, None) jacklib.set_buffer_size_callback(client, buffer_size_callback, None) jacklib.set_sample_rate_callback(client, sample_rate_callback, None) jacklib.on_shutdown(client, shutdown_callback, None) jacklib.activate(client) # Quit when requested signal(SIGINT, signal_handler) signal(SIGTERM, signal_handler) # Get initial values sampleRate = jacklib.get_sample_rate(client) bufferSize = jacklib.get_buffer_size(client) # Create check file if not os.path.exists(checkFile): os.mknod(checkFile) # Keep running until told otherwise firstStart = True
if not jack_client: sys.stderr.write('Unable to make a jack client !\n') sys.exit() jacklib.set_port_registration_callback(jack_client, JackPortRegistrationCallback, None) jacklib.set_port_connect_callback(jack_client, JackPortConnectCallback, None) jacklib.set_port_rename_callback(jack_client, JackPortRenameCallback, None) jacklib.on_shutdown(jack_client, JackShutdownCallback, None) jacklib.activate(jack_client) signaler = Signaler() signaler.port_added.connect(portAdded) signaler.port_removed.connect(portRemoved) signaler.port_renamed.connect(portRenamed) signaler.connection_added.connect(connectionAdded) signaler.connection_removed.connect(connectionRemoved) signaler.server_sends_open.connect(openFile) signaler.server_sends_save.connect(saveFile) #makeMayConnections() NSMServer = nsm_client.NSMThread('ray-jackpatch', signaler, daemon_address, False) NSMServer.start()
def __init__(self,configd=None): """Create a VNA object""" if configd is None: configd = config.__dict__ self.printlevel = configd['printlevel'] self.fftn = configd['fftn'] self.amp = configd['amp'] self.warmuptime = configd['warmuptime'] self.cooldowntime = configd['cooldowntime'] self.docapture = threading.Event() self.docapture.set() self.xrun = threading.Event() self.xrun.clear() self.startframe = 0 #self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackNoStartServer | jacklib.JackSessionID, None) self.jackclient = jacklib.client_open("pysdrvna", jacklib.JackSessionID, None) try: self.jackclient.contents except: print("Problems with Jack") return #raise self.iI = jacklib.port_register(self.jackclient,"iI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0) self.iQ = jacklib.port_register(self.jackclient,"iQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsInput, 0) self.oI = jacklib.port_register(self.jackclient,"oI", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0) self.oQ = jacklib.port_register(self.jackclient,"oQ", jacklib.JACK_DEFAULT_AUDIO_TYPE, jacklib.JackPortIsOutput, 0) jacklib.set_process_callback(self.jackclient, self.JackProcess, 0) jacklib.set_xrun_callback(self.jackclient, self.JackXrun, 0) jacklib.activate(self.jackclient) jacklib.connect(self.jackclient,"pysdrvna:oQ", configd['outQ']) jacklib.connect(self.jackclient,"pysdrvna:oI", configd['outI']) jacklib.connect(self.jackclient,configd['inQ'],"pysdrvna:iQ") jacklib.connect(self.jackclient,configd['inI'],"pysdrvna:iI") self.Sr = float(jacklib.get_sample_rate(self.jackclient)) self.dt = 1.0/self.Sr ## Align frequency to nearest bin self.fftbin = int(round((configd['freq']/self.Sr)*self.fftn)) self.freq = (float(self.fftbin)/self.fftn) * self.Sr ## Windowing function #self.fftwindow = np.blackman(self.fftn) self.fftwindow = np.hanning(self.fftn) #self.fftwindow = np.kaiser(self.fftn,14) #self.fftwindow = np.hamming(self.fftn) #self.fftwindow = np.bartlett(self.fftn) #self.fftwindow = None ## Latency settings jlr = jacklib.jack_latency_range_t() jacklib.port_get_latency_range(self.oI,jacklib.JackPlaybackLatency,jlr) self.minrtframes = jlr.min jacklib.port_get_latency_range(self.iI,jacklib.JackCaptureLatency,jlr) self.minrtframes += jlr.min # The above code does not always work # Reasonable estimate is 3 times the buffer size ## Compute initial array length self.buffersz = int(jacklib.get_buffer_size(self.jackclient)) if self.minrtframes < (3*self.buffersz): self.minrtframes = 3 * self.buffersz ## rtframes is the round trip audio latency, or when the received audio signal will start self.rtframes = configd['rtframes'] if configd['rtframes'] else self.minrtframes ## delta from rtframes to phase shift sync in frames self.rtframes2sync = configd['rtframes2sync'] ## delta from phase shift sync to fft start in frames self.sync2fft = configd['sync2fft'] ## delta from end of fft to end of audio self.fft2end = configd['fft2end'] if configd['rtframes'] is None: ## Loose fit if estimating based on minrtframes buffers, remainder = divmod((2*self.rtframes) + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz) else: ## Tight fit if rtframes is defined buffers, remainder = divmod(self.rtframes + self.rtframes2sync + self.sync2fft + self.fftn + self.fft2end,self.buffersz) if remainder > 0: buffers = buffers + 1 self.synci = self.rtframes self.InitJackArrays(self.freq,buffers*self.buffersz) self.fftia = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128') self.fftoa = pyfftw.n_byte_align_empty(self.fftn, 16, 'complex128') ## Create FFT Plan self.fft = pyfftw.FFTW(self.fftia,self.fftoa) self.OpenSoftRock() self.Info()
if not client: print( "cadence-aloop-daemon is already running, delete \"/tmp/.cadence-aloop-daemon.x\" to close it" ) quit() if jacklib.JACK2: jacklib.set_client_registration_callback(client, client_registration_callback, None) jacklib.set_buffer_size_callback(client, buffer_size_callback, None) jacklib.set_sample_rate_callback(client, sample_rate_callback, None) jacklib.on_shutdown(client, shutdown_callback, None) jacklib.activate(client) # Quit when requested signal(SIGINT, signal_handler) signal(SIGTERM, signal_handler) # Get initial values sampleRate = jacklib.get_sample_rate(client) bufferSize = jacklib.get_buffer_size(client) # Create check file if not os.path.exists(checkFile): os.mknod(checkFile) # Keep running until told otherwise firstStart = True
if jack_midi_in_data.full(): break del event except Exception as e: print e return 0 if __name__ == "__main__": # Start jack jack_client = jacklib.client_open("Floppy Drive", jacklib.NullOption, 0) jack_midi_in_port = jacklib.port_register(jack_client, "midi", jacklib.DEFAULT_MIDI_TYPE, jacklib.PortIsInput, 0) jacklib.set_process_callback(jack_client, jack_process_callback, 0) jacklib.activate(jack_client) floppy = Floppy(port=sys.argv[1], reset=True) noteplaying = None while 1: try: mode, noteid, velo = jack_midi_in_data.get(True, 1) note = Note(noteid) if (mode & MIDI_MASK) == MIDI_NOTEON: floppy.play(note) noteplaying = note elif (mode & MIDI_MASK) == MIDI_NOTEOFF: if note == noteplaying: