3535#include " editor/editor_string_names.h"
3636#include " editor/settings/editor_settings.h"
3737#include " editor/themes/editor_scale.h"
38- #include " scene/resources/audio_stream_wav.h"
3938#include " servers/rendering/rendering_server.h"
4039
4140// AudioStreamEditor
@@ -75,17 +74,31 @@ void AudioStreamEditor::_notification(int p_what) {
7574}
7675
7776void AudioStreamEditor::_draw_preview () {
77+ if (stream.is_null ()) {
78+ return ;
79+ }
7880 Size2 size = get_size ();
7981 int width = size.width ;
8082 if (width <= 0 ) {
81- return ; // No points to draw.
83+ return ;
84+ }
85+ if (stream->get_length () <= 0 .0f ) {
86+ const Color col = get_theme_color (SNAME (" font_disabled_color" ), EditorStringName (Editor));
87+ Ref<Font> font = get_theme_font (SNAME (" status_source" ), EditorStringName (EditorFonts));
88+ int font_size = get_theme_font_size (SNAME (" status_source_size" ), EditorStringName (EditorFonts));
89+ _preview->draw_string (font,
90+ Point2 (8 * EDSCALE, size.height * 0 .5f + font_size * 0 .25f ),
91+ TTR (" Waveform preview not available" ),
92+ HORIZONTAL_ALIGNMENT_LEFT, -1 , font_size, col);
93+ return ;
8294 }
83-
84- Rect2 rect = _preview->get_rect ();
85-
8695 Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton ()->generate_preview (stream);
8796 float preview_len = preview->get_length ();
8897
98+ if (preview_len <= 0 .0f ) {
99+ return ;
100+ }
101+
89102 Vector<Vector2> points;
90103 points.resize (width * 2 );
91104
@@ -96,8 +109,8 @@ void AudioStreamEditor::_draw_preview() {
96109 float min = preview->get_min (ofs, ofs_n) * 0.5 + 0.5 ;
97110
98111 int idx = i;
99- points.write [idx * 2 + 0 ] = Vector2 (i + 1 , rect. position . y + min * rect. size .y );
100- points.write [idx * 2 + 1 ] = Vector2 (i + 1 , rect. position . y + max * rect. size .y );
112+ points.write [idx * 2 + 0 ] = Vector2 (i + 1 , min * size.height );
113+ points.write [idx * 2 + 1 ] = Vector2 (i + 1 , max * size.height );
101114 }
102115
103116 Vector<Color> colors = { get_theme_color (SNAME (" contrast_color_2" ), EditorStringName (Editor)) };
@@ -119,6 +132,9 @@ void AudioStreamEditor::_stream_changed() {
119132}
120133
121134void AudioStreamEditor::_play () {
135+ if (stream.is_null () || stream->get_length () <= 0 .0f ) {
136+ return ;
137+ }
122138 if (_player->is_playing ()) {
123139 _pausing = true ;
124140 _player->stop ();
@@ -152,13 +168,16 @@ void AudioStreamEditor::_on_finished() {
152168}
153169
154170void AudioStreamEditor::_draw_indicator () {
155- if (stream.is_null ()) {
156- return ;
157- }
158-
159- Rect2 rect = _preview->get_rect ();
160- float len = stream->get_length ();
161- float ofs_x = _current / len * rect.size .width ;
171+ if (stream.is_null ()) {
172+ return ;
173+ }
174+ float len = stream->get_length ();
175+ if (len <= 0 .0f ) {
176+ _current_label->set_text (String::num (_current, 2 ).pad_decimals (2 ) + " /" );
177+ return ;
178+ }
179+ Rect2 rect = _preview->get_rect ();
180+ float ofs_x = _current / len * rect.size .width ;
162181 const Color col = get_theme_color (SNAME (" accent_color" ), EditorStringName (Editor));
163182 Ref<Texture2D> icon = get_editor_theme_icon (SNAME (" TimelineIndicator" ));
164183 _indicator->draw_line (Point2 (ofs_x, 0 ), Point2 (ofs_x, rect.size .height ), col, Math::round (2 * EDSCALE));
@@ -209,8 +228,12 @@ void AudioStreamEditor::set_stream(const Ref<AudioStream> &p_stream) {
209228 _player->set_stream (stream);
210229 _current = 0 ;
211230
212- String text = String::num (stream->get_length (), 2 ).pad_decimals (2 ) + " s" ;
213- _duration_label->set_text (text);
231+ float len = stream->get_length ();
232+ if (len > 0 .0f ) {
233+ _duration_label->set_text (String::num (len, 2 ).pad_decimals (2 ) + " s" );
234+ } else {
235+ _duration_label->set_text (TTR (" dynamic" ));
236+ }
214237
215238 queue_redraw ();
216239}
@@ -269,7 +292,7 @@ AudioStreamEditor::AudioStreamEditor() {
269292// EditorInspectorPluginAudioStream
270293
271294bool EditorInspectorPluginAudioStream::can_handle (Object *p_object) {
272- return Object::cast_to<AudioStreamWAV >(p_object) != nullptr ;
295+ return Object::cast_to<AudioStream >(p_object) != nullptr ;
273296}
274297
275298void EditorInspectorPluginAudioStream::parse_begin (Object *p_object) {
0 commit comments