Why Does This Dialog Beep When It Opens?


#1

I’m displaying a dialog as follows, and it beeps when it opens. It’s basically code copied from the Windows demo of the Juce Demo, and those windows also beep when they open. However I don’t see where the beep is coming from. How can the window be opened silently?

            DialogWindow::LaunchOptions options;
            Label *label = new Label();
            label->setText("Hello World", NotificationType::dontSendNotification);
            options.content.setOwned(label);
            Rectangle<int> area(0, 0, 650, 400);
            options.content->setSize(area.getWidth(), area.getHeight());
            options.dialogTitle = "About This Application";
            options.dialogBackgroundColour = Colour(0xff0e345a);
            options.escapeKeyTriggersCloseButton = true;
            options.useNativeTitleBar = true;
            options.resizable = true;
            options.runModal();

#2

I just found this bug also occurs in the ThreadWithProgressWindow class. The progress window always beeps when it opens! Clearly this would be annoying to users. Surely these dialogs should not default to beeping when opened.


#3

Ok. I found how to silence the beeps:

Define this class:

 class GlobalLookAndFeel : public juce::LookAndFeel_V4 {
 public:
    void playAlertSound() override {}
};

Then on program startup call this:

LookAndFeel::setDefaultLookAndFeel (new GlobalLookAndFeel);

However it still seems to me that it should not require a workaround just to make dialogs open quietly!


#4

As always, the documentation decides, if it is a bug or a feature.
I can’t find it in DialogWindows documentation either…

A flag in the LaunchOptions might be a nice addition (plus documentation…)


#5

Can you post the call stack that’s calling playAlertSound? I don’t see it called from anywhere in the juce code except KeyPressMappingSet::keyPressed() when a shortcut key is disabled.


#6

The beep is easy to recreate. Just run the JuceDemo app. Click the Windows demo heading. Then click the Show Windows button. It beeps.

I had posted a workaround for the beep earlier in this thread: Subclassing GlobalLookAndFeel with a feel with a silent beep. However its not a complete solution. It leaves the entire app’s look and feel changed with no way to reset it.

The documentation in juce_Desktop.h for setDefaultLookAndFeel says: “if this is set to nullptr, it will revert to using the system’s default one.”

But this:

LookAndFeel::setDefaultLookAndFeel(nullptr);

… does not work. The look and feel remains changed.

As daniel suggested, could we have an option in LaunchOptions to open silently? Presumably it should default to silent, as usually it’s not considered polite these days to beep on opening a dialog, even an alert.


#7

I can’t reproduce the issue, if I set a break point in playAlertSound() it is never hit.

The only place playAlertSound() is called from is Component::inputAttemptWhenModal() or KeyPressMappingSet::keyPressed(), I don’t see why either of these would be getting called opening a Dialog.

If you could post a callstack, I could maybe figure out why it’s happening.

The only way I can get it to beep is to click on the main demo window after the dialog has opened, in this case it should beep, since the window is blocked from receiving input by the modal dialog.


#8

I just pulled the latest dev branch of JUCE, built Juce Demo, and the beep is gone. It was there in my application and also in Juce Demo when I first posted this thread. I’m not sure why it’s gone now. Anyway I guess we can consider it fixed.


#9

The beep is back! Both in my application and in Juce Demo.
Juce Demo does stop at a breakpoint on playAlertSound() when opening the Windows demo. Since it’s intermittent it’s probably something that’s not being initialized. Here is a stack trace:

