godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add a "Mute Audio" toggle to the editor #1066

Open hmans opened 4 years ago

hmans commented 4 years ago

Describe the project you are working on: Noisy space shootybang. ;-)

Describe the problem or limitation you are having in your project: While developing the game, it would sometimes be very nice to be able to simply mute all audio. At the moment, unless I've missed something obvious, this needs to be done within the project's code. For example, I have the following global AutoLoad in my game:

export var mute_audio = true

func _init():
    if not OS.has_feature("release"):
        if mute_audio:
            AudioServer.set_bus_mute(0, true)

This is an okay solution, but apart from the added overhead of moving an editor concern into the project space, it also means I'm not getting sound in Debug exports, or I need to remember to manually change the value of mute_audio, then think about how and if to version control this, and so on.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: The editor itself should have some toggle in its UI that allows me to mute/unmute all audio, including when running the scene/project from within the editor. This could be housed in the "Debug" menu, but maybe there are better places.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: Assuming there is a "Mute Audio" menu entry in the "Debug" menu:

  1. User starts his project/scene
  2. Project/scene happily outputs audio
  3. User stops project
  4. User enables "Mute Audio" from the "Debug" menu
  5. User once again starts his project/scene
  6. Project/scene is silent

If this enhancement will not be used often, can it be worked around with a few lines of script?: See above -- sort of kind of, but with caveats.

Is there a reason why this should be core and not an add-on in the asset library?: If it's possible to implement this as an addon, I'd be happy to implement it! But I'm not sure if it is.

Edited 2021-02-08: clarified that this includes audio coming from running the actual project from within the editor.

hmans commented 4 years ago

Addendum: of course I could simply switch off my speakers. Duh! But sometimes I have other audio sources (music, videos, ...) active that I actually want to listen to during development, I just don't want to hear the game's audio at the same time.

Calinou commented 4 years ago

Your OS most likely exposes a per-application sound mixer you can use for this purpose. It should persist across application restarts if all goes well.

hmans commented 4 years ago

Thanks @Calinou. We discussed this on IRC for a bit:

I personally still believe this addition to be valuable, if only to provide this functionality across all three supported OS, and making it more accessible.

KoBeWi commented 4 years ago

Many games provide audio settings and you can even mute sfx and music separately. You could implement it in your game too and just go to options and disable sound, bruh. That's what I always do.

Alternatively, you can replace "debug" in your AutoLoad with "editor", so it doesn't affect builds.

hmans commented 4 years ago

Alternatively, you can replace "debug" in your AutoLoad with "editor", so it doesn't affect builds.

Good to know, thanks.

I'm aware that you can solve this in project-space. My current project now has a global hotkey to mute all sound. I'm trying to make a case for this as editor-provided functionality.

Zireael07 commented 4 years ago

I don't recall a per-application toggle in Windows version prior to 10, just btw.

Calinou commented 4 years ago

@Zireael07 Per-application volume sliders have been around since Windows Vista: https://www.howtogeek.com/244963/how-to-adjust-the-volume-for-individual-apps-in-windows/

boukew99 commented 4 years ago

Instead of using code could you not use the editor to turn the Master Audio Bus off? It has the same effect as a "mute all" button, right?. It even has more fine-grained control, if you only want to hear SFX for example.

Beuc commented 3 years ago

@boukew99 setting volume that way applies to all builds, so that's a good way to ship a silent game / game update by mistake.

Hearing the same title music or sound effect over and over is harmful, so I'd welcome an editor mute override that is easy to toggle.

hmans commented 3 years ago

Just want to chime in -- again -- to note that I would still love to see this in Godot. To me, this feature has the same sort of importance to development as toggling on and off physics shape visualizations, and deferring this to either a) code, b) project-global settings or even c) OS features continues to feel weird to me.

Calinou commented 3 years ago

In 3D, you can uncheck Audio Listener in the Perspective menu to disable positional audio while in the 3D editor. There's no equivalent for 2D though.

Hearing the same title music or sound effect over and over is harmful, so I'd welcome an editor mute override that is easy to toggle.

This proposal is only about the editor, not projects running from the editor. It won't help you about music. You'll have to implement a music volume slider in your project for that (and persist the value using ConfigFile).

Edit: This proposal is actually also about projects run from the editor. It can be implemented using similar logic to the "visible collision shapes" debug option, but it requires having more hardcoded logic for this in the main loop which isn't great.

Beuc commented 3 years ago

This proposal is only about the editor, not projects running from the editor.

Reading the OP and the comments, this doesn't seem clear at all for most participants. It would be good to clarify this in the OP.

It won't help you about music. You'll have to implement a music volume slider in your project for that (and persist the value using ConfigFile).

To be fair, if the dev can be annoyed by bgm/sfx, so will some players, so yes, it makes sense ;)

Calinou commented 3 years ago

Thinking about it, you can actually already implement this feature by running the project with the --audio-driver Dummy command line argument. To do so, open the Project Settings and fill in the Editor > Main Run Args setting with --audio-driver Dummy. The value of Main Run Args is only used when running the project from the editor, not in the exported project.

Using the Dummy audio driver will also decrease CPU usage a bit, especially on macOS where the CoreAudio driver is known to cause high CPU usage.

hmans commented 3 years ago

How do I toggle that without quitting and restarting the editor?

hmans commented 3 years ago

Reading the OP and the comments, this doesn't seem clear at all for most participants. It would be good to clarify this in the OP.

At least regarding (my) OP, the statement is not accurate. This is absolutely about projects running from within the editor, and if this isn't clear (does the editor even play sounds without running the scene?!), then I should edit the OP to make this more obvious.

Calinou commented 3 years ago

How do I toggle that without quitting and restarting the editor?

You can add and remove the command line argument from the Main Run Args project setting as needed. It's not a perfect solution, but it's an alternative to installing a third-party macOS application to control the volume on a per-app basis 🙂

(does the editor even play sounds without running the scene?!)

The editor will play sounds whenever the Playing property of an AudioStreamPlayer is checked in the editor. It will also play sounds automatically if the Autoplay property is checked for an AudioStreamPlayer node.

BastiaanOlij commented 3 years ago

Flip your solution around. Go into the audio bus and mute the main audio so that gets saved in your default audio settings. Then in your game init unmute your audio. As long as it isn't a tool script it won't be run so it only unmutes the bus when you run you game.

(or what I'd personally do since I do want to hear audio while developing, just turn the volume on the primary bus down. I'd add volume control to my game anyway and just load the user settings to init game audio)