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.cpp455
1 files changed, 265 insertions, 190 deletions
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 9cd7d781a4..2180742bbb 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -63,118 +63,132 @@ void EditorAudioBus::_update_visible_channels() {
void EditorAudioBus::_notification(int p_what) {
- if (p_what == 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;
- }
-
- disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
-
- Color solo_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#ffe337" : "#ffeb70");
- Color mute_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#ff2929" : "#ff7070");
- Color bypass_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#22ccff" : "#70deff");
-
- 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);
-
- bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
-
- update_bus();
- set_process(true);
- }
+ 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;
+ }
- if (p_what == NOTIFICATION_DRAW) {
+ disabled_vu = get_icon("BusVuFrozen", "EditorIcons");
- 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()));
- }
- }
+ 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_PROCESS) {
+ 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 (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
- cc = AudioServer::get_singleton()->get_bus_channels(get_index());
- _update_visible_channels();
- }
+ bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
- for (int i = 0; i < cc; i++) {
- float real_peak[2] = { -100, -100 };
- bool activity_found = false;
+ update_bus();
+ set_process(true);
+ } break;
+ case NOTIFICATION_DRAW: {
- 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 (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[0] > channel[i].peak_l) {
+ channel[i].peak_l = real_peak[0];
} else {
- channel[i].vu_l->set_over_texture(disabled_vu);
- channel[i].vu_r->set_over_texture(disabled_vu);
+ channel[i].peak_l -= get_process_delta_time() * 60.0;
}
- channel[i].prev_active = activity_found;
- }
- }
- }
+ 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 (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
+ 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 < CHANNELS_MAX; i++) {
- channel[i].peak_l = -100;
- channel[i].peak_r = -100;
- channel[i].prev_active = true;
- }
+ 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);
+ }
- set_process(is_visible_in_tree());
- }
+ channel[i].prev_active = activity_found;
+ }
+ }
+ } break;
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+
+ 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;
- }
+ 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"));
+ bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
+ } break;
+ case NOTIFICATION_MOUSE_EXIT:
+ case NOTIFICATION_DRAG_END: {
+
+ if (hovering_drop) {
+ hovering_drop = false;
+ update();
+ }
+ } break;
}
}
@@ -274,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"));
@@ -309,7 +323,7 @@ void EditorAudioBus::_volume_changed(float p_normalized) {
float p_db = this->_normalized_volume_to_scaled_db(p_normalized);
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
+ 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()));
@@ -386,7 +400,7 @@ 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()));
@@ -400,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()));
@@ -414,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()));
@@ -429,7 +443,7 @@ void EditorAudioBus::_send_selected(int p_which) {
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_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()));
@@ -478,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));
@@ -505,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()));
@@ -553,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);
@@ -560,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;
@@ -589,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";
@@ -649,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);
@@ -690,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);
@@ -749,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."));
@@ -756,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(110, 0) * EDSCALE);
track_name = memnew(LineEdit);
track_name->connect("text_entered", this, "_name_changed");
@@ -800,7 +822,9 @@ 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);
@@ -811,20 +835,19 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
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);
- }
+ 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);
@@ -863,17 +886,18 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
channel[i].peak_r = 0.0f;
}
- scale = memnew(EditorAudioMeterNotches);
+ 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);
@@ -923,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() {
@@ -944,6 +995,8 @@ void EditorAudioBusDrop::_bind_methods() {
}
EditorAudioBusDrop::EditorAudioBusDrop() {
+
+ hovering_drop = false;
}
void EditorAudioBuses::_update_buses() {
@@ -956,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);
@@ -976,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());
@@ -1047,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);
@@ -1071,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");
@@ -1096,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));
@@ -1118,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");
@@ -1189,7 +1238,7 @@ void EditorAudioBuses::_load_default_layout() {
}
edited_path = layout_path;
- file->set_text(layout_path.get_file());
+ 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();
@@ -1206,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();
@@ -1228,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");
@@ -1262,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("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"));
@@ -1301,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);
@@ -1377,38 +1426,65 @@ AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
AudioBusesEditorPlugin::~AudioBusesEditorPlugin() {
}
-void EditorAudioMeterNotches::add_notch(float normalized_offset, float db_value, bool render_value) {
- notches.push_back(AudioNotch(normalized_offset, db_value, render_value));
+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) {
- if (p_what == NOTIFICATION_DRAW) {
- notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0f, 1.0f, 1.0f, 0.8f) : Color(0.0f, 0.0f, 0.0f, 0.8f);
- _draw_audio_notches();
+
+ 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.0f, (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 - 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.0f);
+ 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("{0}dB").format(varray(Math::abs(n.db_value))),
+ String::num(Math::abs(n.db_value)) + "dB",
notch_color);
}
}
@@ -1419,7 +1495,6 @@ EditorAudioMeterNotches::EditorAudioMeterNotches() :
label_space(2.0f),
btm_padding(9.0f),
top_padding(5.0f) {
- this->set_v_size_flags(SIZE_EXPAND_FILL);
- this->set_h_size_flags(SIZE_EXPAND_FILL);
- notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1.0f, 1.0f, 1.0f, 0.8f) : Color(0.0f, 0.0f, 0.0f, 0.8f);
+
+ notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
}