diff options
Diffstat (limited to 'editor/editor_audio_buses.cpp')
-rw-r--r-- | editor/editor_audio_buses.cpp | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 29159c7ad5..a36faeb0de 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -39,10 +39,13 @@ void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); - vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons")); - vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons")); - vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons")); + for (int i = 0; i < cc; 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")); + channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons")); + channel[i].prev_active = true; + } scale->set_texture(get_icon("BusVuDb", "EditorIcons")); disabled_vu = get_icon("BusVuFrozen", "EditorIcons"); @@ -53,7 +56,6 @@ void EditorAudioBus::_notification(int p_what) { bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons")); - prev_active = true; update_bus(); set_process(true); } @@ -67,60 +69,52 @@ void EditorAudioBus::_notification(int p_what) { if (p_what == NOTIFICATION_PROCESS) { - float real_peak[2] = { -100, -100 }; - bool activity_found = false; - - int cc = 0; - switch (AudioServer::get_singleton()->get_speaker_mode()) { - case AudioServer::SPEAKER_MODE_STEREO: cc = 1; break; - case AudioServer::SPEAKER_SURROUND_51: cc = 4; break; - case AudioServer::SPEAKER_SURROUND_71: cc = 5; break; - default: - ERR_PRINT("Unknown speaker_mode"); - break; - } - for (int i = 0; i < cc; i++) { + float real_peak[2] = { -100, -100 }; + bool activity_found = false; + if (AudioServer::get_singleton()->is_bus_channel_active(get_index(), i)) { activity_found = true; real_peak[0] = MAX(real_peak[0], AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(), i)); real_peak[1] = MAX(real_peak[1], AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(), i)); } - } - if (real_peak[0] > peak_l) { - peak_l = real_peak[0]; - } else { - peak_l -= get_process_delta_time() * 60.0; - } - - if (real_peak[1] > peak_r) { - peak_r = real_peak[1]; - } else { - peak_r -= get_process_delta_time() * 60.0; - } - - vu_l->set_value(peak_l); - vu_r->set_value(peak_r); + if (real_peak[0] > channel[i].peak_l) { + channel[i].peak_l = real_peak[0]; + } else { + channel[i].peak_l -= get_process_delta_time() * 60.0; + } - if (activity_found != prev_active) { - if (activity_found) { - vu_l->set_over_texture(Ref<Texture>()); - vu_r->set_over_texture(Ref<Texture>()); + if (real_peak[1] > channel[i].peak_r) { + channel[i].peak_r = real_peak[1]; } else { - vu_l->set_over_texture(disabled_vu); - vu_r->set_over_texture(disabled_vu); + channel[i].peak_r -= get_process_delta_time() * 60.0; } - prev_active = activity_found; + channel[i].vu_l->set_value(channel[i].peak_l); + channel[i].vu_r->set_value(channel[i].peak_r); + + if (activity_found != channel[i].prev_active) { + if (activity_found) { + channel[i].vu_l->set_over_texture(Ref<Texture>()); + channel[i].vu_r->set_over_texture(Ref<Texture>()); + } else { + channel[i].vu_l->set_over_texture(disabled_vu); + channel[i].vu_r->set_over_texture(disabled_vu); + } + + channel[i].prev_active = activity_found; + } } } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - peak_l = -100; - peak_r = -100; - prev_active = true; + for (int i = 0; i < 4; i++) { + channel[i].peak_l = -100; + channel[i].peak_r = -100; + channel[i].prev_active = true; + } set_process(is_visible_in_tree()); } @@ -683,19 +677,24 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) { slider->connect("value_changed", this, "_volume_db_changed"); hb->add_child(slider); - vu_l = memnew(TextureProgress); - vu_l->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); - hb->add_child(vu_l); - vu_l->set_min(-80); - vu_l->set_max(24); - vu_l->set_step(0.1); - - vu_r = memnew(TextureProgress); - vu_r->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); - hb->add_child(vu_r); - vu_r->set_min(-80); - vu_r->set_max(24); - vu_r->set_step(0.1); + + cc = AudioServer::get_singleton()->get_channel_count(); + + for (int i = 0; i < cc; 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); + channel[i].vu_l->set_min(-80); + channel[i].vu_l->set_max(24); + channel[i].vu_l->set_step(0.1); + + channel[i].vu_r = memnew(TextureProgress); + channel[i].vu_r->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); + hb->add_child(channel[i].vu_r); + channel[i].vu_r->set_min(-80); + channel[i].vu_r->set_max(24); + channel[i].vu_r->set_step(0.1); + } scale = memnew(TextureRect); hb->add_child(scale); |