Whenever an AlertWindow or DialogWindow pops up it makes the “dong” sound usually reserved for hitting a key with no shortcut. The AlertWindow is activated in a few parts of my program when clicking certain textButtons:
bool go = true;
if (withWarning)
{
go = AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
"Reset?",
"Are you sure you'd like to reset? You will lose any unsaved changes.",
"Reset",
"Go Back");
}
// execute code related to user's choice
This started happening some time after I updated to 2.0.27. Were any of the updates related to the AlertWindow or DialogWindow classes? I commented out all of the other code that my program usually executes before/after the AlertWindow and it was still doing it.
There’s a standaloneComponent with a synthComponent as its child. The standaloneComponent has a Reset button. When clicked, the reset button triggers the synthComponent’s resetSynth() method which then loads an xml file that resets all of the synths controls to a default state.
standaloneComponent’s reset code:
else if (buttonThatWasClicked == resetButton)
{
//[UserButtonCode_resetButton] -- add your button handler code here..
if (synthComponent->resetSynth(true))
presetLabel->setText("Init", false);
//[/UserButtonCode_resetButton]
}
synthComponent’s reset code:
bool SynthComponent::resetSynth(bool withWarning)
{
if (synthAudioSource->isMidiSeqPlaying())
synthAudioSource->stopMidiSeq(true);
bool go = true;
if (withWarning)
{
go = AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
"Reset?",
"Are you sure you'd like to reset? You will lose any unsaved changes.",
"Reset",
"Go Back");
}
if (go)
{
synthAudioSource->clearSynth();
File resetFile = resetPath;
XmlDocument xmlDoc (resetFile.loadFileAsString());
ScopedPointer <XmlElement> xml (xmlDoc.getDocumentElement());
if (xml->getTagName() != "Syntorial")
{
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
"Cannot reset synth. Reset file is corrupt or missing",
"");
}
else
{
float parArray[66];
getPresetFromXML(xml, parArray);
setParameters(parArray);
lastVoiceCount = 2;
}
}
return go;
}
I checked the synthComponent and standaloneComponent’s keyPressed() methods to see if they’re being called when I click Reset and they’re not. Can other actions besides key presses cause that sound?
I did a little more digging in my synthComponent. After it’s initially loaded it gives keyboard focus to the MidiKeyboardComponent by calling keyboardComponent->grabKeyboardFocus(). This is so the user can play the synth with the computer keyboard. If I remove that grabKeyboardFocus call then the “dong” stops happening. I swear this wasn’t happening before.
I suppose I could have the AlertWindow grabKeyboardFocus when it’s loaded, and then after the user closes it, give the focus back to the keyboardComponent?
Well if you’ve got a modal component open, and another one (that’s blocked) tries to grab the focus then you can expect to hear the warning bong, same as if you tried to click on a background window when there’s a modal one open in front of it.
Makes sense. I just didn’t expect the keyboardComponent to try and grab focus again after the AlertWindow loaded. But now that I know what’s happening, I’ll figure it out. Thanks!