editor_audio_buses.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**************************************************************************/
  2. /* editor_audio_buses.h */
  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. #ifndef EDITOR_AUDIO_BUSES_H
  31. #define EDITOR_AUDIO_BUSES_H
  32. #include "editor/editor_plugin.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/button.h"
  35. #include "scene/gui/control.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/option_button.h"
  39. #include "scene/gui/panel.h"
  40. #include "scene/gui/panel_container.h"
  41. #include "scene/gui/scroll_container.h"
  42. #include "scene/gui/slider.h"
  43. #include "scene/gui/texture_progress_bar.h"
  44. #include "scene/gui/texture_rect.h"
  45. #include "scene/gui/tree.h"
  46. class EditorAudioBuses;
  47. class EditorFileDialog;
  48. class EditorAudioBus : public PanelContainer {
  49. GDCLASS(EditorAudioBus, PanelContainer);
  50. Ref<Texture2D> disabled_vu;
  51. LineEdit *track_name = nullptr;
  52. MenuButton *bus_options = nullptr;
  53. VSlider *slider = nullptr;
  54. int cc;
  55. static const int CHANNELS_MAX = 4;
  56. struct {
  57. bool prev_active = false;
  58. float peak_l = 0;
  59. float peak_r = 0;
  60. TextureProgressBar *vu_l = nullptr;
  61. TextureProgressBar *vu_r = nullptr;
  62. } channel[CHANNELS_MAX];
  63. OptionButton *send = nullptr;
  64. PopupMenu *effect_options = nullptr;
  65. PopupMenu *bus_popup = nullptr;
  66. PopupMenu *delete_effect_popup = nullptr;
  67. Panel *audio_value_preview_box = nullptr;
  68. Label *audio_value_preview_label = nullptr;
  69. Timer *preview_timer = nullptr;
  70. Button *solo = nullptr;
  71. Button *mute = nullptr;
  72. Button *bypass = nullptr;
  73. Tree *effects = nullptr;
  74. bool updating_bus = false;
  75. bool is_master;
  76. mutable bool hovering_drop = false;
  77. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  78. void _effects_gui_input(Ref<InputEvent> p_event);
  79. void _bus_popup_pressed(int p_option);
  80. void _name_changed(const String &p_new_name);
  81. void _name_focus_exit() { _name_changed(track_name->get_text()); }
  82. void _volume_changed(float p_normalized);
  83. float _normalized_volume_to_scaled_db(float normalized);
  84. float _scaled_db_to_normalized_volume(float db);
  85. void _show_value(float slider_value);
  86. void _hide_value_preview();
  87. void _solo_toggled();
  88. void _mute_toggled();
  89. void _bypass_toggled();
  90. void _send_selected(int p_which);
  91. void _effect_edited();
  92. void _effect_add(int p_which);
  93. void _effect_selected();
  94. void _delete_effect_pressed(int p_option);
  95. void _effect_rmb(const Vector2 &p_pos, MouseButton p_button);
  96. void _update_visible_channels();
  97. virtual Variant get_drag_data(const Point2 &p_point) override;
  98. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
  99. virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
  100. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  101. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  102. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  103. friend class EditorAudioBuses;
  104. EditorAudioBuses *buses = nullptr;
  105. protected:
  106. static void _bind_methods();
  107. void _notification(int p_what);
  108. public:
  109. void update_bus();
  110. void update_send();
  111. EditorAudioBus(EditorAudioBuses *p_buses = nullptr, bool p_is_master = false);
  112. };
  113. class EditorAudioBusDrop : public Control {
  114. GDCLASS(EditorAudioBusDrop, Control);
  115. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
  116. virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
  117. mutable bool hovering_drop = false;
  118. protected:
  119. static void _bind_methods();
  120. void _notification(int p_what);
  121. public:
  122. EditorAudioBusDrop();
  123. };
  124. class EditorAudioBuses : public VBoxContainer {
  125. GDCLASS(EditorAudioBuses, VBoxContainer);
  126. HBoxContainer *top_hb = nullptr;
  127. ScrollContainer *bus_scroll = nullptr;
  128. HBoxContainer *bus_hb = nullptr;
  129. EditorAudioBusDrop *drop_end = nullptr;
  130. Label *file = nullptr;
  131. Button *add = nullptr;
  132. Button *load = nullptr;
  133. Button *save_as = nullptr;
  134. Button *_default = nullptr;
  135. Button *_new = nullptr;
  136. Timer *save_timer = nullptr;
  137. String edited_path;
  138. bool renaming_buses = false;
  139. void _set_renaming_buses(bool p_renaming);
  140. void _add_bus();
  141. void _update_buses();
  142. void _update_bus(int p_index);
  143. void _update_sends();
  144. void _delete_bus(Object *p_which);
  145. void _duplicate_bus(int p_which);
  146. void _reset_bus_volume(Object *p_which);
  147. void _request_drop_end();
  148. void _drop_at_index(int p_bus, int p_index);
  149. void _server_save();
  150. void _select_layout();
  151. void _load_layout();
  152. void _save_as_layout();
  153. void _load_default_layout();
  154. void _new_layout();
  155. EditorFileDialog *file_dialog = nullptr;
  156. bool new_layout = false;
  157. void _file_dialog_callback(const String &p_string);
  158. protected:
  159. static void _bind_methods();
  160. void _notification(int p_what);
  161. public:
  162. void open_layout(const String &p_path);
  163. static EditorAudioBuses *register_editor();
  164. EditorAudioBuses();
  165. };
  166. class EditorAudioMeterNotches : public Control {
  167. GDCLASS(EditorAudioMeterNotches, Control);
  168. private:
  169. struct AudioNotch {
  170. float relative_position = 0;
  171. float db_value = 0;
  172. bool render_db_value = false;
  173. _FORCE_INLINE_ AudioNotch(float r_pos, float db_v, bool rndr_val) {
  174. relative_position = r_pos;
  175. db_value = db_v;
  176. render_db_value = rndr_val;
  177. }
  178. _FORCE_INLINE_ AudioNotch(const AudioNotch &n) {
  179. relative_position = n.relative_position;
  180. db_value = n.db_value;
  181. render_db_value = n.render_db_value;
  182. }
  183. _FORCE_INLINE_ void operator=(const EditorAudioMeterNotches::AudioNotch &n) {
  184. relative_position = n.relative_position;
  185. db_value = n.db_value;
  186. render_db_value = n.render_db_value;
  187. }
  188. _FORCE_INLINE_ AudioNotch() {}
  189. };
  190. List<AudioNotch> notches;
  191. struct ThemeCache {
  192. Color notch_color;
  193. Ref<Font> font;
  194. int font_size = 0;
  195. } theme_cache;
  196. public:
  197. const float line_length = 5.0f;
  198. const float label_space = 2.0f;
  199. const float btm_padding = 9.0f;
  200. const float top_padding = 5.0f;
  201. void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
  202. Size2 get_minimum_size() const override;
  203. private:
  204. virtual void _update_theme_item_cache() override;
  205. static void _bind_methods();
  206. void _notification(int p_what);
  207. void _draw_audio_notches();
  208. public:
  209. EditorAudioMeterNotches() {}
  210. };
  211. class AudioBusesEditorPlugin : public EditorPlugin {
  212. GDCLASS(AudioBusesEditorPlugin, EditorPlugin);
  213. EditorAudioBuses *audio_bus_editor = nullptr;
  214. public:
  215. virtual String get_name() const override { return "SampleLibrary"; }
  216. bool has_main_screen() const override { return false; }
  217. virtual void edit(Object *p_node) override;
  218. virtual bool handles(Object *p_node) const override;
  219. virtual void make_visible(bool p_visible) override;
  220. AudioBusesEditorPlugin(EditorAudioBuses *p_node);
  221. ~AudioBusesEditorPlugin();
  222. };
  223. #endif // EDITOR_AUDIO_BUSES_H