| 1 | /**************************************************************************/ |
| 2 | /* audio_stream_import_settings.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 AUDIO_STREAM_IMPORT_SETTINGS_H |
| 32 | #define AUDIO_STREAM_IMPORT_SETTINGS_H |
| 33 | |
| 34 | #include "editor/editor_plugin.h" |
| 35 | #include "scene/audio/audio_stream_player.h" |
| 36 | #include "scene/gui/color_rect.h" |
| 37 | #include "scene/gui/dialogs.h" |
| 38 | #include "scene/gui/spin_box.h" |
| 39 | #include "scene/resources/texture.h" |
| 40 | |
| 41 | class CheckBox; |
| 42 | |
| 43 | class AudioStreamImportSettings : public ConfirmationDialog { |
| 44 | GDCLASS(AudioStreamImportSettings, ConfirmationDialog); |
| 45 | |
| 46 | CheckBox *bpm_enabled = nullptr; |
| 47 | SpinBox *bpm_edit = nullptr; |
| 48 | CheckBox *beats_enabled = nullptr; |
| 49 | SpinBox *beats_edit = nullptr; |
| 50 | Label *bar_beats_label = nullptr; |
| 51 | SpinBox *bar_beats_edit = nullptr; |
| 52 | CheckBox *loop = nullptr; |
| 53 | SpinBox *loop_offset = nullptr; |
| 54 | ColorRect *color_rect = nullptr; |
| 55 | Ref<AudioStream> stream; |
| 56 | AudioStreamPlayer *_player = nullptr; |
| 57 | ColorRect *_preview = nullptr; |
| 58 | Control *_indicator = nullptr; |
| 59 | Label *_current_label = nullptr; |
| 60 | Label *_duration_label = nullptr; |
| 61 | |
| 62 | HScrollBar *zoom_bar = nullptr; |
| 63 | Button *zoom_in = nullptr; |
| 64 | Button *zoom_reset = nullptr; |
| 65 | Button *zoom_out = nullptr; |
| 66 | |
| 67 | Button *_play_button = nullptr; |
| 68 | Button *_stop_button = nullptr; |
| 69 | |
| 70 | bool updating_settings = false; |
| 71 | |
| 72 | float _current = 0; |
| 73 | bool _dragging = false; |
| 74 | bool _beat_len_dragging = false; |
| 75 | bool _pausing = false; |
| 76 | int _hovering_beat = -1; |
| 77 | |
| 78 | HashMap<StringName, Variant> params; |
| 79 | String importer; |
| 80 | String path; |
| 81 | |
| 82 | void _audio_changed(); |
| 83 | |
| 84 | static AudioStreamImportSettings *singleton; |
| 85 | |
| 86 | void _settings_changed(); |
| 87 | |
| 88 | void _reimport(); |
| 89 | |
| 90 | protected: |
| 91 | void _notification(int p_what); |
| 92 | void _preview_changed(ObjectID p_which); |
| 93 | void _preview_zoom_in(); |
| 94 | void _preview_zoom_out(); |
| 95 | void _preview_zoom_reset(); |
| 96 | void _preview_zoom_offset_changed(double); |
| 97 | |
| 98 | void _play(); |
| 99 | void _stop(); |
| 100 | void _on_finished(); |
| 101 | void _draw_preview(); |
| 102 | void _draw_indicator(); |
| 103 | void _on_input_indicator(Ref<InputEvent> p_event); |
| 104 | void _seek_to(real_t p_x); |
| 105 | void _set_beat_len_to(real_t p_x); |
| 106 | void _on_indicator_mouse_exited(); |
| 107 | int _get_beat_at_pos(real_t p_x); |
| 108 | |
| 109 | public: |
| 110 | void edit(const String &p_path, const String &p_importer, const Ref<AudioStream> &p_stream); |
| 111 | |
| 112 | static AudioStreamImportSettings *get_singleton() { return singleton; } |
| 113 | |
| 114 | AudioStreamImportSettings(); |
| 115 | }; |
| 116 | |
| 117 | #endif // AUDIO_STREAM_IMPORT_SETTINGS_H |
| 118 | |