audio_stream_import_settings.h 4.2 KB

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