Beispiel #1
0
    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)
Beispiel #2
0
    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)
            if chStr.isdigit():
                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
    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)
                                 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