|
|
|
@@ -43,6 +43,49 @@ bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager: |
|
|
|
&& useDefaultOutputChannels == other.useDefaultOutputChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
class AudioDeviceManager::CallbackHandler : public AudioIODeviceCallback,
|
|
|
|
public MidiInputCallback,
|
|
|
|
public AudioIODeviceType::Listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CallbackHandler (AudioDeviceManager& adm) noexcept : owner (adm) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void audioDeviceIOCallback (const float** ins, int numIns, float** outs, int numOuts, int numSamples)
|
|
|
|
{
|
|
|
|
owner.audioDeviceIOCallbackInt (ins, numIns, outs, numOuts, numSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audioDeviceAboutToStart (AudioIODevice* device)
|
|
|
|
{
|
|
|
|
owner.audioDeviceAboutToStartInt (device);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audioDeviceStopped()
|
|
|
|
{
|
|
|
|
owner.audioDeviceStoppedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void audioDeviceError (const String& message)
|
|
|
|
{
|
|
|
|
owner.audioDeviceErrorInt (message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
|
|
|
|
{
|
|
|
|
owner.handleIncomingMidiMessageInt (source, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void audioDeviceListChanged()
|
|
|
|
{
|
|
|
|
owner.audioDeviceListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioDeviceManager& owner;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
AudioDeviceManager::AudioDeviceManager()
|
|
|
|
: numInputChansNeeded (0),
|
|
|
|
@@ -55,7 +98,7 @@ AudioDeviceManager::AudioDeviceManager() |
|
|
|
cpuUsageMs (0),
|
|
|
|
timeToCpuScale (0)
|
|
|
|
{
|
|
|
|
callbackHandler.owner = this;
|
|
|
|
callbackHandler = new CallbackHandler (*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioDeviceManager::~AudioDeviceManager()
|
|
|
|
@@ -79,7 +122,7 @@ void AudioDeviceManager::createDeviceTypesIfNeeded() |
|
|
|
currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
|
|
|
|
|
|
|
|
for (int i = 0; i < availableDeviceTypes.size(); ++i)
|
|
|
|
availableDeviceTypes.getUnchecked(i)->addListener (&callbackHandler);
|
|
|
|
availableDeviceTypes.getUnchecked(i)->addListener (callbackHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -200,7 +243,7 @@ String AudioDeviceManager::initialise (const int numInputChannelsNeeded, |
|
|
|
{
|
|
|
|
AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
|
|
|
|
|
|
|
|
StringArray outs (type->getDeviceNames (false));
|
|
|
|
const StringArray outs (type->getDeviceNames (false));
|
|
|
|
|
|
|
|
for (int i = 0; i < outs.size(); ++i)
|
|
|
|
{
|
|
|
|
@@ -211,7 +254,7 @@ String AudioDeviceManager::initialise (const int numInputChannelsNeeded, |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringArray ins (type->getDeviceNames (true));
|
|
|
|
const StringArray ins (type->getDeviceNames (true));
|
|
|
|
|
|
|
|
for (int i = 0; i < ins.size(); ++i)
|
|
|
|
{
|
|
|
|
@@ -404,18 +447,12 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup |
|
|
|
outputChannels.setRange (0, numOutputChansNeeded, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newInputDeviceName.isEmpty())
|
|
|
|
inputChannels.clear();
|
|
|
|
|
|
|
|
if (newOutputDeviceName.isEmpty())
|
|
|
|
outputChannels.clear();
|
|
|
|
if (newInputDeviceName.isEmpty()) inputChannels.clear();
|
|
|
|
if (newOutputDeviceName.isEmpty()) outputChannels.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! newSetup.useDefaultInputChannels)
|
|
|
|
inputChannels = newSetup.inputChannels;
|
|
|
|
|
|
|
|
if (! newSetup.useDefaultOutputChannels)
|
|
|
|
outputChannels = newSetup.outputChannels;
|
|
|
|
if (! newSetup.useDefaultInputChannels) inputChannels = newSetup.inputChannels;
|
|
|
|
if (! newSetup.useDefaultOutputChannels) outputChannels = newSetup.outputChannels;
|
|
|
|
|
|
|
|
currentSetup = newSetup;
|
|
|
|
|
|
|
|
@@ -431,11 +468,11 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup |
|
|
|
{
|
|
|
|
currentDeviceType = currentAudioDevice->getTypeName();
|
|
|
|
|
|
|
|
currentAudioDevice->start (&callbackHandler);
|
|
|
|
currentAudioDevice->start (callbackHandler);
|
|
|
|
|
|
|
|
currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
|
|
|
|
currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
|
|
|
|
currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
|
|
|
|
currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
|
|
|
|
currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
|
|
|
|
currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
|
|
|
|
currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
|
|
|
|
|
|
|
|
for (int i = 0; i < availableDeviceTypes.size(); ++i)
|
|
|
|
@@ -546,10 +583,8 @@ void AudioDeviceManager::updateXml() |
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < enabledMidiInputs.size(); ++i)
|
|
|
|
{
|
|
|
|
XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
|
|
|
|
m->setAttribute ("name", enabledMidiInputs[i]->getName());
|
|
|
|
}
|
|
|
|
lastExplicitSettings->createNewChildElement ("MIDIINPUT")
|
|
|
|
->setAttribute ("name", enabledMidiInputs[i]->getName());
|
|
|
|
|
|
|
|
if (midiInsFromXml.size() > 0)
|
|
|
|
{
|
|
|
|
@@ -561,8 +596,8 @@ void AudioDeviceManager::updateXml() |
|
|
|
{
|
|
|
|
if (! availableMidiDevices.contains (midiInsFromXml[i], true))
|
|
|
|
{
|
|
|
|
XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
|
|
|
|
m->setAttribute ("name", midiInsFromXml[i]);
|
|
|
|
lastExplicitSettings->createNewChildElement ("MIDIINPUT")
|
|
|
|
->setAttribute ("name", midiInsFromXml[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -724,14 +759,20 @@ void AudioDeviceManager::audioDeviceStoppedInt() |
|
|
|
callbacks.getUnchecked(i)->audioDeviceStopped();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::audioDeviceErrorInt (const String& message)
|
|
|
|
{
|
|
|
|
const ScopedLock sl (audioCallbackLock);
|
|
|
|
for (int i = callbacks.size(); --i >= 0;)
|
|
|
|
callbacks.getUnchecked(i)->audioDeviceError (message);
|
|
|
|
}
|
|
|
|
|
|
|
|
double AudioDeviceManager::getCpuUsage() const
|
|
|
|
{
|
|
|
|
return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void AudioDeviceManager::setMidiInputEnabled (const String& name,
|
|
|
|
const bool enabled)
|
|
|
|
void AudioDeviceManager::setMidiInputEnabled (const String& name, const bool enabled)
|
|
|
|
{
|
|
|
|
if (enabled != isMidiInputEnabled (name))
|
|
|
|
{
|
|
|
|
@@ -741,9 +782,7 @@ void AudioDeviceManager::setMidiInputEnabled (const String& name, |
|
|
|
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
MidiInput* const midiIn = MidiInput::openDevice (index, &callbackHandler);
|
|
|
|
|
|
|
|
if (midiIn != nullptr)
|
|
|
|
if (MidiInput* const midiIn = MidiInput::openDevice (index, callbackHandler))
|
|
|
|
{
|
|
|
|
enabledMidiInputs.add (midiIn);
|
|
|
|
midiIn->start();
|
|
|
|
@@ -771,8 +810,7 @@ bool AudioDeviceManager::isMidiInputEnabled (const String& name) const |
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::addMidiInputCallback (const String& name,
|
|
|
|
MidiInputCallback* callbackToAdd)
|
|
|
|
void AudioDeviceManager::addMidiInputCallback (const String& name, MidiInputCallback* callbackToAdd)
|
|
|
|
{
|
|
|
|
removeMidiInputCallback (name, callbackToAdd);
|
|
|
|
|
|
|
|
@@ -797,8 +835,7 @@ void AudioDeviceManager::removeMidiInputCallback (const String& name, MidiInputC |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
|
|
|
|
const MidiMessage& message)
|
|
|
|
void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source, const MidiMessage& message)
|
|
|
|
{
|
|
|
|
if (! message.isActiveSense())
|
|
|
|
{
|
|
|
|
@@ -853,36 +890,6 @@ void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName) |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
|
|
|
|
int numInputChannels,
|
|
|
|
float** outputChannelData,
|
|
|
|
int numOutputChannels,
|
|
|
|
int numSamples)
|
|
|
|
{
|
|
|
|
owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
|
|
|
|
{
|
|
|
|
owner->audioDeviceAboutToStartInt (device);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
|
|
|
|
{
|
|
|
|
owner->audioDeviceStoppedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
|
|
|
|
{
|
|
|
|
owner->handleIncomingMidiMessageInt (source, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDeviceManager::CallbackHandler::audioDeviceListChanged()
|
|
|
|
{
|
|
|
|
owner->audioDeviceListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void AudioDeviceManager::playTestSound()
|
|
|
|
{
|
|
|
|
|