From 75e327718e67dcccfcca9bb73ad085ac1376a513 Mon Sep 17 00:00:00 2001 From: Malcolm Anderson Date: Thu, 21 Nov 2024 21:31:00 -0800 Subject: [PATCH] Add "Mute Audio" button to Game view in editor Update servers/audio_server.cpp Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- 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/icons/AudioMute.svg | 1 + editor/plugins/game_view_plugin.cpp | 25 ++++++++++++++++++++++ editor/plugins/game_view_plugin.h | 9 ++++++++ scene/debugger/scene_debugger.cpp | 6 ++++++ servers/audio_server.cpp | 10 ++++++++- servers/audio_server.h | 5 +++++ 10 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 editor/icons/AudioMute.svg diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 0f948b4ed591..465b789eab93 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_debug_mute_audio(bool p_mute) { + _for_all(tabs, [&](ScriptEditorDebugger *dbg) { + dbg->set_debug_mute_audio(p_mute); + }); + debug_mute_audio = p_mute; +} + 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..b5f3f6d74cde 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 debug_mute_audio = false; + 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_debug_mute_audio(bool p_mute); + 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..9c737e56f987 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_debug_mute_audio() const { + return debug_mute_audio; +} + +void ScriptEditorDebugger::set_debug_mute_audio(bool p_mute) { + Array msg; + msg.push_back(p_mute); + _put_msg("scene:debug_mute_audio", msg); + debug_mute_audio = p_mute; +} + 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..46a392651907 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 debug_mute_audio = false; + 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_debug_mute_audio() const; + void set_debug_mute_audio(bool p_mute); + EditorDebuggerNode::CameraOverride get_camera_override() const; void set_camera_override(EditorDebuggerNode::CameraOverride p_override); diff --git a/editor/icons/AudioMute.svg b/editor/icons/AudioMute.svg new file mode 100644 index 000000000000..02507e722572 --- /dev/null +++ b/editor/icons/AudioMute.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/plugins/game_view_plugin.cpp b/editor/plugins/game_view_plugin.cpp index 5c1f81ee94e3..7b414b04edb5 100644 --- a/editor/plugins/game_view_plugin.cpp +++ b/editor/plugins/game_view_plugin.cpp @@ -60,6 +60,9 @@ void GameViewDebugger::_session_started(Ref p_session) { Array mode; mode.append(select_mode); p_session->send_message("scene:runtime_node_select_set_mode", mode); + Array mute_audio; + mute_audio.append(debug_mute_audio); + p_session->send_message("scene:debug_mute_audio", mute_audio); emit_signal(SNAME("session_started")); } @@ -126,6 +129,11 @@ void GameViewDebugger::set_select_mode(int p_mode) { } } +void GameViewDebugger::set_debug_mute_audio(bool p_enabled) { + debug_mute_audio = p_enabled; + EditorDebuggerNode::get_singleton()->set_debug_mute_audio(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 +243,13 @@ void GameView::_hide_selection_toggled(bool p_pressed) { debugger->set_selection_visible(!p_pressed); } +void GameView::_debug_mute_audio_button_pressed() { + debug_mute_audio = !debug_mute_audio; + debug_mute_audio_button->set_button_icon(get_editor_theme_icon(debug_mute_audio ? SNAME("AudioMute") : SNAME("AudioStreamPlayer"))); + debug_mute_audio_button->set_tooltip_text(debug_mute_audio ? TTR("Unmute game audio.") : TTR("Mute game audio.")); + debugger->set_debug_mute_audio(debug_mute_audio); +} + void GameView::_camera_override_button_toggled(bool p_pressed) { _update_debugger_buttons(); @@ -288,6 +303,8 @@ void GameView::_notification(int p_what) { hide_selection->set_button_icon(get_editor_theme_icon(hide_selection->is_pressed() ? SNAME("GuiVisibilityHidden") : SNAME("GuiVisibilityVisible"))); + debug_mute_audio_button->set_button_icon(get_editor_theme_icon(debug_mute_audio ? SNAME("AudioMute") : 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 +432,14 @@ GameView::GameView(Ref p_debugger) { main_menu_hbox->add_child(memnew(VSeparator)); + debug_mute_audio_button = memnew(Button); + main_menu_hbox->add_child(debug_mute_audio_button); + debug_mute_audio_button->set_theme_type_variation("FlatButton"); + debug_mute_audio_button->connect(SceneStringName(pressed), callable_mp(this, &GameView::_debug_mute_audio_button_pressed)); + debug_mute_audio_button->set_tooltip_text(debug_mute_audio ? TTR("Unmute game audio.") : TTR("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..f2f84eb6022f 100644 --- a/editor/plugins/game_view_plugin.h +++ b/editor/plugins/game_view_plugin.h @@ -46,6 +46,7 @@ class GameViewDebugger : public EditorDebuggerPlugin { int node_type = RuntimeNodeSelect::NODE_TYPE_NONE; bool selection_visible = true; int select_mode = RuntimeNodeSelect::SELECT_MODE_SINGLE; + bool debug_mute_audio = false; EditorDebuggerNode::CameraOverride camera_override_mode = EditorDebuggerNode::OVERRIDE_INGAME; void _session_started(Ref p_session); @@ -63,6 +64,8 @@ class GameViewDebugger : public EditorDebuggerPlugin { void set_selection_visible(bool p_visible); + void set_debug_mute_audio(bool p_enabled); + void set_camera_override(bool p_enabled); void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode); @@ -88,6 +91,8 @@ class GameView : public VBoxContainer { int active_sessions = 0; + bool debug_mute_audio = false; + Button *suspend_button = nullptr; Button *next_frame_button = nullptr; @@ -96,6 +101,8 @@ class GameView : public VBoxContainer { Button *hide_selection = nullptr; + Button *debug_mute_audio_button = nullptr; + Button *camera_override_button = nullptr; MenuButton *camera_override_menu = nullptr; @@ -112,6 +119,8 @@ class GameView : public VBoxContainer { void _hide_selection_toggled(bool p_pressed); + void _debug_mute_audio_button_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..1c92e59a56eb 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 == "debug_mute_audio") { // Enable/disable audio + ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); + bool do_mute = p_args[0]; + AudioServer::get_singleton()->set_debug_mute(do_mute); + } else if (p_msg == "override_cameras") { // Camera ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA); bool enable = p_args[0]; diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 63b2f28e7415..f31ea5339a1b 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 (!debug_mute && master->channels[k].active) { 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_debug_mute(bool p_mute) { + debug_mute = p_mute; +} + +bool AudioServer::get_debug_mute() const { + return debug_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..aed274f6400b 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 debug_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_debug_mute(bool p_mute); + bool get_debug_mute() const; + void set_bus_count(int p_count); int get_bus_count() const;