initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
6
editor/audio/SCsub
Normal file
6
editor/audio/SCsub
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
288
editor/audio/audio_stream_editor_plugin.cpp
Normal file
288
editor/audio/audio_stream_editor_plugin.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_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_editor_plugin.h"
|
||||
|
||||
#include "editor/audio/audio_stream_preview.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "scene/resources/audio_stream_wav.h"
|
||||
|
||||
// AudioStreamEditor
|
||||
|
||||
void AudioStreamEditor::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_READY: {
|
||||
AudioStreamPreviewGenerator::get_singleton()->connect(SNAME("preview_updated"), callable_mp(this, &AudioStreamEditor::_preview_changed));
|
||||
} break;
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
Ref<Font> font = get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts));
|
||||
|
||||
_current_label->add_theme_font_override(SceneStringName(font), font);
|
||||
_duration_label->add_theme_font_override(SceneStringName(font), font);
|
||||
|
||||
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
|
||||
_stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));
|
||||
_preview->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
|
||||
|
||||
set_color(get_theme_color(SNAME("dark_color_1"), EditorStringName(Editor)));
|
||||
|
||||
_indicator->queue_redraw();
|
||||
_preview->queue_redraw();
|
||||
} break;
|
||||
case NOTIFICATION_PROCESS: {
|
||||
_current = _player->get_playback_position();
|
||||
_indicator->queue_redraw();
|
||||
} break;
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
if (!is_visible_in_tree()) {
|
||||
_stop();
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_draw_preview() {
|
||||
Size2 size = get_size();
|
||||
int width = size.width;
|
||||
if (width <= 0) {
|
||||
return; // No points to draw.
|
||||
}
|
||||
|
||||
Rect2 rect = _preview->get_rect();
|
||||
|
||||
Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
|
||||
float preview_len = preview->get_length();
|
||||
|
||||
Vector<Vector2> points;
|
||||
points.resize(width * 2);
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
float ofs = i * preview_len / size.width;
|
||||
float ofs_n = (i + 1) * preview_len / size.width;
|
||||
float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5;
|
||||
float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5;
|
||||
|
||||
int idx = i;
|
||||
points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y);
|
||||
points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y);
|
||||
}
|
||||
|
||||
Vector<Color> colors = { get_theme_color(SNAME("contrast_color_2"), EditorStringName(Editor)) };
|
||||
|
||||
RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), points, colors);
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_preview_changed(ObjectID p_which) {
|
||||
if (stream.is_valid() && stream->get_instance_id() == p_which) {
|
||||
_preview->queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_stream_changed() {
|
||||
if (!is_visible()) {
|
||||
return;
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_play() {
|
||||
if (_player->is_playing()) {
|
||||
_pausing = true;
|
||||
_player->stop();
|
||||
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
|
||||
set_process(false);
|
||||
} else {
|
||||
_pausing = false;
|
||||
_player->play(_current);
|
||||
_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));
|
||||
set_process(true);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_stop() {
|
||||
_player->stop();
|
||||
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
|
||||
_current = 0;
|
||||
_indicator->queue_redraw();
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_on_finished() {
|
||||
_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));
|
||||
if (!_pausing) {
|
||||
_current = 0;
|
||||
_indicator->queue_redraw();
|
||||
} else {
|
||||
_pausing = false;
|
||||
}
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_draw_indicator() {
|
||||
if (stream.is_null()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Rect2 rect = _preview->get_rect();
|
||||
float len = stream->get_length();
|
||||
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"));
|
||||
_indicator->draw_line(Point2(ofs_x, 0), Point2(ofs_x, rect.size.height), col, Math::round(2 * EDSCALE));
|
||||
_indicator->draw_texture(
|
||||
icon,
|
||||
Point2(ofs_x - icon->get_width() * 0.5, 0),
|
||||
col);
|
||||
|
||||
_current_label->set_text(String::num(_current, 2).pad_decimals(2) + " /");
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_on_input_indicator(Ref<InputEvent> p_event) {
|
||||
const Ref<InputEventMouseButton> mb = p_event;
|
||||
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
|
||||
if (mb->is_pressed()) {
|
||||
_seek_to(mb->get_position().x);
|
||||
}
|
||||
_dragging = mb->is_pressed();
|
||||
}
|
||||
|
||||
const Ref<InputEventMouseMotion> mm = p_event;
|
||||
if (mm.is_valid()) {
|
||||
if (_dragging) {
|
||||
_seek_to(mm->get_position().x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_seek_to(real_t p_x) {
|
||||
_current = p_x / _preview->get_rect().size.x * stream->get_length();
|
||||
_current = CLAMP(_current, 0, stream->get_length());
|
||||
_player->seek(_current);
|
||||
_indicator->queue_redraw();
|
||||
}
|
||||
|
||||
void AudioStreamEditor::set_stream(const Ref<AudioStream> &p_stream) {
|
||||
if (stream.is_valid()) {
|
||||
stream->disconnect_changed(callable_mp(this, &AudioStreamEditor::_stream_changed));
|
||||
}
|
||||
|
||||
stream = p_stream;
|
||||
if (stream.is_null()) {
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
stream->connect_changed(callable_mp(this, &AudioStreamEditor::_stream_changed));
|
||||
|
||||
_player->set_stream(stream);
|
||||
_current = 0;
|
||||
|
||||
String text = String::num(stream->get_length(), 2).pad_decimals(2) + "s";
|
||||
_duration_label->set_text(text);
|
||||
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
AudioStreamEditor::AudioStreamEditor() {
|
||||
set_custom_minimum_size(Size2(1, 100) * EDSCALE);
|
||||
|
||||
_player = memnew(AudioStreamPlayer);
|
||||
_player->connect(SceneStringName(finished), callable_mp(this, &AudioStreamEditor::_on_finished));
|
||||
add_child(_player);
|
||||
|
||||
VBoxContainer *vbox = memnew(VBoxContainer);
|
||||
vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
||||
add_child(vbox);
|
||||
|
||||
_preview = memnew(ColorRect);
|
||||
_preview->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
_preview->connect(SceneStringName(draw), callable_mp(this, &AudioStreamEditor::_draw_preview));
|
||||
vbox->add_child(_preview);
|
||||
|
||||
_indicator = memnew(Control);
|
||||
_indicator->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
||||
_indicator->connect(SceneStringName(draw), callable_mp(this, &AudioStreamEditor::_draw_indicator));
|
||||
_indicator->connect(SceneStringName(gui_input), callable_mp(this, &AudioStreamEditor::_on_input_indicator));
|
||||
_preview->add_child(_indicator);
|
||||
|
||||
HBoxContainer *hbox = memnew(HBoxContainer);
|
||||
hbox->add_theme_constant_override("separation", 0);
|
||||
vbox->add_child(hbox);
|
||||
|
||||
_play_button = memnew(Button);
|
||||
hbox->add_child(_play_button);
|
||||
_play_button->set_flat(true);
|
||||
_play_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
|
||||
_play_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamEditor::_play));
|
||||
_play_button->set_shortcut(ED_SHORTCUT("audio_stream_editor/audio_preview_play_pause", TTRC("Audio Preview Play/Pause"), Key::SPACE));
|
||||
_play_button->set_accessibility_name(TTRC("Play"));
|
||||
|
||||
_stop_button = memnew(Button);
|
||||
hbox->add_child(_stop_button);
|
||||
_stop_button->set_flat(true);
|
||||
_stop_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
|
||||
_stop_button->connect(SceneStringName(pressed), callable_mp(this, &AudioStreamEditor::_stop));
|
||||
_stop_button->set_accessibility_name(TTRC("Stop"));
|
||||
|
||||
_current_label = memnew(Label);
|
||||
_current_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
|
||||
_current_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
_current_label->set_modulate(Color(1, 1, 1, 0.5));
|
||||
hbox->add_child(_current_label);
|
||||
|
||||
_duration_label = memnew(Label);
|
||||
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);
|
||||
editor->set_stream(Ref<AudioStream>(stream));
|
||||
|
||||
add_custom_control(editor);
|
||||
}
|
||||
|
||||
// AudioStreamEditorPlugin
|
||||
|
||||
AudioStreamEditorPlugin::AudioStreamEditorPlugin() {
|
||||
Ref<EditorInspectorPluginAudioStream> plugin;
|
||||
plugin.instantiate();
|
||||
add_inspector_plugin(plugin);
|
||||
}
|
90
editor/audio/audio_stream_editor_plugin.h
Normal file
90
editor/audio/audio_stream_editor_plugin.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_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/inspector/editor_inspector.h"
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
#include "scene/audio/audio_stream_player.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/color_rect.h"
|
||||
#include "scene/gui/label.h"
|
||||
|
||||
class AudioStreamEditor : public ColorRect {
|
||||
GDCLASS(AudioStreamEditor, ColorRect);
|
||||
|
||||
Ref<AudioStream> stream;
|
||||
|
||||
AudioStreamPlayer *_player = nullptr;
|
||||
ColorRect *_preview = nullptr;
|
||||
Control *_indicator = nullptr;
|
||||
Label *_current_label = nullptr;
|
||||
Label *_duration_label = nullptr;
|
||||
|
||||
Button *_play_button = nullptr;
|
||||
Button *_stop_button = nullptr;
|
||||
|
||||
float _current = 0;
|
||||
bool _dragging = false;
|
||||
bool _pausing = false;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _preview_changed(ObjectID p_which);
|
||||
void _play();
|
||||
void _stop();
|
||||
void _on_finished();
|
||||
void _draw_preview();
|
||||
void _draw_indicator();
|
||||
void _on_input_indicator(Ref<InputEvent> p_event);
|
||||
void _seek_to(real_t p_x);
|
||||
void _stream_changed();
|
||||
|
||||
public:
|
||||
void set_stream(const Ref<AudioStream> &p_stream);
|
||||
|
||||
AudioStreamEditor();
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
AudioStreamEditorPlugin();
|
||||
};
|
255
editor/audio/audio_stream_preview.cpp
Normal file
255
editor/audio/audio_stream_preview.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_preview.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_preview.h"
|
||||
|
||||
/////////////////////
|
||||
|
||||
float AudioStreamPreview::get_length() const {
|
||||
return length;
|
||||
}
|
||||
|
||||
float AudioStreamPreview::get_max(float p_time, float p_time_next) const {
|
||||
if (length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max = preview.size() / 2;
|
||||
if (max == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int time_from = p_time / length * max;
|
||||
int time_to = p_time_next / length * max;
|
||||
time_from = CLAMP(time_from, 0, max - 1);
|
||||
time_to = CLAMP(time_to, 0, max - 1);
|
||||
|
||||
if (time_to <= time_from) {
|
||||
time_to = time_from + 1;
|
||||
}
|
||||
|
||||
uint8_t vmax = 0;
|
||||
|
||||
for (int i = time_from; i < time_to; i++) {
|
||||
uint8_t v = preview[i * 2 + 1];
|
||||
if (i == 0 || v > vmax) {
|
||||
vmax = v;
|
||||
}
|
||||
}
|
||||
|
||||
return (vmax / 255.0) * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
float AudioStreamPreview::get_min(float p_time, float p_time_next) const {
|
||||
if (length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max = preview.size() / 2;
|
||||
if (max == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int time_from = p_time / length * max;
|
||||
int time_to = p_time_next / length * max;
|
||||
time_from = CLAMP(time_from, 0, max - 1);
|
||||
time_to = CLAMP(time_to, 0, max - 1);
|
||||
|
||||
if (time_to <= time_from) {
|
||||
time_to = time_from + 1;
|
||||
}
|
||||
|
||||
uint8_t vmin = 255;
|
||||
|
||||
for (int i = time_from; i < time_to; i++) {
|
||||
uint8_t v = preview[i * 2];
|
||||
if (i == 0 || v < vmin) {
|
||||
vmin = v;
|
||||
}
|
||||
}
|
||||
|
||||
return (vmin / 255.0) * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
AudioStreamPreview::AudioStreamPreview() {
|
||||
length = 0;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void AudioStreamPreviewGenerator::_update_emit(ObjectID p_id) {
|
||||
emit_signal(SNAME("preview_updated"), p_id);
|
||||
}
|
||||
|
||||
void AudioStreamPreviewGenerator::_preview_thread(void *p_preview) {
|
||||
Thread::set_name("AudioStreamPreviewGenerator");
|
||||
|
||||
Preview *preview = static_cast<Preview *>(p_preview);
|
||||
|
||||
float muxbuff_chunk_s = 0.25;
|
||||
|
||||
int mixbuff_chunk_frames = AudioServer::get_singleton()->get_mix_rate() * muxbuff_chunk_s;
|
||||
|
||||
Vector<AudioFrame> mix_chunk;
|
||||
mix_chunk.resize(mixbuff_chunk_frames);
|
||||
|
||||
int frames_total = AudioServer::get_singleton()->get_mix_rate() * preview->preview->length;
|
||||
int frames_todo = frames_total;
|
||||
|
||||
preview->playback->start();
|
||||
|
||||
while (frames_todo) {
|
||||
int ofs_write = uint64_t(frames_total - frames_todo) * uint64_t(preview->preview->preview.size() / 2) / uint64_t(frames_total);
|
||||
int to_read = MIN(frames_todo, mixbuff_chunk_frames);
|
||||
int to_write = uint64_t(to_read) * uint64_t(preview->preview->preview.size() / 2) / uint64_t(frames_total);
|
||||
to_write = MIN(to_write, (preview->preview->preview.size() / 2) - ofs_write);
|
||||
|
||||
preview->playback->mix(mix_chunk.ptrw(), 1.0, to_read);
|
||||
|
||||
for (int i = 0; i < to_write; i++) {
|
||||
float max = -1000;
|
||||
float min = 1000;
|
||||
int from = uint64_t(i) * to_read / to_write;
|
||||
int to = (uint64_t(i) + 1) * to_read / to_write;
|
||||
to = MIN(to, to_read);
|
||||
from = MIN(from, to_read - 1);
|
||||
if (to == from) {
|
||||
to = from + 1;
|
||||
}
|
||||
|
||||
for (int j = from; j < to; j++) {
|
||||
max = MAX(max, mix_chunk[j].left);
|
||||
max = MAX(max, mix_chunk[j].right);
|
||||
|
||||
min = MIN(min, mix_chunk[j].left);
|
||||
min = MIN(min, mix_chunk[j].right);
|
||||
}
|
||||
|
||||
uint8_t pfrom = CLAMP((min * 0.5 + 0.5) * 255, 0, 255);
|
||||
uint8_t pto = CLAMP((max * 0.5 + 0.5) * 255, 0, 255);
|
||||
|
||||
preview->preview->preview.write[(ofs_write + i) * 2 + 0] = pfrom;
|
||||
preview->preview->preview.write[(ofs_write + i) * 2 + 1] = pto;
|
||||
}
|
||||
|
||||
frames_todo -= to_read;
|
||||
callable_mp(singleton, &AudioStreamPreviewGenerator::_update_emit).call_deferred(preview->id);
|
||||
}
|
||||
|
||||
preview->preview->version++;
|
||||
|
||||
preview->playback->stop();
|
||||
|
||||
preview->generating.clear();
|
||||
}
|
||||
|
||||
Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<AudioStream> &p_stream) {
|
||||
ERR_FAIL_COND_V(p_stream.is_null(), Ref<AudioStreamPreview>());
|
||||
|
||||
if (previews.has(p_stream->get_instance_id())) {
|
||||
return previews[p_stream->get_instance_id()].preview;
|
||||
}
|
||||
|
||||
//no preview exists
|
||||
|
||||
previews[p_stream->get_instance_id()] = Preview();
|
||||
|
||||
Preview *preview = &previews[p_stream->get_instance_id()];
|
||||
preview->base_stream = p_stream;
|
||||
preview->playback = preview->base_stream->instantiate_playback();
|
||||
preview->generating.set();
|
||||
preview->id = p_stream->get_instance_id();
|
||||
|
||||
float len_s = preview->base_stream->get_length();
|
||||
if (len_s == 0) {
|
||||
len_s = 60 * 5; //five minutes
|
||||
}
|
||||
|
||||
int frames = AudioServer::get_singleton()->get_mix_rate() * len_s;
|
||||
|
||||
Vector<uint8_t> maxmin;
|
||||
int pw = frames / 20;
|
||||
maxmin.resize(pw * 2);
|
||||
{
|
||||
uint8_t *ptr = maxmin.ptrw();
|
||||
for (int i = 0; i < pw * 2; i++) {
|
||||
ptr[i] = 127;
|
||||
}
|
||||
}
|
||||
|
||||
preview->preview.instantiate();
|
||||
preview->preview->preview = maxmin;
|
||||
preview->preview->length = len_s;
|
||||
|
||||
if (preview->playback.is_valid()) {
|
||||
preview->thread = memnew(Thread);
|
||||
preview->thread->start(_preview_thread, preview);
|
||||
}
|
||||
|
||||
return preview->preview;
|
||||
}
|
||||
|
||||
void AudioStreamPreviewGenerator::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("generate_preview", "stream"), &AudioStreamPreviewGenerator::generate_preview);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("preview_updated", PropertyInfo(Variant::INT, "obj_id")));
|
||||
}
|
||||
|
||||
AudioStreamPreviewGenerator *AudioStreamPreviewGenerator::singleton = nullptr;
|
||||
|
||||
void AudioStreamPreviewGenerator::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_PROCESS: {
|
||||
List<ObjectID> to_erase;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (to_erase.front()) {
|
||||
previews.erase(to_erase.front()->get());
|
||||
to_erase.pop_front();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
AudioStreamPreviewGenerator::AudioStreamPreviewGenerator() {
|
||||
singleton = this;
|
||||
set_process(true);
|
||||
}
|
105
editor/audio/audio_stream_preview.h
Normal file
105
editor/audio/audio_stream_preview.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_preview.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 "core/os/thread.h"
|
||||
#include "core/templates/safe_refcount.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "servers/audio/audio_stream.h"
|
||||
|
||||
class AudioStreamPreview : public RefCounted {
|
||||
GDCLASS(AudioStreamPreview, RefCounted);
|
||||
friend class AudioStream;
|
||||
Vector<uint8_t> preview;
|
||||
float length;
|
||||
|
||||
friend class AudioStreamPreviewGenerator;
|
||||
uint64_t version = 1;
|
||||
|
||||
public:
|
||||
uint64_t get_version() const { return version; }
|
||||
float get_length() const;
|
||||
float get_max(float p_time, float p_time_next) const;
|
||||
float get_min(float p_time, float p_time_next) const;
|
||||
|
||||
AudioStreamPreview();
|
||||
};
|
||||
|
||||
class AudioStreamPreviewGenerator : public Node {
|
||||
GDCLASS(AudioStreamPreviewGenerator, Node);
|
||||
|
||||
static AudioStreamPreviewGenerator *singleton;
|
||||
|
||||
struct Preview {
|
||||
Ref<AudioStreamPreview> preview;
|
||||
Ref<AudioStream> base_stream;
|
||||
Ref<AudioStreamPlayback> playback;
|
||||
SafeFlag generating;
|
||||
ObjectID id;
|
||||
Thread *thread = nullptr;
|
||||
|
||||
// Needed for the bookkeeping of the Map
|
||||
void operator=(const Preview &p_rhs) {
|
||||
preview = p_rhs.preview;
|
||||
base_stream = p_rhs.base_stream;
|
||||
playback = p_rhs.playback;
|
||||
generating.set_to(generating.is_set());
|
||||
id = p_rhs.id;
|
||||
thread = p_rhs.thread;
|
||||
}
|
||||
Preview(const Preview &p_rhs) {
|
||||
preview = p_rhs.preview;
|
||||
base_stream = p_rhs.base_stream;
|
||||
playback = p_rhs.playback;
|
||||
generating.set_to(generating.is_set());
|
||||
id = p_rhs.id;
|
||||
thread = p_rhs.thread;
|
||||
}
|
||||
Preview() {}
|
||||
};
|
||||
|
||||
HashMap<ObjectID, Preview> previews;
|
||||
|
||||
static void _preview_thread(void *p_preview);
|
||||
|
||||
void _update_emit(ObjectID p_id);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static AudioStreamPreviewGenerator *get_singleton() { return singleton; }
|
||||
|
||||
Ref<AudioStreamPreview> generate_preview(const Ref<AudioStream> &p_stream);
|
||||
|
||||
AudioStreamPreviewGenerator();
|
||||
};
|
121
editor/audio/audio_stream_randomizer_editor_plugin.cpp
Normal file
121
editor/audio/audio_stream_randomizer_editor_plugin.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_randomizer_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_randomizer_editor_plugin.h"
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_undo_redo_manager.h"
|
||||
#include "servers/audio/audio_stream.h"
|
||||
|
||||
void AudioStreamRandomizerEditorPlugin::edit(Object *p_object) {
|
||||
}
|
||||
|
||||
bool AudioStreamRandomizerEditorPlugin::handles(Object *p_object) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AudioStreamRandomizerEditorPlugin::make_visible(bool p_visible) {
|
||||
}
|
||||
|
||||
void AudioStreamRandomizerEditorPlugin::_move_stream_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos) {
|
||||
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
|
||||
ERR_FAIL_NULL(undo_redo_man);
|
||||
|
||||
AudioStreamRandomizer *randomizer = Object::cast_to<AudioStreamRandomizer>(p_edited);
|
||||
if (!randomizer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the array indices to save.
|
||||
int begin = 0;
|
||||
int end;
|
||||
if (p_array_prefix == "stream_") {
|
||||
end = randomizer->get_streams_count();
|
||||
} else {
|
||||
ERR_FAIL_MSG("Invalid array prefix for AudioStreamRandomizer.");
|
||||
}
|
||||
if (p_from_index < 0) {
|
||||
// Adding new.
|
||||
if (p_to_pos >= 0) {
|
||||
begin = p_to_pos;
|
||||
} else {
|
||||
end = 0; // Nothing to save when adding at the end.
|
||||
}
|
||||
} else if (p_to_pos < 0) {
|
||||
// Removing.
|
||||
begin = p_from_index;
|
||||
} else {
|
||||
// Moving.
|
||||
begin = MIN(p_from_index, p_to_pos);
|
||||
end = MIN(MAX(p_from_index, p_to_pos) + 1, end);
|
||||
}
|
||||
|
||||
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
|
||||
// Save layers' properties.
|
||||
if (p_from_index < 0) {
|
||||
undo_redo_man->add_undo_method(randomizer, "remove_stream", p_to_pos < 0 ? randomizer->get_streams_count() : p_to_pos);
|
||||
} else if (p_to_pos < 0) {
|
||||
undo_redo_man->add_undo_method(randomizer, "add_stream", p_from_index, Ref<AudioStream>());
|
||||
}
|
||||
|
||||
List<PropertyInfo> properties;
|
||||
randomizer->get_property_list(&properties);
|
||||
for (PropertyInfo pi : properties) {
|
||||
if (pi.name.begins_with(p_array_prefix)) {
|
||||
String str = pi.name.trim_prefix(p_array_prefix);
|
||||
int to_char_index = 0;
|
||||
while (to_char_index < str.length()) {
|
||||
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
|
||||
break;
|
||||
}
|
||||
to_char_index++;
|
||||
}
|
||||
if (to_char_index > 0) {
|
||||
int array_index = str.left(to_char_index).to_int();
|
||||
if (array_index >= begin && array_index < end) {
|
||||
ADD_UNDO(randomizer, pi.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef ADD_UNDO
|
||||
|
||||
if (p_from_index < 0) {
|
||||
undo_redo_man->add_do_method(randomizer, "add_stream", p_to_pos, Ref<AudioStream>());
|
||||
} else if (p_to_pos < 0) {
|
||||
undo_redo_man->add_do_method(randomizer, "remove_stream", p_from_index);
|
||||
} else {
|
||||
undo_redo_man->add_do_method(randomizer, "move_stream", p_from_index, p_to_pos);
|
||||
}
|
||||
}
|
||||
|
||||
AudioStreamRandomizerEditorPlugin::AudioStreamRandomizerEditorPlugin() {
|
||||
EditorNode::get_editor_data().add_move_array_element_function(SNAME("AudioStreamRandomizer"), callable_mp(this, &AudioStreamRandomizerEditorPlugin::_move_stream_array_element));
|
||||
}
|
49
editor/audio/audio_stream_randomizer_editor_plugin.h
Normal file
49
editor/audio/audio_stream_randomizer_editor_plugin.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**************************************************************************/
|
||||
/* audio_stream_randomizer_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/plugins/editor_plugin.h"
|
||||
|
||||
class AudioStreamRandomizerEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(AudioStreamRandomizerEditorPlugin, EditorPlugin);
|
||||
|
||||
private:
|
||||
void _move_stream_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos);
|
||||
|
||||
public:
|
||||
virtual String get_plugin_name() const override { return "AudioStreamRandomizer"; }
|
||||
bool has_main_screen() const override { return false; }
|
||||
virtual void edit(Object *p_object) override;
|
||||
virtual bool handles(Object *p_object) const override;
|
||||
virtual void make_visible(bool p_visible) override;
|
||||
|
||||
AudioStreamRandomizerEditorPlugin();
|
||||
};
|
1494
editor/audio/editor_audio_buses.cpp
Normal file
1494
editor/audio/editor_audio_buses.cpp
Normal file
File diff suppressed because it is too large
Load Diff
277
editor/audio/editor_audio_buses.h
Normal file
277
editor/audio/editor_audio_buses.h
Normal file
@@ -0,0 +1,277 @@
|
||||
/**************************************************************************/
|
||||
/* editor_audio_buses.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/plugins/editor_plugin.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/panel.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
#include "scene/gui/scroll_container.h"
|
||||
#include "scene/gui/slider.h"
|
||||
#include "scene/gui/texture_progress_bar.h"
|
||||
#include "scene/gui/texture_rect.h"
|
||||
#include "scene/gui/tree.h"
|
||||
|
||||
class EditorAudioBuses;
|
||||
class EditorFileDialog;
|
||||
|
||||
class EditorAudioBus : public PanelContainer {
|
||||
GDCLASS(EditorAudioBus, PanelContainer);
|
||||
|
||||
Ref<Texture2D> disabled_vu;
|
||||
LineEdit *track_name = nullptr;
|
||||
MenuButton *bus_options = nullptr;
|
||||
VSlider *slider = nullptr;
|
||||
|
||||
int cc;
|
||||
static const int CHANNELS_MAX = 4;
|
||||
|
||||
struct {
|
||||
bool prev_active = false;
|
||||
|
||||
float peak_l = 0;
|
||||
float peak_r = 0;
|
||||
|
||||
TextureProgressBar *vu_l = nullptr;
|
||||
TextureProgressBar *vu_r = nullptr;
|
||||
} channel[CHANNELS_MAX];
|
||||
|
||||
OptionButton *send = nullptr;
|
||||
|
||||
PopupMenu *effect_options = nullptr;
|
||||
PopupMenu *bus_popup = nullptr;
|
||||
PopupMenu *delete_effect_popup = nullptr;
|
||||
|
||||
Panel *audio_value_preview_box = nullptr;
|
||||
Label *audio_value_preview_label = nullptr;
|
||||
Timer *preview_timer = nullptr;
|
||||
|
||||
Button *solo = nullptr;
|
||||
Button *mute = nullptr;
|
||||
Button *bypass = nullptr;
|
||||
|
||||
Tree *effects = nullptr;
|
||||
|
||||
bool updating_bus = false;
|
||||
bool is_master;
|
||||
mutable bool hovering_drop = false;
|
||||
|
||||
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
||||
void _effects_gui_input(Ref<InputEvent> p_event);
|
||||
void _bus_popup_pressed(int p_option);
|
||||
|
||||
void _name_changed(const String &p_new_name);
|
||||
void _name_focus_exit() { _name_changed(track_name->get_text()); }
|
||||
void _volume_changed(float p_normalized);
|
||||
float _normalized_volume_to_scaled_db(float normalized);
|
||||
float _scaled_db_to_normalized_volume(float db);
|
||||
void _show_value(float slider_value);
|
||||
void _hide_value_preview();
|
||||
void _solo_toggled();
|
||||
void _mute_toggled();
|
||||
void _bypass_toggled();
|
||||
void _send_selected(int p_which);
|
||||
void _effect_edited();
|
||||
void _effect_add(int p_which);
|
||||
void _effect_selected();
|
||||
void _delete_effect_pressed(int p_option);
|
||||
void _effect_rmb(const Vector2 &p_pos, MouseButton p_button);
|
||||
void _update_visible_channels();
|
||||
|
||||
virtual Variant get_drag_data(const Point2 &p_point) override;
|
||||
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
|
||||
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
|
||||
|
||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
friend class EditorAudioBuses;
|
||||
|
||||
EditorAudioBuses *buses = nullptr;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
void update_bus();
|
||||
void update_send();
|
||||
|
||||
EditorAudioBus(EditorAudioBuses *p_buses = nullptr, bool p_is_master = false);
|
||||
};
|
||||
|
||||
class EditorAudioBusDrop : public Control {
|
||||
GDCLASS(EditorAudioBusDrop, Control);
|
||||
|
||||
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
|
||||
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
|
||||
|
||||
mutable bool hovering_drop = false;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
};
|
||||
|
||||
class EditorAudioBuses : public VBoxContainer {
|
||||
GDCLASS(EditorAudioBuses, VBoxContainer);
|
||||
|
||||
HBoxContainer *top_hb = nullptr;
|
||||
|
||||
ScrollContainer *bus_scroll = nullptr;
|
||||
HBoxContainer *bus_hb = nullptr;
|
||||
|
||||
EditorAudioBusDrop *drop_end = nullptr;
|
||||
|
||||
Label *file = nullptr;
|
||||
|
||||
Button *add = nullptr;
|
||||
Button *load = nullptr;
|
||||
Button *save_as = nullptr;
|
||||
Button *_default = nullptr;
|
||||
Button *_new = nullptr;
|
||||
|
||||
Timer *save_timer = nullptr;
|
||||
String edited_path;
|
||||
|
||||
void _rebuild_buses();
|
||||
void _update_bus(int p_index);
|
||||
void _update_sends();
|
||||
|
||||
void _add_bus();
|
||||
void _delete_bus(Object *p_which);
|
||||
void _duplicate_bus(int p_which);
|
||||
void _reset_bus_volume(Object *p_which);
|
||||
|
||||
void _request_drop_end();
|
||||
void _drop_at_index(int p_bus, int p_index);
|
||||
|
||||
void _server_save();
|
||||
|
||||
void _select_layout();
|
||||
void _load_layout();
|
||||
void _save_as_layout();
|
||||
void _load_default_layout();
|
||||
void _new_layout();
|
||||
|
||||
EditorFileDialog *file_dialog = nullptr;
|
||||
bool new_layout = false;
|
||||
|
||||
void _file_dialog_callback(const String &p_string);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
void open_layout(const String &p_path);
|
||||
|
||||
static EditorAudioBuses *register_editor();
|
||||
|
||||
EditorAudioBuses();
|
||||
};
|
||||
|
||||
class EditorAudioMeterNotches : public Control {
|
||||
GDCLASS(EditorAudioMeterNotches, Control);
|
||||
|
||||
private:
|
||||
struct AudioNotch {
|
||||
float relative_position = 0;
|
||||
float db_value = 0;
|
||||
bool render_db_value = false;
|
||||
|
||||
_FORCE_INLINE_ AudioNotch(float r_pos, float db_v, bool rndr_val) {
|
||||
relative_position = r_pos;
|
||||
db_value = db_v;
|
||||
render_db_value = rndr_val;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ AudioNotch(const AudioNotch &n) {
|
||||
relative_position = n.relative_position;
|
||||
db_value = n.db_value;
|
||||
render_db_value = n.render_db_value;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void operator=(const EditorAudioMeterNotches::AudioNotch &n) {
|
||||
relative_position = n.relative_position;
|
||||
db_value = n.db_value;
|
||||
render_db_value = n.render_db_value;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ AudioNotch() {}
|
||||
};
|
||||
|
||||
List<AudioNotch> notches;
|
||||
|
||||
struct ThemeCache {
|
||||
Color notch_color;
|
||||
|
||||
Ref<Font> font;
|
||||
int font_size = 0;
|
||||
} theme_cache;
|
||||
|
||||
public:
|
||||
const float line_length = 5.0f;
|
||||
const float label_space = 2.0f;
|
||||
const float btm_padding = 9.0f;
|
||||
const float top_padding = 5.0f;
|
||||
|
||||
void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);
|
||||
Size2 get_minimum_size() const override;
|
||||
|
||||
private:
|
||||
virtual void _update_theme_item_cache() override;
|
||||
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
void _draw_audio_notches();
|
||||
};
|
||||
|
||||
class AudioBusesEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(AudioBusesEditorPlugin, EditorPlugin);
|
||||
|
||||
EditorAudioBuses *audio_bus_editor = nullptr;
|
||||
|
||||
public:
|
||||
virtual String get_plugin_name() const override { return "SampleLibrary"; }
|
||||
bool has_main_screen() const override { return false; }
|
||||
virtual void edit(Object *p_node) override;
|
||||
virtual bool handles(Object *p_node) const override;
|
||||
virtual void make_visible(bool p_visible) override;
|
||||
|
||||
AudioBusesEditorPlugin(EditorAudioBuses *p_node);
|
||||
};
|
Reference in New Issue
Block a user