From e1d47875b7449c863853aeada4b7deaa8e2fef09 Mon Sep 17 00:00:00 2001 From: Malcolm Anderson Date: Thu, 21 Nov 2024 21:31:00 -0800 Subject: [PATCH 1/2] Initial shot at muting/unmuting via the editor I think the SceneDebugger approach is unnecessary - we should just be able to call methods on the AudioServer singleton from higher up. But we need to figure out how to mute and unmute the AudioServer without interacting with the Master bus, since the user may also be messing with it... Perhaps a new variable/property of the AudioServer that mutes or unmutes is necessary? --- editor/debugger/editor_debugger_node.cpp | 7 +++++++ editor/debugger/editor_debugger_node.h | 4 ++++ editor/debugger/script_editor_debugger.cpp | 11 +++++++++++ editor/debugger/script_editor_debugger.h | 5 +++++ editor/plugins/game_view_plugin.cpp | 19 +++++++++++++++++++ editor/plugins/game_view_plugin.h | 6 ++++++ scene/debugger/scene_debugger.cpp | 6 ++++++ 7 files changed, 58 insertions(+) diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 0f948b4ed591..61b1b6c58d38 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -801,6 +801,13 @@ void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const No }); } +void EditorDebuggerNode::set_audio_enabled(bool p_enabled) { + _for_all(tabs, [&](ScriptEditorDebugger *dbg) { + dbg->set_audio_enabled(p_enabled); + }); + audio_enabled = p_enabled; +} + void EditorDebuggerNode::set_camera_override(CameraOverride p_override) { _for_all(tabs, [&](ScriptEditorDebugger *dbg) { dbg->set_camera_override(p_override); diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 12c0d30c4261..dd4192ea1e80 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -111,6 +111,8 @@ class EditorDebuggerNode : public MarginContainer { bool keep_open = false; String current_uri; + bool audio_enabled = true; + CameraOverride camera_override = OVERRIDE_NONE; HashMap breakpoints; @@ -205,6 +207,8 @@ class EditorDebuggerNode : public MarginContainer { void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); + void set_audio_enabled(bool p_enabled); + void set_camera_override(CameraOverride p_override); CameraOverride get_camera_override(); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index da59450dd0a5..e47aa9a48632 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1482,6 +1482,17 @@ void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const } } +bool ScriptEditorDebugger::get_audio_enabled() const { + return audio_enabled; +} + +void ScriptEditorDebugger::set_audio_enabled(bool p_enabled) { + Array msg; + msg.push_back(p_enabled); + _put_msg("scene:enable_audio", msg); + audio_enabled = p_enabled; +} + CameraOverride ScriptEditorDebugger::get_camera_override() const { return camera_override; } diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h index 06a968e14100..ae7cb1053fd8 100644 --- a/editor/debugger/script_editor_debugger.h +++ b/editor/debugger/script_editor_debugger.h @@ -183,6 +183,8 @@ class ScriptEditorDebugger : public MarginContainer { void _select_thread(int p_index); + bool audio_enabled = true; + EditorDebuggerNode::CameraOverride camera_override; void _stack_dump_frame_selected(); @@ -299,6 +301,9 @@ class ScriptEditorDebugger : public MarginContainer { void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); + bool get_audio_enabled() const; + void set_audio_enabled(bool p_enabled); + EditorDebuggerNode::CameraOverride get_camera_override() const; void set_camera_override(EditorDebuggerNode::CameraOverride p_override); diff --git a/editor/plugins/game_view_plugin.cpp b/editor/plugins/game_view_plugin.cpp index 5c1f81ee94e3..4befe44f8718 100644 --- a/editor/plugins/game_view_plugin.cpp +++ b/editor/plugins/game_view_plugin.cpp @@ -126,6 +126,10 @@ void GameViewDebugger::set_select_mode(int p_mode) { } } +void GameViewDebugger::set_audio_enabled(bool p_enabled) { + EditorDebuggerNode::get_singleton()->set_audio_enabled(p_enabled); +} + void GameViewDebugger::set_camera_override(bool p_enabled) { EditorDebuggerNode::get_singleton()->set_camera_override(p_enabled ? camera_override_mode : EditorDebuggerNode::OVERRIDE_NONE); } @@ -235,6 +239,10 @@ void GameView::_hide_selection_toggled(bool p_pressed) { debugger->set_selection_visible(!p_pressed); } +void GameView::_enable_audio_button_toggled(bool p_pressed) { + debugger->set_audio_enabled(p_pressed); +} + void GameView::_camera_override_button_toggled(bool p_pressed) { _update_debugger_buttons(); @@ -288,6 +296,7 @@ void GameView::_notification(int p_what) { hide_selection->set_button_icon(get_editor_theme_icon(hide_selection->is_pressed() ? SNAME("GuiVisibilityHidden") : SNAME("GuiVisibilityVisible"))); + enable_audio_button->set_button_icon(get_editor_theme_icon(SNAME("AudioStreamPlayer"))); camera_override_button->set_button_icon(get_editor_theme_icon(SNAME("Camera"))); camera_override_menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl"))); } break; @@ -415,6 +424,16 @@ GameView::GameView(Ref p_debugger) { main_menu_hbox->add_child(memnew(VSeparator)); + enable_audio_button = memnew(Button); + main_menu_hbox->add_child(enable_audio_button); + enable_audio_button->set_toggle_mode(true); + enable_audio_button->set_pressed(true); + enable_audio_button->set_theme_type_variation("FlatButton"); + enable_audio_button->connect(SceneStringName(toggled), callable_mp(this, &GameView::_enable_audio_button_toggled)); + enable_audio_button->set_tooltip_text("Enable or mute game audio."); + + main_menu_hbox->add_child(memnew(VSeparator)); + camera_override_button = memnew(Button); main_menu_hbox->add_child(camera_override_button); camera_override_button->set_toggle_mode(true); diff --git a/editor/plugins/game_view_plugin.h b/editor/plugins/game_view_plugin.h index f8701c3e76fd..1ec2db241ebe 100644 --- a/editor/plugins/game_view_plugin.h +++ b/editor/plugins/game_view_plugin.h @@ -63,6 +63,8 @@ class GameViewDebugger : public EditorDebuggerPlugin { void set_selection_visible(bool p_visible); + void set_audio_enabled(bool p_enabled); + void set_camera_override(bool p_enabled); void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode); @@ -96,6 +98,8 @@ class GameView : public VBoxContainer { Button *hide_selection = nullptr; + Button *enable_audio_button = nullptr; + Button *camera_override_button = nullptr; MenuButton *camera_override_menu = nullptr; @@ -112,6 +116,8 @@ class GameView : public VBoxContainer { void _hide_selection_toggled(bool p_pressed); + void _enable_audio_button_toggled(bool p_pressed); + void _camera_override_button_toggled(bool p_pressed); void _camera_override_menu_id_pressed(int p_id); diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 377bc0eefe91..693ff2b3caa8 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -52,6 +52,7 @@ #include "scene/main/window.h" #include "scene/resources/packed_scene.h" #include "scene/theme/theme_db.h" +#include "servers/audio_server.h" SceneDebugger::SceneDebugger() { singleton = this; @@ -144,6 +145,11 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra } else if (p_msg == "next_frame") { _next_frame(); + } else if (p_msg == "enable_audio") { // Enable/disable audio + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); + bool enable = p_args[0]; + AudioServer::get_singleton()->set_bus_mute(0, !enable); + } else if (p_msg == "override_cameras") { // Camera ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); bool enable = p_args[0]; From 938e0e5a8fed3fc8139852597048c899c29d5477 Mon Sep 17 00:00:00 2001 From: Malcolm Anderson Date: Thu, 21 Nov 2024 22:21:00 -0800 Subject: [PATCH 2/2] Mute bypasses buses in AudioServer Perhaps should be named to like `debug_mute` so that it's clearly not for external use? Also may need/want signals? --- scene/debugger/scene_debugger.cpp | 2 +- servers/audio_server.cpp | 10 +++++++++- servers/audio_server.h | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 693ff2b3caa8..a57b8c76632c 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -148,7 +148,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra } else if (p_msg == "enable_audio") { // Enable/disable audio ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); bool enable = p_args[0]; - AudioServer::get_singleton()->set_bus_mute(0, !enable); + AudioServer::get_singleton()->set_mute(!enable); } else if (p_msg == "override_cameras") { // Camera ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 63b2f28e7415..e4a796029bf5 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -295,7 +295,7 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) { // The destination start for data will be the same in all cases. int32_t *dest = &p_buffer[from_buf * (cs * 2) + (k * 2)]; - if (master->channels[k].active) { + if (master->channels[k].active && !mute) { const AudioFrame *buf = master->channels[k].buffer.ptr(); for (int j = 0; j < to_copy; j++) { @@ -766,6 +766,14 @@ int AudioServer::thread_find_bus_index(const StringName &p_name) { } } +void AudioServer::set_mute(bool p_mute) { + mute = p_mute; +} + +bool AudioServer::get_mute() const { + return mute; +} + void AudioServer::set_bus_count(int p_count) { ERR_FAIL_COND(p_count < 1); ERR_FAIL_INDEX(p_count, 256); diff --git a/servers/audio_server.h b/servers/audio_server.h index 9a80882dd7a1..928739789b73 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -229,6 +229,8 @@ class AudioServer : public Object { bool tag_used_audio_streams = false; + bool mute = false; + struct Bus { StringName name; bool solo = false; @@ -367,6 +369,9 @@ class AudioServer : public Object { int thread_get_mix_buffer_size() const; int thread_find_bus_index(const StringName &p_name); + void set_mute(bool p_mute); + bool get_mute() const; + void set_bus_count(int p_count); int get_bus_count() const;