Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/import/audio_stream_import_settings.cpp
9903 views
1
/**************************************************************************/
2
/* audio_stream_import_settings.cpp */
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
#include "audio_stream_import_settings.h"
32
33
#include "editor/audio/audio_stream_preview.h"
34
#include "editor/editor_string_names.h"
35
#include "editor/file_system/editor_file_system.h"
36
#include "editor/themes/editor_scale.h"
37
#include "scene/gui/check_box.h"
38
39
AudioStreamImportSettingsDialog *AudioStreamImportSettingsDialog::singleton = nullptr;
40
41
void AudioStreamImportSettingsDialog::_notification(int p_what) {
42
switch (p_what) {
43
case NOTIFICATION_READY: {
44
AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AudioStreamImportSettingsDialog::_preview_changed));
45
connect(SceneStringName(confirmed), callable_mp(this, &AudioStreamImportSettingsDialog::_reimport));
46
} break;
47
48
case NOTIFICATION_THEME_CHANGED: {
49
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
50
_stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));
51
52
_preview->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
53
color_rect->set_color(get_theme_color(SNAME("dark_color_1"), EditorStringName(Editor)));
54
55
_current_label->begin_bulk_theme_override();
56
_current_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
57
_current_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
58
_current_label->end_bulk_theme_override();
59
60
_duration_label->begin_bulk_theme_override();
61
_duration_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
62
_duration_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
63
_duration_label->end_bulk_theme_override();
64
65
zoom_in->set_button_icon(get_editor_theme_icon(SNAME("ZoomMore")));
66
zoom_out->set_button_icon(get_editor_theme_icon(SNAME("ZoomLess")));
67
zoom_reset->set_button_icon(get_editor_theme_icon(SNAME("ZoomReset")));
68
69
_indicator->queue_redraw();
70
_preview->queue_redraw();
71
} break;
72
73
case NOTIFICATION_PROCESS: {
74
_current = _player->get_playback_position();
75
_indicator->queue_redraw();
76
} break;
77
78
case NOTIFICATION_VISIBILITY_CHANGED: {
79
if (!is_visible()) {
80
_stop();
81
}
82
} break;
83
}
84
}
85
86
void AudioStreamImportSettingsDialog::_draw_preview() {
87
Rect2 rect = _preview->get_rect();
88
Size2 rect_size = rect.size;
89
int width = rect_size.width;
90
91
Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
92
float preview_offset = zoom_bar->get_value();
93
float preview_len = zoom_bar->get_page();
94
95
Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));
96
int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));
97
Vector<Vector2> points;
98
points.resize(width * 2);
99
Color color_active = get_theme_color(SNAME("contrast_color_2"), EditorStringName(Editor));
100
Color color_inactive = color_active;
101
color_inactive.a *= 0.5;
102
Vector<Color> colors;
103
colors.resize(width);
104
105
float inactive_from = 1e20;
106
float beat_size = 0;
107
int last_beat = 0;
108
if (stream->get_bpm() > 0) {
109
beat_size = 60 / float(stream->get_bpm());
110
int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;
111
rect.position.y += y_ofs;
112
rect.size.y -= y_ofs;
113
114
if (stream->get_beat_count() > 0) {
115
last_beat = stream->get_beat_count();
116
inactive_from = last_beat * beat_size;
117
}
118
}
119
120
for (int i = 0; i < width; i++) {
121
float ofs = preview_offset + i * preview_len / rect_size.width;
122
float ofs_n = preview_offset + (i + 1) * preview_len / rect_size.width;
123
float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5;
124
float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5;
125
126
int idx = i;
127
points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y);
128
points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y);
129
130
colors.write[idx] = ofs > inactive_from ? color_inactive : color_active;
131
}
132
133
if (!points.is_empty()) {
134
RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), points, colors);
135
}
136
137
if (beat_size) {
138
Color beat_color = Color(1, 1, 1, 1);
139
Color final_beat_color = beat_color;
140
Color bar_color = beat_color;
141
beat_color.a *= 0.4;
142
bar_color.a *= 0.6;
143
144
int prev_beat = 0; // Do not draw beat zero
145
Color color_bg = color_active;
146
color_bg.a *= 0.2;
147
_preview->draw_rect(Rect2(0, 0, rect.size.width, rect.position.y), color_bg);
148
int bar_beats = stream->get_bar_beats();
149
150
int last_text_end_x = 0;
151
for (int i = 0; i < width; i++) {
152
float ofs = preview_offset + i * preview_len / rect_size.width;
153
int beat = int(ofs / beat_size);
154
if (beat != prev_beat) {
155
String text = itos(beat);
156
int text_w = beat_font->get_string_size(text).width;
157
if (i - text_w / 2 > last_text_end_x + 2 * EDSCALE) {
158
int x_ofs = i - text_w / 2;
159
_preview->draw_string(beat_font, Point2(x_ofs, 2 * EDSCALE + beat_font->get_ascent(main_size)), text, HORIZONTAL_ALIGNMENT_LEFT, rect.size.width - x_ofs, Font::DEFAULT_FONT_SIZE, color_active);
160
last_text_end_x = i + text_w / 2;
161
}
162
163
if (beat == last_beat) {
164
_preview->draw_rect(Rect2i(i, rect.position.y, 2, rect.size.height), final_beat_color);
165
// Darken subsequent beats
166
beat_color.a *= 0.3;
167
color_active.a *= 0.3;
168
} else {
169
_preview->draw_rect(Rect2i(i, rect.position.y, 1, rect.size.height), (beat % bar_beats) == 0 ? bar_color : beat_color);
170
}
171
prev_beat = beat;
172
}
173
}
174
}
175
}
176
177
void AudioStreamImportSettingsDialog::_preview_changed(ObjectID p_which) {
178
if (stream.is_valid() && stream->get_instance_id() == p_which) {
179
_preview->queue_redraw();
180
}
181
}
182
183
void AudioStreamImportSettingsDialog::_preview_zoom_in() {
184
if (stream.is_null()) {
185
return;
186
}
187
float page_size = zoom_bar->get_page();
188
zoom_bar->set_page(page_size * 0.5);
189
zoom_bar->set_value(zoom_bar->get_value() + page_size * 0.25);
190
zoom_bar->show();
191
192
_preview->queue_redraw();
193
_indicator->queue_redraw();
194
}
195
196
void AudioStreamImportSettingsDialog::_preview_zoom_out() {
197
if (stream.is_null()) {
198
return;
199
}
200
float page_size = zoom_bar->get_page();
201
zoom_bar->set_page(MIN(zoom_bar->get_max(), page_size * 2.0));
202
zoom_bar->set_value(zoom_bar->get_value() - page_size * 0.5);
203
if (zoom_bar->get_value() == 0) {
204
zoom_bar->hide();
205
}
206
207
_preview->queue_redraw();
208
_indicator->queue_redraw();
209
}
210
211
void AudioStreamImportSettingsDialog::_preview_zoom_reset() {
212
if (stream.is_null()) {
213
return;
214
}
215
zoom_bar->set_max(stream->get_length());
216
zoom_bar->set_page(zoom_bar->get_max());
217
zoom_bar->set_value(0);
218
zoom_bar->hide();
219
220
_preview->queue_redraw();
221
_indicator->queue_redraw();
222
}
223
224
void AudioStreamImportSettingsDialog::_preview_zoom_offset_changed(double) {
225
_preview->queue_redraw();
226
_indicator->queue_redraw();
227
}
228
229
void AudioStreamImportSettingsDialog::_audio_changed() {
230
if (!is_visible()) {
231
return;
232
}
233
_preview->queue_redraw();
234
_indicator->queue_redraw();
235
color_rect->queue_redraw();
236
}
237
238
void AudioStreamImportSettingsDialog::_play() {
239
if (_player->is_playing()) {
240
// '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'.
241
_pausing = true;
242
_player->stop();
243
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
244
set_process(false);
245
} else {
246
_player->play(_current);
247
_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));
248
set_process(true);
249
}
250
}
251
252
void AudioStreamImportSettingsDialog::_stop() {
253
_player->stop();
254
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
255
_current = 0;
256
_indicator->queue_redraw();
257
set_process(false);
258
}
259
260
void AudioStreamImportSettingsDialog::_on_finished() {
261
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
262
if (!_pausing) {
263
_current = 0;
264
_indicator->queue_redraw();
265
} else {
266
_pausing = false;
267
}
268
set_process(false);
269
}
270
271
void AudioStreamImportSettingsDialog::_draw_indicator() {
272
if (stream.is_null()) {
273
return;
274
}
275
276
Rect2 rect = _preview->get_rect();
277
278
Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));
279
int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));
280
281
if (stream->get_bpm() > 0) {
282
int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;
283
rect.position.y += y_ofs;
284
rect.size.height -= y_ofs;
285
}
286
287
_current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /");
288
289
float ofs_x = (_current - zoom_bar->get_value()) * rect.size.width / zoom_bar->get_page();
290
if (ofs_x < 0 || ofs_x >= rect.size.width) {
291
return;
292
}
293
294
const Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
295
_indicator->draw_line(Point2(ofs_x, rect.position.y), Point2(ofs_x, rect.position.y + rect.size.height), color, Math::round(2 * EDSCALE));
296
_indicator->draw_texture(
297
get_editor_theme_icon(SNAME("TimelineIndicator")),
298
Point2(ofs_x - get_editor_theme_icon(SNAME("TimelineIndicator"))->get_width() * 0.5, rect.position.y),
299
color);
300
301
if (stream->get_bpm() > 0 && _hovering_beat != -1) {
302
// Draw hovered beat.
303
float preview_offset = zoom_bar->get_value();
304
float preview_len = zoom_bar->get_page();
305
float beat_size = 60 / float(stream->get_bpm());
306
int prev_beat = 0;
307
for (int i = 0; i < rect.size.width; i++) {
308
float ofs = preview_offset + i * preview_len / rect.size.width;
309
int beat = int(ofs / beat_size);
310
if (beat != prev_beat) {
311
String text = itos(beat);
312
int text_w = beat_font->get_string_size(text).width;
313
if (i - text_w / 2 > 2 * EDSCALE && beat == _hovering_beat) {
314
int x_ofs = i - text_w / 2;
315
_indicator->draw_string(beat_font, Point2(x_ofs, 2 * EDSCALE + beat_font->get_ascent(main_size)), text, HORIZONTAL_ALIGNMENT_LEFT, rect.size.width - x_ofs, Font::DEFAULT_FONT_SIZE, color);
316
break;
317
}
318
prev_beat = beat;
319
}
320
}
321
}
322
}
323
324
void AudioStreamImportSettingsDialog::_on_indicator_mouse_exited() {
325
_hovering_beat = -1;
326
_indicator->queue_redraw();
327
}
328
329
void AudioStreamImportSettingsDialog::_on_input_indicator(Ref<InputEvent> p_event) {
330
const Ref<InputEventMouseButton> mb = p_event;
331
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
332
if (stream->get_bpm() > 0) {
333
int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));
334
Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));
335
int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;
336
if ((!_dragging && mb->get_position().y < y_ofs) || _beat_len_dragging) {
337
if (mb->is_pressed()) {
338
_set_beat_len_to(mb->get_position().x);
339
_beat_len_dragging = true;
340
} else {
341
_beat_len_dragging = false;
342
}
343
return;
344
}
345
}
346
347
if (mb->is_pressed()) {
348
_seek_to(mb->get_position().x);
349
}
350
_dragging = mb->is_pressed();
351
}
352
353
const Ref<InputEventMouseMotion> mm = p_event;
354
if (mm.is_valid()) {
355
if (_dragging) {
356
_seek_to(mm->get_position().x);
357
}
358
if (_beat_len_dragging) {
359
_set_beat_len_to(mm->get_position().x);
360
}
361
if (stream->get_bpm() > 0) {
362
int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));
363
Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));
364
int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;
365
if (mm->get_position().y < y_ofs) {
366
int new_hovering_beat = _get_beat_at_pos(mm->get_position().x);
367
if (new_hovering_beat != _hovering_beat) {
368
_hovering_beat = new_hovering_beat;
369
_indicator->queue_redraw();
370
}
371
} else if (_hovering_beat != -1) {
372
_hovering_beat = -1;
373
_indicator->queue_redraw();
374
}
375
}
376
}
377
}
378
379
int AudioStreamImportSettingsDialog::_get_beat_at_pos(real_t p_x) {
380
float ofs_sec = zoom_bar->get_value() + p_x * zoom_bar->get_page() / _preview->get_size().width;
381
ofs_sec = CLAMP(ofs_sec, 0, stream->get_length());
382
float beat_size = 60 / float(stream->get_bpm());
383
int beat = int(ofs_sec / beat_size + 0.5);
384
385
if (beat * beat_size > stream->get_length() + 0.001) { // Stream may end few audio frames before but may still want to use full loop.
386
beat--;
387
}
388
return beat;
389
}
390
391
void AudioStreamImportSettingsDialog::_set_beat_len_to(real_t p_x) {
392
int beat = _get_beat_at_pos(p_x);
393
if (beat < 1) {
394
beat = 1; // Because 0 is disable.
395
}
396
updating_settings = true;
397
beats_enabled->set_pressed(true);
398
beats_edit->set_value(beat);
399
updating_settings = false;
400
_settings_changed();
401
}
402
403
void AudioStreamImportSettingsDialog::_seek_to(real_t p_x) {
404
_current = zoom_bar->get_value() + p_x / _preview->get_rect().size.x * zoom_bar->get_page();
405
_current = CLAMP(_current, 0, stream->get_length());
406
_player->seek(_current);
407
_indicator->queue_redraw();
408
}
409
410
void AudioStreamImportSettingsDialog::edit(const String &p_path, const String &p_importer, const Ref<AudioStream> &p_stream) {
411
if (stream.is_valid()) {
412
stream->disconnect_changed(callable_mp(this, &AudioStreamImportSettingsDialog::_audio_changed));
413
}
414
415
importer = p_importer;
416
path = p_path;
417
418
stream = p_stream;
419
_player->set_stream(stream);
420
_current = 0;
421
String text = String::num(stream->get_length(), 2).pad_decimals(2) + "s";
422
_duration_label->set_text(text);
423
424
if (stream.is_valid()) {
425
stream->connect_changed(callable_mp(this, &AudioStreamImportSettingsDialog::_audio_changed));
426
_preview->queue_redraw();
427
_indicator->queue_redraw();
428
color_rect->queue_redraw();
429
} else {
430
hide();
431
}
432
params.clear();
433
434
if (stream.is_valid()) {
435
Ref<ConfigFile> config_file;
436
config_file.instantiate();
437
Error err = config_file->load(p_path + ".import");
438
updating_settings = true;
439
if (err == OK) {
440
double bpm = config_file->get_value("params", "bpm", 0);
441
int beats = config_file->get_value("params", "beat_count", 0);
442
bpm_edit->set_value(bpm > 0 ? bpm : 120);
443
bpm_enabled->set_pressed(bpm > 0);
444
beats_edit->set_value(beats);
445
beats_enabled->set_pressed(beats > 0);
446
loop->set_pressed(config_file->get_value("params", "loop", false));
447
loop_offset->set_value(config_file->get_value("params", "loop_offset", 0));
448
bar_beats_edit->set_value(config_file->get_value("params", "bar_beats", 4));
449
450
Vector<String> keys = config_file->get_section_keys("params");
451
for (const String &K : keys) {
452
params[K] = config_file->get_value("params", K);
453
}
454
} else {
455
bpm_edit->set_value(false);
456
bpm_enabled->set_pressed(false);
457
beats_edit->set_value(0);
458
beats_enabled->set_pressed(false);
459
bar_beats_edit->set_value(4);
460
loop->set_pressed(false);
461
loop_offset->set_value(0);
462
}
463
464
_preview_zoom_reset();
465
updating_settings = false;
466
_settings_changed();
467
468
set_title(vformat(TTR("Audio Stream Importer: %s"), p_path.get_file()));
469
popup_centered();
470
}
471
}
472
473
void AudioStreamImportSettingsDialog::_settings_changed() {
474
if (updating_settings) {
475
return;
476
}
477
478
updating_settings = true;
479
stream->call("set_loop", loop->is_pressed());
480
stream->call("set_loop_offset", loop_offset->get_value());
481
if (loop->is_pressed()) {
482
loop_offset->set_editable(true);
483
} else {
484
loop_offset->set_editable(false);
485
}
486
487
if (bpm_enabled->is_pressed()) {
488
stream->call("set_bpm", bpm_edit->get_value());
489
beats_enabled->set_disabled(false);
490
beats_edit->set_editable(true);
491
bar_beats_edit->set_editable(true);
492
double bpm = bpm_edit->get_value();
493
if (bpm > 0) {
494
float beat_size = 60 / float(bpm);
495
int beat_max = int((stream->get_length() + 0.001) / beat_size);
496
int current_beat = beats_edit->get_value();
497
beats_edit->set_max(beat_max);
498
if (current_beat > beat_max) {
499
beats_edit->set_value(beat_max);
500
stream->call("set_beat_count", beat_max);
501
}
502
}
503
stream->call("set_bar_beats", bar_beats_edit->get_value());
504
} else {
505
stream->call("set_bpm", 0);
506
stream->call("set_bar_beats", 4);
507
beats_enabled->set_disabled(true);
508
beats_edit->set_editable(false);
509
bar_beats_edit->set_editable(false);
510
}
511
if (bpm_enabled->is_pressed() && beats_enabled->is_pressed()) {
512
stream->call("set_beat_count", beats_edit->get_value());
513
} else {
514
stream->call("set_beat_count", 0);
515
}
516
517
updating_settings = false;
518
519
_preview->queue_redraw();
520
_indicator->queue_redraw();
521
color_rect->queue_redraw();
522
}
523
524
void AudioStreamImportSettingsDialog::_reimport() {
525
params["loop"] = loop->is_pressed();
526
params["loop_offset"] = loop_offset->get_value();
527
params["bpm"] = bpm_enabled->is_pressed() ? double(bpm_edit->get_value()) : double(0);
528
params["beat_count"] = (bpm_enabled->is_pressed() && beats_enabled->is_pressed()) ? int(beats_edit->get_value()) : int(0);
529
params["bar_beats"] = (bpm_enabled->is_pressed()) ? int(bar_beats_edit->get_value()) : int(4);
530
531
EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(path, importer, params);
532
}
533
534
AudioStreamImportSettingsDialog::AudioStreamImportSettingsDialog() {
535
get_ok_button()->set_text(TTR("Reimport"));
536
get_cancel_button()->set_text(TTR("Close"));
537
538
VBoxContainer *main_vbox = memnew(VBoxContainer);
539
add_child(main_vbox);
540
541
HBoxContainer *loop_hb = memnew(HBoxContainer);
542
loop_hb->add_theme_constant_override("separation", 4 * EDSCALE);
543
loop = memnew(CheckBox);
544
loop->set_text(TTR("Enable"));
545
loop->set_tooltip_text(TTR("Enable looping."));
546
loop->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
547
loop_hb->add_child(loop);
548
loop_hb->add_spacer();
549
loop_hb->add_child(memnew(Label(TTR("Offset:"))));
550
loop_offset = memnew(SpinBox);
551
loop_offset->set_accessibility_name(TTRC("Offset:"));
552
loop_offset->set_max(10000);
553
loop_offset->set_step(0.001);
554
loop_offset->set_suffix("s");
555
loop_offset->set_h_size_flags(Control::SIZE_EXPAND_FILL);
556
loop_offset->set_stretch_ratio(0.33);
557
loop_offset->set_tooltip_text(TTR("Loop offset (from beginning). Note that if BPM is set, this setting will be ignored."));
558
loop_offset->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
559
loop_hb->add_child(loop_offset);
560
main_vbox->add_margin_child(TTR("Loop:"), loop_hb);
561
562
HBoxContainer *interactive_hb = memnew(HBoxContainer);
563
interactive_hb->add_theme_constant_override("separation", 4 * EDSCALE);
564
bpm_enabled = memnew(CheckBox);
565
bpm_enabled->set_text((TTR("BPM:")));
566
bpm_enabled->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
567
interactive_hb->add_child(bpm_enabled);
568
bpm_edit = memnew(SpinBox);
569
bpm_edit->set_max(400);
570
bpm_edit->set_step(0.01);
571
bpm_edit->set_accessibility_name(TTRC("BPM:"));
572
bpm_edit->set_tooltip_text(TTR("Configure the Beats Per Measure (tempo) used for the interactive streams.\nThis is required in order to configure beat information."));
573
bpm_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
574
interactive_hb->add_child(bpm_edit);
575
interactive_hb->add_spacer();
576
beats_enabled = memnew(CheckBox);
577
beats_enabled->set_text(TTR("Beat Count:"));
578
beats_enabled->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
579
interactive_hb->add_child(beats_enabled);
580
beats_edit = memnew(SpinBox);
581
beats_edit->set_tooltip_text(TTR("Configure the amount of Beats used for music-aware looping. If zero, it will be autodetected from the length.\nIt is recommended to set this value (either manually or by clicking on a beat number in the preview) to ensure looping works properly."));
582
beats_edit->set_max(99999);
583
beats_edit->set_accessibility_name(TTRC("Beat Count:"));
584
beats_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
585
interactive_hb->add_child(beats_edit);
586
bar_beats_label = memnew(Label(TTR("Bar Beats:")));
587
interactive_hb->add_child(bar_beats_label);
588
bar_beats_edit = memnew(SpinBox);
589
bar_beats_edit->set_tooltip_text(TTR("Configure the Beats Per Bar. This used for music-aware transitions between AudioStreams."));
590
bar_beats_edit->set_min(2);
591
bar_beats_edit->set_max(32);
592
bar_beats_edit->set_accessibility_name(TTRC("Bar Beats:"));
593
bar_beats_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));
594
interactive_hb->add_child(bar_beats_edit);
595
main_vbox->add_margin_child(TTR("Music Playback:"), interactive_hb);
596
597
color_rect = memnew(ColorRect);
598
main_vbox->add_margin_child(TTR("Preview:"), color_rect, true);
599
color_rect->set_custom_minimum_size(Size2(600, 200) * EDSCALE);
600
color_rect->set_v_size_flags(Control::SIZE_EXPAND_FILL);
601
602
_player = memnew(AudioStreamPlayer);
603
_player->connect(SceneStringName(finished), callable_mp(this, &AudioStreamImportSettingsDialog::_on_finished));
604
color_rect->add_child(_player);
605
606
VBoxContainer *vbox = memnew(VBoxContainer);
607
vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 0);
608
color_rect->add_child(vbox);
609
vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
610
611
_preview = memnew(ColorRect);
612
_preview->set_v_size_flags(Control::SIZE_EXPAND_FILL);
613
_preview->connect(SceneStringName(draw), callable_mp(this, &AudioStreamImportSettingsDialog::_draw_preview));
614
_preview->set_v_size_flags(Control::SIZE_EXPAND_FILL);
615
vbox->add_child(_preview);
616
617
zoom_bar = memnew(HScrollBar);
618
zoom_bar->hide();
619
vbox->add_child(zoom_bar);
620
zoom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
621
zoom_bar->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_offset_changed));
622
623
HBoxContainer *hbox = memnew(HBoxContainer);
624
hbox->add_theme_constant_override("separation", 0);
625
vbox->add_child(hbox);
626
627
_indicator = memnew(Control);
628
_indicator->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
629
_indicator->connect(SceneStringName(draw), callable_mp(this, &AudioStreamImportSettingsDialog::_draw_indicator));
630
_indicator->connect(SceneStringName(gui_input), callable_mp(this, &AudioStreamImportSettingsDialog::_on_input_indicator));
631
_indicator->connect(SceneStringName(mouse_exited), callable_mp(this, &AudioStreamImportSettingsDialog::_on_indicator_mouse_exited));
632
_preview->add_child(_indicator);
633
634
_play_button = memnew(Button);
635
_play_button->set_accessibility_name(TTRC("Play"));
636
_play_button->set_flat(true);
637
hbox->add_child(_play_button);
638
_play_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_play));
639
640
_stop_button = memnew(Button);
641
_stop_button->set_accessibility_name(TTRC("Stop"));
642
_stop_button->set_flat(true);
643
hbox->add_child(_stop_button);
644
_stop_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_stop));
645
646
_current_label = memnew(Label);
647
_current_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
648
_current_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
649
_current_label->set_modulate(Color(1, 1, 1, 0.5));
650
hbox->add_child(_current_label);
651
652
_duration_label = memnew(Label);
653
hbox->add_child(_duration_label);
654
655
zoom_in = memnew(Button);
656
zoom_in->set_accessibility_name(TTRC("Zoom In"));
657
zoom_in->set_flat(true);
658
zoom_reset = memnew(Button);
659
zoom_reset->set_accessibility_name(TTRC("Reset Zoom"));
660
zoom_reset->set_flat(true);
661
zoom_out = memnew(Button);
662
zoom_out->set_accessibility_name(TTRC("Zoom Out"));
663
zoom_out->set_flat(true);
664
hbox->add_child(zoom_out);
665
hbox->add_child(zoom_reset);
666
hbox->add_child(zoom_in);
667
zoom_in->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_in));
668
zoom_reset->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_reset));
669
zoom_out->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_out));
670
671
singleton = this;
672
}
673
674