summaryrefslogtreecommitdiff
path: root/editor/audio_stream_preview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/audio_stream_preview.cpp')
-rw-r--r--editor/audio_stream_preview.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp
index 2e0c3491f7..2efcdcda31 100644
--- a/editor/audio_stream_preview.cpp
+++ b/editor/audio_stream_preview.cpp
@@ -97,7 +97,7 @@ AudioStreamPreview::AudioStreamPreview() {
////
void AudioStreamPreviewGenerator::_update_emit(ObjectID p_id) {
- emit_signal("preview_updated", p_id);
+ emit_signal(SNAME("preview_updated"), p_id);
}
void AudioStreamPreviewGenerator::_preview_thread(void *p_preview) {
@@ -150,12 +150,12 @@ void AudioStreamPreviewGenerator::_preview_thread(void *p_preview) {
}
frames_todo -= to_read;
- singleton->call_deferred("_update_emit", preview->id);
+ singleton->call_deferred(SNAME("_update_emit"), preview->id);
}
preview->playback->stop();
- preview->generating = false;
+ preview->generating.clear();
}
Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<AudioStream> &p_stream) {
@@ -172,7 +172,7 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
Preview *preview = &previews[p_stream->get_instance_id()];
preview->base_stream = p_stream;
preview->playback = preview->base_stream->instance_playback();
- preview->generating = true;
+ preview->generating.set();
preview->id = p_stream->get_instance_id();
float len_s = preview->base_stream->get_length();
@@ -192,12 +192,13 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
}
}
- preview->preview.instance();
+ preview->preview.instantiate();
preview->preview->preview = maxmin;
preview->preview->length = len_s;
if (preview->playback.is_valid()) {
- preview->thread = Thread::create(_preview_thread, preview);
+ preview->thread = memnew(Thread);
+ preview->thread->start(_preview_thread, preview);
}
return preview->preview;
@@ -215,14 +216,15 @@ AudioStreamPreviewGenerator *AudioStreamPreviewGenerator::singleton = nullptr;
void AudioStreamPreviewGenerator::_notification(int p_what) {
if (p_what == NOTIFICATION_PROCESS) {
List<ObjectID> to_erase;
- for (Map<ObjectID, Preview>::Element *E = previews.front(); E; E = E->next()) {
- if (!E->get().generating) {
- if (E->get().thread) {
- Thread::wait_to_finish(E->get().thread);
- E->get().thread = nullptr;
+ for (KeyValue<ObjectID, Preview> &E : previews) {
+ if (!E.value.generating.is_set()) {
+ if (E.value.thread) {
+ E.value.thread->wait_to_finish();
+ memdelete(E.value.thread);
+ E.value.thread = nullptr;
}
- if (!ObjectDB::get_instance(E->key())) { //no longer in use, get rid of preview
- to_erase.push_back(E->key());
+ if (!ObjectDB::get_instance(E.key)) { //no longer in use, get rid of preview
+ to_erase.push_back(E.key);
}
}
}