editor_audio_buses.cpp 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  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. #include "editor_audio_buses.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input.h"
  33. #include "core/io/resource_saver.h"
  34. #include "core/os/keyboard.h"
  35. #include "editor/editor_command_palette.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_settings.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/editor_undo_redo_manager.h"
  40. #include "editor/filesystem_dock.h"
  41. #include "editor/gui/editor_bottom_panel.h"
  42. #include "editor/gui/editor_file_dialog.h"
  43. #include "editor/themes/editor_scale.h"
  44. #include "editor/themes/editor_theme_manager.h"
  45. #include "scene/gui/separator.h"
  46. #include "scene/resources/font.h"
  47. #include "servers/audio_server.h"
  48. void EditorAudioBus::_update_visible_channels() {
  49. int i = 0;
  50. for (; i < cc; i++) {
  51. if (!channel[i].vu_l->is_visible()) {
  52. channel[i].vu_l->show();
  53. }
  54. if (!channel[i].vu_r->is_visible()) {
  55. channel[i].vu_r->show();
  56. }
  57. }
  58. for (; i < CHANNELS_MAX; i++) {
  59. if (channel[i].vu_l->is_visible()) {
  60. channel[i].vu_l->hide();
  61. }
  62. if (channel[i].vu_r->is_visible()) {
  63. channel[i].vu_r->hide();
  64. }
  65. }
  66. }
  67. void EditorAudioBus::_notification(int p_what) {
  68. switch (p_what) {
  69. case NOTIFICATION_ENTER_TREE:
  70. case NOTIFICATION_THEME_CHANGED: {
  71. Ref<Texture2D> active_bus_texture = get_editor_theme_icon(SNAME("BusVuActive"));
  72. for (int i = 0; i < CHANNELS_MAX; i++) {
  73. channel[i].vu_l->set_under_texture(active_bus_texture);
  74. channel[i].vu_l->set_tint_under(Color(0.75, 0.75, 0.75));
  75. channel[i].vu_l->set_progress_texture(active_bus_texture);
  76. channel[i].vu_r->set_under_texture(active_bus_texture);
  77. channel[i].vu_r->set_tint_under(Color(0.75, 0.75, 0.75));
  78. channel[i].vu_r->set_progress_texture(active_bus_texture);
  79. channel[i].prev_active = true;
  80. }
  81. disabled_vu = get_editor_theme_icon(SNAME("BusVuFrozen"));
  82. Color solo_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.89, 0.22) : Color(1.9, 1.74, 0.83);
  83. Color mute_color = EditorThemeManager::is_dark_theme() ? Color(1.0, 0.16, 0.16) : Color(2.35, 1.03, 1.03);
  84. Color bypass_color = EditorThemeManager::is_dark_theme() ? Color(0.13, 0.8, 1.0) : Color(1.03, 2.04, 2.35);
  85. float darkening_factor = EditorThemeManager::is_dark_theme() ? 0.15 : 0.65;
  86. Ref<StyleBoxFlat>(solo->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(solo_color.darkened(darkening_factor));
  87. Ref<StyleBoxFlat>(mute->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(mute_color.darkened(darkening_factor));
  88. Ref<StyleBoxFlat>(bypass->get_theme_stylebox(SceneStringName(pressed)))->set_border_color(bypass_color.darkened(darkening_factor));
  89. solo->set_icon(get_editor_theme_icon(SNAME("AudioBusSolo")));
  90. solo->add_theme_color_override("icon_pressed_color", solo_color);
  91. mute->set_icon(get_editor_theme_icon(SNAME("AudioBusMute")));
  92. mute->add_theme_color_override("icon_pressed_color", mute_color);
  93. bypass->set_icon(get_editor_theme_icon(SNAME("AudioBusBypass")));
  94. bypass->add_theme_color_override("icon_pressed_color", bypass_color);
  95. bus_options->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
  96. audio_value_preview_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), SNAME("TooltipLabel")));
  97. audio_value_preview_label->add_theme_color_override("font_shadow_color", get_theme_color(SNAME("font_shadow_color"), SNAME("TooltipLabel")));
  98. audio_value_preview_box->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("TooltipPanel")));
  99. for (int i = 0; i < effect_options->get_item_count(); i++) {
  100. String class_name = effect_options->get_item_metadata(i);
  101. Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(class_name);
  102. effect_options->set_item_icon(i, icon);
  103. }
  104. } break;
  105. case NOTIFICATION_READY: {
  106. update_bus();
  107. set_process(true);
  108. } break;
  109. case NOTIFICATION_DRAW: {
  110. if (is_master) {
  111. draw_style_box(get_theme_stylebox(SNAME("disabled"), SNAME("Button")), Rect2(Vector2(), get_size()));
  112. } else if (has_focus()) {
  113. draw_style_box(get_theme_stylebox(SNAME("focus"), SNAME("Button")), Rect2(Vector2(), get_size()));
  114. } else {
  115. draw_style_box(get_theme_stylebox(SceneStringName(panel), SNAME("TabContainer")), Rect2(Vector2(), get_size()));
  116. }
  117. if (get_index() != 0 && hovering_drop) {
  118. Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
  119. accent.a *= 0.7;
  120. draw_rect(Rect2(Point2(), get_size()), accent, false);
  121. }
  122. } break;
  123. case NOTIFICATION_PROCESS: {
  124. if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
  125. cc = AudioServer::get_singleton()->get_bus_channels(get_index());
  126. _update_visible_channels();
  127. }
  128. for (int i = 0; i < cc; i++) {
  129. float real_peak[2] = { -100, -100 };
  130. bool activity_found = false;
  131. if (AudioServer::get_singleton()->is_bus_channel_active(get_index(), i)) {
  132. activity_found = true;
  133. real_peak[0] = MAX(real_peak[0], AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(), i));
  134. real_peak[1] = MAX(real_peak[1], AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(), i));
  135. }
  136. if (real_peak[0] > channel[i].peak_l) {
  137. channel[i].peak_l = real_peak[0];
  138. } else {
  139. channel[i].peak_l -= get_process_delta_time() * 60.0;
  140. }
  141. if (real_peak[1] > channel[i].peak_r) {
  142. channel[i].peak_r = real_peak[1];
  143. } else {
  144. channel[i].peak_r -= get_process_delta_time() * 60.0;
  145. }
  146. channel[i].vu_l->set_value(channel[i].peak_l);
  147. channel[i].vu_r->set_value(channel[i].peak_r);
  148. if (activity_found != channel[i].prev_active) {
  149. if (activity_found) {
  150. channel[i].vu_l->set_over_texture(Ref<Texture2D>());
  151. channel[i].vu_r->set_over_texture(Ref<Texture2D>());
  152. } else {
  153. channel[i].vu_l->set_over_texture(disabled_vu);
  154. channel[i].vu_r->set_over_texture(disabled_vu);
  155. }
  156. channel[i].prev_active = activity_found;
  157. }
  158. }
  159. } break;
  160. case NOTIFICATION_VISIBILITY_CHANGED: {
  161. for (int i = 0; i < CHANNELS_MAX; i++) {
  162. channel[i].peak_l = -100;
  163. channel[i].peak_r = -100;
  164. channel[i].prev_active = true;
  165. }
  166. set_process(is_visible_in_tree());
  167. } break;
  168. case NOTIFICATION_MOUSE_EXIT:
  169. case NOTIFICATION_DRAG_END: {
  170. if (hovering_drop) {
  171. hovering_drop = false;
  172. queue_redraw();
  173. }
  174. } break;
  175. }
  176. }
  177. void EditorAudioBus::update_send() {
  178. send->clear();
  179. if (is_master) {
  180. send->set_disabled(true);
  181. send->set_text(TTR("Speakers"));
  182. } else {
  183. send->set_disabled(false);
  184. StringName current_send = AudioServer::get_singleton()->get_bus_send(get_index());
  185. int current_send_index = 0; //by default to master
  186. for (int i = 0; i < get_index(); i++) {
  187. StringName send_name = AudioServer::get_singleton()->get_bus_name(i);
  188. send->add_item(send_name);
  189. if (send_name == current_send) {
  190. current_send_index = i;
  191. }
  192. }
  193. send->select(current_send_index);
  194. }
  195. }
  196. void EditorAudioBus::update_bus() {
  197. if (updating_bus) {
  198. return;
  199. }
  200. updating_bus = true;
  201. int index = get_index();
  202. float db_value = AudioServer::get_singleton()->get_bus_volume_db(index);
  203. slider->set_value(_scaled_db_to_normalized_volume(db_value));
  204. track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
  205. if (is_master) {
  206. track_name->set_editable(false);
  207. }
  208. solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index));
  209. mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index));
  210. bypass->set_pressed(AudioServer::get_singleton()->is_bus_bypassing_effects(index));
  211. // effects..
  212. effects->clear();
  213. TreeItem *root = effects->create_item();
  214. for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
  215. Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index, i);
  216. TreeItem *fx = effects->create_item(root);
  217. fx->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  218. fx->set_editable(0, true);
  219. fx->set_checked(0, AudioServer::get_singleton()->is_bus_effect_enabled(index, i));
  220. fx->set_text(0, afx->get_name());
  221. fx->set_metadata(0, i);
  222. }
  223. TreeItem *add = effects->create_item(root);
  224. add->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM);
  225. add->set_editable(0, true);
  226. add->set_selectable(0, false);
  227. add->set_text(0, TTR("Add Effect"));
  228. update_send();
  229. updating_bus = false;
  230. }
  231. void EditorAudioBus::_name_changed(const String &p_new_name) {
  232. if (updating_bus) {
  233. return;
  234. }
  235. updating_bus = true;
  236. track_name->release_focus();
  237. if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) {
  238. updating_bus = false;
  239. return;
  240. }
  241. String attempt = p_new_name;
  242. int attempts = 1;
  243. while (true) {
  244. bool name_free = true;
  245. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  246. if (AudioServer::get_singleton()->get_bus_name(i) == attempt) {
  247. name_free = false;
  248. break;
  249. }
  250. }
  251. if (name_free) {
  252. break;
  253. }
  254. attempts++;
  255. attempt = p_new_name + " " + itos(attempts);
  256. }
  257. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  258. StringName current = AudioServer::get_singleton()->get_bus_name(get_index());
  259. ur->create_action(TTR("Rename Audio Bus"));
  260. ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", get_index(), attempt);
  261. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", get_index(), current);
  262. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  263. if (AudioServer::get_singleton()->get_bus_send(i) == current) {
  264. ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", i, attempt);
  265. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", i, current);
  266. }
  267. }
  268. ur->add_do_method(buses, "_update_bus", get_index());
  269. ur->add_undo_method(buses, "_update_bus", get_index());
  270. ur->add_do_method(buses, "_update_sends");
  271. ur->add_undo_method(buses, "_update_sends");
  272. ur->commit_action();
  273. updating_bus = false;
  274. }
  275. void EditorAudioBus::_volume_changed(float p_normalized) {
  276. if (updating_bus) {
  277. return;
  278. }
  279. updating_bus = true;
  280. const float p_db = _normalized_volume_to_scaled_db(p_normalized);
  281. if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
  282. // Snap the value when holding Ctrl for easier editing.
  283. // To do so, it needs to be converted back to normalized volume (as the slider uses that unit).
  284. slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db)));
  285. }
  286. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  287. ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS);
  288. ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), p_db);
  289. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", get_index(), AudioServer::get_singleton()->get_bus_volume_db(get_index()));
  290. ur->add_do_method(buses, "_update_bus", get_index());
  291. ur->add_undo_method(buses, "_update_bus", get_index());
  292. ur->commit_action();
  293. updating_bus = false;
  294. }
  295. float EditorAudioBus::_normalized_volume_to_scaled_db(float normalized) {
  296. /* There are three different formulas for the conversion from normalized
  297. * values to relative decibal values.
  298. * One formula is an exponential graph which intends to counteract
  299. * the logarithmic nature of human hearing. This is an approximation
  300. * of the behavior of a 'logarithmic potentiometer' found on most
  301. * musical instruments and also emulated in popular software.
  302. * The other two equations are hand-tuned linear tapers that intend to
  303. * try to ease the exponential equation in areas where it makes sense.*/
  304. if (normalized > 0.6f) {
  305. return 22.22f * normalized - 16.2f;
  306. } else if (normalized < 0.05f) {
  307. return 830.72 * normalized - 80.0f;
  308. } else {
  309. return 45.0f * Math::pow(normalized - 1.0, 3);
  310. }
  311. }
  312. float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
  313. /* Inversion of equations found in _normalized_volume_to_scaled_db.
  314. * IMPORTANT: If one function changes, the other much change to reflect it. */
  315. if (db > -2.88) {
  316. return (db + 16.2f) / 22.22f;
  317. } else if (db < -38.602f) {
  318. return (db + 80.00f) / 830.72f;
  319. } else {
  320. if (db < 0.0) {
  321. /* To accommodate for NaN on negative numbers for root, we will mirror the
  322. * results of the positive db range in order to get the desired numerical
  323. * value on the negative side. */
  324. float positive_x = Math::pow(Math::abs(db) / 45.0f, 1.0f / 3.0f) + 1.0f;
  325. Vector2 translation = Vector2(1.0f, 0.0f) - Vector2(positive_x, Math::abs(db));
  326. Vector2 reflected_position = Vector2(1.0, 0.0f) + translation;
  327. return reflected_position.x;
  328. } else {
  329. return Math::pow(db / 45.0f, 1.0f / 3.0f) + 1.0f;
  330. }
  331. }
  332. }
  333. void EditorAudioBus::_show_value(float slider_value) {
  334. float db;
  335. if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
  336. // Display the correct (snapped) value when holding Ctrl
  337. db = Math::round(_normalized_volume_to_scaled_db(slider_value));
  338. } else {
  339. db = _normalized_volume_to_scaled_db(slider_value);
  340. }
  341. String text;
  342. if (Math::is_zero_approx(Math::snapped(db, 0.1))) {
  343. // Prevent displaying `-0.0 dB` and show ` 0.0 dB` instead.
  344. // The leading space makes the text visually line up with its positive/negative counterparts.
  345. text = " 0.0 dB";
  346. } else {
  347. // Show an explicit `+` sign if positive.
  348. text = vformat("%+.1f dB", db);
  349. }
  350. // Also set the preview text as a standard Control tooltip.
  351. // This way, it can be seen when the slider is merely hovered (instead of dragged).
  352. slider->set_tooltip_text(text);
  353. audio_value_preview_label->set_text(text);
  354. const Vector2 slider_size = slider->get_size();
  355. const Vector2 slider_position = slider->get_global_position();
  356. const float vert_padding = 10.0f;
  357. const Vector2 box_position = Vector2(slider_size.x, (slider_size.y - vert_padding) * (1.0f - slider->get_value()) - vert_padding);
  358. audio_value_preview_box->set_position(slider_position + box_position);
  359. audio_value_preview_box->set_size(audio_value_preview_label->get_size());
  360. if (slider->has_focus() && !audio_value_preview_box->is_visible()) {
  361. audio_value_preview_box->show();
  362. }
  363. preview_timer->start();
  364. }
  365. void EditorAudioBus::_hide_value_preview() {
  366. audio_value_preview_box->hide();
  367. }
  368. void EditorAudioBus::_solo_toggled() {
  369. updating_bus = true;
  370. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  371. ur->create_action(TTR("Toggle Audio Bus Solo"));
  372. ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), solo->is_pressed());
  373. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", get_index(), AudioServer::get_singleton()->is_bus_solo(get_index()));
  374. ur->add_do_method(buses, "_update_bus", get_index());
  375. ur->add_undo_method(buses, "_update_bus", get_index());
  376. ur->commit_action();
  377. updating_bus = false;
  378. }
  379. void EditorAudioBus::_mute_toggled() {
  380. updating_bus = true;
  381. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  382. ur->create_action(TTR("Toggle Audio Bus Mute"));
  383. ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), mute->is_pressed());
  384. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", get_index(), AudioServer::get_singleton()->is_bus_mute(get_index()));
  385. ur->add_do_method(buses, "_update_bus", get_index());
  386. ur->add_undo_method(buses, "_update_bus", get_index());
  387. ur->commit_action();
  388. updating_bus = false;
  389. }
  390. void EditorAudioBus::_bypass_toggled() {
  391. updating_bus = true;
  392. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  393. ur->create_action(TTR("Toggle Audio Bus Bypass Effects"));
  394. ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), bypass->is_pressed());
  395. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", get_index(), AudioServer::get_singleton()->is_bus_bypassing_effects(get_index()));
  396. ur->add_do_method(buses, "_update_bus", get_index());
  397. ur->add_undo_method(buses, "_update_bus", get_index());
  398. ur->commit_action();
  399. updating_bus = false;
  400. }
  401. void EditorAudioBus::_send_selected(int p_which) {
  402. updating_bus = true;
  403. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  404. ur->create_action(TTR("Select Audio Bus Send"));
  405. ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", get_index(), send->get_item_text(p_which));
  406. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", get_index(), AudioServer::get_singleton()->get_bus_send(get_index()));
  407. ur->add_do_method(buses, "_update_bus", get_index());
  408. ur->add_undo_method(buses, "_update_bus", get_index());
  409. ur->commit_action();
  410. updating_bus = false;
  411. }
  412. void EditorAudioBus::_effect_selected() {
  413. TreeItem *effect = effects->get_selected();
  414. if (!effect) {
  415. return;
  416. }
  417. updating_bus = true;
  418. if (effect->get_metadata(0) != Variant()) {
  419. int index = effect->get_metadata(0);
  420. Ref<AudioEffect> effect2 = AudioServer::get_singleton()->get_bus_effect(get_index(), index);
  421. if (effect2.is_valid()) {
  422. EditorNode::get_singleton()->push_item(effect2.ptr());
  423. }
  424. }
  425. updating_bus = false;
  426. }
  427. void EditorAudioBus::_effect_edited() {
  428. if (updating_bus) {
  429. return;
  430. }
  431. TreeItem *effect = effects->get_edited();
  432. if (!effect) {
  433. return;
  434. }
  435. if (effect->get_metadata(0) == Variant()) {
  436. Rect2 area = effects->get_item_rect(effect);
  437. effect_options->set_position(effects->get_screen_position() + area.position + Vector2(0, area.size.y));
  438. effect_options->reset_size();
  439. effect_options->popup();
  440. //add effect
  441. } else {
  442. int index = effect->get_metadata(0);
  443. updating_bus = true;
  444. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  445. ur->create_action(TTR("Select Audio Bus Send"));
  446. ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, effect->is_checked(0));
  447. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index));
  448. ur->add_do_method(buses, "_update_bus", get_index());
  449. ur->add_undo_method(buses, "_update_bus", get_index());
  450. ur->commit_action();
  451. updating_bus = false;
  452. }
  453. }
  454. void EditorAudioBus::_effect_add(int p_which) {
  455. if (updating_bus) {
  456. return;
  457. }
  458. StringName name = effect_options->get_item_metadata(p_which);
  459. Object *fx = ClassDB::instantiate(name);
  460. ERR_FAIL_NULL(fx);
  461. AudioEffect *afx = Object::cast_to<AudioEffect>(fx);
  462. ERR_FAIL_NULL(afx);
  463. Ref<AudioEffect> afxr = Ref<AudioEffect>(afx);
  464. afxr->set_name(effect_options->get_item_text(p_which));
  465. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  466. ur->create_action(TTR("Add Audio Bus Effect"));
  467. ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), afxr, -1);
  468. ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect_count(get_index()));
  469. ur->add_do_method(buses, "_update_bus", get_index());
  470. ur->add_undo_method(buses, "_update_bus", get_index());
  471. ur->commit_action();
  472. }
  473. void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) {
  474. ERR_FAIL_COND(p_event.is_null());
  475. Ref<InputEventMouseButton> mb = p_event;
  476. if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
  477. bus_popup->set_position(get_screen_position() + mb->get_position());
  478. bus_popup->reset_size();
  479. bus_popup->popup();
  480. }
  481. }
  482. void EditorAudioBus::_effects_gui_input(Ref<InputEvent> p_event) {
  483. Ref<InputEventKey> k = p_event;
  484. if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == Key::KEY_DELETE) {
  485. TreeItem *current_effect = effects->get_selected();
  486. if (current_effect && current_effect->get_metadata(0).get_type() == Variant::INT) {
  487. _delete_effect_pressed(0);
  488. accept_event();
  489. }
  490. }
  491. }
  492. void EditorAudioBus::_bus_popup_pressed(int p_option) {
  493. if (p_option == 2) {
  494. // Reset volume
  495. emit_signal(SNAME("vol_reset_request"));
  496. } else if (p_option == 1) {
  497. emit_signal(SNAME("delete_request"));
  498. } else if (p_option == 0) {
  499. //duplicate
  500. emit_signal(SNAME("duplicate_request"), get_index());
  501. }
  502. }
  503. Variant EditorAudioBus::get_drag_data(const Point2 &p_point) {
  504. if (get_index() == 0) {
  505. return Variant();
  506. }
  507. Control *c = memnew(Control);
  508. Panel *p = memnew(Panel);
  509. c->add_child(p);
  510. p->set_modulate(Color(1, 1, 1, 0.7));
  511. p->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("focus"), SNAME("Button")));
  512. p->set_size(get_size());
  513. p->set_position(-p_point);
  514. set_drag_preview(c);
  515. Dictionary d;
  516. d["type"] = "move_audio_bus";
  517. d["index"] = get_index();
  518. if (get_index() < AudioServer::get_singleton()->get_bus_count() - 1) {
  519. emit_signal(SNAME("drop_end_request"));
  520. }
  521. return d;
  522. }
  523. bool EditorAudioBus::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
  524. if (get_index() == 0) {
  525. return false;
  526. }
  527. Dictionary d = p_data;
  528. if (d.has("type") && String(d["type"]) == "move_audio_bus" && (int)d["index"] != get_index()) {
  529. hovering_drop = true;
  530. return true;
  531. }
  532. return false;
  533. }
  534. void EditorAudioBus::drop_data(const Point2 &p_point, const Variant &p_data) {
  535. Dictionary d = p_data;
  536. emit_signal(SNAME("dropped"), d["index"], get_index());
  537. }
  538. Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  539. TreeItem *item = effects->get_item_at_position(p_point);
  540. if (!item) {
  541. return Variant();
  542. }
  543. Variant md = item->get_metadata(0);
  544. if (md.get_type() == Variant::INT) {
  545. Dictionary fxd;
  546. fxd["type"] = "audio_bus_effect";
  547. fxd["bus"] = get_index();
  548. fxd["effect"] = md;
  549. Label *l = memnew(Label);
  550. l->set_text(item->get_text(0));
  551. effects->set_drag_preview(l);
  552. return fxd;
  553. }
  554. return Variant();
  555. }
  556. bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  557. Dictionary d = p_data;
  558. if (!d.has("type") || String(d["type"]) != "audio_bus_effect") {
  559. return false;
  560. }
  561. TreeItem *item = effects->get_item_at_position(p_point);
  562. if (!item) {
  563. return false;
  564. }
  565. effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  566. return true;
  567. }
  568. void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  569. Dictionary d = p_data;
  570. TreeItem *item = effects->get_item_at_position(p_point);
  571. if (!item) {
  572. return;
  573. }
  574. int pos = effects->get_drop_section_at_position(p_point);
  575. Variant md = item->get_metadata(0);
  576. int paste_at;
  577. int bus = d["bus"];
  578. int effect = d["effect"];
  579. if (md.get_type() == Variant::INT) {
  580. paste_at = md;
  581. if (pos > 0) {
  582. paste_at++;
  583. }
  584. if (bus == get_index() && paste_at > effect) {
  585. paste_at--;
  586. }
  587. } else {
  588. paste_at = -1;
  589. }
  590. bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus, effect);
  591. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  592. ur->create_action(TTR("Move Bus Effect"));
  593. ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", bus, effect);
  594. ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(bus, effect), paste_at);
  595. if (paste_at == -1) {
  596. paste_at = AudioServer::get_singleton()->get_bus_effect_count(get_index());
  597. if (bus == get_index()) {
  598. paste_at--;
  599. }
  600. }
  601. if (!enabled) {
  602. ur->add_do_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), paste_at, false);
  603. }
  604. ur->add_undo_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), paste_at);
  605. ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", bus, AudioServer::get_singleton()->get_bus_effect(bus, effect), effect);
  606. if (!enabled) {
  607. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", bus, effect, false);
  608. }
  609. ur->add_do_method(buses, "_update_bus", get_index());
  610. ur->add_undo_method(buses, "_update_bus", get_index());
  611. if (get_index() != bus) {
  612. ur->add_do_method(buses, "_update_bus", bus);
  613. ur->add_undo_method(buses, "_update_bus", bus);
  614. }
  615. ur->commit_action();
  616. }
  617. void EditorAudioBus::_delete_effect_pressed(int p_option) {
  618. TreeItem *item = effects->get_selected();
  619. if (!item) {
  620. return;
  621. }
  622. if (item->get_metadata(0).get_type() != Variant::INT) {
  623. return;
  624. }
  625. int index = item->get_metadata(0);
  626. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  627. ur->create_action(TTR("Delete Bus Effect"));
  628. ur->add_do_method(AudioServer::get_singleton(), "remove_bus_effect", get_index(), index);
  629. ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", get_index(), AudioServer::get_singleton()->get_bus_effect(get_index(), index), index);
  630. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", get_index(), index, AudioServer::get_singleton()->is_bus_effect_enabled(get_index(), index));
  631. ur->add_do_method(buses, "_update_bus", get_index());
  632. ur->add_undo_method(buses, "_update_bus", get_index());
  633. ur->commit_action();
  634. }
  635. void EditorAudioBus::_effect_rmb(const Vector2 &p_pos, MouseButton p_button) {
  636. if (p_button != MouseButton::RIGHT) {
  637. return;
  638. }
  639. TreeItem *item = effects->get_selected();
  640. if (!item) {
  641. return;
  642. }
  643. if (item->get_metadata(0).get_type() != Variant::INT) {
  644. return;
  645. }
  646. delete_effect_popup->set_position(get_screen_position() + get_local_mouse_position());
  647. delete_effect_popup->reset_size();
  648. delete_effect_popup->popup();
  649. }
  650. void EditorAudioBus::_bind_methods() {
  651. ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
  652. ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
  653. ADD_SIGNAL(MethodInfo("duplicate_request"));
  654. ADD_SIGNAL(MethodInfo("delete_request"));
  655. ADD_SIGNAL(MethodInfo("vol_reset_request"));
  656. ADD_SIGNAL(MethodInfo("drop_end_request"));
  657. ADD_SIGNAL(MethodInfo("dropped"));
  658. }
  659. EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
  660. buses = p_buses;
  661. is_master = p_is_master;
  662. set_tooltip_text(TTR("Drag & drop to rearrange."));
  663. VBoxContainer *vb = memnew(VBoxContainer);
  664. vb->add_theme_constant_override("separation", 4 * EDSCALE);
  665. add_child(vb);
  666. set_v_size_flags(SIZE_EXPAND_FILL);
  667. track_name = memnew(LineEdit);
  668. track_name->connect("text_submitted", callable_mp(this, &EditorAudioBus::_name_changed));
  669. track_name->connect(SceneStringName(focus_exited), callable_mp(this, &EditorAudioBus::_name_focus_exit));
  670. vb->add_child(track_name);
  671. HBoxContainer *hbc = memnew(HBoxContainer);
  672. vb->add_child(hbc);
  673. solo = memnew(Button);
  674. solo->set_theme_type_variation("FlatButton");
  675. solo->set_toggle_mode(true);
  676. solo->set_tooltip_text(TTR("Solo"));
  677. solo->set_focus_mode(FOCUS_NONE);
  678. solo->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_solo_toggled));
  679. hbc->add_child(solo);
  680. mute = memnew(Button);
  681. mute->set_theme_type_variation("FlatButton");
  682. mute->set_toggle_mode(true);
  683. mute->set_tooltip_text(TTR("Mute"));
  684. mute->set_focus_mode(FOCUS_NONE);
  685. mute->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_mute_toggled));
  686. hbc->add_child(mute);
  687. bypass = memnew(Button);
  688. bypass->set_theme_type_variation("FlatButton");
  689. bypass->set_toggle_mode(true);
  690. bypass->set_tooltip_text(TTR("Bypass"));
  691. bypass->set_focus_mode(FOCUS_NONE);
  692. bypass->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBus::_bypass_toggled));
  693. hbc->add_child(bypass);
  694. hbc->add_spacer();
  695. Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
  696. for (int i = 0; i < hbc->get_child_count(); i++) {
  697. Control *child = Object::cast_to<Control>(hbc->get_child(i));
  698. child->begin_bulk_theme_override();
  699. child->add_theme_style_override(CoreStringName(normal), sbempty);
  700. child->add_theme_style_override("hover", sbempty);
  701. child->add_theme_style_override("focus", sbempty);
  702. Ref<StyleBoxFlat> sbflat = memnew(StyleBoxFlat);
  703. sbflat->set_content_margin_all(0);
  704. sbflat->set_bg_color(Color(1, 1, 1, 0));
  705. sbflat->set_border_width(Side::SIDE_BOTTOM, Math::round(3 * EDSCALE));
  706. child->add_theme_style_override(SceneStringName(pressed), sbflat);
  707. child->end_bulk_theme_override();
  708. }
  709. HSeparator *separator = memnew(HSeparator);
  710. separator->set_mouse_filter(MOUSE_FILTER_PASS);
  711. vb->add_child(separator);
  712. Control *spacer_top = memnew(Control);
  713. spacer_top->set_custom_minimum_size(Size2(0, 6 * EDSCALE));
  714. vb->add_child(spacer_top);
  715. HBoxContainer *hb = memnew(HBoxContainer);
  716. vb->add_child(hb);
  717. Control *spacer_bottom = memnew(Control);
  718. spacer_bottom->set_custom_minimum_size(Size2(0, 2 * EDSCALE));
  719. vb->add_child(spacer_bottom);
  720. slider = memnew(VSlider);
  721. slider->set_min(0.0);
  722. slider->set_max(1.0);
  723. slider->set_step(0.0001);
  724. slider->set_clip_contents(false);
  725. audio_value_preview_box = memnew(Panel);
  726. slider->add_child(audio_value_preview_box);
  727. audio_value_preview_box->set_as_top_level(true);
  728. audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS);
  729. audio_value_preview_box->hide();
  730. HBoxContainer *audioprev_hbc = memnew(HBoxContainer);
  731. audioprev_hbc->set_v_size_flags(SIZE_EXPAND_FILL);
  732. audioprev_hbc->set_h_size_flags(SIZE_EXPAND_FILL);
  733. audio_value_preview_box->add_child(audioprev_hbc);
  734. audio_value_preview_label = memnew(Label);
  735. audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL);
  736. audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL);
  737. audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS);
  738. audioprev_hbc->add_child(audio_value_preview_label);
  739. preview_timer = memnew(Timer);
  740. preview_timer->set_wait_time(0.8f);
  741. preview_timer->set_one_shot(true);
  742. add_child(preview_timer);
  743. slider->connect(SceneStringName(value_changed), callable_mp(this, &EditorAudioBus::_volume_changed));
  744. slider->connect(SceneStringName(value_changed), callable_mp(this, &EditorAudioBus::_show_value));
  745. preview_timer->connect("timeout", callable_mp(this, &EditorAudioBus::_hide_value_preview));
  746. hb->add_child(slider);
  747. cc = 0;
  748. for (int i = 0; i < CHANNELS_MAX; i++) {
  749. channel[i].vu_l = memnew(TextureProgressBar);
  750. channel[i].vu_l->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP);
  751. hb->add_child(channel[i].vu_l);
  752. channel[i].vu_l->set_min(-80);
  753. channel[i].vu_l->set_max(24);
  754. channel[i].vu_l->set_step(0.1);
  755. channel[i].vu_r = memnew(TextureProgressBar);
  756. channel[i].vu_r->set_fill_mode(TextureProgressBar::FILL_BOTTOM_TO_TOP);
  757. hb->add_child(channel[i].vu_r);
  758. channel[i].vu_r->set_min(-80);
  759. channel[i].vu_r->set_max(24);
  760. channel[i].vu_r->set_step(0.1);
  761. channel[i].peak_l = 0.0f;
  762. channel[i].peak_r = 0.0f;
  763. }
  764. EditorAudioMeterNotches *scale = memnew(EditorAudioMeterNotches);
  765. for (float db = 6.0f; db >= -80.0f; db -= 6.0f) {
  766. bool renderNotch = (db >= -6.0f || db == -24.0f || db == -72.0f);
  767. scale->add_notch(_scaled_db_to_normalized_volume(db), db, renderNotch);
  768. }
  769. scale->set_mouse_filter(MOUSE_FILTER_PASS);
  770. hb->add_child(scale);
  771. effects = memnew(Tree);
  772. effects->set_hide_root(true);
  773. effects->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
  774. effects->set_hide_folding(true);
  775. effects->set_v_size_flags(SIZE_EXPAND_FILL);
  776. vb->add_child(effects);
  777. effects->connect("item_edited", callable_mp(this, &EditorAudioBus::_effect_edited));
  778. effects->connect("cell_selected", callable_mp(this, &EditorAudioBus::_effect_selected));
  779. effects->connect(SceneStringName(focus_exited), callable_mp(effects, &Tree::deselect_all));
  780. effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
  781. SET_DRAG_FORWARDING_GCD(effects, EditorAudioBus);
  782. effects->connect("item_mouse_selected", callable_mp(this, &EditorAudioBus::_effect_rmb));
  783. effects->set_allow_rmb_select(true);
  784. effects->set_focus_mode(FOCUS_CLICK);
  785. effects->set_allow_reselect(true);
  786. effects->connect(SceneStringName(gui_input), callable_mp(this, &EditorAudioBus::_effects_gui_input));
  787. send = memnew(OptionButton);
  788. send->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  789. send->set_clip_text(true);
  790. send->connect(SceneStringName(item_selected), callable_mp(this, &EditorAudioBus::_send_selected));
  791. vb->add_child(send);
  792. set_focus_mode(FOCUS_CLICK);
  793. effect_options = memnew(PopupMenu);
  794. effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add));
  795. add_child(effect_options);
  796. List<StringName> effect_list;
  797. ClassDB::get_inheriters_from_class("AudioEffect", &effect_list);
  798. effect_list.sort_custom<StringName::AlphCompare>();
  799. for (const StringName &E : effect_list) {
  800. if (!ClassDB::can_instantiate(E) || ClassDB::is_virtual(E)) {
  801. continue;
  802. }
  803. String name = E.operator String().replace("AudioEffect", "");
  804. effect_options->add_item(name);
  805. effect_options->set_item_metadata(-1, E);
  806. }
  807. bus_options = memnew(MenuButton);
  808. bus_options->set_shortcut_context(this);
  809. bus_options->set_h_size_flags(SIZE_SHRINK_END);
  810. bus_options->set_anchor(SIDE_RIGHT, 0.0);
  811. bus_options->set_tooltip_text(TTR("Bus Options"));
  812. hbc->add_child(bus_options);
  813. bus_popup = bus_options->get_popup();
  814. bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/duplicate_selected_bus", TTR("Duplicate Bus"), KeyModifierMask::CMD_OR_CTRL | Key::D));
  815. bus_popup->add_shortcut(ED_SHORTCUT("audio_bus_editor/delete_selected_bus", TTR("Delete Bus"), Key::KEY_DELETE));
  816. bus_popup->set_item_disabled(1, is_master);
  817. bus_popup->add_item(TTR("Reset Volume"));
  818. bus_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_bus_popup_pressed));
  819. delete_effect_popup = memnew(PopupMenu);
  820. delete_effect_popup->add_item(TTR("Delete Effect"));
  821. add_child(delete_effect_popup);
  822. delete_effect_popup->connect("index_pressed", callable_mp(this, &EditorAudioBus::_delete_effect_pressed));
  823. }
  824. void EditorAudioBusDrop::_notification(int p_what) {
  825. switch (p_what) {
  826. case NOTIFICATION_DRAW: {
  827. draw_style_box(get_theme_stylebox(CoreStringName(normal), SNAME("Button")), Rect2(Vector2(), get_size()));
  828. if (hovering_drop) {
  829. Color accent = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
  830. accent.a *= 0.7;
  831. draw_rect(Rect2(Point2(), get_size()), accent, false);
  832. }
  833. } break;
  834. case NOTIFICATION_MOUSE_ENTER: {
  835. if (!hovering_drop) {
  836. hovering_drop = true;
  837. queue_redraw();
  838. }
  839. } break;
  840. case NOTIFICATION_MOUSE_EXIT:
  841. case NOTIFICATION_DRAG_END: {
  842. if (hovering_drop) {
  843. hovering_drop = false;
  844. queue_redraw();
  845. }
  846. } break;
  847. }
  848. }
  849. bool EditorAudioBusDrop::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
  850. Dictionary d = p_data;
  851. return (d.has("type") && String(d["type"]) == "move_audio_bus");
  852. }
  853. void EditorAudioBusDrop::drop_data(const Point2 &p_point, const Variant &p_data) {
  854. Dictionary d = p_data;
  855. emit_signal(SNAME("dropped"), d["index"], AudioServer::get_singleton()->get_bus_count());
  856. }
  857. void EditorAudioBusDrop::_bind_methods() {
  858. ADD_SIGNAL(MethodInfo("dropped"));
  859. }
  860. EditorAudioBusDrop::EditorAudioBusDrop() {
  861. }
  862. void EditorAudioBuses::_rebuild_buses() {
  863. for (int i = bus_hb->get_child_count() - 1; i >= 0; i--) {
  864. EditorAudioBus *audio_bus = Object::cast_to<EditorAudioBus>(bus_hb->get_child(i));
  865. if (audio_bus) {
  866. bus_hb->remove_child(audio_bus);
  867. audio_bus->queue_free();
  868. }
  869. }
  870. if (drop_end) {
  871. bus_hb->remove_child(drop_end);
  872. drop_end->queue_free();
  873. drop_end = nullptr;
  874. }
  875. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  876. bool is_master = (i == 0);
  877. EditorAudioBus *audio_bus = memnew(EditorAudioBus(this, is_master));
  878. bus_hb->add_child(audio_bus);
  879. audio_bus->connect("delete_request", callable_mp(this, &EditorAudioBuses::_delete_bus).bind(audio_bus), CONNECT_DEFERRED);
  880. audio_bus->connect("duplicate_request", callable_mp(this, &EditorAudioBuses::_duplicate_bus), CONNECT_DEFERRED);
  881. audio_bus->connect("vol_reset_request", callable_mp(this, &EditorAudioBuses::_reset_bus_volume).bind(audio_bus), CONNECT_DEFERRED);
  882. audio_bus->connect("drop_end_request", callable_mp(this, &EditorAudioBuses::_request_drop_end));
  883. audio_bus->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED);
  884. }
  885. }
  886. EditorAudioBuses *EditorAudioBuses::register_editor() {
  887. EditorAudioBuses *audio_buses = memnew(EditorAudioBuses);
  888. EditorNode::get_bottom_panel()->add_item(TTR("Audio"), audio_buses, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_audio_bottom_panel", TTR("Toggle Audio Bottom Panel"), KeyModifierMask::ALT | Key::A));
  889. return audio_buses;
  890. }
  891. void EditorAudioBuses::_notification(int p_what) {
  892. switch (p_what) {
  893. case NOTIFICATION_ENTER_TREE:
  894. case NOTIFICATION_THEME_CHANGED: {
  895. bus_scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
  896. } break;
  897. case NOTIFICATION_READY: {
  898. _rebuild_buses();
  899. } break;
  900. case NOTIFICATION_DRAG_END: {
  901. if (drop_end) {
  902. bus_hb->remove_child(drop_end);
  903. drop_end->queue_free();
  904. drop_end = nullptr;
  905. }
  906. } break;
  907. case NOTIFICATION_PROCESS: {
  908. // Check if anything was edited.
  909. bool edited = AudioServer::get_singleton()->is_edited();
  910. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  911. for (int j = 0; j < AudioServer::get_singleton()->get_bus_effect_count(i); j++) {
  912. Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i, j);
  913. if (effect->is_edited()) {
  914. edited = true;
  915. effect->set_edited(false);
  916. }
  917. }
  918. }
  919. AudioServer::get_singleton()->set_edited(false);
  920. if (edited) {
  921. save_timer->start();
  922. }
  923. } break;
  924. }
  925. }
  926. void EditorAudioBuses::_add_bus() {
  927. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  928. ur->create_action(TTR("Add Audio Bus"));
  929. ur->add_do_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count() + 1);
  930. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_count", AudioServer::get_singleton()->get_bus_count());
  931. ur->commit_action();
  932. }
  933. void EditorAudioBuses::_update_bus(int p_index) {
  934. if (p_index >= bus_hb->get_child_count()) {
  935. return;
  936. }
  937. bus_hb->get_child(p_index)->call("update_bus");
  938. }
  939. void EditorAudioBuses::_update_sends() {
  940. for (int i = 0; i < bus_hb->get_child_count(); i++) {
  941. bus_hb->get_child(i)->call("update_send");
  942. }
  943. }
  944. void EditorAudioBuses::_delete_bus(Object *p_which) {
  945. EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
  946. int index = bus->get_index();
  947. if (index == 0) {
  948. EditorNode::get_singleton()->show_warning(TTR("Master bus can't be deleted!"));
  949. return;
  950. }
  951. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  952. ur->create_action(TTR("Delete Audio Bus"));
  953. ur->add_do_method(AudioServer::get_singleton(), "remove_bus", index);
  954. ur->add_undo_method(AudioServer::get_singleton(), "add_bus", index);
  955. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_name", index, AudioServer::get_singleton()->get_bus_name(index));
  956. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index));
  957. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_send", index, AudioServer::get_singleton()->get_bus_send(index));
  958. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_solo", index, AudioServer::get_singleton()->is_bus_solo(index));
  959. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_mute", index, AudioServer::get_singleton()->is_bus_mute(index));
  960. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_bypass_effects", index, AudioServer::get_singleton()->is_bus_bypassing_effects(index));
  961. for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(index); i++) {
  962. ur->add_undo_method(AudioServer::get_singleton(), "add_bus_effect", index, AudioServer::get_singleton()->get_bus_effect(index, i));
  963. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_effect_enabled", index, i, AudioServer::get_singleton()->is_bus_effect_enabled(index, i));
  964. }
  965. ur->commit_action();
  966. }
  967. void EditorAudioBuses::_duplicate_bus(int p_which) {
  968. int add_at_pos = p_which + 1;
  969. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  970. ur->create_action(TTR("Duplicate Audio Bus"));
  971. ur->add_do_method(AudioServer::get_singleton(), "add_bus", add_at_pos);
  972. ur->add_do_method(AudioServer::get_singleton(), "set_bus_name", add_at_pos, AudioServer::get_singleton()->get_bus_name(p_which) + " Copy");
  973. ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", add_at_pos, AudioServer::get_singleton()->get_bus_volume_db(p_which));
  974. ur->add_do_method(AudioServer::get_singleton(), "set_bus_send", add_at_pos, AudioServer::get_singleton()->get_bus_send(p_which));
  975. ur->add_do_method(AudioServer::get_singleton(), "set_bus_solo", add_at_pos, AudioServer::get_singleton()->is_bus_solo(p_which));
  976. ur->add_do_method(AudioServer::get_singleton(), "set_bus_mute", add_at_pos, AudioServer::get_singleton()->is_bus_mute(p_which));
  977. ur->add_do_method(AudioServer::get_singleton(), "set_bus_bypass_effects", add_at_pos, AudioServer::get_singleton()->is_bus_bypassing_effects(p_which));
  978. for (int i = 0; i < AudioServer::get_singleton()->get_bus_effect_count(p_which); i++) {
  979. ur->add_do_method(AudioServer::get_singleton(), "add_bus_effect", add_at_pos, AudioServer::get_singleton()->get_bus_effect(p_which, i));
  980. 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));
  981. }
  982. ur->add_do_method(this, "_update_bus", add_at_pos);
  983. ur->add_undo_method(AudioServer::get_singleton(), "remove_bus", add_at_pos);
  984. ur->commit_action();
  985. }
  986. void EditorAudioBuses::_reset_bus_volume(Object *p_which) {
  987. EditorAudioBus *bus = Object::cast_to<EditorAudioBus>(p_which);
  988. int index = bus->get_index();
  989. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  990. ur->create_action(TTR("Reset Bus Volume"));
  991. ur->add_do_method(AudioServer::get_singleton(), "set_bus_volume_db", index, 0.f);
  992. ur->add_undo_method(AudioServer::get_singleton(), "set_bus_volume_db", index, AudioServer::get_singleton()->get_bus_volume_db(index));
  993. ur->add_do_method(this, "_update_bus", index);
  994. ur->add_undo_method(this, "_update_bus", index);
  995. ur->commit_action();
  996. }
  997. void EditorAudioBuses::_request_drop_end() {
  998. if (!drop_end && bus_hb->get_child_count()) {
  999. drop_end = memnew(EditorAudioBusDrop);
  1000. bus_hb->add_child(drop_end);
  1001. drop_end->set_custom_minimum_size(Object::cast_to<Control>(bus_hb->get_child(0))->get_size());
  1002. drop_end->connect("dropped", callable_mp(this, &EditorAudioBuses::_drop_at_index), CONNECT_DEFERRED);
  1003. }
  1004. }
  1005. void EditorAudioBuses::_drop_at_index(int p_bus, int p_index) {
  1006. EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
  1007. ur->create_action(TTR("Move Audio Bus"));
  1008. ur->add_do_method(AudioServer::get_singleton(), "move_bus", p_bus, p_index);
  1009. int real_bus = p_index > p_bus ? p_bus : p_bus + 1;
  1010. int real_index = p_index > p_bus ? p_index - 1 : p_index;
  1011. ur->add_undo_method(AudioServer::get_singleton(), "move_bus", real_index, real_bus);
  1012. ur->commit_action();
  1013. }
  1014. void EditorAudioBuses::_server_save() {
  1015. Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout();
  1016. ResourceSaver::save(state, edited_path);
  1017. }
  1018. void EditorAudioBuses::_select_layout() {
  1019. FileSystemDock::get_singleton()->navigate_to_path(edited_path);
  1020. }
  1021. void EditorAudioBuses::_save_as_layout() {
  1022. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  1023. file_dialog->set_title(TTR("Save Audio Bus Layout As..."));
  1024. file_dialog->set_current_path(edited_path);
  1025. file_dialog->popup_file_dialog();
  1026. new_layout = false;
  1027. }
  1028. void EditorAudioBuses::_new_layout() {
  1029. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  1030. file_dialog->set_title(TTR("Location for New Layout..."));
  1031. file_dialog->set_current_path(edited_path);
  1032. file_dialog->popup_file_dialog();
  1033. new_layout = true;
  1034. }
  1035. void EditorAudioBuses::_load_layout() {
  1036. file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1037. file_dialog->set_title(TTR("Open Audio Bus Layout"));
  1038. file_dialog->set_current_path(edited_path);
  1039. file_dialog->popup_file_dialog();
  1040. new_layout = false;
  1041. }
  1042. void EditorAudioBuses::_load_default_layout() {
  1043. String layout_path = GLOBAL_GET("audio/buses/default_bus_layout");
  1044. Ref<AudioBusLayout> state;
  1045. if (ResourceLoader::exists(layout_path)) {
  1046. state = ResourceLoader::load(layout_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
  1047. }
  1048. if (state.is_null()) {
  1049. EditorNode::get_singleton()->show_warning(vformat(TTR("There is no '%s' file."), layout_path));
  1050. return;
  1051. }
  1052. edited_path = layout_path;
  1053. file->set_text(String(TTR("Layout:")) + " " + layout_path.get_file());
  1054. AudioServer::get_singleton()->set_bus_layout(state);
  1055. _rebuild_buses();
  1056. EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY);
  1057. callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred();
  1058. }
  1059. void EditorAudioBuses::_file_dialog_callback(const String &p_string) {
  1060. if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_OPEN_FILE) {
  1061. Ref<AudioBusLayout> state = ResourceLoader::load(p_string, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
  1062. if (state.is_null()) {
  1063. EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout."));
  1064. return;
  1065. }
  1066. edited_path = p_string;
  1067. file->set_text(String(TTR("Layout:")) + " " + p_string.get_file());
  1068. AudioServer::get_singleton()->set_bus_layout(state);
  1069. _rebuild_buses();
  1070. EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY);
  1071. callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred();
  1072. } else if (file_dialog->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
  1073. if (new_layout) {
  1074. Ref<AudioBusLayout> empty_state;
  1075. empty_state.instantiate();
  1076. AudioServer::get_singleton()->set_bus_layout(empty_state);
  1077. }
  1078. Error err = ResourceSaver::save(AudioServer::get_singleton()->generate_bus_layout(), p_string);
  1079. if (err != OK) {
  1080. EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file: %s"), p_string));
  1081. return;
  1082. }
  1083. edited_path = p_string;
  1084. file->set_text(String(TTR("Layout:")) + " " + p_string.get_file());
  1085. _rebuild_buses();
  1086. EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY);
  1087. callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred();
  1088. }
  1089. }
  1090. void EditorAudioBuses::_bind_methods() {
  1091. ClassDB::bind_method("_update_bus", &EditorAudioBuses::_update_bus);
  1092. ClassDB::bind_method("_update_sends", &EditorAudioBuses::_update_sends);
  1093. }
  1094. EditorAudioBuses::EditorAudioBuses() {
  1095. top_hb = memnew(HBoxContainer);
  1096. add_child(top_hb);
  1097. file = memnew(Label);
  1098. String layout_path = GLOBAL_GET("audio/buses/default_bus_layout");
  1099. file->set_text(String(TTR("Layout:")) + " " + layout_path.get_file());
  1100. file->set_clip_text(true);
  1101. file->set_h_size_flags(SIZE_EXPAND_FILL);
  1102. top_hb->add_child(file);
  1103. add = memnew(Button);
  1104. top_hb->add_child(add);
  1105. add->set_text(TTR("Add Bus"));
  1106. add->set_tooltip_text(TTR("Add a new Audio Bus to this layout."));
  1107. add->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_add_bus));
  1108. VSeparator *separator = memnew(VSeparator);
  1109. top_hb->add_child(separator);
  1110. load = memnew(Button);
  1111. load->set_text(TTR("Load"));
  1112. load->set_tooltip_text(TTR("Load an existing Bus Layout."));
  1113. top_hb->add_child(load);
  1114. load->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_load_layout));
  1115. save_as = memnew(Button);
  1116. save_as->set_text(TTR("Save As"));
  1117. save_as->set_tooltip_text(TTR("Save this Bus Layout to a file."));
  1118. top_hb->add_child(save_as);
  1119. save_as->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_save_as_layout));
  1120. _default = memnew(Button);
  1121. _default->set_text(TTR("Load Default"));
  1122. _default->set_tooltip_text(TTR("Load the default Bus Layout."));
  1123. top_hb->add_child(_default);
  1124. _default->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_load_default_layout));
  1125. _new = memnew(Button);
  1126. _new->set_text(TTR("Create"));
  1127. _new->set_tooltip_text(TTR("Create a new Bus Layout."));
  1128. top_hb->add_child(_new);
  1129. _new->connect(SceneStringName(pressed), callable_mp(this, &EditorAudioBuses::_new_layout));
  1130. bus_scroll = memnew(ScrollContainer);
  1131. bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL);
  1132. bus_scroll->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  1133. add_child(bus_scroll);
  1134. bus_hb = memnew(HBoxContainer);
  1135. bus_hb->set_v_size_flags(SIZE_EXPAND_FILL);
  1136. bus_scroll->add_child(bus_hb);
  1137. save_timer = memnew(Timer);
  1138. save_timer->set_wait_time(0.8);
  1139. save_timer->set_one_shot(true);
  1140. add_child(save_timer);
  1141. save_timer->connect("timeout", callable_mp(this, &EditorAudioBuses::_server_save));
  1142. set_v_size_flags(SIZE_EXPAND_FILL);
  1143. edited_path = GLOBAL_GET("audio/buses/default_bus_layout");
  1144. file_dialog = memnew(EditorFileDialog);
  1145. List<String> ext;
  1146. ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext);
  1147. for (const String &E : ext) {
  1148. file_dialog->add_filter("*." + E, TTR("Audio Bus Layout"));
  1149. }
  1150. add_child(file_dialog);
  1151. file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback));
  1152. AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &EditorAudioBuses::_rebuild_buses));
  1153. set_process(true);
  1154. }
  1155. void EditorAudioBuses::open_layout(const String &p_path) {
  1156. EditorNode::get_bottom_panel()->make_item_visible(this);
  1157. Ref<AudioBusLayout> state = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
  1158. if (state.is_null()) {
  1159. EditorNode::get_singleton()->show_warning(TTR("Invalid file, not an audio bus layout."));
  1160. return;
  1161. }
  1162. edited_path = p_path;
  1163. file->set_text(p_path.get_file());
  1164. AudioServer::get_singleton()->set_bus_layout(state);
  1165. _rebuild_buses();
  1166. EditorUndoRedoManager::get_singleton()->clear_history(true, EditorUndoRedoManager::GLOBAL_HISTORY);
  1167. callable_mp(this, &EditorAudioBuses::_select_layout).call_deferred();
  1168. }
  1169. void AudioBusesEditorPlugin::edit(Object *p_node) {
  1170. if (Object::cast_to<AudioBusLayout>(p_node)) {
  1171. String path = Object::cast_to<AudioBusLayout>(p_node)->get_path();
  1172. if (path.is_resource_file()) {
  1173. audio_bus_editor->open_layout(path);
  1174. }
  1175. }
  1176. }
  1177. bool AudioBusesEditorPlugin::handles(Object *p_node) const {
  1178. return (Object::cast_to<AudioBusLayout>(p_node) != nullptr);
  1179. }
  1180. void AudioBusesEditorPlugin::make_visible(bool p_visible) {
  1181. }
  1182. AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) {
  1183. audio_bus_editor = p_node;
  1184. }
  1185. AudioBusesEditorPlugin::~AudioBusesEditorPlugin() {
  1186. }
  1187. void EditorAudioMeterNotches::add_notch(float p_normalized_offset, float p_db_value, bool p_render_value) {
  1188. notches.push_back(AudioNotch(p_normalized_offset, p_db_value, p_render_value));
  1189. }
  1190. Size2 EditorAudioMeterNotches::get_minimum_size() const {
  1191. Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
  1192. int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
  1193. float font_height = font->get_height(font_size);
  1194. float width = 0;
  1195. float height = top_padding + btm_padding;
  1196. for (const EditorAudioMeterNotches::AudioNotch &notch : notches) {
  1197. if (notch.render_db_value) {
  1198. width = MAX(width, font->get_string_size(String::num(Math::abs(notch.db_value)) + "dB", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x);
  1199. height += font_height;
  1200. }
  1201. }
  1202. width += line_length + label_space;
  1203. return Size2(width, height);
  1204. }
  1205. void EditorAudioMeterNotches::_update_theme_item_cache() {
  1206. Control::_update_theme_item_cache();
  1207. theme_cache.notch_color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor));
  1208. theme_cache.font = get_theme_font(SceneStringName(font), SNAME("Label"));
  1209. theme_cache.font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
  1210. }
  1211. void EditorAudioMeterNotches::_bind_methods() {
  1212. ClassDB::bind_method("add_notch", &EditorAudioMeterNotches::add_notch);
  1213. ClassDB::bind_method("_draw_audio_notches", &EditorAudioMeterNotches::_draw_audio_notches);
  1214. }
  1215. void EditorAudioMeterNotches::_notification(int p_what) {
  1216. switch (p_what) {
  1217. case NOTIFICATION_DRAW: {
  1218. _draw_audio_notches();
  1219. } break;
  1220. }
  1221. }
  1222. void EditorAudioMeterNotches::_draw_audio_notches() {
  1223. float font_height = theme_cache.font->get_height(theme_cache.font_size);
  1224. for (const AudioNotch &n : notches) {
  1225. draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
  1226. Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
  1227. theme_cache.notch_color,
  1228. Math::round(EDSCALE));
  1229. if (n.render_db_value) {
  1230. draw_string(theme_cache.font,
  1231. Vector2((line_length + label_space) * EDSCALE,
  1232. (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding),
  1233. String::num(Math::abs(n.db_value)) + "dB",
  1234. HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size,
  1235. theme_cache.notch_color);
  1236. }
  1237. }
  1238. }