editor_audio_buses.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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/plugins/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. void _rebuild_buses();
  139. void _update_bus(int p_index);
  140. void _update_sends();
  141. void _add_bus();
  142. void _delete_bus(Object *p_which);
  143. void _duplicate_bus(int p_which);
  144. void _reset_bus_volume(Object *p_which);
  145. void _request_drop_end();
  146. void _drop_at_index(int p_bus, int p_index);
  147. void _server_save();
  148. void _select_layout();
  149. void _load_layout();
  150. void _save_as_layout();
  151. void _load_default_layout();
  152. void _new_layout();
  153. EditorFileDialog *file_dialog = nullptr;
  154. bool new_layout = false;
  155. void _file_dialog_callback(const String &p_string);
  156. protected:
  157. static void _bind_methods();
  158. void _notification(int p_what);
  159. public:
  160. void open_layout(const String &p_path);
  161. static EditorAudioBuses *register_editor();
  162. EditorAudioBuses();
  163. };
  164. class EditorAudioMeterNotches : public Control {
  165. GDCLASS(EditorAudioMeterNotches, Control);
  166. private:
  167. struct AudioNotch {
  168. float relative_position = 0;
  169. float db_value = 0;
  170. bool render_db_value = false;
  171. _FORCE_INLINE_ AudioNotch(float r_pos, float db_v, bool rndr_val) {
  172. relative_position = r_pos;
  173. db_value = db_v;
  174. render_db_value = rndr_val;
  175. }
  176. _FORCE_INLINE_ AudioNotch(const AudioNotch &n) {
  177. relative_position = n.relative_position;
  178. db_value = n.db_value;
  179. render_db_value = n.render_db_value;
  180. }
  181. _FORCE_INLINE_ void operator=(const EditorAudioMeterNotches::AudioNotch &n) {
  182. relative_position = n.relative_position;
  183. db_value = n.db_value;
  184. render_db_value = n.render_db_value;
  185. }
  186. _FORCE_INLINE_ AudioNotch() {}
  187. };
  188. List<AudioNotch> notches;
  189. struct ThemeCache {
  190. Color notch_color;
  191. Ref<Font> font;
  192. int font_size = 0;
  193. } theme_cache;
  194. public:
  195. const float line_length = 5.0f;
  196. const float label_space = 2.0f;
  197. const float btm_padding = 9.0f;
  198. const float top_padding = 5.0f;
  199. void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
  200. Size2 get_minimum_size() const override;
  201. private:
  202. virtual void _update_theme_item_cache() override;
  203. static void _bind_methods();
  204. void _notification(int p_what);
  205. void _draw_audio_notches();
  206. public:
  207. EditorAudioMeterNotches() {}
  208. };
  209. class AudioBusesEditorPlugin : public EditorPlugin {
  210. GDCLASS(AudioBusesEditorPlugin, EditorPlugin);
  211. EditorAudioBuses *audio_bus_editor = nullptr;
  212. public:
  213. virtual String get_name() const override { return "SampleLibrary"; }
  214. bool has_main_screen() const override { return false; }
  215. virtual void edit(Object *p_node) override;
  216. virtual bool handles(Object *p_node) const override;
  217. virtual void make_visible(bool p_visible) override;
  218. AudioBusesEditorPlugin(EditorAudioBuses *p_node);
  219. ~AudioBusesEditorPlugin();
  220. };
  221. #endif // EDITOR_AUDIO_BUSES_H