String open (const BigInteger& inputChannels, const BigInteger& outputChannels, double /* sampleRate */, int /* bufferSizeSamples */) { jack_Log ("opening client"); lastError = client.open (KV_JACK_NAME, 0); if (lastError.isNotEmpty()) { jack_Log (lastError); return lastError; } DBG("num inputs: " << inputChannels.getHighestBit()); DBG("num outputs: " << outputChannels.getHighestBit()); jack_on_shutdown (client, JackDevice::shutdownCallback, this); jack_set_error_function (JackDevice::errorCallback); jack_set_port_connect_callback (client, JackDevice::portConnectCallback, this); jack_set_process_callback (client, JackDevice::processCallback, this); jack_set_thread_init_callback (client, JackDevice::threadInitCallback, this); jack_set_port_registration_callback (client, JackDevice::_portRegistration, this); client.registerPort ("audio_1", Jack::audioPort, JackPortIsOutput); client.registerPort ("audio_2", Jack::audioPort, JackPortIsOutput); return lastError; }
static void shutdownCallback (void* callbackArgument) { jack_Log ("JackAudioIODevice::shutdown"); if (JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument) { device->client = nullptr; device->close(); } }
static void dumpJackErrorMessage (const jack_status_t status) throw() { if (status & JackServerFailed || status & JackServerError) jack_Log ("Unable to connect to JACK server"); if (status & JackVersionError) jack_Log ("Client's protocol version does not match"); if (status & JackInvalidOption) jack_Log ("The operation contained an invalid or unsupported option"); if (status & JackNameNotUnique) jack_Log ("The desired client name was not unique"); if (status & JackNoSuchClient) jack_Log ("Requested client does not exist"); if (status & JackInitFailure) jack_Log ("Unable to initialize client"); }
static void errorCallback (const char* msg) { jack_Log ("JackIODevice::errorCallback " + String (msg)); }
static void shutdownCallback (void* arg) { jack_Log ("JackIODevice::shutdown"); }
static void threadInitCallback (void* /* callbackArgument */) { jack_Log ("JackIODevice::threadInitCallback"); }
static void portConnectCallback (jack_port_id_t, jack_port_id_t, int, void* arg) { jack_Log ("JackIODevice::portConnectCallback"); }
void stop() { jack_Log ("jack stop \n"); start (nullptr); client.deactivate(); }
static void threadInitCallback (void* /* callbackArgument */) { jack_Log ("JackAudioIODevice::initialise"); }
String open (const BigInteger& inputChannels, const BigInteger& outputChannels, double /* sampleRate */, int /* bufferSizeSamples */) { if (client == nullptr) { lastError = "No JACK client running"; return lastError; } lastError = String::empty; close(); juce::jack_set_process_callback (client, processCallback, this); juce::jack_set_port_connect_callback (client, portConnectCallback, this); juce::jack_on_shutdown (client, shutdownCallback, this); juce::jack_activate (client); isOpen_ = true; if (! inputChannels.isZero()) { if (const char** const ports = getJackPorts (client, true)) { const int numInputChannels = inputChannels.getHighestBit() + 1; for (int i = 0; i < numInputChannels; ++i) { const String portName (ports[i]); if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName()) { int error = juce::jack_connect (client, ports[i], juce::jack_port_name ((jack_port_t*) inputPorts[i])); if (error != 0) jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error)); } } free (ports); } } if (! outputChannels.isZero()) { if (const char** const ports = getJackPorts (client, false)) { const int numOutputChannels = outputChannels.getHighestBit() + 1; for (int i = 0; i < numOutputChannels; ++i) { const String portName (ports[i]); if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName()) { int error = juce::jack_connect (client, juce::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]); if (error != 0) jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error)); } } free (ports); } } return lastError; }
const String open (const BitArray& inputChannels, const BitArray& outputChannels, double sampleRate, int bufferSizeSamples) { if (client == 0) { lastError = T("No JACK client running"); return lastError; } lastError = String::empty; close(); JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this); JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this); JUCE_NAMESPACE::jack_activate (client); isOpen_ = true; if (! inputChannels.isEmpty()) { const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput); if (ports != 0) { const int numInputChannels = inputChannels.getHighestBit () + 1; for (int i = 0; i < numInputChannels; ++i) { const String portName (ports[i]); if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName()) { int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i])); if (error != 0) jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error)); } } free (ports); } } if (! outputChannels.isEmpty()) { const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput); if (ports != 0) { const int numOutputChannels = outputChannels.getHighestBit () + 1; for (int i = 0; i < numOutputChannels; ++i) { const String portName (ports[i]); if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName()) { int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]); if (error != 0) jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error)); } } free (ports); } } return lastError; }