Skip to content

Commit

Permalink
Add "Mute Audio" button to Game view in editor
Browse files Browse the repository at this point in the history
Update servers/audio_server.cpp

Co-authored-by: A Thousand Ships <[email protected]>
  • Loading branch information
Meorge and AThousandShips committed Nov 26, 2024
1 parent 5efd124 commit 75e3277
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 1 deletion.
7 changes: 7 additions & 0 deletions editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions editor/debugger/editor_debugger_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Breakpoint, bool, Breakpoint> breakpoints;

Expand Down Expand Up @@ -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();

Expand Down
11 changes: 11 additions & 0 deletions editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions editor/debugger/script_editor_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions editor/icons/AudioMute.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions editor/plugins/game_view_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> 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"));
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -415,6 +432,14 @@ GameView::GameView(Ref<GameViewDebugger> 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);
Expand Down
9 changes: 9 additions & 0 deletions editor/plugins/game_view_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditorDebuggerSession> p_session);
Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions scene/debugger/scene_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
10 changes: 9 additions & 1 deletion servers/audio_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions servers/audio_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 75e3277

Please sign in to comment.