Path: blob/master/editor/import/audio_stream_import_settings.cpp
9903 views
/**************************************************************************/1/* audio_stream_import_settings.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "audio_stream_import_settings.h"3132#include "editor/audio/audio_stream_preview.h"33#include "editor/editor_string_names.h"34#include "editor/file_system/editor_file_system.h"35#include "editor/themes/editor_scale.h"36#include "scene/gui/check_box.h"3738AudioStreamImportSettingsDialog *AudioStreamImportSettingsDialog::singleton = nullptr;3940void AudioStreamImportSettingsDialog::_notification(int p_what) {41switch (p_what) {42case NOTIFICATION_READY: {43AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AudioStreamImportSettingsDialog::_preview_changed));44connect(SceneStringName(confirmed), callable_mp(this, &AudioStreamImportSettingsDialog::_reimport));45} break;4647case NOTIFICATION_THEME_CHANGED: {48_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));49_stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));5051_preview->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));52color_rect->set_color(get_theme_color(SNAME("dark_color_1"), EditorStringName(Editor)));5354_current_label->begin_bulk_theme_override();55_current_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));56_current_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));57_current_label->end_bulk_theme_override();5859_duration_label->begin_bulk_theme_override();60_duration_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));61_duration_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));62_duration_label->end_bulk_theme_override();6364zoom_in->set_button_icon(get_editor_theme_icon(SNAME("ZoomMore")));65zoom_out->set_button_icon(get_editor_theme_icon(SNAME("ZoomLess")));66zoom_reset->set_button_icon(get_editor_theme_icon(SNAME("ZoomReset")));6768_indicator->queue_redraw();69_preview->queue_redraw();70} break;7172case NOTIFICATION_PROCESS: {73_current = _player->get_playback_position();74_indicator->queue_redraw();75} break;7677case NOTIFICATION_VISIBILITY_CHANGED: {78if (!is_visible()) {79_stop();80}81} break;82}83}8485void AudioStreamImportSettingsDialog::_draw_preview() {86Rect2 rect = _preview->get_rect();87Size2 rect_size = rect.size;88int width = rect_size.width;8990Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);91float preview_offset = zoom_bar->get_value();92float preview_len = zoom_bar->get_page();9394Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));95int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));96Vector<Vector2> points;97points.resize(width * 2);98Color color_active = get_theme_color(SNAME("contrast_color_2"), EditorStringName(Editor));99Color color_inactive = color_active;100color_inactive.a *= 0.5;101Vector<Color> colors;102colors.resize(width);103104float inactive_from = 1e20;105float beat_size = 0;106int last_beat = 0;107if (stream->get_bpm() > 0) {108beat_size = 60 / float(stream->get_bpm());109int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;110rect.position.y += y_ofs;111rect.size.y -= y_ofs;112113if (stream->get_beat_count() > 0) {114last_beat = stream->get_beat_count();115inactive_from = last_beat * beat_size;116}117}118119for (int i = 0; i < width; i++) {120float ofs = preview_offset + i * preview_len / rect_size.width;121float ofs_n = preview_offset + (i + 1) * preview_len / rect_size.width;122float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5;123float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5;124125int idx = i;126points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y);127points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y);128129colors.write[idx] = ofs > inactive_from ? color_inactive : color_active;130}131132if (!points.is_empty()) {133RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), points, colors);134}135136if (beat_size) {137Color beat_color = Color(1, 1, 1, 1);138Color final_beat_color = beat_color;139Color bar_color = beat_color;140beat_color.a *= 0.4;141bar_color.a *= 0.6;142143int prev_beat = 0; // Do not draw beat zero144Color color_bg = color_active;145color_bg.a *= 0.2;146_preview->draw_rect(Rect2(0, 0, rect.size.width, rect.position.y), color_bg);147int bar_beats = stream->get_bar_beats();148149int last_text_end_x = 0;150for (int i = 0; i < width; i++) {151float ofs = preview_offset + i * preview_len / rect_size.width;152int beat = int(ofs / beat_size);153if (beat != prev_beat) {154String text = itos(beat);155int text_w = beat_font->get_string_size(text).width;156if (i - text_w / 2 > last_text_end_x + 2 * EDSCALE) {157int x_ofs = i - text_w / 2;158_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);159last_text_end_x = i + text_w / 2;160}161162if (beat == last_beat) {163_preview->draw_rect(Rect2i(i, rect.position.y, 2, rect.size.height), final_beat_color);164// Darken subsequent beats165beat_color.a *= 0.3;166color_active.a *= 0.3;167} else {168_preview->draw_rect(Rect2i(i, rect.position.y, 1, rect.size.height), (beat % bar_beats) == 0 ? bar_color : beat_color);169}170prev_beat = beat;171}172}173}174}175176void AudioStreamImportSettingsDialog::_preview_changed(ObjectID p_which) {177if (stream.is_valid() && stream->get_instance_id() == p_which) {178_preview->queue_redraw();179}180}181182void AudioStreamImportSettingsDialog::_preview_zoom_in() {183if (stream.is_null()) {184return;185}186float page_size = zoom_bar->get_page();187zoom_bar->set_page(page_size * 0.5);188zoom_bar->set_value(zoom_bar->get_value() + page_size * 0.25);189zoom_bar->show();190191_preview->queue_redraw();192_indicator->queue_redraw();193}194195void AudioStreamImportSettingsDialog::_preview_zoom_out() {196if (stream.is_null()) {197return;198}199float page_size = zoom_bar->get_page();200zoom_bar->set_page(MIN(zoom_bar->get_max(), page_size * 2.0));201zoom_bar->set_value(zoom_bar->get_value() - page_size * 0.5);202if (zoom_bar->get_value() == 0) {203zoom_bar->hide();204}205206_preview->queue_redraw();207_indicator->queue_redraw();208}209210void AudioStreamImportSettingsDialog::_preview_zoom_reset() {211if (stream.is_null()) {212return;213}214zoom_bar->set_max(stream->get_length());215zoom_bar->set_page(zoom_bar->get_max());216zoom_bar->set_value(0);217zoom_bar->hide();218219_preview->queue_redraw();220_indicator->queue_redraw();221}222223void AudioStreamImportSettingsDialog::_preview_zoom_offset_changed(double) {224_preview->queue_redraw();225_indicator->queue_redraw();226}227228void AudioStreamImportSettingsDialog::_audio_changed() {229if (!is_visible()) {230return;231}232_preview->queue_redraw();233_indicator->queue_redraw();234color_rect->queue_redraw();235}236237void AudioStreamImportSettingsDialog::_play() {238if (_player->is_playing()) {239// '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'.240_pausing = true;241_player->stop();242_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));243set_process(false);244} else {245_player->play(_current);246_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));247set_process(true);248}249}250251void AudioStreamImportSettingsDialog::_stop() {252_player->stop();253_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));254_current = 0;255_indicator->queue_redraw();256set_process(false);257}258259void AudioStreamImportSettingsDialog::_on_finished() {260_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));261if (!_pausing) {262_current = 0;263_indicator->queue_redraw();264} else {265_pausing = false;266}267set_process(false);268}269270void AudioStreamImportSettingsDialog::_draw_indicator() {271if (stream.is_null()) {272return;273}274275Rect2 rect = _preview->get_rect();276277Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));278int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));279280if (stream->get_bpm() > 0) {281int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;282rect.position.y += y_ofs;283rect.size.height -= y_ofs;284}285286_current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /");287288float ofs_x = (_current - zoom_bar->get_value()) * rect.size.width / zoom_bar->get_page();289if (ofs_x < 0 || ofs_x >= rect.size.width) {290return;291}292293const Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));294_indicator->draw_line(Point2(ofs_x, rect.position.y), Point2(ofs_x, rect.position.y + rect.size.height), color, Math::round(2 * EDSCALE));295_indicator->draw_texture(296get_editor_theme_icon(SNAME("TimelineIndicator")),297Point2(ofs_x - get_editor_theme_icon(SNAME("TimelineIndicator"))->get_width() * 0.5, rect.position.y),298color);299300if (stream->get_bpm() > 0 && _hovering_beat != -1) {301// Draw hovered beat.302float preview_offset = zoom_bar->get_value();303float preview_len = zoom_bar->get_page();304float beat_size = 60 / float(stream->get_bpm());305int prev_beat = 0;306for (int i = 0; i < rect.size.width; i++) {307float ofs = preview_offset + i * preview_len / rect.size.width;308int beat = int(ofs / beat_size);309if (beat != prev_beat) {310String text = itos(beat);311int text_w = beat_font->get_string_size(text).width;312if (i - text_w / 2 > 2 * EDSCALE && beat == _hovering_beat) {313int x_ofs = i - text_w / 2;314_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);315break;316}317prev_beat = beat;318}319}320}321}322323void AudioStreamImportSettingsDialog::_on_indicator_mouse_exited() {324_hovering_beat = -1;325_indicator->queue_redraw();326}327328void AudioStreamImportSettingsDialog::_on_input_indicator(Ref<InputEvent> p_event) {329const Ref<InputEventMouseButton> mb = p_event;330if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {331if (stream->get_bpm() > 0) {332int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));333Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));334int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;335if ((!_dragging && mb->get_position().y < y_ofs) || _beat_len_dragging) {336if (mb->is_pressed()) {337_set_beat_len_to(mb->get_position().x);338_beat_len_dragging = true;339} else {340_beat_len_dragging = false;341}342return;343}344}345346if (mb->is_pressed()) {347_seek_to(mb->get_position().x);348}349_dragging = mb->is_pressed();350}351352const Ref<InputEventMouseMotion> mm = p_event;353if (mm.is_valid()) {354if (_dragging) {355_seek_to(mm->get_position().x);356}357if (_beat_len_dragging) {358_set_beat_len_to(mm->get_position().x);359}360if (stream->get_bpm() > 0) {361int main_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));362Ref<Font> beat_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));363int y_ofs = beat_font->get_height(main_size) + 4 * EDSCALE;364if (mm->get_position().y < y_ofs) {365int new_hovering_beat = _get_beat_at_pos(mm->get_position().x);366if (new_hovering_beat != _hovering_beat) {367_hovering_beat = new_hovering_beat;368_indicator->queue_redraw();369}370} else if (_hovering_beat != -1) {371_hovering_beat = -1;372_indicator->queue_redraw();373}374}375}376}377378int AudioStreamImportSettingsDialog::_get_beat_at_pos(real_t p_x) {379float ofs_sec = zoom_bar->get_value() + p_x * zoom_bar->get_page() / _preview->get_size().width;380ofs_sec = CLAMP(ofs_sec, 0, stream->get_length());381float beat_size = 60 / float(stream->get_bpm());382int beat = int(ofs_sec / beat_size + 0.5);383384if (beat * beat_size > stream->get_length() + 0.001) { // Stream may end few audio frames before but may still want to use full loop.385beat--;386}387return beat;388}389390void AudioStreamImportSettingsDialog::_set_beat_len_to(real_t p_x) {391int beat = _get_beat_at_pos(p_x);392if (beat < 1) {393beat = 1; // Because 0 is disable.394}395updating_settings = true;396beats_enabled->set_pressed(true);397beats_edit->set_value(beat);398updating_settings = false;399_settings_changed();400}401402void AudioStreamImportSettingsDialog::_seek_to(real_t p_x) {403_current = zoom_bar->get_value() + p_x / _preview->get_rect().size.x * zoom_bar->get_page();404_current = CLAMP(_current, 0, stream->get_length());405_player->seek(_current);406_indicator->queue_redraw();407}408409void AudioStreamImportSettingsDialog::edit(const String &p_path, const String &p_importer, const Ref<AudioStream> &p_stream) {410if (stream.is_valid()) {411stream->disconnect_changed(callable_mp(this, &AudioStreamImportSettingsDialog::_audio_changed));412}413414importer = p_importer;415path = p_path;416417stream = p_stream;418_player->set_stream(stream);419_current = 0;420String text = String::num(stream->get_length(), 2).pad_decimals(2) + "s";421_duration_label->set_text(text);422423if (stream.is_valid()) {424stream->connect_changed(callable_mp(this, &AudioStreamImportSettingsDialog::_audio_changed));425_preview->queue_redraw();426_indicator->queue_redraw();427color_rect->queue_redraw();428} else {429hide();430}431params.clear();432433if (stream.is_valid()) {434Ref<ConfigFile> config_file;435config_file.instantiate();436Error err = config_file->load(p_path + ".import");437updating_settings = true;438if (err == OK) {439double bpm = config_file->get_value("params", "bpm", 0);440int beats = config_file->get_value("params", "beat_count", 0);441bpm_edit->set_value(bpm > 0 ? bpm : 120);442bpm_enabled->set_pressed(bpm > 0);443beats_edit->set_value(beats);444beats_enabled->set_pressed(beats > 0);445loop->set_pressed(config_file->get_value("params", "loop", false));446loop_offset->set_value(config_file->get_value("params", "loop_offset", 0));447bar_beats_edit->set_value(config_file->get_value("params", "bar_beats", 4));448449Vector<String> keys = config_file->get_section_keys("params");450for (const String &K : keys) {451params[K] = config_file->get_value("params", K);452}453} else {454bpm_edit->set_value(false);455bpm_enabled->set_pressed(false);456beats_edit->set_value(0);457beats_enabled->set_pressed(false);458bar_beats_edit->set_value(4);459loop->set_pressed(false);460loop_offset->set_value(0);461}462463_preview_zoom_reset();464updating_settings = false;465_settings_changed();466467set_title(vformat(TTR("Audio Stream Importer: %s"), p_path.get_file()));468popup_centered();469}470}471472void AudioStreamImportSettingsDialog::_settings_changed() {473if (updating_settings) {474return;475}476477updating_settings = true;478stream->call("set_loop", loop->is_pressed());479stream->call("set_loop_offset", loop_offset->get_value());480if (loop->is_pressed()) {481loop_offset->set_editable(true);482} else {483loop_offset->set_editable(false);484}485486if (bpm_enabled->is_pressed()) {487stream->call("set_bpm", bpm_edit->get_value());488beats_enabled->set_disabled(false);489beats_edit->set_editable(true);490bar_beats_edit->set_editable(true);491double bpm = bpm_edit->get_value();492if (bpm > 0) {493float beat_size = 60 / float(bpm);494int beat_max = int((stream->get_length() + 0.001) / beat_size);495int current_beat = beats_edit->get_value();496beats_edit->set_max(beat_max);497if (current_beat > beat_max) {498beats_edit->set_value(beat_max);499stream->call("set_beat_count", beat_max);500}501}502stream->call("set_bar_beats", bar_beats_edit->get_value());503} else {504stream->call("set_bpm", 0);505stream->call("set_bar_beats", 4);506beats_enabled->set_disabled(true);507beats_edit->set_editable(false);508bar_beats_edit->set_editable(false);509}510if (bpm_enabled->is_pressed() && beats_enabled->is_pressed()) {511stream->call("set_beat_count", beats_edit->get_value());512} else {513stream->call("set_beat_count", 0);514}515516updating_settings = false;517518_preview->queue_redraw();519_indicator->queue_redraw();520color_rect->queue_redraw();521}522523void AudioStreamImportSettingsDialog::_reimport() {524params["loop"] = loop->is_pressed();525params["loop_offset"] = loop_offset->get_value();526params["bpm"] = bpm_enabled->is_pressed() ? double(bpm_edit->get_value()) : double(0);527params["beat_count"] = (bpm_enabled->is_pressed() && beats_enabled->is_pressed()) ? int(beats_edit->get_value()) : int(0);528params["bar_beats"] = (bpm_enabled->is_pressed()) ? int(bar_beats_edit->get_value()) : int(4);529530EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(path, importer, params);531}532533AudioStreamImportSettingsDialog::AudioStreamImportSettingsDialog() {534get_ok_button()->set_text(TTR("Reimport"));535get_cancel_button()->set_text(TTR("Close"));536537VBoxContainer *main_vbox = memnew(VBoxContainer);538add_child(main_vbox);539540HBoxContainer *loop_hb = memnew(HBoxContainer);541loop_hb->add_theme_constant_override("separation", 4 * EDSCALE);542loop = memnew(CheckBox);543loop->set_text(TTR("Enable"));544loop->set_tooltip_text(TTR("Enable looping."));545loop->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));546loop_hb->add_child(loop);547loop_hb->add_spacer();548loop_hb->add_child(memnew(Label(TTR("Offset:"))));549loop_offset = memnew(SpinBox);550loop_offset->set_accessibility_name(TTRC("Offset:"));551loop_offset->set_max(10000);552loop_offset->set_step(0.001);553loop_offset->set_suffix("s");554loop_offset->set_h_size_flags(Control::SIZE_EXPAND_FILL);555loop_offset->set_stretch_ratio(0.33);556loop_offset->set_tooltip_text(TTR("Loop offset (from beginning). Note that if BPM is set, this setting will be ignored."));557loop_offset->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));558loop_hb->add_child(loop_offset);559main_vbox->add_margin_child(TTR("Loop:"), loop_hb);560561HBoxContainer *interactive_hb = memnew(HBoxContainer);562interactive_hb->add_theme_constant_override("separation", 4 * EDSCALE);563bpm_enabled = memnew(CheckBox);564bpm_enabled->set_text((TTR("BPM:")));565bpm_enabled->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));566interactive_hb->add_child(bpm_enabled);567bpm_edit = memnew(SpinBox);568bpm_edit->set_max(400);569bpm_edit->set_step(0.01);570bpm_edit->set_accessibility_name(TTRC("BPM:"));571bpm_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."));572bpm_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));573interactive_hb->add_child(bpm_edit);574interactive_hb->add_spacer();575beats_enabled = memnew(CheckBox);576beats_enabled->set_text(TTR("Beat Count:"));577beats_enabled->connect(SceneStringName(toggled), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));578interactive_hb->add_child(beats_enabled);579beats_edit = memnew(SpinBox);580beats_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."));581beats_edit->set_max(99999);582beats_edit->set_accessibility_name(TTRC("Beat Count:"));583beats_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));584interactive_hb->add_child(beats_edit);585bar_beats_label = memnew(Label(TTR("Bar Beats:")));586interactive_hb->add_child(bar_beats_label);587bar_beats_edit = memnew(SpinBox);588bar_beats_edit->set_tooltip_text(TTR("Configure the Beats Per Bar. This used for music-aware transitions between AudioStreams."));589bar_beats_edit->set_min(2);590bar_beats_edit->set_max(32);591bar_beats_edit->set_accessibility_name(TTRC("Bar Beats:"));592bar_beats_edit->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_settings_changed).unbind(1));593interactive_hb->add_child(bar_beats_edit);594main_vbox->add_margin_child(TTR("Music Playback:"), interactive_hb);595596color_rect = memnew(ColorRect);597main_vbox->add_margin_child(TTR("Preview:"), color_rect, true);598color_rect->set_custom_minimum_size(Size2(600, 200) * EDSCALE);599color_rect->set_v_size_flags(Control::SIZE_EXPAND_FILL);600601_player = memnew(AudioStreamPlayer);602_player->connect(SceneStringName(finished), callable_mp(this, &AudioStreamImportSettingsDialog::_on_finished));603color_rect->add_child(_player);604605VBoxContainer *vbox = memnew(VBoxContainer);606vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 0);607color_rect->add_child(vbox);608vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);609610_preview = memnew(ColorRect);611_preview->set_v_size_flags(Control::SIZE_EXPAND_FILL);612_preview->connect(SceneStringName(draw), callable_mp(this, &AudioStreamImportSettingsDialog::_draw_preview));613_preview->set_v_size_flags(Control::SIZE_EXPAND_FILL);614vbox->add_child(_preview);615616zoom_bar = memnew(HScrollBar);617zoom_bar->hide();618vbox->add_child(zoom_bar);619zoom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);620zoom_bar->connect(SceneStringName(value_changed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_offset_changed));621622HBoxContainer *hbox = memnew(HBoxContainer);623hbox->add_theme_constant_override("separation", 0);624vbox->add_child(hbox);625626_indicator = memnew(Control);627_indicator->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);628_indicator->connect(SceneStringName(draw), callable_mp(this, &AudioStreamImportSettingsDialog::_draw_indicator));629_indicator->connect(SceneStringName(gui_input), callable_mp(this, &AudioStreamImportSettingsDialog::_on_input_indicator));630_indicator->connect(SceneStringName(mouse_exited), callable_mp(this, &AudioStreamImportSettingsDialog::_on_indicator_mouse_exited));631_preview->add_child(_indicator);632633_play_button = memnew(Button);634_play_button->set_accessibility_name(TTRC("Play"));635_play_button->set_flat(true);636hbox->add_child(_play_button);637_play_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_play));638639_stop_button = memnew(Button);640_stop_button->set_accessibility_name(TTRC("Stop"));641_stop_button->set_flat(true);642hbox->add_child(_stop_button);643_stop_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_stop));644645_current_label = memnew(Label);646_current_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);647_current_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);648_current_label->set_modulate(Color(1, 1, 1, 0.5));649hbox->add_child(_current_label);650651_duration_label = memnew(Label);652hbox->add_child(_duration_label);653654zoom_in = memnew(Button);655zoom_in->set_accessibility_name(TTRC("Zoom In"));656zoom_in->set_flat(true);657zoom_reset = memnew(Button);658zoom_reset->set_accessibility_name(TTRC("Reset Zoom"));659zoom_reset->set_flat(true);660zoom_out = memnew(Button);661zoom_out->set_accessibility_name(TTRC("Zoom Out"));662zoom_out->set_flat(true);663hbox->add_child(zoom_out);664hbox->add_child(zoom_reset);665hbox->add_child(zoom_in);666zoom_in->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_in));667zoom_reset->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_reset));668zoom_out->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamImportSettingsDialog::_preview_zoom_out));669670singleton = this;671}672673674