editor_audio_buses.h 8.1 KB

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