summaryrefslogtreecommitdiff
path: root/editor/editor_audio_buses.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_audio_buses.cpp')
-rw-r--r--editor/editor_audio_buses.cpp587
1 files changed, 411 insertions, 176 deletions
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 5d0abef4b8..2180742bbb 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -34,6 +34,7 @@
#include "core/os/keyboard.h"
#include "editor_node.h"
#include "filesystem_dock.h"
+#include "scene/resources/font.h"
#include "servers/audio_server.h"
void EditorAudioBus::_update_visible_channels() {
@@ -62,113 +63,132 @@ void EditorAudioBus::_update_visible_channels() {
void EditorAudioBus::_notification(int p_what) {
- if (p_what == NOTIFICATION_READY) {
+ switch (p_what) {
+ case NOTIFICATION_READY: {
- 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"));
- 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");
-
- solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
- mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
- bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
+ 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"));
+ channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
+ channel[i].prev_active = true;
+ }
- bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
+ disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
- update_bus();
- set_process(true);
- }
+ Color solo_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.0, 0.92, 0.44);
+ Color mute_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(1.0, 0.44, 0.44);
+ Color bypass_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(0.44, 0.87, 1.0);
- if (p_what == NOTIFICATION_DRAW) {
+ solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
+ solo->add_color_override("icon_color_pressed", solo_color);
+ mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
+ mute->add_color_override("icon_color_pressed", mute_color);
+ bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
+ bypass->add_color_override("icon_color_pressed", bypass_color);
- if (has_focus()) {
- draw_style_box(get_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
- } else if (is_master) {
- draw_style_box(get_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
- }
- }
+ bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
- if (p_what == NOTIFICATION_PROCESS) {
+ update_bus();
+ set_process(true);
+ } break;
+ case NOTIFICATION_DRAW: {
- 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;
-
- 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 (is_master) {
+ draw_style_box(get_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
+ } else if (has_focus()) {
+ draw_style_box(get_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
+ } else {
+ draw_style_box(get_stylebox("panel", "TabContainer"), Rect2(Vector2(), get_size()));
}
- 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 (get_index() != 0 && hovering_drop) {
+ Color accent = get_color("accent_color", "Editor");
+ accent.a *= 0.7;
+ draw_rect(Rect2(Point2(), get_size()), accent, false);
}
+ } break;
+ case NOTIFICATION_PROCESS: {
- if (real_peak[1] > channel[i].peak_r) {
- channel[i].peak_r = real_peak[1];
- } else {
- channel[i].peak_r -= get_process_delta_time() * 60.0;
+ if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
+ cc = AudioServer::get_singleton()->get_bus_channels(get_index());
+ _update_visible_channels();
}
- channel[i].vu_l->set_value(channel[i].peak_l);
- channel[i].vu_r->set_value(channel[i].peak_r);
+ 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] > 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 != 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>());
+ if (real_peak[1] > channel[i].peak_r) {
+ channel[i].peak_r = real_peak[1];
} else {
- channel[i].vu_l->set_over_texture(disabled_vu);
- channel[i].vu_r->set_over_texture(disabled_vu);
+ channel[i].peak_r -= get_process_delta_time() * 60.0;
}
- channel[i].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 (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
+ 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);
+ }
- for (int i = 0; i < CHANNELS_MAX; i++) {
- channel[i].peak_l = -100;
- channel[i].peak_r = -100;
- channel[i].prev_active = true;
- }
+ channel[i].prev_active = activity_found;
+ }
+ }
+ } break;
+ case NOTIFICATION_VISIBILITY_CHANGED: {
- set_process(is_visible_in_tree());
- }
+ for (int i = 0; i < CHANNELS_MAX; i++) {
+ channel[i].peak_l = -100;
+ channel[i].peak_r = -100;
+ channel[i].prev_active = true;
+ }
- if (p_what == NOTIFICATION_THEME_CHANGED) {
+ set_process(is_visible_in_tree());
+ } break;
+ case NOTIFICATION_THEME_CHANGED: {
- 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"));
- channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
- channel[i].prev_active = true;
- }
- scale->set_texture(get_icon("BusVuDb", "EditorIcons"));
+ 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"));
+ channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
+ channel[i].prev_active = true;
+ }
+
+ disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
- disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
+ solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
+ mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
+ bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
- solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
- mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
- bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
+ bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
+ } break;
+ case NOTIFICATION_MOUSE_EXIT:
+ case NOTIFICATION_DRAG_END: {
- bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
+ if (hovering_drop) {
+ hovering_drop = false;
+ update();
+ }
+ } break;
}
}
@@ -204,7 +224,8 @@ void EditorAudioBus::update_bus() {
int index = get_index();
- slider->set_value(AudioServer::get_singleton()->get_bus_volume_db(index));
+ float db_value = AudioServer::get_singleton()->get_bus_volume_db(index);
+ slider->set_value(_scaled_db_to_normalized_volume(db_value));
track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
if (is_master)
track_name->set_editable(false);
@@ -267,7 +288,7 @@ void EditorAudioBus::_name_changed(const String &p_new_name) {
}
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
StringName current = AudioServer::get_singleton()->get_bus_name(get_index());
ur->create_action(TTR("Rename Audio Bus"));
@@ -293,14 +314,16 @@ void EditorAudioBus::_name_changed(const String &p_new_name) {
track_name->release_focus();
}
-void EditorAudioBus::_volume_db_changed(float p_db) {
+void EditorAudioBus::_volume_changed(float p_normalized) {
if (updating_bus)
return;
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ float p_db = this->_normalized_volume_to_scaled_db(p_normalized);
+
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS);
ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), p_db);
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), AudioServer::get_singleton()->get_bus_volume_db(get_index()));
@@ -310,11 +333,74 @@ void EditorAudioBus::_volume_db_changed(float p_db) {
updating_bus = false;
}
+
+float EditorAudioBus::_normalized_volume_to_scaled_db(float normalized) {
+ /* There are three different formulas for the conversion from normalized
+ * values to relative decibal values.
+ * One formula is an exponential graph which intends to counteract
+ * the logorithmic nature of human hearing. This is an approximation
+ * of the behaviour of a 'logarithmic potentiometer' found on most
+ * musical instruments and also emulated in popular software.
+ * The other two equations are hand-tuned linear tapers that intend to
+ * try to ease the exponential equation in areas where it makes sense.*/
+
+ if (normalized > 0.6f) {
+ return 22.22f * normalized - 16.2f;
+ } else if (normalized < 0.05f) {
+ return 830.72 * normalized - 80.0f;
+ } else {
+ return 45.0f * Math::pow(normalized - 1.0, 3);
+ }
+}
+
+float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
+ /* Inversion of equations found in _normalized_volume_to_scaled_db.
+ * IMPORTANT: If one function changes, the other much change to reflect it. */
+ if (db > -2.88) {
+ return (db + 16.2f) / 22.22f;
+ } else if (db < -38.602f) {
+ return (db + 80.00f) / 830.72f;
+ } else {
+ if (db < 0.0) {
+ /* To accommodate for NaN on negative numbers for root, we will mirror the
+ * results of the positive db range in order to get the desired numerical
+ * value on the negative side. */
+ float positive_x = Math::pow(Math::abs(db) / 45.0f, 1.0f / 3.0f) + 1.0f;
+ Vector2 translation = Vector2(1.0f, 0.0f) - Vector2(positive_x, Math::abs(db));
+ Vector2 reflected_position = Vector2(1.0, 0.0f) + translation;
+ return reflected_position.x;
+ } else {
+ return Math::pow(db / 45.0f, 1.0f / 3.0f) + 1.0f;
+ }
+ }
+}
+
+void EditorAudioBus::_show_value(float slider_value) {
+ String text = vformat("%10.1f dB", _normalized_volume_to_scaled_db(slider_value));
+
+ audio_value_preview_label->set_text(text);
+ Vector2 slider_size = slider->get_size();
+ Vector2 slider_position = slider->get_global_position();
+ float left_padding = 5.0f;
+ float vert_padding = 10.0f;
+ Vector2 box_position = Vector2(slider_size.x + left_padding, (slider_size.y - vert_padding) * (1.0f - slider_value) - vert_padding);
+ audio_value_preview_box->set_position(slider_position + box_position);
+ audio_value_preview_box->set_size(audio_value_preview_label->get_size());
+ if (slider->has_focus() && !audio_value_preview_box->is_visible()) {
+ audio_value_preview_box->show();
+ }
+ preview_timer->start();
+}
+
+void EditorAudioBus::_hide_value_preview() {
+ audio_value_preview_box->hide();
+}
+
void EditorAudioBus::_solo_toggled() {
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Toggle Audio Bus Solo"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), solo->is_pressed());
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), AudioServer::get_singleton()->is_bus_solo(get_index()));
@@ -328,7 +414,7 @@ void EditorAudioBus::_mute_toggled() {
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Toggle Audio Bus Mute"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), mute->is_pressed());
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), AudioServer::get_singleton()->is_bus_mute(get_index()));
@@ -342,7 +428,7 @@ void EditorAudioBus::_bypass_toggled() {
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Toggle Audio Bus Bypass Effects"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), bypass->is_pressed());
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), AudioServer::get_singleton()->is_bus_bypassing_effects(get_index()));
@@ -357,8 +443,8 @@ void EditorAudioBus::_send_selected(int p_which) {
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
- ur->create_action("Select Audio Bus Send");
+ UndoRedo *ur = EditorNode::get_undo_redo();
+ ur->create_action(TTR("Select Audio Bus Send"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", get_index(), send->get_item_text(p_which));
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", get_index(), AudioServer::get_singleton()->get_bus_send(get_index()));
ur->add_do_method(buses, "_update_bus", get_index());
@@ -378,9 +464,9 @@ void EditorAudioBus::_effect_selected() {
if (effect->get_metadata(0) != Variant()) {
int index = effect->get_metadata(0);
- Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
- if (effect.is_valid()) {
- EditorNode::get_singleton()->push_item(effect.ptr());
+ Ref<AudioEffect> effect2 = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
+ if (effect2.is_valid()) {
+ EditorNode::get_singleton()->push_item(effect2.ptr());
}
}
@@ -406,7 +492,7 @@ void EditorAudioBus::_effect_edited() {
int index = effect->get_metadata(0);
updating_bus = true;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Select Audio Bus Send"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, effect->is_checked(0));
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index));
@@ -433,7 +519,7 @@ void EditorAudioBus::_effect_add(int p_which) {
afxr->set_name(effect_options->get_item_text(p_which));
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Add Audio Bus Effect"));
ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), afxr, -1);
ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect_count(get_index()));
@@ -481,6 +567,7 @@ Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
Control *c = memnew(Control);
Panel *p = memnew(Panel);
c->add_child(p);
+ p->set_modulate(Color(1, 1, 1, 0.7));
p->add_style_override("panel", get_stylebox("focus", "Button"));
p->set_size(get_size());
p->set_position(-p_point);
@@ -488,21 +575,29 @@ Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
Dictionary d;
d["type"] = "move_audio_bus";
d["index"] = get_index();
- emit_signal("drop_end_request");
+
+ if (get_index() < AudioServer::get_singleton()->get_bus_count() - 1) {
+ emit_signal("drop_end_request");
+ }
+
return d;
}
bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
- if (get_index() == 0)
+ if (get_index() == 0) {
return false;
+ }
+
Dictionary d = p_data;
- if (d.has("type") && String(d["type"]) == "move_audio_bus") {
+ if (d.has("type") && String(d["type"]) == "move_audio_bus" && (int)d["index"] != get_index()) {
+ hovering_drop = true;
return true;
}
return false;
}
+
void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) {
Dictionary d = p_data;
@@ -517,7 +612,6 @@ Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from)
}
Variant md = item->get_metadata(0);
-
if (md.get_type() == Variant::INT) {
Dictionary fxd;
fxd["type"] = "audio_bus_effect";
@@ -577,7 +671,7 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus, effect);
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Move Bus Effect"));
ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", bus, effect);
ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(bus, effect), paste_at);
@@ -618,7 +712,7 @@ void EditorAudioBus::_delete_effect_pressed(int p_option) {
int index = item->get_metadata(0);
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Delete Bus Effect"));
ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), index);
ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(get_index(), index), index);
@@ -646,7 +740,9 @@ void EditorAudioBus::_bind_methods() {
ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
ClassDB::bind_method("_name_changed", &EditorAudioBus::_name_changed);
- ClassDB::bind_method("_volume_db_changed", &EditorAudioBus::_volume_db_changed);
+ ClassDB::bind_method("_volume_changed", &EditorAudioBus::_volume_changed);
+ ClassDB::bind_method("_show_value", &EditorAudioBus::_show_value);
+ ClassDB::bind_method("_hide_value_preview", &EditorAudioBus::_hide_value_preview);
ClassDB::bind_method("_solo_toggled", &EditorAudioBus::_solo_toggled);
ClassDB::bind_method("_mute_toggled", &EditorAudioBus::_mute_toggled);
ClassDB::bind_method("_bypass_toggled", &EditorAudioBus::_bypass_toggled);
@@ -675,6 +771,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
buses = p_buses;
updating_bus = false;
is_master = p_is_master;
+ hovering_drop = false;
set_tooltip(TTR("Audio Bus, Drag and Drop to rearrange."));
@@ -682,7 +779,6 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
add_child(vb);
set_v_size_flags(SIZE_EXPAND_FILL);
- set_custom_minimum_size(Size2(100, 0) * EDSCALE);
track_name = memnew(LineEdit);
track_name->connect("text_entered", this, "_name_changed");
@@ -726,16 +822,48 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
child->add_style_override("pressed", sbempty);
}
- vb->add_child(memnew(HSeparator));
+ HSeparator *separator = memnew(HSeparator);
+ separator->set_mouse_filter(MOUSE_FILTER_PASS);
+ vb->add_child(separator);
HBoxContainer *hb = memnew(HBoxContainer);
vb->add_child(hb);
slider = memnew(VSlider);
- slider->set_min(-80);
- slider->set_max(24);
- slider->set_step(0.1);
-
- slider->connect("value_changed", this, "_volume_db_changed");
+ slider->set_min(0.0);
+ slider->set_max(1.0);
+ slider->set_step(0.0001);
+ slider->set_clip_contents(false);
+
+ audio_value_preview_box = memnew(Panel);
+ HBoxContainer *audioprev_hbc = memnew(HBoxContainer);
+ audioprev_hbc->set_v_size_flags(SIZE_EXPAND_FILL);
+ audioprev_hbc->set_h_size_flags(SIZE_EXPAND_FILL);
+ audioprev_hbc->set_mouse_filter(MOUSE_FILTER_PASS);
+ audio_value_preview_box->add_child(audioprev_hbc);
+
+ audio_value_preview_label = memnew(Label);
+ audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL);
+ audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL);
+ audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS);
+
+ audioprev_hbc->add_child(audio_value_preview_label);
+
+ slider->add_child(audio_value_preview_box);
+ audio_value_preview_box->set_as_toplevel(true);
+ Ref<StyleBoxFlat> panel_style = memnew(StyleBoxFlat);
+ panel_style->set_bg_color(Color(0.0f, 0.0f, 0.0f, 0.8f));
+ audio_value_preview_box->add_style_override("panel", panel_style);
+ audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS);
+ audio_value_preview_box->hide();
+
+ preview_timer = memnew(Timer);
+ preview_timer->set_wait_time(0.8f);
+ preview_timer->set_one_shot(true);
+ add_child(preview_timer);
+
+ slider->connect("value_changed", this, "_volume_changed");
+ slider->connect("value_changed", this, "_show_value");
+ preview_timer->connect("timeout", this, "_hide_value_preview");
hb->add_child(slider);
cc = 0;
@@ -758,12 +886,18 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
channel[i].peak_r = 0.0f;
}
- scale = memnew(TextureRect);
+ EditorAudioMeterNotches *scale = memnew(EditorAudioMeterNotches);
+
+ for (float db = 6.0f; db >= -80.0f; db -= 6.0f) {
+ bool renderNotch = (db >= -6.0f || db == -24.0f || db == -72.0f);
+ scale->add_notch(_scaled_db_to_normalized_volume(db), db, renderNotch);
+ }
+ scale->set_mouse_filter(MOUSE_FILTER_PASS);
hb->add_child(scale);
effects = memnew(Tree);
effects->set_hide_root(true);
- effects->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
+ effects->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
effects->set_hide_folding(true);
effects->set_v_size_flags(SIZE_EXPAND_FILL);
vb->add_child(effects);
@@ -813,19 +947,46 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
delete_effect_popup->connect("index_pressed", this, "_delete_effect_pressed");
}
-bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
+void EditorAudioBusDrop::_notification(int p_what) {
- Dictionary d = p_data;
- if (d.has("type") && String(d["type"]) == "move_audio_bus") {
- return true;
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ draw_style_box(get_stylebox("normal", "Button"), Rect2(Vector2(), get_size()));
+
+ if (hovering_drop) {
+ Color accent = get_color("accent_color", "Editor");
+ accent.a *= 0.7;
+ draw_rect(Rect2(Point2(), get_size()), accent, false);
+ }
+ } break;
+ case NOTIFICATION_MOUSE_ENTER: {
+
+ if (!hovering_drop) {
+ hovering_drop = true;
+ update();
+ }
+ } break;
+ case NOTIFICATION_MOUSE_EXIT:
+ case NOTIFICATION_DRAG_END: {
+
+ if (hovering_drop) {
+ hovering_drop = false;
+ update();
+ }
+ } break;
}
+}
- return false;
+bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
+
+ Dictionary d = p_data;
+ return (d.has("type") && String(d["type"]) == "move_audio_bus");
}
+
void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) {
Dictionary d = p_data;
- emit_signal("dropped", d["index"], -1);
+ emit_signal("dropped", d["index"], AudioServer::get_singleton()->get_bus_count());
}
void EditorAudioBusDrop::_bind_methods() {
@@ -834,6 +995,8 @@ void EditorAudioBusDrop::_bind_methods() {
}
EditorAudioBusDrop::EditorAudioBusDrop() {
+
+ hovering_drop = false;
}
void EditorAudioBuses::_update_buses() {
@@ -846,7 +1009,7 @@ void EditorAudioBuses::_update_buses() {
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- bool is_master = i == 0 ? true : false;
+ bool is_master = (i == 0);
EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master));
bus_hb->add_child(audio_bus);
audio_bus->connect("delete_request", this, "_delete_bus", varray(audio_bus), CONNECT_DEFERRED);
@@ -866,45 +1029,50 @@ EditorAudioBuses *EditorAudioBuses::register_editor() {
void EditorAudioBuses::_notification(int p_what) {
- if (p_what == NOTIFICATION_READY) {
- _update_buses();
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
- if (p_what == NOTIFICATION_DRAG_END) {
- if (drop_end) {
- drop_end->queue_delete();
- drop_end = NULL;
- }
- }
+ bus_scroll->add_style_override("bg", get_stylebox("bg", "Tree"));
+ } break;
+ case NOTIFICATION_READY: {
- if (p_what == NOTIFICATION_PROCESS) {
+ _update_buses();
+ } break;
+ case NOTIFICATION_DRAG_END: {
- //check if anything was edited
- bool edited = AudioServer::get_singleton()->is_edited();
- for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- for (int j = 0; j < AudioServer::get_singleton()->get_bus_effect_count(i); j++) {
- Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i, j);
- if (effect->is_edited()) {
- edited = true;
- effect->set_edited(false);
+ if (drop_end) {
+ drop_end->queue_delete();
+ drop_end = NULL;
+ }
+ } break;
+ case NOTIFICATION_PROCESS: {
+
+ // Check if anything was edited.
+ bool edited = AudioServer::get_singleton()->is_edited();
+ for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
+ for (int j = 0; j < AudioServer::get_singleton()->get_bus_effect_count(i); j++) {
+ Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i, j);
+ if (effect->is_edited()) {
+ edited = true;
+ effect->set_edited(false);
+ }
}
}
- }
- AudioServer::get_singleton()->set_edited(false);
+ AudioServer::get_singleton()->set_edited(false);
- if (edited) {
-
- save_timer->start();
- }
+ if (edited) {
+ save_timer->start();
+ }
+ } break;
}
}
void EditorAudioBuses::_add_bus() {
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
- //need to simulate new name, so we can undi :(
ur->create_action(TTR("Add Audio Bus"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count() + 1);
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count());
@@ -937,7 +1105,7 @@ void EditorAudioBuses::_delete_bus(Object *p_which) {
return;
}
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Delete Audio Bus"));
ur->add_do_method(AudioServer::get_singleton(), "remove_bus", index);
@@ -961,7 +1129,7 @@ void EditorAudioBuses::_delete_bus(Object *p_which) {
void EditorAudioBuses::_duplicate_bus(int p_which) {
int add_at_pos = p_which + 1;
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Duplicate Audio Bus"));
ur->add_do_method(AudioServer::get_singleton(), "add_bus", add_at_pos);
ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", add_at_pos, AudioServer::get_singleton()->get_bus_name(p_which) + " Copy");
@@ -986,7 +1154,7 @@ void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
int index = bus->get_index();
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Reset Bus Volume"));
ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", index, 0.f);
ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index));
@@ -1008,22 +1176,13 @@ void EditorAudioBuses::_request_drop_end() {
void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
-
- //need to simulate new name, so we can undi :(
+ UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Move Audio Bus"));
+
ur->add_do_method(AudioServer::get_singleton(), "move_bus", p_bus, p_index);
- int final_pos;
- if (p_index == p_bus) {
- final_pos = p_bus;
- } else if (p_index == -1) {
- final_pos = AudioServer::get_singleton()->get_bus_count() - 1;
- } else if (p_index < p_bus) {
- final_pos = p_index;
- } else {
- final_pos = p_index - 1;
- }
- ur->add_undo_method(AudioServer::get_singleton(), "move_bus", final_pos, p_bus);
+ int real_bus = p_index > p_bus ? p_bus : p_bus + 1;
+ int real_index = p_index > p_bus ? p_index - 1 : p_index;
+ ur->add_undo_method(AudioServer::get_singleton(), "move_bus", real_index, real_bus);
ur->add_do_method(this, "_update_buses");
ur->add_undo_method(this, "_update_buses");
@@ -1070,14 +1229,16 @@ void EditorAudioBuses::_load_layout() {
void EditorAudioBuses::_load_default_layout() {
- Ref<AudioBusLayout> state = ResourceLoader::load("res://default_bus_layout.tres");
+ String layout_path = ProjectSettings::get_singleton()->get("audio/default_bus_layout");
+
+ Ref<AudioBusLayout> state = ResourceLoader::load(layout_path);
if (state.is_null()) {
- EditorNode::get_singleton()->show_warning(TTR("There is no 'res://default_bus_layout.tres' file."));
+ EditorNode::get_singleton()->show_warning(vformat(TTR("There is no '%s' file."), layout_path));
return;
}
- edited_path = "res://default_bus_layout.tres";
- file->set_text(edited_path.get_file());
+ edited_path = layout_path;
+ file->set_text(String(TTR("Layout")) + ": " + layout_path.get_file());
AudioServer::get_singleton()->set_bus_layout(state);
_update_buses();
EditorNode::get_singleton()->get_undo_redo()->clear_history();
@@ -1094,7 +1255,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
}
edited_path = p_string;
- file->set_text(p_string.get_file());
+ file->set_text(String(TTR("Layout")) + ": " + p_string.get_file());
AudioServer::get_singleton()->set_bus_layout(state);
_update_buses();
EditorNode::get_singleton()->get_undo_redo()->clear_history();
@@ -1116,7 +1277,7 @@ void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
}
edited_path = p_string;
- file->set_text(p_string.get_file());
+ file->set_text(String(TTR("Layout")) + ": " + p_string.get_file());
_update_buses();
EditorNode::get_singleton()->get_undo_redo()->clear_history();
call_deferred("_select_layout");
@@ -1150,19 +1311,20 @@ EditorAudioBuses::EditorAudioBuses() {
top_hb = memnew(HBoxContainer);
add_child(top_hb);
- file = memnew(ToolButton);
- file->set_text("default_bus_layout.tres");
+ file = memnew(Label);
+ file->set_text(String(TTR("Layout")) + ": " + "default_bus_layout.tres");
+ file->set_clip_text(true);
+ file->set_h_size_flags(SIZE_EXPAND_FILL);
top_hb->add_child(file);
- file->connect("pressed", this, "_select_layout");
add = memnew(Button);
top_hb->add_child(add);
add->set_text(TTR("Add Bus"));
- add->set_tooltip(TTR("Create a new Bus Layout."));
-
+ add->set_tooltip(TTR("Add a new Audio Bus to this layout."));
add->connect("pressed", this, "_add_bus");
- top_hb->add_spacer();
+ VSeparator *separator = memnew(VSeparator);
+ top_hb->add_child(separator);
load = memnew(Button);
load->set_text(TTR("Load"));
@@ -1189,7 +1351,6 @@ EditorAudioBuses::EditorAudioBuses() {
_new->connect("pressed", this, "_new_layout");
bus_scroll = memnew(ScrollContainer);
- bus_scroll->add_style_override("panel", memnew(StyleBoxEmpty));
bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
bus_scroll->set_enable_h_scroll(true);
bus_scroll->set_enable_v_scroll(false);
@@ -1206,7 +1367,7 @@ EditorAudioBuses::EditorAudioBuses() {
set_v_size_flags(SIZE_EXPAND_FILL);
- edited_path = "res://default_bus_layout.tres";
+ edited_path = ProjectSettings::get_singleton()->get("audio/default_bus_layout");
file_dialog = memnew(EditorFileDialog);
List<String> ext;
@@ -1219,6 +1380,7 @@ EditorAudioBuses::EditorAudioBuses() {
set_process(true);
}
+
void EditorAudioBuses::open_layout(const String &p_path) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
@@ -1263,3 +1425,76 @@ AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
AudioBusesEditorPlugin::~AudioBusesEditorPlugin() {
}
+
+void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_value, bool p_render_value) {
+
+ notches.push_back(AudioNotch(p_normalized_offset, p_db_value, p_render_value));
+}
+
+Size2 EditorAudioMeterNotches::get_minimum_size() const {
+
+ Ref<Font> font = get_font("font", "Label");
+ float font_height = font->get_height();
+
+ float width = 0;
+ float height = top_padding + btm_padding;
+
+ for (uint8_t i = 0; i < notches.size(); i++) {
+ if (notches[i].render_db_value) {
+ width = MAX(width, font->get_string_size(String::num(Math::abs(notches[i].db_value)) + "dB").x);
+ height += font_height;
+ }
+ }
+ width += line_length + label_space;
+
+ return Size2(width, height);
+}
+
+void EditorAudioMeterNotches::_bind_methods() {
+
+ ClassDB::bind_method("add_notch", &EditorAudioMeterNotches::add_notch);
+ ClassDB::bind_method("_draw_audio_notches", &EditorAudioMeterNotches::_draw_audio_notches);
+}
+
+void EditorAudioMeterNotches::_notification(int p_what) {
+
+ switch (p_what) {
+ case NOTIFICATION_THEME_CHANGED: {
+ notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
+ } break;
+ case NOTIFICATION_DRAW: {
+ _draw_audio_notches();
+ } break;
+ }
+}
+
+void EditorAudioMeterNotches::_draw_audio_notches() {
+
+ Ref<Font> font = get_font("font", "Label");
+ float font_height = font->get_height();
+
+ for (uint8_t 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, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
+ notch_color,
+ 1);
+
+ if (n.render_db_value) {
+ draw_string(font,
+ Vector2(line_length + label_space,
+ (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding),
+ String::num(Math::abs(n.db_value)) + "dB",
+ notch_color);
+ }
+ }
+}
+
+EditorAudioMeterNotches::EditorAudioMeterNotches() :
+ line_length(5.0f),
+ label_space(2.0f),
+ btm_padding(9.0f),
+ top_padding(5.0f) {
+
+ notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
+}