载入中...
搜索中...
未找到
AudioEditorModule.cpp
浏览该文件的文档.
2#include <cstdint>
3#include <simplesquirrel/simplesquirrel.hpp>
4#include <stdexcept>
5#include <string>
6#include <string_view>
7#include <vector>
14#include "common/Capability.h"
20
21// AudioEditorModule.cpp
23
25public:
26 std::vector<std::string_view> types() const override { return {"audio-source", "audio-mixer", "audio-effects"}; }
27
29 const editor::EditorValue::Object&) override {
31 if (type == "audio-source") {
32 owned.target = std::make_unique<audio_editing::AudioSourceTarget>(target.value());
33 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
34 }
35 if (type == "audio-mixer") {
36 owned.target = std::make_unique<audio_editing::AudioMixerTarget>(target.value());
37 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
38 }
39 owned.target = std::make_unique<audio_editing::AudioEffectChainTarget>(target.value());
40 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
41 }
42};
43
45
47 auto* registry = eve::cap::query<editing::IEditingCommandRegistry>();
48 if (!registry || !audio_editing::registerEditingCommands(*registry).ok())
49 throw std::runtime_error("Failed to register audio editing commands");
50 eve::cap::addListener<editor::IEditorAutomationTargetFactory>(factory_.get());
51}
52
54 eve::cap::removeListener<editor::IEditorAutomationTargetFactory>(factory_.get());
55 if (auto* registry = eve::cap::query<editing::IEditingCommandRegistry>())
56 registry->unregisterOwner("audio_editing").ignore("audio editor adapter shutdown");
57}
58
59void AudioEditorModule::expose(ssq::Table& table) {
60 auto module = table.addClass(name, AudioEditorModule::create, false);
62}
63void AudioEditorModule::expose(ssq::Class&) {}
64
65} // namespace eve::audio_editor
66
67// AudioSourceEditorScriptBindings.cpp
68namespace eve::audio_editor {
69namespace {
70
71constexpr const char* kBindingSource = "editor.audio.source.squirrel";
72
73class ScriptAudioSourceEditor {
74public:
75 explicit ScriptAudioSourceEditor(std::string targetId) : editor_(std::move(targetId)) {}
76
77 editor::WorkspacePresentation& presentation() noexcept { return presentation_; }
78
79 AudioSourceEditor& editor() noexcept { return editor_; }
80 const AudioSourceEditor& editor() const noexcept { return editor_; }
81
82private:
83 AudioSourceEditor editor_;
84 editor::WorkspacePresentation presentation_;
85};
86
87const char* transportLabel(audio_editing::AudioTransportState state) {
88 switch (state) {
92 }
93 return "stopped";
94}
95
96} // namespace
97
98void exposeAudioSourceEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
99 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
100 auto sourceEditor = editor::addScriptClass<ScriptAudioSourceEditor>(table, "AudioSourceEditor");
101
102 editor::exposeWorkspacePresentation<ScriptAudioSourceEditor, AudioSourcePresentation>(sourceEditor,
103 table.getHandle());
104 editor::registerEditorWorkspace<ScriptAudioSourceEditor>(sourceEditor, bind,
105 "audio source editor and workspace must not be null");
106 sourceEditor.addFunc("setViewportWidth", [bind](ScriptAudioSourceEditor* self, float width) {
107 return bind.checked(self, "audio source editor must not be null",
108 [&] { return self->editor().setViewportWidth(width); });
109 });
110 sourceEditor.addFunc("seekX", [bind](ScriptAudioSourceEditor* self, float x) {
111 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().seekX(x); });
112 });
113 sourceEditor.addFunc("seekSeconds", [bind](ScriptAudioSourceEditor* self, float seconds) {
114 return bind.checked(self, "audio source editor must not be null",
115 [&] { return self->editor().seekSeconds(static_cast<double>(seconds)); });
116 });
117 sourceEditor.addFunc("setFloat", [bind](ScriptAudioSourceEditor* self, const std::string& path, float value) {
118 return bind.checked(self, "audio source editor must not be null", [&] {
119 return self->editor().setProperty(path, audio_editing::EditorValue(static_cast<double>(value)));
120 });
121 });
122 sourceEditor.addFunc("setBool", [bind](ScriptAudioSourceEditor* self, const std::string& path, bool value) {
123 return bind.checked(self, "audio source editor must not be null",
124 [&] { return self->editor().setProperty(path, audio_editing::EditorValue(value)); });
125 });
126 editor::registerEditorHistory<ScriptAudioSourceEditor>(sourceEditor, bind, "audio source editor must not be null");
127 sourceEditor.addFunc("play", [bind](ScriptAudioSourceEditor* self) {
128 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().play(); });
129 });
130 sourceEditor.addFunc("pause", [bind](ScriptAudioSourceEditor* self) {
131 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().pause(); });
132 });
133 sourceEditor.addFunc("stop", [bind](ScriptAudioSourceEditor* self) {
134 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().stop(); });
135 });
136 sourceEditor.addFunc("update", [bind](ScriptAudioSourceEditor* self, float deltaSeconds) {
137 if (!self) return bind.fail(DiagnosticCode::InvalidArgument, "audio source editor must not be null");
138 auto result = self->editor().update(static_cast<double>(deltaSeconds));
139 return editor::project(bind.vm(), result, Value(result.ok() ? result.value().position : 0.0));
140 });
141 sourceEditor.addFunc("attachLiveAudition", [bind](ScriptAudioSourceEditor* self) {
142 return bind.checked(self, "audio source editor must not be null",
143 [&] { return self->editor().attachLiveAudition(); });
144 });
145 sourceEditor.addFunc("isPlaying", [](ScriptAudioSourceEditor* self) { return self && self->editor().isPlaying(); });
146 sourceEditor.addFunc("getDuration", [](ScriptAudioSourceEditor* self) {
147 return self ? static_cast<float>(self->editor().duration()) : 0.0f;
148 });
149 sourceEditor.addFunc("getPlayhead", [](ScriptAudioSourceEditor* self) {
150 return self ? static_cast<float>(self->editor().playhead()) : 0.0f;
151 });
152 sourceEditor.addFunc("getLayoutWidth",
153 [](ScriptAudioSourceEditor* self) { return self ? self->editor().layoutWidth() : 0.0f; });
154 sourceEditor.addFunc("getPlayheadX",
155 [](ScriptAudioSourceEditor* self) { return self ? self->editor().playheadX() : 0.0f; });
156 sourceEditor.addFunc("getLoopStartX",
157 [](ScriptAudioSourceEditor* self) { return self ? self->editor().loopStartX() : 0.0f; });
158 sourceEditor.addFunc("getLoopEndX",
159 [](ScriptAudioSourceEditor* self) { return self ? self->editor().loopEndX() : 0.0f; });
160 sourceEditor.addFunc("getBucketCount",
161 [](ScriptAudioSourceEditor* self) { return self ? self->editor().bucketCount() : 0; });
162 sourceEditor.addFunc("getBucketMin", [](ScriptAudioSourceEditor* self, int index) {
163 if (!self) return 0.0f;
164 const auto* bucket = self->editor().bucket(index);
165 return bucket ? bucket->minimum : 0.0f;
166 });
167 sourceEditor.addFunc("getBucketMax", [](ScriptAudioSourceEditor* self, int index) {
168 if (!self) return 0.0f;
169 const auto* bucket = self->editor().bucket(index);
170 return bucket ? bucket->maximum : 0.0f;
171 });
172 sourceEditor.addFunc("getTransportState", [](ScriptAudioSourceEditor* self) {
173 return std::string(self ? transportLabel(self->editor().transport().state) : "stopped");
174 });
175 sourceEditor.addFunc("getFloat", [](ScriptAudioSourceEditor* self, const std::string& path) {
176 if (!self) return 0.0f;
177 auto value = self->editor().read(path);
178 if (const auto* real = value.value.getIf<double>()) return static_cast<float>(*real);
179 if (const auto* integer = value.value.getIf<std::int64_t>()) return static_cast<float>(*integer);
180 return 0.0f;
181 });
182 sourceEditor.addFunc("getBool", [](ScriptAudioSourceEditor* self, const std::string& path) {
183 if (!self) return false;
184 auto value = self->editor().read(path);
185 const auto* flag = value.value.getIf<bool>();
186 return flag ? *flag : false;
187 });
188 sourceEditor.addFunc("getString", [](ScriptAudioSourceEditor* self, const std::string& path) {
189 if (!self) return std::string{};
190 auto value = self->editor().read(path);
191 const auto* text = value.value.getIf<std::string>();
192 return text ? *text : std::string{};
193 });
194
195 editor::registerEditorOwnedCreate<ScriptAudioSourceEditor, AudioEditorModule>(
196 moduleClass, bind, "audio source target id must not be empty");
197}
198
199} // namespace eve::audio_editor
double x
LogicalId target
ActiveSource owned
Squirrel adapter for the audio source editor.
UI-neutral audio source editor: workspace, waveform, audition, undo.
std::uint32_t width
Poco::JSON::Object::Ptr result
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::unique_ptr< DeformMeshPresentation > presentation
std::string path
Definition PlayHost.cpp:111
std::uint32_t targetId
const eve::script::BindingContractRegistry & registry
Object::Ptr value
std::string text
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::vector< std::string_view > types() const override
Stable target type names this factory accepts.
editor::Result< editor::AutomationOwnedTarget > create(const editor::TargetId &target, std::string_view type, const editor::EditorValue::Object &) override
Create a domain target from an automation request. @ownership Success transfers the target and any su...
Composition adapter that contributes audio editing commands, automation targets, and the script-owned...
~AudioEditorModule() override
Audio editor module.
Deterministic owning value tree shared by authoring hosts.
std::map< std::string, Value > Object
Multi-provider extension point for domain-specific automation target creation.
Editor facade binder: common script::BindContext plus history/owned-create helpers.
AudioTransportState
Playback state exposed to audio and dialogue editor presenters.
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry &registry)
Register audio-owned planned commands with a generic editing host.
void exposeAudioSourceEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned AudioSourceEditor factory on AudioEditorModule.
ssq::Table project(HSQUIRRELVM vm, const eve::Result< void > &result)
Project a completed editing result that has no payload.
Target plus optional borrowed-dependency owner returned by an automation factory.
std::unique_ptr< IEditableTarget > target
uint32_t bucket