editor_audio_buses.h 8.4 KB

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