Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Generalize `AudioStream` editor preview support

AR-DEV-1b0a5fb6759bc
diff --git a/editor/audio/audio_stream_editor_plugin.cpp b/editor/audio/audio_stream_editor_plugin.cpp
index 459e4302e93..6f35348fb10 100644
--- a/editor/audio/audio_stream_editor_plugin.cpp
+++ b/editor/audio/audio_stream_editor_plugin.cpp
@@ -75,15 +75,20 @@ void AudioStreamEditor::_notification(int p_what) {
}
void AudioStreamEditor::_draw_preview() {
+ if (stream.is_null() || stream->get_length() <= 0.0) {
+ return;
+ }
+
Size2 size = get_size();
int width = size.width;
if (width <= 0) {
return; // No points to draw.
}
+ Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
+
Rect2 rect = _preview->get_rect();
- Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
float preview_len = preview->get_length();
Vector<Vector2> points;
@@ -158,6 +163,11 @@ void AudioStreamEditor::_draw_indicator() {
Rect2 rect = _preview->get_rect();
float len = stream->get_length();
+ if (len <= 0.0f) {
+ _current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /");
+ return;
+ }
+
float ofs_x = _current / len * rect.size.width;
const Color col = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
Ref<Texture2D> icon = get_editor_theme_icon(SNAME("TimelineIndicator"));
@@ -209,8 +219,13 @@ void AudioStreamEditor::set_stream(const Ref<AudioStream> &p_stream) {
_player->set_stream(stream);
_current = 0;
- String text = String::num(stream->get_length(), 2).pad_decimals(2) + "s";
- _duration_label->set_text(text);
+ const double length = stream->get_length();
+
+ if (length > 0.0) {
+ _duration_label->set_text(String::num(length, 2).pad_decimals(2) + "s");
+ } else {
+ _duration_label->set_text(TTR("Dynamic"));
+ }
queue_redraw();
}
@@ -266,25 +281,16 @@ AudioStreamEditor::AudioStreamEditor() {
hbox->add_child(_duration_label);
}
-// EditorInspectorPluginAudioStream
-
-bool EditorInspectorPluginAudioStream::can_handle(Object *p_object) {
- return Object::cast_to<AudioStreamWAV>(p_object) != nullptr;
-}
-
void EditorInspectorPluginAudioStream::parse_begin(Object *p_object) {
AudioStream *stream = Object::cast_to<AudioStream>(p_object);
- editor = memnew(AudioStreamEditor);
+ AudioStreamEditor *editor = memnew(AudioStreamEditor);
editor->set_stream(Ref<AudioStream>(stream));
-
add_custom_control(editor);
}
-// AudioStreamEditorPlugin
+// EditorInspectorPluginAudioStream
-AudioStreamEditorPlugin::AudioStreamEditorPlugin() {
- Ref<EditorInspectorPluginAudioStream> plugin;
- plugin.instantiate();
- add_inspector_plugin(plugin);
+bool EditorInspectorPluginAudioStreamWAV::can_handle(Object *p_object) {
+ return Object::cast_to<AudioStreamWAV>(p_object) != nullptr;
}
diff --git a/editor/audio/audio_stream_editor_plugin.h b/editor/audio/audio_stream_editor_plugin.h
index 78868be5d86..2f439577be4 100644
--- a/editor/audio/audio_stream_editor_plugin.h
+++ b/editor/audio/audio_stream_editor_plugin.h
@@ -75,16 +75,14 @@ public:
class EditorInspectorPluginAudioStream : public EditorInspectorPlugin {
GDCLASS(EditorInspectorPluginAudioStream, EditorInspectorPlugin);
- AudioStreamEditor *editor = nullptr;
public:
- virtual bool can_handle(Object *p_object) override;
virtual void parse_begin(Object *p_object) override;
};
-class AudioStreamEditorPlugin : public EditorPlugin {
- GDCLASS(AudioStreamEditorPlugin, EditorPlugin);
+class EditorInspectorPluginAudioStreamWAV : public EditorInspectorPluginAudioStream {
+ GDCLASS(EditorInspectorPluginAudioStreamWAV, EditorInspectorPluginAudioStream);
public:
- AudioStreamEditorPlugin();
+ virtual bool can_handle(Object *p_object) override;
};
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 166efc2117b..9857b5675c3 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -51,6 +51,7 @@
#include "core/version.h"
#include "editor/animation/animation_player_editor_plugin.h"
#include "editor/asset_library/asset_library_editor_plugin.h"
+#include "editor/audio/audio_stream_editor_plugin.h"
#include "editor/audio/audio_stream_preview.h"
#include "editor/audio/editor_audio_buses.h"
#include "editor/debugger/debugger_editor_plugin.h"
@@ -8656,6 +8657,10 @@ EditorNode::EditorNode() {
Ref<EditorInspectorParticleProcessMaterialPlugin> ppm;
ppm.instantiate();
EditorInspector::add_inspector_plugin(ppm);
+
+ Ref<EditorInspectorPluginAudioStreamWAV> plugin;
+ plugin.instantiate();
+ EditorInspector::add_inspector_plugin(plugin);
}
editor_selection = memnew(EditorSelection);
diff --git a/editor/register_editor_types.cpp b/editor/register_editor_types.cpp
index 68022c98f53..21c473917ce 100644
--- a/editor/register_editor_types.cpp
+++ b/editor/register_editor_types.cpp
@@ -37,7 +37,6 @@
#include "core/object/script_language.h"
#include "core/os/os.h"
#include "editor/animation/animation_tree_editor_plugin.h"
-#include "editor/audio/audio_stream_editor_plugin.h"
#include "editor/audio/audio_stream_randomizer_editor_plugin.h"
#include "editor/debugger/debug_adapter/debug_adapter_server.h"
#include "editor/debugger/editor_debugger_plugin.h"
@@ -225,7 +224,6 @@ void register_editor_types() {
// This list is alphabetized, and plugins that depend on Node2D or Node3D are in their own section below.
EditorPlugins::add_by_type<AnimationTreeEditorPlugin>();
- EditorPlugins::add_by_type<AudioStreamEditorPlugin>();
EditorPlugins::add_by_type<AudioStreamRandomizerEditorPlugin>();
EditorPlugins::add_by_type<BitMapEditorPlugin>();
EditorPlugins::add_by_type<ControlEditorPlugin>();
diff --git a/modules/mp3/SCsub b/modules/mp3/SCsub
index 4439da7d274..cca13a77b51 100644
--- a/modules/mp3/SCsub
+++ b/modules/mp3/SCsub
@@ -11,3 +11,6 @@ if not env["mp3_extra_formats"]:
# Godot source files
env_mp3.add_source_files(env.modules_sources, "*.cpp")
+
+if env.editor_build:
+ env_mp3.add_source_files(env.modules_sources, "editor/*.cpp")
diff --git a/modules/mp3/editor/audio_stream_mp3_editor_plugin.cpp b/modules/mp3/editor/audio_stream_mp3_editor_plugin.cpp
new file mode 100644
index 00000000000..393c8c4e0c5
--- /dev/null
+++ b/modules/mp3/editor/audio_stream_mp3_editor_plugin.cpp
@@ -0,0 +1,37 @@
+/**************************************************************************/
+/* audio_stream_mp3_editor_plugin.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "audio_stream_mp3_editor_plugin.h"
+
+#include "modules/mp3/audio_stream_mp3.h"
+
+bool EditorInspectorPluginAudioStreamMP3::can_handle(Object *p_object) {
+ return Object::cast_to<AudioStreamMP3>(p_object) != nullptr;
+}
diff --git a/modules/mp3/editor/audio_stream_mp3_editor_plugin.h b/modules/mp3/editor/audio_stream_mp3_editor_plugin.h
new file mode 100644
index 00000000000..2207dcb98fc
--- /dev/null
+++ b/modules/mp3/editor/audio_stream_mp3_editor_plugin.h
@@ -0,0 +1,40 @@
+/**************************************************************************/
+/* audio_stream_mp3_editor_plugin.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#pragma once
+
+#include "editor/audio/audio_stream_editor_plugin.h"
+
+class EditorInspectorPluginAudioStreamMP3 : public EditorInspectorPluginAudioStream {
+ GDCLASS(EditorInspectorPluginAudioStreamMP3, EditorInspectorPluginAudioStream);
+
+public:
+ virtual bool can_handle(Object *p_object) override;
+};
diff --git a/modules/mp3/register_types.cpp b/modules/mp3/register_types.cpp
index 65bbe93ad0d..8bd2f5ac7b4 100644
--- a/modules/mp3/register_types.cpp
+++ b/modules/mp3/register_types.cpp
@@ -39,11 +39,18 @@
#include "resource_importer_mp3.h"
#include "editor/editor_node.h"
+#include "editor/inspector/editor_inspector.h"
+
+#include "modules/mp3/editor/audio_stream_mp3_editor_plugin.h"
static void _editor_init() {
Ref<ResourceImporterMP3> mp3_import;
mp3_import.instantiate();
ResourceFormatImporter::get_singleton()->add_importer(mp3_import);
+
+ Ref<EditorInspectorPluginAudioStreamMP3> plugin;
+ plugin.instantiate();
+ EditorInspector::add_inspector_plugin(plugin);
}
#endif
diff --git a/modules/vorbis/SCsub b/modules/vorbis/SCsub
index 7ec00f3e3a5..279db1bd28f 100644
--- a/modules/vorbis/SCsub
+++ b/modules/vorbis/SCsub
@@ -63,6 +63,10 @@ if env["builtin_libvorbis"]:
module_obj = []
env_vorbis.add_source_files(module_obj, "*.cpp")
+
+if env.editor_build:
+ env_vorbis.add_source_files(module_obj, "editor/*.cpp")
+
env.modules_sources += module_obj
# Needed to force rebuilding the module files when the thirdparty library is updated.
diff --git a/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.cpp b/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.cpp
new file mode 100644
index 00000000000..be941af4257
--- /dev/null
+++ b/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.cpp
@@ -0,0 +1,37 @@
+/**************************************************************************/
+/* audio_stream_ogg_vorbis_editor_plugin.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "audio_stream_ogg_vorbis_editor_plugin.h"
+
+#include "modules/vorbis/audio_stream_ogg_vorbis.h"
+
+bool EditorInspectorPluginAudioStreamOggVorbis::can_handle(Object *p_object) {
+ return Object::cast_to<AudioStreamOggVorbis>(p_object) != nullptr;
+}
diff --git a/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.h b/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.h
new file mode 100644
index 00000000000..a249376656a
--- /dev/null
+++ b/modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.h
@@ -0,0 +1,40 @@
+/**************************************************************************/
+/* audio_stream_ogg_vorbis_editor_plugin.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#pragma once
+
+#include "editor/audio/audio_stream_editor_plugin.h"
+
+class EditorInspectorPluginAudioStreamOggVorbis : public EditorInspectorPluginAudioStream {
+ GDCLASS(EditorInspectorPluginAudioStreamOggVorbis, EditorInspectorPluginAudioStream);
+
+public:
+ virtual bool can_handle(Object *p_object) override;
+};
diff --git a/modules/vorbis/register_types.cpp b/modules/vorbis/register_types.cpp
index 622ef1edee6..3068540f784 100644
--- a/modules/vorbis/register_types.cpp
+++ b/modules/vorbis/register_types.cpp
@@ -39,11 +39,18 @@
#include "resource_importer_ogg_vorbis.h"
#include "editor/editor_node.h"
+#include "editor/inspector/editor_inspector.h"
+
+#include "modules/vorbis/editor/audio_stream_ogg_vorbis_editor_plugin.h"
static void _editor_init() {
Ref<ResourceImporterOggVorbis> ogg_vorbis_importer;
ogg_vorbis_importer.instantiate();
ResourceFormatImporter::get_singleton()->add_importer(ogg_vorbis_importer);
+
+ Ref<EditorInspectorPluginAudioStreamOggVorbis> plugin;
+ plugin.instantiate();
+ EditorInspector::add_inspector_plugin(plugin);
}
#endif