Debian Codegraph @

editor/audio/editor_audio_buses.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_audio_buses.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "editor_audio_buses.h"
32
33 #include "core/config/project_settings.h"
34 #include "core/input/input.h"
35 #include "core/io/resource_saver.h"
36 #include "core/os/keyboard.h"
37 #include "editor/docks/editor_dock_manager.h"
38 #include "editor/docks/filesystem_dock.h"
39 #include "editor/editor_node.h"
40 #include "editor/editor_string_names.h"
41 #include "editor/editor_undo_redo_manager.h"
42 #include "editor/gui/editor_file_dialog.h"
43 #include "editor/settings/editor_command_palette.h"
44 #include "editor/settings/editor_settings.h"
45 #include "editor/themes/editor_scale.h"
46 #include "editor/themes/editor_theme_manager.h"
47 #include "scene/gui/box_container.h"
48 #include "scene/gui/separator.h"
49 #include "scene/main/timer.h"
50 #include "scene/resources/font.h"
51 #include "scene/resources/style_box_flat.h"
52 #include "servers/audio/audio_server.h"
53
54 void EditorAudioBus::_update_visible_channels() {
55 int i = 0;
56 for (; i < cc; i++) {
57 if (!channel[i].vu_l->is_visible()) {
58 channel[i].vu_l->show();
59 }
60 if (!channel[i].vu_r->is_visible()) {
61 channel[i].vu_r->show();
62 }
63 }
64
65 for (; i < CHANNELS_MAX; i++) {
66 if (channel[i].vu_l->is_visible()) {
67 channel[i].vu_l->hide();
68 }
69 if (channel[i].vu_r->is_visible()) {
70 channel[i].vu_r->hide();
71 }
72 }
73 }
74
75 void EditorAudioBus::_notification(int p_what) {
76 switch (p_what) {
77 case NOTIFICATION_THEME_CHANGED: {
78 Ref<Texture2D> active_bus_texture = get_editor_theme_icon(SNAME("BusVuActive"));
79 for (int i = 0; i < CHANNELS_MAX; i++) {
80 channel[i].vu_l->set_under_texture(active_bus_texture);
81 channel[i].vu_l->set_tint_under(Color(0.75, 0.75, 0.75));
82 channel[i].vu_l->set_progress_texture(active_bus_texture);
83
84 channel[i].vu_r->set_under_texture(active_bus_texture);
85 channel[i].vu_r->set_tint_under(Color(0.75, 0.75, 0.75));
86 channel[i].vu_r->set_progress_texture(active_bus_texture);
87 channel[i].prev_active = true;
88 }
89
90 disabled_vu = get_editor_theme_icon(SNAME("BusVuFrozen"));
91
92 bool dark_icon_and_font = EditorThemeManager::is_dark_icon_and_font();
93 Color solo_color = dark_icon_and_font ? Color(1.0, 0.89, 0.22) : Color(1.9, 1.74, 0.83);
94 Color mute_color = dark_icon_and_font ? Color(1.0, 0.16, 0.16) : Color(2.35, 1.03, 1.03);
95 Color bypass_color = dark_icon_and_font ? Color(0.13, 0.8, 1.0) : Color(1.03, 2.04, 2.35);
96 float darkening_factor = dark_icon_and_font ? 0.15 : 0.65;
97 Color solo_color_darkened = solo_color.darkened(darkening_factor);
98 Color mute_color_darkened = mute_color.darkened(darkening_factor);
99 Color bypass_color_darkened = bypass_color.darkened(darkening_factor);
100
101 Ref<StyleBoxFlat>(solo->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(solo_color_darkened);
102 Ref<StyleBoxFlat>(mute->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(mute_color_darkened);
103 Ref<StyleBoxFlat>(bypass->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(bypass_color_darkened);
104 Ref<StyleBoxFlat>(solo->get_theme_stylebox("hover_pressed"))->set_border_color(solo_color_darkened);
105 Ref<StyleBoxFlat>(mute->get_theme_stylebox("hover_pressed"))->set_border_color(mute_color_darkened);
106 Ref<StyleBoxFlat>(bypass->get_theme_stylebox("hover_pressed"))->set_border_color(bypass_color_darkened);
107
108 solo->set_button_icon(get_editor_theme_icon(SNAME("AudioBusSolo")));
109 solo->add_theme_color_override("icon_pressed_color", solo_color);
110 solo->add_theme_color_override("icon_hover_pressed_color", solo_color_darkened);
111 mute->set_button_icon(get_editor_theme_icon(SNAME("AudioBusMute")));
112 mute->add_theme_color_override("icon_pressed_color", mute_color);
113 mute->add_theme_color_override("icon_hover_pressed_color", mute_color_darkened);
114 bypass->set_button_icon(get_editor_theme_icon(SNAME("AudioBusBypass")));
115 bypass->add_theme_color_override("icon_pressed_color", bypass_color);
116 bypass->add_theme_color_override("icon_hover_pressed_color", bypass_color_darkened);
117
118 bus_options->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
119
120 audio_value_preview_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("TooltipLabel")));
121 audio_value_preview_label->add_theme_color_override("font_shadow_color", get_theme_color(SNAME("font_shadow_color"), SNAME("TooltipLabel")));
122 audio_value_preview_box->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("TooltipPanel")));
123
124 for (int i = 0; i < effect_options->get_item_count(); i++) {
125 String class_name = effect_options->get_item_metadata(i);
126 Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(class_name);
127 effect_options->set_item_icon(i, icon);
128 }
129 } break;
130
131 case NOTIFICATION_READY: {
132 update_bus();
133 set_process(true);
134 } break;
135
136 case NOTIFICATION_ACCESSIBILITY_UPDATE: {
137 RID ae = get_accessibility_element();
138 ERR_FAIL_COND(ae.is_null());
139
140 DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_STATIC_TEXT);
141 DisplayServer::get_singleton()->accessibility_update_set_value(ae, TTR(vformat("The %s is not accessible at this time.", "Audio bus editor")));
142 } break;
143
144 case NOTIFICATION_DRAW: {
145 if (is_master) {
146 draw_style_box(get_theme_stylebox(SNAME("master"), SNAME("EditorAudioBus")), Rect2(Vector2(), get_size()));
147 } else if (has_focus()) {
148 draw_style_box(get_theme_stylebox(SNAME("focus"), SNAME("EditorAudioBus")), Rect2(Vector2(), get_size()));
149 } else {
150 draw_style_box(get_theme_stylebox(SNAME("normal"), SNAME("EditorAudioBus")), Rect2(Vector2(), get_size()));
151 }
152
153 if (get_index() != 0 && hovering_drop) {
154 Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
155 accent.a *= 0.7;
156 draw_rect(Rect2(Point2(), get_size()), accent, false);
157 }
158 } break;
159
160 case NOTIFICATION_PROCESS: {
161 if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
162 cc = AudioServer::get_singleton()->get_bus_channels(get_index());
163 _update_visible_channels();
164 }
165
166 for (int i = 0; i < cc; i++) {
167 float real_peak[2] = { -100, -100 };
168 bool activity_found = false;
169
170 if (AudioServer::get_singleton()->is_bus_channel_active(get_index(), i)) {
171 activity_found = true;
172 real_peak[0] = MAX(real_peak[0], AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(), i));
173 real_peak[1] = MAX(real_peak[1], AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(), i));
174 }
175
176 if (real_peak[0] > channel[i].peak_l) {
177 channel[i].peak_l = real_peak[0];
178 } else {
179 channel[i].peak_l -= get_process_delta_time() * 60.0;
180 }
181
182 if (real_peak[1] > channel[i].peak_r) {
183 channel[i].peak_r = real_peak[1];
184 } else {
185 channel[i].peak_r -= get_process_delta_time() * 60.0;
186 }
187
188 channel[i].vu_l->set_value(channel[i].peak_l);
189 channel[i].vu_r->set_value(channel[i].peak_r);
190
191 if (activity_found != channel[i].prev_active) {
192 if (activity_found) {
193 channel[i].vu_l->set_over_texture(Ref<Texture2D>());
194 channel[i].vu_r->set_over_texture(Ref<Texture2D>());
195 } else {
196 channel[i].vu_l->set_over_texture(disabled_vu);
197 channel[i].vu_r->set_over_texture(disabled_vu);
198 }
199
200 channel[i].prev_active = activity_found;
201 }
202 }
203 } break;
204
205 case NOTIFICATION_VISIBILITY_CHANGED: {
206 for (int i = 0; i < CHANNELS_MAX; i++) {
207 channel[i].peak_l = -100;
208 channel[i].peak_r = -100;
209 channel[i].prev_active = true;
210 }
211
212 set_process(is_visible_in_tree());
213 } break;
214
215 case NOTIFICATION_MOUSE_EXIT:
216 case NOTIFICATION_DRAG_END: {
217 if (hovering_drop) {
218 hovering_drop = false;
219 queue_redraw();
220 }
221 } break;
222 }
223 }
224
225 void EditorAudioBus::update_send() {
226 send->clear();
227 if (is_master) {
228 send->set_disabled(true);
229 send->set_text(TTR("Speakers"));
230 } else {
231 send->set_disabled(false);
232 StringName current_send = AudioServer::get_singleton()->get_bus_send(get_index());
233 int current_send_index = 0; //by default to master
234
235 for (int i = 0; i < get_index(); i++) {
236 StringName send_name = AudioServer::get_singleton()->get_bus_name(i);
237 send->add_item(send_name);
238 if (send_name == current_send) {
239 current_send_index = i;
240 }
241 }
242
243 send->select(current_send_index);
244 }
245 }
246
247 void EditorAudioBus::update_bus() {
248 if (updating_bus) {
249 return;
250 }
251
252 updating_bus = true;
253
254 int index = get_index();
255
256 float db_value = AudioServer::get_singleton()->get_bus_volume_db(index);
257 slider->set_value(_scaled_db_to_normalized_volume(db_value));
258 track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
259 if (is_master) {
260 track_name->set_editable(false);
261 }
262
263 solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index));
264 mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index));
265 bypass->set_pressed(AudioServer::get_singleton()->is_bus_bypassing_effects(index));
266 // effects..
267 effects->clear();
268
269 TreeItem *root = effects->create_item();
270 for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
271 Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index, i);
272
273 TreeItem *fx = effects->create_item(root);
274 fx->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
275 fx->set_editable(0, true);
276 fx->set_checked(0, AudioServer::get_singleton()->is_bus_effect_enabled(index, i));
277 fx->set_text(0, afx->get_name());
278 fx->set_metadata(0, i);
279 }
280
281 TreeItem *add = effects->create_item(root);
282 add->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM);
283 add->set_editable(0, true);
284 add->set_selectable(0, false);
285 add->set_text(0, TTR("Add Effect"));
286
287 update_send();
288
289 updating_bus = false;
290 }
291
292 void EditorAudioBus::_name_changed(const String &p_new_name) {
293 if (updating_bus) {
294 return;
295 }
296 updating_bus = true;
297 track_name->release_focus();
298
299 if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) {
300 updating_bus = false;
301 return;
302 }
303
304 String attempt = p_new_name;
305 int attempts = 1;
306
307 while (true) {
308 bool name_free = true;
309 for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
310 if (AudioServer::get_singleton()->get_bus_name(i) == attempt) {
311 name_free = false;
312 break;
313 }
314 }
315
316 if (name_free) {
317 break;
318 }
319
320 attempts++;
321 attempt = p_new_name + " " + itos(attempts);
322 }
323
324 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
325
326 StringName current = AudioServer::get_singleton()->get_bus_name(get_index());
327
328 ur->create_action(TTR("Rename Audio Bus"));
329
330 ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", get_index(), attempt);
331 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", get_index(), current);
332
333 for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
334 if (AudioServer::get_singleton()->get_bus_send(i) == current) {
335 ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", i, attempt);
336 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", i, current);
337 }
338 }
339
340 ur->add_do_method(buses, "_update_bus", get_index());
341 ur->add_undo_method(buses, "_update_bus", get_index());
342
343 ur->add_do_method(buses, "_update_sends");
344 ur->add_undo_method(buses, "_update_sends");
345
346 ur->commit_action();
347
348 updating_bus = false;
349 }
350
351 void EditorAudioBus::_volume_changed(float p_normalized) {
352 if (updating_bus) {
353 return;
354 }
355
356 updating_bus = true;
357
358 const float p_db = _normalized_volume_to_scaled_db(p_normalized);
359
360 if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
361 // Snap the value when holding Ctrl for easier editing.
362 // To do so, it needs to be converted back to normalized volume (as the slider uses that unit).
363 slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db)));
364 }
365
366 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
367 ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS);
368 ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), p_db);
369 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), AudioServer::get_singleton()->get_bus_volume_db(get_index()));
370 ur->add_do_method(buses, "_update_bus", get_index());
371 ur->add_undo_method(buses, "_update_bus", get_index());
372 ur->commit_action();
373
374 updating_bus = false;
375 }
376
377 float EditorAudioBus::_normalized_volume_to_scaled_db(float normalized) {
378 /* There are three different formulas for the conversion from normalized
379 * values to relative decibal values.
380 * One formula is an exponential graph which intends to counteract
381 * the logarithmic nature of human hearing. This is an approximation
382 * of the behavior of a 'logarithmic potentiometer' found on most
383 * musical instruments and also emulated in popular software.
384 * The other two equations are hand-tuned linear tapers that intend to
385 * try to ease the exponential equation in areas where it makes sense.*/
386
387 if (normalized > 0.6f) {
388 return 22.22f * normalized - 16.2f;
389 } else if (normalized < 0.05f) {
390 return 830.72 * normalized - 80.0f;
391 } else {
392 return 45.0f * Math::pow(normalized - 1.0, 3);
393 }
394 }
395
396 float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
397 /* Inversion of equations found in _normalized_volume_to_scaled_db.
398 * IMPORTANT: If one function changes, the other much change to reflect it. */
399 if (db > -2.88) {
400 return (db + 16.2f) / 22.22f;
401 } else if (db < -38.602f) {
402 return (db + 80.00f) / 830.72f;
403 } else {
404 if (db < 0.0) {
405 /* To accommodate for NaN on negative numbers for root, we will mirror the
406 * results of the positive db range in order to get the desired numerical
407 * value on the negative side. */
408 float positive_x = Math::pow(Math::abs(db) / 45.0f, 1.0f / 3.0f) + 1.0f;
409 Vector2 translation = Vector2(1.0f, 0.0f) - Vector2(positive_x, Math::abs(db));
410 Vector2 reflected_position = Vector2(1.0, 0.0f) + translation;
411 return reflected_position.x;
412 } else {
413 return Math::pow(db / 45.0f, 1.0f / 3.0f) + 1.0f;
414 }
415 }
416 }
417
418 void EditorAudioBus::_show_value(float slider_value) {
419 float db;
420 if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
421 // Display the correct (snapped) value when holding Ctrl
422 db = Math::round(_normalized_volume_to_scaled_db(slider_value));
423 } else {
424 db = _normalized_volume_to_scaled_db(slider_value);
425 }
426
427 String text;
428 if (Math::is_zero_approx(Math::snapped(db, 0.1))) {
429 // Prevent displaying `-0.0 dB` and show ` 0.0 dB` instead.
430 // The leading space makes the text visually line up with its positive/negative counterparts.
431 text = " 0.0 dB";
432 } else {
433 // Show an explicit `+` sign if positive.
434 text = vformat("%+.1f dB", db);
435 }
436
437 // Also set the preview text as a standard Control tooltip.
438 // This way, it can be seen when the slider is merely hovered (instead of dragged).
439 slider->set_tooltip_text(text);
440 audio_value_preview_label->set_text(text);
441 const Vector2 slider_size = slider->get_size();
442 const Vector2 slider_position = slider->get_global_position();
443 const float vert_padding = 10.0f;
444 const Vector2 box_position = Vector2(slider_size.x, (slider_size.y - vert_padding) * (1.0f - slider->get_value()) - vert_padding);
445 audio_value_preview_box->set_position(slider_position + box_position);
446 audio_value_preview_box->set_size(audio_value_preview_label->get_size());
447 if (slider->has_focus() && !audio_value_preview_box->is_visible()) {
448 audio_value_preview_box->show();
449 }
450 preview_timer->start();
451 }
452
453 void EditorAudioBus::_hide_value_preview() {
454 audio_value_preview_box->hide();
455 }
456
457 void EditorAudioBus::_solo_toggled() {
458 updating_bus = true;
459
460 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
461 ur->create_action(TTR("Toggle Audio Bus Solo"));
462 ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), solo->is_pressed());
463 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), AudioServer::get_singleton()->is_bus_solo(get_index()));
464 ur->add_do_method(buses, "_update_bus", get_index());
465 ur->add_undo_method(buses, "_update_bus", get_index());
466 ur->commit_action();
467
468 updating_bus = false;
469 }
470
471 void EditorAudioBus::_mute_toggled() {
472 updating_bus = true;
473
474 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
475 ur->create_action(TTR("Toggle Audio Bus Mute"));
476 ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), mute->is_pressed());
477 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), AudioServer::get_singleton()->is_bus_mute(get_index()));
478 ur->add_do_method(buses, "_update_bus", get_index());
479 ur->add_undo_method(buses, "_update_bus", get_index());
480 ur->commit_action();
481
482 updating_bus = false;
483 }
484
485 void EditorAudioBus::_bypass_toggled() {
486 updating_bus = true;
487
488 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
489 ur->create_action(TTR("Toggle Audio Bus Bypass Effects"));
490 ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), bypass->is_pressed());
491 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), AudioServer::get_singleton()->is_bus_bypassing_effects(get_index()));
492 ur->add_do_method(buses, "_update_bus", get_index());
493 ur->add_undo_method(buses, "_update_bus", get_index());
494 ur->commit_action();
495
496 updating_bus = false;
497 }
498
499 void EditorAudioBus::_send_selected(int p_which) {
500 updating_bus = true;
501
502 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
503 ur->create_action(TTR("Select Audio Bus Send"));
504 ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", get_index(), send->get_item_text(p_which));
505 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", get_index(), AudioServer::get_singleton()->get_bus_send(get_index()));
506 ur->add_do_method(buses, "_update_bus", get_index());
507 ur->add_undo_method(buses, "_update_bus", get_index());
508 ur->commit_action();
509
510 updating_bus = false;
511 }
512
513 void EditorAudioBus::_effect_selected() {
514 TreeItem *effect = effects->get_selected();
515 if (!effect) {
516 return;
517 }
518 updating_bus = true;
519
520 if (effect->get_metadata(0) != Variant()) {
521 int index = effect->get_metadata(0);
522 Ref<AudioEffect> effect2 = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
523 if (effect2.is_valid()) {
524 EditorNode::get_singleton()->push_item(effect2.ptr());
525 }
526 }
527
528 updating_bus = false;
529 }
530
531 void EditorAudioBus::_effect_edited() {
532 if (updating_bus) {
533 return;
534 }
535
536 TreeItem *effect = effects->get_edited();
537 if (!effect) {
538 return;
539 }
540
541 if (effect->get_metadata(0) == Variant()) {
542 Rect2 area = effects->get_item_rect(effect);
543
544 effect_options->set_position(effects->get_screen_position() + area.position + Vector2(0, area.size.y));
545 effect_options->reset_size();
546 effect_options->popup();
547 //add effect
548 } else {
549 int index = effect->get_metadata(0);
550 updating_bus = true;
551
552 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
553 ur->create_action(TTR("Select Audio Bus Send"));
554 ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, effect->is_checked(0));
555 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index));
556 ur->add_do_method(buses, "_update_bus", get_index());
557 ur->add_undo_method(buses, "_update_bus", get_index());
558 ur->commit_action();
559
560 updating_bus = false;
561 }
562 }
563
564 void EditorAudioBus::_effect_add(int p_which) {
565 if (updating_bus) {
566 return;
567 }
568
569 StringName name = effect_options->get_item_metadata(p_which);
570
571 Object *fx = ClassDB::instantiate(name);
572 ERR_FAIL_NULL(fx);
573 AudioEffect *afx = Object::cast_to<AudioEffect>(fx);
574 ERR_FAIL_NULL(afx);
575 Ref<AudioEffect> afxr = Ref<AudioEffect>(afx);
576
577 afxr->set_name(effect_options->get_item_text(p_which));
578
579 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
580 ur->create_action(TTR("Add Audio Bus Effect"));
581 ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), afxr, -1);
582 ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect_count(get_index()));
583 ur->add_do_method(buses, "_update_bus", get_index());
584 ur->add_undo_method(buses, "_update_bus", get_index());
585 ur->commit_action();
586 }
587
588 void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) {
589 ERR_FAIL_COND(p_event.is_null());
590
591 Ref<InputEventMouseButton> mb = p_event;
592 if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
593 bus_popup->set_position(get_screen_position() + mb->get_position());
594 bus_popup->reset_size();
595 bus_popup->popup();
596 }
597
598 Ref<InputEventKey> k = p_event;
599 if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) {
600 bus_popup->set_position(get_screen_position());
601 bus_popup->reset_size();
602 bus_popup->popup();
603
604 accept_event();
605 }
606 }
607
608 void EditorAudioBus::_effects_gui_input(Ref<InputEvent> p_event) {
609 Ref<InputEventKey> k = p_event;
610 if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == Key::KEY_DELETE) {
611 TreeItem *current_effect = effects->get_selected();
612 if (current_effect && current_effect->get_metadata(0).get_type() == Variant::INT) {
613 _delete_effect_pressed(0);
614 accept_event();
615 }
616 }
617 }
618
619 void EditorAudioBus::_bus_popup_pressed(int p_option) {
620 if (p_option == 2) {
621 // Reset volume
622 emit_signal(SNAME("vol_reset_request"));
623 } else if (p_option == 1) {
624 emit_signal(SNAME("delete_request"));
625 } else if (p_option == 0) {
626 //duplicate
627 emit_signal(SNAME("duplicate_request"), get_index());
628 }
629 }
630
631 Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
632 if (get_index() == 0) {
633 return Variant();
634 }
635
636 Control *c = memnew(Control);
637 Panel *p = memnew(Panel);
638 c->add_child(p);
639 p->set_modulate(Color(1, 1, 1, 0.7));
640 p->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("focus"), SNAME("Button")));
641 p->set_size(get_size());
642 p->set_position((p_point == Vector2(Math::INF, Math::INF)) ? Vector2() : -p_point);
643 set_drag_preview(c);
644 Dictionary d;
645 d["type"] = "move_audio_bus";
646 d["index"] = get_index();
647
648 if (get_index() < AudioServer::get_singleton()->get_bus_count() - 1) {
649 emit_signal(SNAME("drop_end_request"));
650 }
651
652 return d;
653 }
654
655 bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
656 if (get_index() == 0) {
657 return false;
658 }
659
660 Dictionary d = p_data;
661 if (d.has("type") && String(d["type"]) == "move_audio_bus" && (int)d["index"] != get_index()) {
662 hovering_drop = true;
663 return true;
664 }
665
666 return false;
667 }
668
669 void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) {
670 Dictionary d = p_data;
671 emit_signal(SNAME("dropped"), d["index"], get_index());
672 }
673
674 Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
675 TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? effects->get_selected() : effects->get_item_at_position(p_point);
676 if (!item) {
677 return Variant();
678 }
679
680 Variant md = item->get_metadata(0);
681 if (md.get_type() == Variant::INT) {
682 Dictionary fxd;
683 fxd["type"] = "audio_bus_effect";
684 fxd["bus"] = get_index();
685 fxd["effect"] = md;
686
687 Label *l = memnew(Label);
688 l->set_focus_mode(FOCUS_ACCESSIBILITY);
689 l->set_text(item->get_text(0));
690 l->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
691 effects->set_drag_preview(l);
692
693 return fxd;
694 }
695
696 return Variant();
697 }
698
699 bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
700 Dictionary d = p_data;
701 if (!d.has("type") || String(d["type"]) != "audio_bus_effect") {
702 return false;
703 }
704
705 TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? effects->get_selected() : effects->get_item_at_position(p_point);
706 if (!item) {
707 return false;
708 }
709
710 effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
711
712 return true;
713 }
714
715 void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
716 Dictionary d = p_data;
717
718 TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? effects->get_selected() : effects->get_item_at_position(p_point);
719 if (!item) {
720 return;
721 }
722 int pos = (p_point == Vector2(Math::INF, Math::INF)) ? effects->get_drop_section_at_position(effects->get_item_rect(item).position) : effects->get_drop_section_at_position(p_point);
723 Variant md = item->get_metadata(0);
724
725 int paste_at;
726 int bus = d["bus"];
727 int effect = d["effect"];
728
729 if (md.get_type() == Variant::INT) {
730 paste_at = md;
731 if (pos > 0) {
732 paste_at++;
733 }
734
735 if (bus == get_index() && paste_at > effect) {
736 paste_at--;
737 }
738 } else {
739 paste_at = -1;
740 }
741
742 bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus, effect);
743
744 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
745 ur->create_action(TTR("Move Bus Effect"));
746 ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", bus, effect);
747 ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(bus, effect), paste_at);
748
749 if (paste_at == -1) {
750 paste_at = AudioServer::get_singleton()->get_bus_effect_count(get_index());
751 if (bus == get_index()) {
752 paste_at--;
753 }
754 }
755 if (!enabled) {
756 ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), paste_at, false);
757 }
758
759 ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), paste_at);
760 ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", bus, AudioServer::get_singleton()->get_bus_effect(bus, effect), effect);
761 if (!enabled) {
762 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", bus, effect, false);
763 }
764
765 ur->add_do_method(buses, "_update_bus", get_index());
766 ur->add_undo_method(buses, "_update_bus", get_index());
767 if (get_index() != bus) {
768 ur->add_do_method(buses, "_update_bus", bus);
769 ur->add_undo_method(buses, "_update_bus", bus);
770 }
771 ur->commit_action();
772 }
773
774 void EditorAudioBus::_delete_effect_pressed(int p_option) {
775 TreeItem *item = effects->get_selected();
776 if (!item) {
777 return;
778 }
779
780 if (item->get_metadata(0).get_type() != Variant::INT) {
781 return;
782 }
783
784 int index = item->get_metadata(0);
785
786 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
787 ur->create_action(TTR("Delete Bus Effect"));
788 ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), index);
789 ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(get_index(), index), index);
790 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index));
791 ur->add_do_method(buses, "_update_bus", get_index());
792 ur->add_undo_method(buses, "_update_bus", get_index());
793 ur->commit_action();
794 }
795
796 void EditorAudioBus::_effect_rmb(const Vector2 &p_pos, MouseButton p_button) {
797 if (p_button != MouseButton::RIGHT) {
798 return;
799 }
800
801 TreeItem *item = effects->get_selected();
802 if (!item) {
803 return;
804 }
805
806 if (item->get_metadata(0).get_type() != Variant::INT) {
807 return;
808 }
809
810 delete_effect_popup->set_position(get_screen_position() + get_local_mouse_position());
811 delete_effect_popup->reset_size();
812 delete_effect_popup->popup();
813 }
814
815 void EditorAudioBus::_bind_methods() {
816 ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
817 ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
818
819 ADD_SIGNAL(MethodInfo("duplicate_request"));
820 ADD_SIGNAL(MethodInfo("delete_request"));
821 ADD_SIGNAL(MethodInfo("vol_reset_request"));
822 ADD_SIGNAL(MethodInfo("drop_end_request"));
823 ADD_SIGNAL(MethodInfo("dropped"));
824 }
825
826 EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
827 buses = p_buses;
828 is_master = p_is_master;
829
830 set_tooltip_text(TTR("Drag & drop to rearrange."));
831
832 VBoxContainer *vb = memnew(VBoxContainer);
833 vb->add_theme_constant_override("separation", 4 * EDSCALE);
834 add_child(vb);
835
836 set_v_size_flags(SIZE_EXPAND_FILL);
837
838 track_name = memnew(LineEdit);
839 track_name->set_accessibility_name(TTRC("Track Name"));
840 track_name->connect(SceneStringName(text_submitted), callable_mp(this, &EditorAudioBus::_name_changed));
841 track_name->connect(SceneStringName(focus_exited), callable_mp(this, &EditorAudioBus::_name_focus_exit));
842 vb->add_child(track_name);
843
844 HBoxContainer *hbc = memnew(HBoxContainer);
845 vb->add_child(hbc);
846 solo = memnew(Button);
847 solo->set_theme_type_variation(SceneStringName(FlatButton));
848 solo->set_toggle_mode(true);
849 solo->set_tooltip_text(TTR("Solo"));
850 solo->set_focus_mode(FOCUS_ACCESSIBILITY);
851 solo->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_solo_toggled));
852 hbc->add_child(solo);
853 mute = memnew(Button);
854 mute->set_theme_type_variation(SceneStringName(FlatButton));
855 mute->set_toggle_mode(true);
856 mute->set_tooltip_text(TTR("Mute"));
857 mute->set_focus_mode(FOCUS_ACCESSIBILITY);
858 mute->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_mute_toggled));
859 hbc->add_child(mute);
860 bypass = memnew(Button);
861 bypass->set_theme_type_variation(SceneStringName(FlatButton));
862 bypass->set_toggle_mode(true);
863 bypass->set_tooltip_text(TTR("Bypass"));
864 bypass->set_focus_mode(FOCUS_ACCESSIBILITY);
865 bypass->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_bypass_toggled));
866 hbc->add_child(bypass);
867 hbc->add_spacer();
868
869 Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
870 for (int i = 0; i < hbc->get_child_count(); i++) {
871 Control *child = Object::cast_to<Control>(hbc->get_child(i));
872 child->begin_bulk_theme_override();
873 child->add_theme_style_override(CoreStringName(normal), sbempty);
874 child->add_theme_style_override(SceneStringName(hover), sbempty);
875 child->add_theme_style_override("hover_mirrored", sbempty);
876 child->add_theme_style_override("focus", sbempty);
877 child->add_theme_style_override("focus_mirrored", sbempty);
878
879 Ref<StyleBoxFlat> sbflat = memnew(StyleBoxFlat);
880 sbflat->set_content_margin_all(0);
881 sbflat->set_bg_color(Color(1, 1, 1, 0));
882 sbflat->set_border_width(Side::SIDE_BOTTOM, Math::round(3 * EDSCALE));
883 child->add_theme_style_override(SceneStringName(pressed), sbflat);
884 child->add_theme_style_override("pressed_mirrored", sbflat);
885 child->add_theme_style_override("hover_pressed", sbflat);
886 child->add_theme_style_override("hover_pressed_mirrored", sbflat);
887
888 child->end_bulk_theme_override();
889 }
890
891 HSeparator *separator = memnew(HSeparator);
892 separator->set_mouse_filter(MOUSE_FILTER_PASS);
893 vb->add_child(separator);
894
895 Control *spacer_top = memnew(Control);
896 spacer_top->set_custom_minimum_size(Size2(0, 6 * EDSCALE));
897 vb->add_child(spacer_top);
898
899 HBoxContainer *hb = memnew(HBoxContainer);
900 vb->add_child(hb);
901
902 Control *spacer_bottom = memnew(Control);
903 spacer_bottom->set_custom_minimum_size(Size2(0, 2 * EDSCALE));
904 vb->add_child(spacer_bottom);
905
906 slider = memnew(VSlider);
907 slider->set_min(0.0);
908 slider->set_max(1.0);
909 slider->set_step(0.0001);
910 slider->set_clip_contents(false);
911 slider->set_accessibility_name(TTRC("Volume"));
912
913 audio_value_preview_box = memnew(Panel);
914 slider->add_child(audio_value_preview_box);
915 audio_value_preview_box->set_as_top_level(true);
916 audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS);
917 audio_value_preview_box->hide();
918
919 HBoxContainer *audioprev_hbc = memnew(HBoxContainer);
920 audioprev_hbc->set_v_size_flags(SIZE_EXPAND_FILL);
921 audioprev_hbc->set_h_size_flags(SIZE_EXPAND_FILL);
922 audio_value_preview_box->add_child(audioprev_hbc);
923
924 audio_value_preview_label = memnew(Label);
925 audio_value_preview_label->set_focus_mode(FOCUS_ACCESSIBILITY);
926 audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL);
927 audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL);
928 audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS);
929 audioprev_hbc->add_child(audio_value_preview_label);
930
931 preview_timer = memnew(Timer);
932 preview_timer->set_wait_time(0.8f);
933 preview_timer->set_one_shot(true);
934 add_child(preview_timer);
935
936 slider->connect(SceneStringName(value_changed), callable_mp(this, &EditorAudioBus::_volume_changed));
937 slider->connect(SceneStringName(value_changed), callable_mp(this, &EditorAudioBus::_show_value));
938 preview_timer->connect("timeout", callable_mp(this, &EditorAudioBus::_hide_value_preview));
939 hb->add_child(slider);
940
941 cc = 0;
942 for (int i = 0; i < CHANNELS_MAX; i++) {
943 channel[i].vu_l = memnew(TextureProgressBar);
944 channel[i].vu_l->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP);
945 hb->add_child(channel[i].vu_l);
946 channel[i].vu_l->set_min(-80);
947 channel[i].vu_l->set_max(24);
948 channel[i].vu_l->set_step(0.1);
949 channel[i].vu_l->set_accessibility_name(vformat(TTR("Channel %d, Left VU"), i));
950
951 channel[i].vu_r = memnew(TextureProgressBar);
952 channel[i].vu_r->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP);
953 hb->add_child(channel[i].vu_r);
954 channel[i].vu_r->set_min(-80);
955 channel[i].vu_r->set_max(24);
956 channel[i].vu_r->set_step(0.1);
957 channel[i].vu_r->set_accessibility_name(vformat(TTR("Channel %d, Right VU"), i));
958
959 channel[i].peak_l = 0.0f;
960 channel[i].peak_r = 0.0f;
961 }
962
963 EditorAudioMeterNotches *scale = memnew(EditorAudioMeterNotches);
964
965 for (float db = 6.0f; db >= -80.0f; db -= 6.0f) {
966 bool renderNotch = (db >= -6.0f || db == -24.0f || db == -72.0f);
967 scale->add_notch(_scaled_db_to_normalized_volume(db), db, renderNotch);
968 }
969 scale->set_mouse_filter(MOUSE_FILTER_PASS);
970 hb->add_child(scale);
971
972 effects = memnew(Tree);
973 effects->set_accessibility_name(TTRC("Effects"));
974 effects->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
975 effects->set_hide_root(true);
976 effects->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
977 effects->set_hide_folding(true);
978 effects->set_v_size_flags(SIZE_EXPAND_FILL);
979 vb->add_child(effects);
980 effects->connect("item_edited", callable_mp(this, &EditorAudioBus::_effect_edited));
981 effects->connect("cell_selected", callable_mp(this, &EditorAudioBus::_effect_selected));
982 effects->connect(SceneStringName(focus_exited), callable_mp(effects, &Tree::deselect_all));
983 effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
984 SET_DRAG_FORWARDING_GCD(effects, EditorAudioBus);
985 effects->connect("item_mouse_selected", callable_mp(this, &EditorAudioBus::_effect_rmb));
986 effects->set_allow_rmb_select(true);
987 effects->set_focus_mode(FOCUS_CLICK);
988 effects->set_allow_reselect(true);
989 effects->set_theme_type_variation("EditorAudioBusEffectsTree");
990 effects->connect(SceneStringName(gui_input), callable_mp(this, &EditorAudioBus::_effects_gui_input));
991
992 send = memnew(OptionButton);
993 send->set_accessibility_name(TTRC("Send"));
994 send->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
995 send->set_clip_text(true);
996 send->connect(SceneStringName(item_selected), callable_mp(this, &EditorAudioBus::_send_selected));
997 vb->add_child(send);
998
999 set_focus_mode(FOCUS_CLICK);
1000
1001 effect_options = memnew(PopupMenu);
1002 effect_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate class names.
1003 effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add));
1004 add_child(effect_options);
1005 LocalVector<StringName> effect_list;
1006 ClassDB::get_inheriters_from_class("AudioEffect", effect_list);
1007 effect_list.sort_custom<StringName::AlphCompare>();
1008 for (const StringName &E : effect_list) {
1009 if (!ClassDB::can_instantiate(E) || ClassDB::is_virtual(E)) {
1010 continue;
1011 }
1012
1013 String name = E.operator String().replace("AudioEffect", "");
1014 effect_options->add_item(name);
1015 effect_options->set_item_metadata(-1, E);
1016 }
1017
1018 bus_options = memnew(MenuButton);
1019 bus_options->set_shortcut_context(this);
1020 bus_options->set_h_size_flags(SIZE_SHRINK_END);
1021 bus_options->set_anchor(SIDE_RIGHT, 0.0);
1022 bus_options->set_tooltip_text(TTR("Bus Options"));
1023 hbc->add_child(bus_options);
1024
1025 bus_popup = bus_options->get_popup();
1026 bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/duplicate_selected_bus", TTRC("Duplicate Bus"), KeyModifierMask::CMD_OR_CTRL | Key::D));
1027 bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/delete_selected_bus", TTRC("Delete Bus"), Key::KEY_DELETE));
1028 bus_popup->set_item_disabled(1, is_master);
1029 bus_popup->add_item(TTR("Reset Volume"));
1030 bus_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_bus_popup_pressed));
1031
1032 delete_effect_popup = memnew(PopupMenu);
1033 delete_effect_popup->add_item(TTR("Delete Effect"));
1034 add_child(delete_effect_popup);
1035 delete_effect_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_delete_effect_pressed));
1036 }
1037
1038 void EditorAudioBusDrop::_notification(int p_what) {
1039 switch (p_what) {
1040 case NOTIFICATION_DRAW: {
1041 draw_style_box(get_theme_stylebox(CoreStringName(normal), SNAME("Button")), Rect2(Vector2(), get_size()));
1042
1043 if (hovering_drop) {
1044 Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
1045 accent.a *= 0.7;
1046 draw_rect(Rect2(Point2(), get_size()), accent, false);
1047 }
1048 } break;
1049
1050 case NOTIFICATION_MOUSE_ENTER: {
1051 if (!hovering_drop) {
1052 hovering_drop = true;
1053 queue_redraw();
1054 }
1055 } break;
1056
1057 case NOTIFICATION_MOUSE_EXIT:
1058 case NOTIFICATION_DRAG_END: {
1059 if (hovering_drop) {
1060 hovering_drop = false;
1061 queue_redraw();
1062 }
1063 } break;
1064 }
1065 }
1066
1067 bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
1068 Dictionary d = p_data;
1069 return (d.has("type") && String(d["type"]) == "move_audio_bus");
1070 }
1071
1072 void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) {
1073 Dictionary d = p_data;
1074 emit_signal(SNAME("dropped"), d["index"], AudioServer::get_singleton()->get_bus_count());
1075 }
1076
1077 void EditorAudioBusDrop::_bind_methods() {
1078 ADD_SIGNAL(MethodInfo("dropped"));
1079 }
1080
1081 void EditorAudioBuses::_update_file_label() {
1082 const String filename = ResourceUID::ensure_path(edited_path).get_file();
1083 file->set_text(filename);
1084 file->set_tooltip_text(filename);
1085
1086 if (is_visible_in_tree()) {
1087 _update_file_label_size();
1088 }
1089 }
1090
1091 void EditorAudioBuses::_update_file_label_size() {
1092 int label_min_width = file->get_minimum_size().x + file->get_character_bounds(0).size.x;
1093 file->set_custom_minimum_size(Size2(label_min_width, 0));
1094 }
1095
1096 void EditorAudioBuses::_rebuild_buses() {
1097 for (int i = bus_hb->get_child_count() - 1; i >= 0; i--) {
1098 EditorAudioBus *audio_bus = Object::cast_to<EditorAudioBus>(bus_hb->get_child(i));
1099 if (audio_bus) {
1100 bus_hb->remove_child(audio_bus);
1101 audio_bus->queue_free();
1102 }
1103 }
1104
1105 if (drop_end) {
1106 bus_hb->remove_child(drop_end);
1107 drop_end->queue_free();
1108 drop_end = nullptr;
1109 }
1110
1111 for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
1112 bool is_master = (i == 0);
1113 EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master));
1114 bus_hb->add_child(audio_bus);
1115 audio_bus->connect("delete_request", callable_mp(this, &EditorAudioBuses::_delete_bus).bind(audio_bus), CONNECT_DEFERRED);
1116 audio_bus->connect("duplicate_request", callable_mp(this, &EditorAudioBuses::_duplicate_bus), CONNECT_DEFERRED);
1117 audio_bus->connect("vol_reset_request", callable_mp(this, &EditorAudioBuses::_reset_bus_volume).bind(audio_bus), CONNECT_DEFERRED);
1118 audio_bus->connect("drop_end_request", callable_mp(this, &EditorAudioBuses::_request_drop_end));
1119 audio_bus->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED);
1120 }
1121 }
1122
1123 EditorAudioBuses *EditorAudioBuses::register_editor() {
1124 EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
1125 EditorDockManager::get_singleton()->add_dock(audio_buses);
1126 return audio_buses;
1127 }
1128
1129 void EditorAudioBuses::_notification(int p_what) {
1130 switch (p_what) {
1131 case NOTIFICATION_THEME_CHANGED: {
1132 bus_scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
1133 if (is_visible_in_tree()) {
1134 _update_file_label_size();
1135 }
1136 } break;
1137
1138 case NOTIFICATION_READY: {
1139 _rebuild_buses();
1140 } break;
1141
1142 case NOTIFICATION_DRAG_END: {
1143 if (drop_end) {
1144 bus_hb->remove_child(drop_end);
1145 drop_end->queue_free();
1146 drop_end = nullptr;
1147 }
1148 } break;
1149
1150 case NOTIFICATION_PROCESS: {
1151 // Check if anything was edited.
1152 bool edited = AudioServer::get_singleton()->is_edited();
1153 for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
1154 for (int j = 0; j < AudioServer::get_singleton()->get_bus_effect_count(i); j++) {
1155 Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i, j);
1156 if (effect->is_edited()) {
1157 edited = true;
1158 effect->set_edited(false);
1159 }
1160 }
1161 }
1162
1163 if (edited) {
1164 AudioServer::get_singleton()->set_edited(false);
1165 save_timer->start();
1166 }
1167 } break;
1168 case NOTIFICATION_VISIBILITY_CHANGED: {
1169 if (is_visible_in_tree()) {
1170 _update_file_label();
1171 }
1172 } break;
1173 }
1174 }
1175
1176 void EditorAudioBuses::_add_bus() {
1177 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
1178
1179 ur->create_action(TTR("Add Audio Bus"));
1180 ur->add_do_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count() + 1);
1181 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count());
1182 ur->commit_action();
1183 }
1184
1185 void EditorAudioBuses::_update_bus(int p_index) {
1186 if (p_index >= bus_hb->get_child_count()) {
1187 return;
1188 }
1189
1190 bus_hb->get_child(p_index)->call("update_bus");
1191 }
1192
1193 void EditorAudioBuses::_update_sends() {
1194 for (int i = 0; i < bus_hb->get_child_count(); i++) {
1195 bus_hb->get_child(i)->call("update_send");
1196 }
1197 }
1198
1199 void EditorAudioBuses::_delete_bus(Object *p_which) {
1200 EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
1201 int index = bus->get_index();
1202 if (index == 0) {
1203 EditorNode::get_singleton()->show_warning(TTR("Master bus can't be deleted!"));
1204 return;
1205 }
1206
1207 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
1208
1209 ur->create_action(TTR("Delete Audio Bus"));
1210 ur->add_do_method(AudioServer::get_singleton(), "remove_bus", index);
1211 ur->add_undo_method(AudioServer::get_singleton(), "add_bus", index);
1212 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", index, AudioServer::get_singleton()->get_bus_name(index));
1213 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index));
1214 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", index, AudioServer::get_singleton()->get_bus_send(index));
1215 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", index, AudioServer::get_singleton()->is_bus_solo(index));
1216 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", index, AudioServer::get_singleton()->is_bus_mute(index));
1217 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", index, AudioServer::get_singleton()->is_bus_bypassing_effects(index));
1218 for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
1219 ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", index, AudioServer::get_singleton()->get_bus_effect(index, i));
1220 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", index, i, AudioServer::get_singleton()->is_bus_effect_enabled(index, i));
1221 }
1222 ur->commit_action();
1223 }
1224
1225 void EditorAudioBuses::_duplicate_bus(int p_which) {
1226 int add_at_pos = p_which + 1;
1227 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
1228 ur->create_action(TTR("Duplicate Audio Bus"));
1229 ur->add_do_method(AudioServer::get_singleton(), "add_bus", add_at_pos);
1230 ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", add_at_pos, AudioServer::get_singleton()->get_bus_name(p_which) + " Copy");
1231 ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", add_at_pos, AudioServer::get_singleton()->get_bus_volume_db(p_which));
1232 ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", add_at_pos, AudioServer::get_singleton()->get_bus_send(p_which));
1233 ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", add_at_pos, AudioServer::get_singleton()->is_bus_solo(p_which));
1234 ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", add_at_pos, AudioServer::get_singleton()->is_bus_mute(p_which));
1235 ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", add_at_pos, AudioServer::get_singleton()->is_bus_bypassing_effects(p_which));
1236 for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(p_which); i++) {
1237 ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", add_at_pos, AudioServer::get_singleton()->get_bus_effect(p_which, i));
1238 ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", add_at_pos, i, AudioServer::get_singleton()->is_bus_effect_enabled(p_which, i));
1239 }
1240 ur->add_do_method(this, "_update_bus", add_at_pos);
1241 ur->add_undo_method(AudioServer::get_singleton(), "remove_bus", add_at_pos);
1242 ur->commit_action();
1243 }
1244
1245 void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
1246 EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
1247 int index = bus->get_index();
1248
1249 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
1250 ur->create_action(TTR("Reset Bus Volume"));
1251 ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", index, 0.f);
1252 ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index));
1253 ur->add_do_method(this, "_update_bus", index);
1254 ur->add_undo_method(this, "_update_bus", index);
1255 ur->commit_action();
1256 }
1257
1258 void EditorAudioBuses::_request_drop_end() {
1259 if (!drop_end && bus_hb->get_child_count()) {
1260 drop_end = memnew(EditorAudioBusDrop);
1261
1262 bus_hb->add_child(drop_end);
1263 drop_end->set_custom_minimum_size(Object::cast_to<Control>(bus_hb->get_child(0))->get_size());
1264 drop_end->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED);
1265 }
1266 }
1267
1268 void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
1269 EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
1270 ur->create_action(TTR("Move Audio Bus"));
1271
1272 ur->add_do_method(AudioServer::get_singleton(), "move_bus", p_bus, p_index);
1273 int real_bus = p_index > p_bus ? p_bus : p_bus + 1;
1274 int real_index = p_index > p_bus ? p_index - 1 : p_index;
1275 ur->add_undo_method(AudioServer::get_singleton(), "move_bus", real_index, real_bus);
1276
1277 ur->commit_action();
1278 }
1279
1280 void EditorAudioBuses::_server_save() {
1281 Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout();
1282 if (edited_path.is_empty()) {
1283 ResourceSaver::save(state, "res://default_bus_layout.tres");
1284 edited_path = ResourceUID::path_to_uid("res://default_bus_layout.tres");
1285 ProjectSettings::get_singleton()->set_setting("audio/buses/default_bus_layout", edited_path);
1286 _update_file_label();
1287 } else if (!edited_path.begins_with("uid://")) {
1288 ResourceSaver::save(state, edited_path);
1289 edited_path = ResourceUID::path_to_uid(edited_path);
1290 ProjectSettings::get_singleton()->set_setting("audio/buses/default_bus_layout", edited_path);
1291 } else {
1292 ResourceSaver::save(state, ResourceUID::ensure_path(edited_path));
1293 }
1294 }
1295
1296 void EditorAudioBuses::_file_moved(const String &p_old_path, const String &p_new_path) {
1297 if (is_visible_in_tree() && !edited_path.is_empty()) {
1298 callable_mp(this, &EditorAudioBuses::_update_file_label).call_deferred();
1299 }
1300 }
1301
1302 void EditorAudioBuses::_select_layout() {
1303 FileSystemDock::get_singleton()->navigate_to_path(ResourceUID::ensure_path(edited_path));
1304 }
1305
1306 void EditorAudioBuses::_save_as_layout() {
1307 file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
1308 file_dialog->set_title(TTR("Save Audio Bus Layout As..."));
1309 file_dialog->set_current_path(ResourceUID::ensure_path(edited_path));
1310 file_dialog->popup_file_dialog();
1311 new_layout = false;
1312 }
1313
1314 void EditorAudioBuses::_new_layout() {
1315 file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
1316 file_dialog->set_title(TTR("Location for New Layout..."));
1317 file_dialog->set_current_path("new_bus_layout.tres");
1318 file_dialog->popup_file_dialog();
1319 new_layout = true;
1320 }
1321
1322 void EditorAudioBuses::_load_layout() {
1323 file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
1324 file_dialog->set_title(TTR("Open Audio Bus Layout"));
1325 file_dialog->set_current_path(ResourceUID::ensure_path(edited_path));
1326 file_dialog->popup_file_dialog();
1327 new_layout = false;
1328 }
1329
1330 void EditorAudioBuses::_load_default_layout() {
1331 open_layout(GLOBAL_GET("audio/buses/default_bus_layout"));
1332 }
1333
1334 void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
1335 if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
1336 if (new_layout) {
1337 Ref<AudioBusLayout> empty_state;
1338 empty_state.instantiate();
1339 AudioServer::get_singleton()->set_bus_layout(empty_state);
1340 }
1341
1342 Error err = ResourceSaver::save(AudioServer::get_singleton()->generate_bus_layout(), p_string);
1343 if (err != OK) {
1344 EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file: %s"), p_string));
1345 return;
1346 }
1347 }
1348 open_layout(ResourceUID::path_to_uid(p_string));
1349 }
1350
1351 void EditorAudioBuses::update_layout(EditorDock::DockLayout p_layout) {
1352 bool new_floating = (p_layout == EditorDock::DOCK_LAYOUT_FLOATING);
1353 if (floating == new_floating) {
1354 return;
1355 }
1356 floating = new_floating;
1357
1358 if (floating) {
1359 bus_mc->set_theme_type_variation("NoBorderHorizontalBottom");
1360 bus_scroll->set_scroll_hint_mode(ScrollContainer::SCROLL_HINT_MODE_TOP_AND_LEFT);
1361 } else {
1362 bus_mc->set_theme_type_variation("NoBorderBottomPanel");
1363 bus_scroll->set_scroll_hint_mode(ScrollContainer::SCROLL_HINT_MODE_ALL);
1364 }
1365 }
1366
1367 void EditorAudioBuses::_bind_methods() {
1368 ClassDB::bind_method("_update_bus", &EditorAudioBuses::_update_bus);
1369 ClassDB::bind_method("_update_sends", &EditorAudioBuses::_update_sends);
1370 }
1371
1372 EditorAudioBuses::EditorAudioBuses() {
1373 set_name(TTRC("Audio"));
1374 set_icon_name("AudioStreamPlayer");
1375 set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_audio_bottom_panel", TTRC("Toggle Audio Dock"), KeyModifierMask::ALT | Key::A));
1376 set_default_slot(EditorDock::DOCK_SLOT_BOTTOM);
1377 set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
1378
1379 VBoxContainer *main_vb = memnew(VBoxContainer);
1380 add_child(main_vb);
1381
1382 top_hb = memnew(HBoxContainer);
1383 main_vb->add_child(top_hb);
1384
1385 edited_path = GLOBAL_GET("audio/buses/default_bus_layout");
1386
1387 Label *layout_label = memnew(Label(TTRC("Layout:")));
1388 top_hb->add_child(layout_label);
1389
1390 file = memnew(Label);
1391 file->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1392 file->set_mouse_filter(MOUSE_FILTER_PASS);
1393 file->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
1394 file->set_h_size_flags(SIZE_EXPAND_FILL);
1395 top_hb->add_child(file);
1396
1397 add = memnew(Button);
1398 top_hb->add_child(add);
1399 add->set_text(TTR("Add Bus"));
1400 add->set_tooltip_text(TTR("Add a new Audio Bus to this layout."));
1401 add->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_add_bus));
1402
1403 VSeparator *separator = memnew(VSeparator);
1404 top_hb->add_child(separator);
1405
1406 load = memnew(Button);
1407 load->set_text(TTR("Load"));
1408 load->set_tooltip_text(TTR("Load an existing Bus Layout."));
1409 top_hb->add_child(load);
1410 load->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_load_layout));
1411
1412 save_as = memnew(Button);
1413 save_as->set_text(TTR("Save As"));
1414 save_as->set_tooltip_text(TTR("Save this Bus Layout to a file."));
1415 top_hb->add_child(save_as);
1416 save_as->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_save_as_layout));
1417
1418 _default = memnew(Button);
1419 _default->set_text(TTR("Load Default"));
1420 _default->set_tooltip_text(TTR("Load the default Bus Layout."));
1421 top_hb->add_child(_default);
1422 _default->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_load_default_layout));
1423
1424 _new = memnew(Button);
1425 _new->set_text(TTR("Create"));
1426 _new->set_tooltip_text(TTR("Create a new Bus Layout."));
1427 top_hb->add_child(_new);
1428 _new->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_new_layout));
1429
1430 bus_mc = memnew(MarginContainer);
1431 bus_mc->set_theme_type_variation("NoBorderBottomPanel");
1432 bus_mc->set_v_size_flags(SIZE_EXPAND_FILL);
1433 main_vb->add_child(bus_mc);
1434
1435 bus_scroll = memnew(ScrollContainer);
1436 bus_scroll->set_scroll_hint_mode(ScrollContainer::SCROLL_HINT_MODE_ALL);
1437 bus_scroll->set_custom_minimum_size(Size2(0, 40 * EDSCALE));
1438 bus_mc->add_child(bus_scroll);
1439
1440 bus_hb = memnew(HBoxContainer);
1441 bus_hb->set_v_size_flags(SIZE_EXPAND_FILL);
1442 bus_scroll->add_child(bus_hb);
1443
1444 save_timer = memnew(Timer);
1445 save_timer->set_wait_time(0.8);
1446 save_timer->set_one_shot(true);
1447 main_vb->add_child(save_timer);
1448 save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save));
1449
1450 set_v_size_flags(SIZE_EXPAND_FILL);
1451
1452 file_dialog = memnew(EditorFileDialog);
1453 List<String> ext;
1454 ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext);
1455 for (const String &E : ext) {
1456 file_dialog->add_filter("*." + E, TTR("Audio Bus Layout"));
1457 }
1458 add_child(file_dialog);
1459 file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback));
1460
1461 AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &EditorAudioBuses::_rebuild_buses));
1462 FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &EditorAudioBuses::_file_moved));
1463
1464 set_process(true);
1465 }
1466
1467 void EditorAudioBuses::open_layout(const String &p_path) {
1468 make_visible();
1469
1470 const String path = ResourceUID::ensure_path(p_path);
1471 if (!ResourceLoader::exists(path)) {
1472 EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" doesn't exist.)"), path));
1473 return;
1474 }
1475
1476 Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
1477 if (state.is_null()) {
1478 EditorNode::get_singleton()->show_warning(vformat(TTR(R"(Can't open audio bus layout: "%s" is not a valid audio bus layout.)"), path));
1479 return;
1480 }
1481
1482 edited_path = p_path; // Use UID when available.
1483 _update_file_label();
1484
1485 AudioServer::get_singleton()->set_bus_layout(state);
1486 _rebuild_buses();
1487 EditorUndoRedoManager::get_singleton()->clear_history(EditorUndoRedoManager::GLOBAL_HISTORY);
1488 callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred();
1489 }
1490
1491 void AudioBusesEditorPlugin::edit(Object *p_node) {
1492 Ref<AudioBusLayout> bus_layout(p_node);
1493 if (bus_layout.is_null()) {
1494 return;
1495 }
1496 const String path = bus_layout->get_path();
1497 if (path.is_resource_file()) {
1498 audio_bus_editor->open_layout(ResourceUID::path_to_uid(path));
1499 }
1500 }
1501
1502 bool AudioBusesEditorPlugin::handles(Object *p_node) const {
1503 return (Object::cast_to<AudioBusLayout>(p_node) != nullptr);
1504 }
1505
1506 void AudioBusesEditorPlugin::make_visible(bool p_visible) {
1507 }
1508
1509 AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
1510 audio_bus_editor = p_node;
1511 }
1512
1513 void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_value, bool p_render_value) {
1514 notches.push_back(AudioNotch(p_normalized_offset, p_db_value, p_render_value));
1515 }
1516
1517 Size2 EditorAudioMeterNotches::get_minimum_size() const {
1518 Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
1519 int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
1520 float font_height = font->get_height(font_size);
1521
1522 float width = 0;
1523 float height = top_padding + btm_padding;
1524
1525 for (const EditorAudioMeterNotches::AudioNotch &notch : notches) {
1526 if (notch.render_db_value) {
1527 width = MAX(width, font->get_string_size(String::num(Math::abs(notch.db_value)) + "dB", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x);
1528 height += font_height;
1529 }
1530 }
1531 width += line_length + label_space;
1532
1533 return Size2(width, height);
1534 }
1535
1536 void EditorAudioMeterNotches::_update_theme_item_cache() {
1537 Control::_update_theme_item_cache();
1538
1539 theme_cache.notch_color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor));
1540
1541 theme_cache.font = get_theme_font(SceneStringName(font), SNAME("Label"));
1542 theme_cache.font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
1543 }
1544
1545 void EditorAudioMeterNotches::_bind_methods() {
1546 ClassDB::bind_method("add_notch", &EditorAudioMeterNotches::add_notch);
1547 ClassDB::bind_method("_draw_audio_notches", &EditorAudioMeterNotches::_draw_audio_notches);
1548 }
1549
1550 void EditorAudioMeterNotches::_notification(int p_what) {
1551 switch (p_what) {
1552 case NOTIFICATION_DRAW: {
1553 _draw_audio_notches();
1554 } break;
1555 }
1556 }
1557
1558 void EditorAudioMeterNotches::_draw_audio_notches() {
1559 float font_height = theme_cache.font->get_height(theme_cache.font_size);
1560
1561 for (const AudioNotch &n : notches) {
1562 draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
1563 Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
1564 theme_cache.notch_color,
1565 Math::round(EDSCALE));
1566
1567 if (n.render_db_value) {
1568 draw_string(theme_cache.font,
1569 Vector2((line_length + label_space) * EDSCALE,
1570 (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding),
1571 String::num(Math::abs(n.db_value)) + "dB",
1572 HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size,
1573 theme_cache.notch_color);
1574 }
1575 }
1576 }