1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00
This commit is contained in:
jules 2008-05-16 15:31:40 +00:00
parent b3aabd8c2f
commit 5a40751a83
2 changed files with 62 additions and 3 deletions

View file

@ -106,7 +106,7 @@ const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
setMidiInputEnabled (allMidiIns[i], enabledMidiIns.contains (allMidiIns[i])); setMidiInputEnabled (allMidiIns[i], enabledMidiIns.contains (allMidiIns[i]));
if (error.isNotEmpty() && selectDefaultDeviceOnFailure) if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0, error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
false, preferredDefaultDeviceName); false, preferredDefaultDeviceName);
setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput"))); setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
@ -357,6 +357,44 @@ void AudioDeviceManager::stopDevice()
currentAudioDevice->stop(); currentAudioDevice->stop();
} }
void AudioDeviceManager::closeAudioDevice()
{
if (currentAudioDevice != 0)
{
lastRunningDevice = currentAudioDevice->getName();
lastRunningBlockSize = currentAudioDevice->getCurrentBufferSizeSamples();
lastRunningSampleRate = currentAudioDevice->getCurrentSampleRate();
lastRunningIns = inputChannels;
lastRunningOuts = outputChannels;
stopDevice();
setAudioDevice (String::empty, 0, 0, 0, 0, false);
}
}
void AudioDeviceManager::restartLastAudioDevice()
{
if (currentAudioDevice == 0)
{
if (lastRunningDevice.isEmpty())
{
// This method will only reload the last device that was running
// before closeAudioDevice() was called - you need to actually open
// one first, with setAudioDevice().
jassertfalse
return;
}
setAudioDevice (lastRunningDevice,
lastRunningBlockSize,
lastRunningSampleRate,
&lastRunningIns,
&lastRunningOuts,
false);
}
}
void AudioDeviceManager::setInputChannels (const BitArray& newEnabledChannels, void AudioDeviceManager::setInputChannels (const BitArray& newEnabledChannels,
const bool treatAsChosenDevice) const bool treatAsChosenDevice)
{ {

View file

@ -109,12 +109,12 @@ public:
fails to open, then a default device will be used fails to open, then a default device will be used
instead. If false, then on failure, no device is instead. If false, then on failure, no device is
opened. opened.
@param preferredDefaultDeviceName if this is not empty, and there's a device with this @param preferredDefaultDeviceName if this is not empty, and there's a device with this
name, then that will be used as the default device name, then that will be used as the default device
(assuming that there wasn't one specified in the XML). (assuming that there wasn't one specified in the XML).
The string can actually be a simple wildcard, containing "*" The string can actually be a simple wildcard, containing "*"
and "?" characters and "?" characters
@returns an error message if anything went wrong, or an empty string if it worked ok. @returns an error message if anything went wrong, or an empty string if it worked ok.
*/ */
const String initialise (const int numInputChannelsNeeded, const String initialise (const int numInputChannelsNeeded,
@ -195,6 +195,23 @@ public:
const BitArray* outputChans, const BitArray* outputChans,
const bool treatAsChosenDevice); const bool treatAsChosenDevice);
/** Closes the currently-open device.
You can call restartLastAudioDevice() later to reopen it in the same state
that it was just in.
*/
void closeAudioDevice();
/** Tries to reload the last audio device that was running.
Note that this only reloads the last device that was running before
closeAudioDevice() was called - it doesn't reload any kind of saved-state,
and can only be called after a device has been opened with SetAudioDevice().
If a device is already open, this call will do nothing.
*/
void restartLastAudioDevice();
/** Returns the name of the currently selected audio device. /** Returns the name of the currently selected audio device.
This will be an empty string if none is active. This will be an empty string if none is active.
@ -384,6 +401,10 @@ private:
}; };
CallbackHandler callbackHandler; CallbackHandler callbackHandler;
String lastRunningDevice;
int lastRunningBlockSize;
double lastRunningSampleRate;
BitArray lastRunningIns, lastRunningOuts;
friend class CallbackHandler; friend class CallbackHandler;