Skip to content

Commit

Permalink
Fix AudioBus volume level display in editor
Browse files Browse the repository at this point in the history
Updated dB to normalized value to use with TextureProgressBar

Updated BusVuActive.svg and BusVuFrozen.svg to line up gap at 0 dB, and more
completely fill in the icon vertically

Moved padding from EditorAudioMeterNotches to a MarginContainer that includes
the full HBoxContainer, to keep child items lined up with each other

Fixes godotengine#88952
  • Loading branch information
aaronp64 committed Mar 27, 2024
1 parent 7d151c8 commit 928e61f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
32 changes: 19 additions & 13 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "editor/gui/editor_file_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/separator.h"
#include "scene/resources/font.h"
#include "servers/audio_server.h"
Expand Down Expand Up @@ -160,8 +161,8 @@ void EditorAudioBus::_notification(int p_what) {
channel[i].peak_r -= get_process_delta_time() * 60.0;
}

channel[i].vu_l->set_value(channel[i].peak_l);
channel[i].vu_r->set_value(channel[i].peak_r);
channel[i].vu_l->set_value(_scaled_db_to_normalized_volume(channel[i].peak_l));
channel[i].vu_r->set_value(_scaled_db_to_normalized_volume(channel[i].peak_r));

if (activity_found != channel[i].prev_active) {
if (activity_found) {
Expand Down Expand Up @@ -844,7 +845,12 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
vb->add_child(separator);

HBoxContainer *hb = memnew(HBoxContainer);
vb->add_child(hb);
MarginContainer *mc = memnew(MarginContainer);
mc->add_theme_constant_override("margin_top", 5.0);
mc->add_theme_constant_override("margin_bottom", 9.0);
mc->add_child(hb);

vb->add_child(mc);
slider = memnew(VSlider);
slider->set_min(0.0);
slider->set_max(1.0);
Expand Down Expand Up @@ -883,16 +889,16 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
channel[i].vu_l = memnew(TextureProgressBar);
channel[i].vu_l->set_fill_mode(TextureProgressBar::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_l->set_min(0.0);
channel[i].vu_l->set_max(1.0);
channel[i].vu_l->set_step(0.001);

channel[i].vu_r = memnew(TextureProgressBar);
channel[i].vu_r->set_fill_mode(TextureProgressBar::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);
channel[i].vu_r->set_min(0.0);
channel[i].vu_r->set_max(1.0);
channel[i].vu_r->set_step(0.001);

channel[i].peak_l = 0.0f;
channel[i].peak_r = 0.0f;
Expand Down Expand Up @@ -1408,7 +1414,7 @@ Size2 EditorAudioMeterNotches::get_minimum_size() const {
float font_height = font->get_height(font_size);

float width = 0;
float height = top_padding + btm_padding;
float height = 0;

for (int i = 0; i < notches.size(); i++) {
if (notches[i].render_db_value) {
Expand Down Expand Up @@ -1448,15 +1454,15 @@ void EditorAudioMeterNotches::_draw_audio_notches() {

for (int i = 0; i < notches.size(); i++) {
AudioNotch n = notches[i];
draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
draw_line(Vector2(0, (1.0f - n.relative_position) * get_size().y),
Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * get_size().y),
theme_cache.notch_color,
Math::round(EDSCALE));

if (n.render_db_value) {
draw_string(theme_cache.font,
Vector2((line_length + label_space) * EDSCALE,
(1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding),
(1.0f - n.relative_position) * get_size().y + (font_height / 4)),
String::num(Math::abs(n.db_value)) + "dB",
HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size,
theme_cache.notch_color);
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_audio_buses.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ class EditorAudioMeterNotches : public Control {
public:
const float line_length = 5.0f;
const float label_space = 2.0f;
const float btm_padding = 9.0f;
const float top_padding = 5.0f;

void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
Size2 get_minimum_size() const override;
Expand Down
2 changes: 1 addition & 1 deletion editor/icons/BusVuActive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion editor/icons/BusVuFrozen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 928e61f

Please sign in to comment.