diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-12-12 13:55:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 13:55:21 +0100 |
commit | 4fe5a1dbefaa8bedc14755e84702342d7aea1157 (patch) | |
tree | dd4e7f58e90e875ffeaab7da737fb340f75def03 | |
parent | ac87560fda1dedabfc42ceaa215ad1f9174bd42b (diff) | |
parent | 792786b4b7e8d1fd4f708178d77537b6811e9be1 (diff) |
Merge pull request #24214 from marcelofg55/editor_audio_buses_fix
Fix EditorAudioBuses not updating when changing to a device with different channels
-rw-r--r-- | doc/classes/AudioServer.xml | 9 | ||||
-rw-r--r-- | editor/editor_audio_buses.cpp | 40 | ||||
-rw-r--r-- | editor/editor_audio_buses.h | 4 | ||||
-rw-r--r-- | servers/audio_server.cpp | 8 | ||||
-rw-r--r-- | servers/audio_server.h | 2 |
5 files changed, 56 insertions, 7 deletions
diff --git a/doc/classes/AudioServer.xml b/doc/classes/AudioServer.xml index 3ae5454e65..e1939e679d 100644 --- a/doc/classes/AudioServer.xml +++ b/doc/classes/AudioServer.xml @@ -61,6 +61,15 @@ Generates an [AudioBusLayout] using the available busses and effects. </description> </method> + <method name="get_bus_channels" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="bus_idx" type="int"> + </argument> + <description> + Returns the amount of channels of the bus at index [code]bus_idx[/code]. + </description> + </method> <method name="get_bus_count" qualifiers="const"> <return type="int"> </return> diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 6cd81626c7..b1f5bc4908 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -36,11 +36,35 @@ #include "filesystem_dock.h" #include "servers/audio_server.h" +void EditorAudioBus::_update_visible_channels() { + + int i = 0; + for (; i < cc; i++) { + + if (!channel[i].vu_l->is_visible()) { + channel[i].vu_l->show(); + } + if (!channel[i].vu_r->is_visible()) { + channel[i].vu_r->show(); + } + } + + for (; i < CHANNELS_MAX; i++) { + + if (channel[i].vu_l->is_visible()) { + channel[i].vu_l->hide(); + } + if (channel[i].vu_r->is_visible()) { + channel[i].vu_r->hide(); + } + } +} + void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - for (int i = 0; i < cc; i++) { + for (int i = 0; i < CHANNELS_MAX; i++) { channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons")); channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); @@ -72,6 +96,11 @@ void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_PROCESS) { + if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) { + cc = AudioServer::get_singleton()->get_bus_channels(get_index()); + _update_visible_channels(); + } + for (int i = 0; i < cc; i++) { float real_peak[2] = { -100, -100 }; bool activity_found = false; @@ -113,7 +142,7 @@ void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < CHANNELS_MAX; i++) { channel[i].peak_l = -100; channel[i].peak_r = -100; channel[i].prev_active = true; @@ -124,7 +153,7 @@ void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED) { - for (int i = 0; i < cc; i++) { + for (int i = 0; i < CHANNELS_MAX; i++) { channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons")); channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); @@ -709,9 +738,8 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { slider->connect("value_changed", this, "_volume_db_changed"); hb->add_child(slider); - cc = AudioServer::get_singleton()->get_channel_count(); - - for (int i = 0; i < cc; i++) { + cc = 0; + for (int i = 0; i < CHANNELS_MAX; i++) { channel[i].vu_l = memnew(TextureProgress); channel[i].vu_l->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); hb->add_child(channel[i].vu_l); diff --git a/editor/editor_audio_buses.h b/editor/editor_audio_buses.h index 4cdcb65d7b..02038fbe18 100644 --- a/editor/editor_audio_buses.h +++ b/editor/editor_audio_buses.h @@ -59,6 +59,7 @@ class EditorAudioBus : public PanelContainer { VSlider *slider; int cc; + static const int CHANNELS_MAX = 4; struct { bool prev_active; @@ -68,7 +69,7 @@ class EditorAudioBus : public PanelContainer { TextureProgress *vu_l; TextureProgress *vu_r; - } channel[4]; + } channel[CHANNELS_MAX]; TextureRect *scale; OptionButton *send; @@ -102,6 +103,7 @@ class EditorAudioBus : public PanelContainer { void _effect_selected(); void _delete_effect_pressed(int p_option); void _effect_rmb(const Vector2 &p_pos); + void _update_visible_channels(); virtual Variant get_drag_data(const Point2 &p_point); virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const; diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 6fd996c3d3..530976f084 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -737,6 +737,12 @@ float AudioServer::get_bus_volume_db(int p_bus) const { return buses[p_bus]->volume_db; } +int AudioServer::get_bus_channels(int p_bus) const { + + ERR_FAIL_INDEX_V(p_bus, buses.size(), 0); + return buses[p_bus]->channels.size(); +} + void AudioServer::set_bus_send(int p_bus, const StringName &p_send) { ERR_FAIL_INDEX(p_bus, buses.size()); @@ -1267,6 +1273,8 @@ void AudioServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bus_name", "bus_idx"), &AudioServer::get_bus_name); ClassDB::bind_method(D_METHOD("get_bus_index", "bus_name"), &AudioServer::get_bus_index); + ClassDB::bind_method(D_METHOD("get_bus_channels", "bus_idx"), &AudioServer::get_bus_channels); + ClassDB::bind_method(D_METHOD("set_bus_volume_db", "bus_idx", "volume_db"), &AudioServer::set_bus_volume_db); ClassDB::bind_method(D_METHOD("get_bus_volume_db", "bus_idx"), &AudioServer::get_bus_volume_db); diff --git a/servers/audio_server.h b/servers/audio_server.h index 52fa84e3e6..642af9b252 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -299,6 +299,8 @@ public: String get_bus_name(int p_bus) const; int get_bus_index(const StringName &p_bus_name) const; + int get_bus_channels(int p_bus) const; + void set_bus_volume_db(int p_bus, float p_volume_db); float get_bus_volume_db(int p_bus) const; |