载入中...
搜索中...
未找到
AudioSourceEditorScriptBindings.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <cstdint>
10#include <string>
12
13namespace eve::audio_editor {
14namespace {
15
16constexpr const char* kBindingSource = "editor.audio.source.squirrel";
17
18class ScriptAudioSourceEditor {
19public:
20 explicit ScriptAudioSourceEditor(std::string targetId) : editor_(std::move(targetId)) {}
21
22 AudioSourceEditor& editor() noexcept { return editor_; }
23 const AudioSourceEditor& editor() const noexcept { return editor_; }
24
25private:
26 AudioSourceEditor editor_;
27};
28
29const char* transportLabel(audio_editing::AudioTransportState state) {
30 switch (state) {
34 }
35 return "stopped";
36}
37
38} // namespace
39
40void exposeAudioSourceEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
41 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
42 auto sourceEditor = editor::addScriptClass<ScriptAudioSourceEditor>(table, "AudioSourceEditor");
43
44 editor::registerEditorWorkspace<ScriptAudioSourceEditor>(sourceEditor, bind,
45 "audio source editor and workspace must not be null");
46 sourceEditor.addFunc("setViewportWidth", [bind](ScriptAudioSourceEditor* self, float width) {
47 return bind.checked(self, "audio source editor must not be null",
48 [&] { return self->editor().setViewportWidth(width); });
49 });
50 sourceEditor.addFunc("seekX", [bind](ScriptAudioSourceEditor* self, float x) {
51 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().seekX(x); });
52 });
53 sourceEditor.addFunc("seekSeconds", [bind](ScriptAudioSourceEditor* self, float seconds) {
54 return bind.checked(self, "audio source editor must not be null",
55 [&] { return self->editor().seekSeconds(static_cast<double>(seconds)); });
56 });
57 sourceEditor.addFunc("setFloat", [bind](ScriptAudioSourceEditor* self, const std::string& path, float value) {
58 return bind.checked(self, "audio source editor must not be null", [&] {
59 return self->editor().setProperty(path, audio_editing::EditorValue(static_cast<double>(value)));
60 });
61 });
62 sourceEditor.addFunc("setBool", [bind](ScriptAudioSourceEditor* self, const std::string& path, bool value) {
63 return bind.checked(self, "audio source editor must not be null",
64 [&] { return self->editor().setProperty(path, audio_editing::EditorValue(value)); });
65 });
66 editor::registerEditorHistory<ScriptAudioSourceEditor>(sourceEditor, bind,
67 "audio source editor must not be null");
68 sourceEditor.addFunc("play", [bind](ScriptAudioSourceEditor* self) {
69 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().play(); });
70 });
71 sourceEditor.addFunc("pause", [bind](ScriptAudioSourceEditor* self) {
72 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().pause(); });
73 });
74 sourceEditor.addFunc("stop", [bind](ScriptAudioSourceEditor* self) {
75 return bind.checked(self, "audio source editor must not be null", [&] { return self->editor().stop(); });
76 });
77 sourceEditor.addFunc("update", [bind](ScriptAudioSourceEditor* self, float deltaSeconds) {
78 if (!self) return bind.fail(DiagnosticCode::InvalidArgument, "audio source editor must not be null");
79 auto result = self->editor().update(static_cast<double>(deltaSeconds));
80 return editor::project(bind.vm(), result, Value(result.ok() ? result.value().position : 0.0));
81 });
82 sourceEditor.addFunc("attachLiveAudition", [bind](ScriptAudioSourceEditor* self) {
83 return bind.checked(self, "audio source editor must not be null",
84 [&] { return self->editor().attachLiveAudition(); });
85 });
86 sourceEditor.addFunc("isPlaying", [](ScriptAudioSourceEditor* self) { return self && self->editor().isPlaying(); });
87 sourceEditor.addFunc("getDuration", [](ScriptAudioSourceEditor* self) {
88 return self ? static_cast<float>(self->editor().duration()) : 0.0f;
89 });
90 sourceEditor.addFunc("getPlayhead", [](ScriptAudioSourceEditor* self) {
91 return self ? static_cast<float>(self->editor().playhead()) : 0.0f;
92 });
93 sourceEditor.addFunc("getLayoutWidth", [](ScriptAudioSourceEditor* self) {
94 return self ? self->editor().layoutWidth() : 0.0f;
95 });
96 sourceEditor.addFunc("getPlayheadX", [](ScriptAudioSourceEditor* self) {
97 return self ? self->editor().playheadX() : 0.0f;
98 });
99 sourceEditor.addFunc("getLoopStartX", [](ScriptAudioSourceEditor* self) {
100 return self ? self->editor().loopStartX() : 0.0f;
101 });
102 sourceEditor.addFunc("getLoopEndX", [](ScriptAudioSourceEditor* self) {
103 return self ? self->editor().loopEndX() : 0.0f;
104 });
105 sourceEditor.addFunc("getBucketCount", [](ScriptAudioSourceEditor* self) {
106 return self ? self->editor().bucketCount() : 0;
107 });
108 sourceEditor.addFunc("getBucketMin", [](ScriptAudioSourceEditor* self, int index) {
109 if (!self) return 0.0f;
110 const auto* bucket = self->editor().bucket(index);
111 return bucket ? bucket->minimum : 0.0f;
112 });
113 sourceEditor.addFunc("getBucketMax", [](ScriptAudioSourceEditor* self, int index) {
114 if (!self) return 0.0f;
115 const auto* bucket = self->editor().bucket(index);
116 return bucket ? bucket->maximum : 0.0f;
117 });
118 sourceEditor.addFunc("getTransportState", [](ScriptAudioSourceEditor* self) {
119 return std::string(self ? transportLabel(self->editor().transport().state) : "stopped");
120 });
121 sourceEditor.addFunc("getFloat", [](ScriptAudioSourceEditor* self, const std::string& path) {
122 if (!self) return 0.0f;
123 auto value = self->editor().read(path);
124 if (const auto* real = value.value.getIf<double>()) return static_cast<float>(*real);
125 if (const auto* integer = value.value.getIf<std::int64_t>()) return static_cast<float>(*integer);
126 return 0.0f;
127 });
128 sourceEditor.addFunc("getBool", [](ScriptAudioSourceEditor* self, const std::string& path) {
129 if (!self) return false;
130 auto value = self->editor().read(path);
131 const auto* flag = value.value.getIf<bool>();
132 return flag ? *flag : false;
133 });
134 sourceEditor.addFunc("getString", [](ScriptAudioSourceEditor* self, const std::string& path) {
135 if (!self) return std::string{};
136 auto value = self->editor().read(path);
137 const auto* text = value.value.getIf<std::string>();
138 return text ? *text : std::string{};
139 });
140
141 editor::registerEditorOwnedCreate<ScriptAudioSourceEditor, AudioEditorModule>(
142 moduleClass, bind, "audio source target id must not be empty");
143}
144
145} // namespace eve::audio_editor
double value
float x
Definition AnimClip.cpp:738
Squirrel adapter for the audio source editor.
UI-neutral audio source editor: workspace, waveform, audition, undo.
std::uint32_t width
std::string text
std::string path
Definition PlayHost.cpp:110
std::uint32_t targetId
uint32_t index
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
Deterministic owning value tree shared by authoring hosts.
Editor facade binder: common script::BindContext plus history/owned-create helpers.
AudioTransportState
Playback state exposed to audio and dialogue editor presenters.
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.
uint32_t bucket