Skip to content

Commit a39f859

Browse files
authored
Merge pull request #229 from tne-lab/audio-initialize-loop
Loop if device initialization fails and 'Retry' clicked
2 parents 04f34c2 + ab8e039 commit a39f859

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

Source/Audio/AudioComponent.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,41 @@
2727

2828
AudioComponent::AudioComponent() : isPlaying(false)
2929
{
30-
// if this is nonempty, we got an error
31-
String error = deviceManager.initialise(0, // numInputChannelsNeeded
32-
2, // numOutputChannelsNeeded
33-
0, // *savedState (XmlElement)
34-
true, // selectDefaultDeviceOnFailure
35-
String::empty, // preferred device
36-
0); // preferred device setup options
37-
if (error != String::empty)
30+
bool initialized = false;
31+
while (!initialized)
3832
{
39-
String titleMessage = String("Audio device initialization error");
40-
String contentMessage = String("There was a problem initializing the audio device:\n" + error);
41-
// this uses a bool since there are only two options
42-
// also, omitting parameters works fine, even though the docs don't show defaults
43-
bool retryButtonClicked = AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon,
44-
titleMessage,
45-
contentMessage,
46-
String("Retry"),
47-
String("Quit"));
48-
49-
if (retryButtonClicked)
33+
// if this is nonempty, we got an error
34+
String error = deviceManager.initialise(0, // numInputChannelsNeeded
35+
2, // numOutputChannelsNeeded
36+
0, // *savedState (XmlElement)
37+
true, // selectDefaultDeviceOnFailure
38+
String::empty, // preferred device
39+
0); // preferred device setup options
40+
41+
if (error == String::empty)
5042
{
51-
// as above
52-
error = deviceManager.initialise(0, 2, 0, true, String::empty, 0);
43+
initialized = true;
5344
}
54-
else // quit button clicked
45+
else
5546
{
56-
JUCEApplication::quit();
47+
String titleMessage = String("Audio device initialization error");
48+
String contentMessage = String("There was a problem initializing the audio device:\n" + error);
49+
// this uses a bool since there are only two options
50+
// also, omitting parameters works fine, even though the docs don't show defaults
51+
bool retryButtonClicked = AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon,
52+
titleMessage,
53+
contentMessage,
54+
String("Retry"),
55+
String("Quit"));
56+
57+
if (!retryButtonClicked) // quit button clicked
58+
{
59+
JUCEApplication::quit();
60+
break;
61+
}
5762
}
5863
}
5964

60-
6165
AudioIODevice* aIOd = deviceManager.getCurrentAudioDevice();
6266

6367
// the error string doesn't tell you if there's no audio device found...

0 commit comments

Comments
 (0)