JUCE v5.2.1
(lldb) bt
* thread #1, name = 'JUCE Message Thread', queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: 0x00000001006c4f4c JuceDemo`juce::LookAndFeel::playAlertSound(this=0x0000000103815878) at juce_mac_Windowing.mm:32
    frame #1: 0x00000001005d9573 JuceDemo`juce::Component::inputAttemptWhenModal(this=0x000000010310b9d0) at juce_Component.cpp:2221
    frame #2: 0x00000001007479fa JuceDemo`juce::NSViewComponentPeer::sendModalInputAttemptIfBlocked(this=0x00006080001651c0) at juce_mac_NSViewComponentPeer.mm:989
    frame #3: 0x0000000100746ac5 JuceDemo`juce::JuceNSWindowClass::canBecomeMainWindow(self=0x0000000103134720, (null)="canBecomeMainWindow") at juce_mac_NSViewComponentPeer.mm:1931
    frame #4: 0x00007fff2debf0f7 AppKit`-[NSWindow(NSWindowAccessibility) accessibilitySubroleAttribute] + 44
    frame #5: 0x00007fff2d663697 AppKit`NSAccessibilityGetObjectForAttributeUsingLegacyAPI + 371
    frame #6: 0x00007fff2d662b7a AppKit`NSAccessibilityGetObjectValueForAttribute + 1367
    frame #7: 0x00007fff2d6621da AppKit`-[NSAccessibilityAttributeAccessorInfo getAttributeValue:forObject:] + 58
    frame #8: 0x00007fff2dc19517 AppKit`___NSAccessibilityEntryPointValueForAttribute_block_invoke.816.llvm.BD228857 + 880
    frame #9: 0x00007fff2dc153bf AppKit`NSAccessibilityPerformEntryPointObject.llvm.BD228857 + 16
    frame #10: 0x00007fff2dc1558b AppKit`_NSAccessibilityEntryPointValueForAttribute.llvm.BD228857 + 182
    frame #11: 0x00007fff2d9bca81 AppKit`-[NSObject(NSAccessibilityInternal) _accessibilityValueForAttribute:clientError:] + 351
    frame #12: 0x00007fff2d9c36e4 AppKit`CopyAppKitUIElementAttributeValueNoCatch + 98
    frame #13: 0x00007fff2d9c131e AppKit`CopyAttributeValue + 172
    frame #14: 0x00007fff2e8c3231 HIServices`_AXXMIGCopyAttributeValue + 282
    frame #15: 0x00007fff2e8cd1ac HIServices`_XCopyAttributeValue + 455
    frame #16: 0x00007fff2e8a5939 HIServices`mshMIGPerform + 212
    frame #17: 0x00007fff300051b9 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    frame #18: 0x00007fff30005105 CoreFoundation`__CFRunLoopDoSource1 + 533
    frame #19: 0x00007fff2fffccf0 CoreFoundation`__CFRunLoopRun + 2848
    frame #20: 0x00007fff2fffbf43 CoreFoundation`CFRunLoopRunSpecific + 483
    frame #21: 0x00007fff2f313e26 HIToolbox`RunCurrentEventLoopInMode + 286
    frame #22: 0x00007fff2f313b96 HIToolbox`ReceiveNextEventCommon + 613
    frame #23: 0x00007fff2f313914 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 64
    frame #24: 0x00007fff2d5def5f AppKit`_DPSNextEvent + 2085
    frame #25: 0x00007fff2dd74b4c AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
    frame #26: 0x00007fff2d5d3d6d AppKit`-[NSApplication run] + 764
    frame #27: 0x00000001004b3fd1 JuceDemo`juce::MessageManager::runDispatchLoop(this=0x00006000000437e0) at juce_mac_MessageManager.mm:341
    frame #28: 0x00000001004b3eb7 JuceDemo`juce::JUCEApplicationBase::main() at juce_ApplicationBase.cpp:262
    frame #29: 0x00000001004b3ccc JuceDemo`juce::JUCEApplicationBase::main(argc=3, argv=0x00007ffeefbff770) at juce_ApplicationBase.cpp:240
    frame #30: 0x0000000100001813 JuceDemo`main(argc=3, argv=0x00007ffeefbff770) at Main.cpp:98
    frame #31: 0x00007fff57913115 libdyld.dylib`start + 1
(lldb)