JackAudioIODevice (const String& deviceName, const String& inId, const String& outId) : AudioIODevice (deviceName, "JACK"), inputId (inId), outputId (outId), isOpen_ (false), callback (nullptr), totalNumberOfInputChannels (0), totalNumberOfOutputChannels (0) { jassert (deviceName.isNotEmpty()); jack_status_t status; client = juce::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status); if (client == nullptr) { dumpJackErrorMessage (status); } else { juce::jack_set_error_function (errorCallback); // open input ports const StringArray inputChannels (getInputChannelNames()); for (int i = 0; i < inputChannels.size(); ++i) { String inputName; inputName << "in_" << ++totalNumberOfInputChannels; inputPorts.add (juce::jack_port_register (client, inputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)); } // open output ports const StringArray outputChannels (getOutputChannelNames()); for (int i = 0; i < outputChannels.size (); ++i) { String outputName; outputName << "out_" << ++totalNumberOfOutputChannels; outputPorts.add (juce::jack_port_register (client, outputName.toUTF8(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)); } inChans.calloc (totalNumberOfInputChannels + 2); outChans.calloc (totalNumberOfOutputChannels + 2); } }
void scanForDevices() { hasScanned = true; inputNames.clear(); inputIds.clear(); outputNames.clear(); outputIds.clear(); if (juce_libjackHandle == nullptr) { juce_libjackHandle = dlopen ("libjack.so", RTLD_LAZY); if (juce_libjackHandle == nullptr) return; } jack_status_t status; // open a dummy client if (jack_client_t* const client = juce::jack_client_open ("JuceJackDummy", JackNoStartServer, &status)) { // scan for output devices if (const char** const ports = getJackPorts (client, false)) { for (int j = 0; ports[j] != nullptr; ++j) { String clientName (ports[j]); clientName = clientName.upToFirstOccurrenceOf (":", false, false); if (clientName != (JUCE_JACK_CLIENT_NAME) && ! inputNames.contains (clientName)) { inputNames.add (clientName); inputIds.add (ports [j]); } } free (ports); } // scan for input devices if (const char** const ports = getJackPorts (client, true)) { for (int j = 0; ports[j] != nullptr; ++j) { String clientName (ports[j]); clientName = clientName.upToFirstOccurrenceOf (":", false, false); if (clientName != (JUCE_JACK_CLIENT_NAME) && ! outputNames.contains (clientName)) { outputNames.add (clientName); outputIds.add (ports [j]); } } free (ports); } juce::jack_client_close (client); } else { dumpJackErrorMessage (status); } }
//============================================================================== void scanForDevices() { hasScanned = true; inputNames.clear(); inputIds.clear(); outputNames.clear(); outputIds.clear(); if (juce_libjack_handle == 0) { juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY); if (juce_libjack_handle == 0) return; } // open a dummy client jack_status_t status; jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status); if (client == 0) { dumpJackErrorMessage (status); } else { // scan for output devices const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput); if (ports != 0) { int j = 0; while (ports[j] != 0) { String clientName (ports[j]); clientName = clientName.upToFirstOccurrenceOf (":", false, false); if (clientName != String (JUCE_JACK_CLIENT_NAME) && ! inputNames.contains (clientName)) { inputNames.add (clientName); inputIds.add (ports [j]); } ++j; } free (ports); } // scan for input devices ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput); if (ports != 0) { int j = 0; while (ports[j] != 0) { String clientName (ports[j]); clientName = clientName.upToFirstOccurrenceOf (":", false, false); if (clientName != String (JUCE_JACK_CLIENT_NAME) && ! outputNames.contains (clientName)) { outputNames.add (clientName); outputIds.add (ports [j]); } ++j; } free (ports); } JUCE_NAMESPACE::jack_client_close (client); } }