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