Browse Source

JACK port change callback.

tags/2021-05-28
jules 13 years ago
parent
commit
d547fc0b98
1 changed files with 15 additions and 12 deletions
  1. +15
    -12
      modules/juce_audio_devices/native/juce_linux_JackAudio.cpp

+ 15
- 12
modules/juce_audio_devices/native/juce_linux_JackAudio.cpp View File

@@ -113,6 +113,11 @@ static const char** getJackPorts (jack_client_t* const client, const bool forInp
return nullptr;
}
class JackAudioIODeviceType;
static Array<JackAudioIODeviceType*> activeDeviceTypes;
static void portConnectCallback (jack_port_id_t, jack_port_id_t, int, void*);
//==============================================================================
class JackAudioIODevice : public AudioIODevice
{
@@ -218,7 +223,7 @@ public:
close();
juce::jack_set_process_callback (client, processCallback, this);
juce::jack_set_port_connect_callback (client, portConnectCallback, this);
juce::jack_set_port_connect_callback (client, portConnectCallback, nullptr);
juce::jack_on_shutdown (client, shutdownCallback, this);
juce::jack_activate (client);
isOpen_ = true;
@@ -280,7 +285,6 @@ public:
{
juce::jack_deactivate (client);
juce::jack_set_process_callback (client, processCallback, nullptr);
juce::jack_set_port_connect_callback (client, portConnectCallback, nullptr);
juce::jack_on_shutdown (client, shutdownCallback, nullptr);
}
@@ -389,10 +393,6 @@ private:
void updateActivePorts()
{
// This function is called on open(), and from jack as callback on external
// jack port changes. Jules, is there any risk that this can happen in a
// separate thread from the audio thread, meaning we need a critical section?
// the below two activeOut/InputChannels are used in process()
activeOutputChannels.clear();
activeInputChannels.clear();
@@ -405,12 +405,6 @@ private:
activeInputChannels.setBit (i);
}
static void portConnectCallback (jack_port_id_t, jack_port_id_t, int, void* callbackArgument)
{
if (callbackArgument != nullptr)
static_cast<JackAudioIODevice*> (callbackArgument)->updateActivePorts();
}
static void threadInitCallback (void* /* callbackArgument */)
{
jack_Log ("JackAudioIODevice::initialise");
@@ -563,6 +557,8 @@ public:
return nullptr;
}
void portConnectionChange() { callDeviceChangeListeners(); }
private:
StringArray inputNames, outputNames, inputIds, outputIds;
bool hasScanned;
@@ -570,6 +566,13 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JackAudioIODeviceType);
};
static void portConnectCallback (jack_port_id_t, jack_port_id_t, int, void*)
{
for (int i = activeDeviceTypes.size(); --i >= 0;)
if (JackAudioIODeviceType* d = activeDeviceTypes[i])
d->portConnectionChange();
}
//==============================================================================
AudioIODeviceType* AudioIODeviceType::createAudioIODeviceType_JACK()
{


Loading…
Cancel
Save