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