editor_audio_buses.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 EDITORAUDIOBUSES_H
  31. #define EDITORAUDIOBUSES_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/tree.h"
  47. class EditorAudioBuses;
  48. class EditorAudioBus : public PanelContainer {
  49. GDCLASS(EditorAudioBus, PanelContainer);
  50. Ref<Texture2D> disabled_vu;
  51. LineEdit *track_name;
  52. MenuButton *bus_options;
  53. VSlider *slider;
  54. int cc;
  55. static const int CHANNELS_MAX = 4;
  56. struct {
  57. bool prev_active;
  58. float peak_l;
  59. float peak_r;
  60. TextureProgress *vu_l;
  61. TextureProgress *vu_r;
  62. } channel[CHANNELS_MAX];
  63. OptionButton *send;
  64. PopupMenu *effect_options;
  65. PopupMenu *bus_popup;
  66. PopupMenu *delete_effect_popup;
  67. Panel *audio_value_preview_box;
  68. Label *audio_value_preview_label;
  69. Timer *preview_timer;
  70. Button *solo;
  71. Button *mute;
  72. Button *bypass;
  73. Tree *effects;
  74. bool updating_bus;
  75. bool is_master;
  76. mutable bool hovering_drop;
  77. void _gui_input(const Ref<InputEvent> &p_event);
  78. void _unhandled_key_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);
  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;
  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;
  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;
  127. ScrollContainer *bus_scroll;
  128. HBoxContainer *bus_hb;
  129. EditorAudioBusDrop *drop_end;
  130. Label *file;
  131. Button *add;
  132. Button *load;
  133. Button *save_as;
  134. Button *_default;
  135. Button *_new;
  136. Timer *save_timer;
  137. String edited_path;
  138. void _add_bus();
  139. void _update_buses();
  140. void _update_bus(int p_index);
  141. void _update_sends();
  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;
  154. bool new_layout;
  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;
  169. float db_value;
  170. bool render_db_value;
  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_ AudioNotch 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. return *this;
  186. }
  187. _FORCE_INLINE_ AudioNotch() {}
  188. };
  189. List<AudioNotch> notches;
  190. public:
  191. float line_length = 5.0f;
  192. float label_space = 2.0f;
  193. float btm_padding = 9.0f;
  194. float top_padding = 5.0f;
  195. Color notch_color;
  196. void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
  197. Size2 get_minimum_size() const override;
  198. private:
  199. static void _bind_methods();
  200. void _notification(int p_what);
  201. void _draw_audio_notches();
  202. public:
  203. EditorAudioMeterNotches();
  204. };
  205. class AudioBusesEditorPlugin : public EditorPlugin {
  206. GDCLASS(AudioBusesEditorPlugin, EditorPlugin);
  207. EditorAudioBuses *audio_bus_editor;
  208. public:
  209. virtual String get_name() const override { return "SampleLibrary"; }
  210. bool has_main_screen() const override { return false; }
  211. virtual void edit(Object *p_node) override;
  212. virtual bool handles(Object *p_node) const override;
  213. virtual void make_visible(bool p_visible) override;
  214. AudioBusesEditorPlugin(EditorAudioBuses *p_node);
  215. ~AudioBusesEditorPlugin();
  216. };
  217. #endif // EDITORAUDIOBUSES_H