Fix EditorAudioBuses not updating when changing to a device with different channels

This commit is contained in:
Marcelo Fernandez 2018-12-07 13:38:40 -03:00
parent 19f2a188bb
commit 792786b4b7
5 changed files with 56 additions and 7 deletions

View file

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