Debian Codegraph @

editor/audio/editor_audio_buses.h

raw symbols SCIP
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 #pragma once
32
33 #include "editor/docks/editor_dock.h"
34 #include "editor/plugins/editor_plugin.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_bar.h"
45 #include "scene/gui/tree.h"
46
47 class EditorAudioBuses;
48 class EditorFileDialog;
49 class HBoxContainer;
50 class Timer;
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 *bus_popup = nullptr;
77 PopupMenu *delete_effect_popup = 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 _bus_popup_pressed(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
151 class EditorAudioBuses : public EditorDock {
152 GDCLASS(EditorAudioBuses, EditorDock);
153
154 HBoxContainer *top_hb = nullptr;
155
156 MarginContainer *bus_mc = nullptr;
157 ScrollContainer *bus_scroll = nullptr;
158 HBoxContainer *bus_hb = nullptr;
159
160 EditorAudioBusDrop *drop_end = nullptr;
161
162 Label *file = nullptr;
163
164 Button *add = nullptr;
165 Button *load = nullptr;
166 Button *save_as = nullptr;
167 Button *_default = nullptr;
168 Button *_new = nullptr;
169
170 Timer *save_timer = nullptr;
171 String edited_path;
172
173 bool floating = false;
174
175 void _update_file_label();
176 void _update_file_label_size();
177
178 void _rebuild_buses();
179 void _update_bus(int p_index);
180 void _update_sends();
181
182 void _add_bus();
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 void _file_moved(const String &p_old_path, const String &p_new_path);
192
193 void _select_layout();
194 void _load_layout();
195 void _save_as_layout();
196 void _load_default_layout();
197 void _new_layout();
198
199 EditorFileDialog *file_dialog = nullptr;
200 bool new_layout = false;
201
202 void _file_dialog_callback(const String &p_string);
203
204 protected:
205 static void _bind_methods();
206 void _notification(int p_what);
207
208 virtual void update_layout(EditorDock::DockLayout p_layout) override;
209
210 public:
211 void open_layout(const String &p_path);
212
213 static EditorAudioBuses *register_editor();
214
215 EditorAudioBuses();
216 };
217
218 class EditorAudioMeterNotches : public Control {
219 GDCLASS(EditorAudioMeterNotches, Control);
220
221 private:
222 struct AudioNotch {
223 float relative_position = 0;
224 float db_value = 0;
225 bool render_db_value = false;
226
227 _FORCE_INLINE_ AudioNotch(float r_pos, float db_v, bool rndr_val) {
228 relative_position = r_pos;
229 db_value = db_v;
230 render_db_value = rndr_val;
231 }
232
233 _FORCE_INLINE_ AudioNotch(const AudioNotch &n) {
234 relative_position = n.relative_position;
235 db_value = n.db_value;
236 render_db_value = n.render_db_value;
237 }
238
239 _FORCE_INLINE_ void operator=(const EditorAudioMeterNotches::AudioNotch &n) {
240 relative_position = n.relative_position;
241 db_value = n.db_value;
242 render_db_value = n.render_db_value;
243 }
244
245 _FORCE_INLINE_ AudioNotch() {}
246 };
247
248 List<AudioNotch> notches;
249
250 struct ThemeCache {
251 Color notch_color;
252
253 Ref<Font> font;
254 int font_size = 0;
255 } theme_cache;
256
257 public:
258 const float line_length = 5.0f;
259 const float label_space = 2.0f;
260 const float btm_padding = 9.0f;
261 const float top_padding = 5.0f;
262
263 void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
264 Size2 get_minimum_size() const override;
265
266 private:
267 virtual void _update_theme_item_cache() override;
268
269 static void _bind_methods();
270 void _notification(int p_what);
271 void _draw_audio_notches();
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_plugin_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 };