feat: initial Cutdex application

Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
lingjhf committed 2026-10-05 23:36:23 +08:00
commit 27e77fff39
718 files changed
+183958

No files matched your search

+180
View File
@@ -0,0 +1,180 @@
import 'dart:async';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex_sdk/timeline/engine.dart';
import 'package:cutdex_sdk/timeline/layout.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:cutdex_sdk/tools.dart';
import '../workspace/timeline_session.dart';
final _sessionTools = Expando<Map<SequenceId, EditorToolDispatcher>>();
final _toolReferences = Expando<Map<EditorToolDispatcher, int>>();
/// Remove a dispatcher from its session cache before closing admission.
Future<void> releaseEditorTools(
EditorSession session,
EditorToolDispatcher dispatcher,
) async {
final references = _toolReferences[session];
final remaining = (references?[dispatcher] ?? 1) - 1;
if (remaining > 0) {
references![dispatcher] = remaining;
return;
}
references?.remove(dispatcher);
_sessionTools[session]?.removeWhere(
(_, value) => identical(value, dispatcher),
);
await dispatcher.dispose();
}
EditorToolDispatcher editorToolsFor(
EditorSession session,
SequenceId sequence,
) {
session.commands.ensureOpen(sequence);
var tools = _sessionTools[session];
if (tools == null) {
final owned = <SequenceId, EditorToolDispatcher>{};
_sessionTools[session] = tools = owned;
session.onDispose(() {
for (final dispatcher in owned.values) {
unawaited(dispatcher.dispose());
}
});
}
final dispatcher = tools.putIfAbsent(
sequence,
() => EditorToolDispatcher(host: _EditorCommandHost(session, sequence)),
);
final references = _toolReferences[session] ??= {};
references[dispatcher] = (references[dispatcher] ?? 0) + 1;
return dispatcher;
}
/// Maps SDK command outcomes to tools and adapts the app-owned UI selection.
final class _EditorCommandHost extends EditorSessionCommandHost {
const _EditorCommandHost(super.session, super.sequence);
@override
Set<EditorOperation> get supportedOperations => {
...session.supportedCommandOperations.where(
(operation) => operation != EditorOperation.startVocalSeparation,
),
if (session is EditorTimelineSession) ...{
EditorOperation.querySelection,
EditorOperation.setSelection,
},
};
@override
Future<CommandResult> execute(
EditorCommand command,
CommandContext context,
) async {
if (command is StartVocalSeparation) {
throw const CommandRejected(
'unsupported',
'Vocal separation is temporarily unavailable',
);
}
return _execute(command, context);
}
Future<CommandResult> _execute(
EditorCommand command,
CommandContext context,
) async {
if (command is QuerySelection || command is SetSelection) {
session.commands.ensureOpen(sequence);
if (context.isCancelled()) {
throw const CommandRejected('cancelled', 'Cancelled before execution');
}
if (!supportedOperations.contains(command.operation)) {
throw const CommandRejected(
'unsupported',
'Operation is not available',
);
}
if (command.expectedVersion != null &&
command.expectedVersion != session.version) {
throw const CommandRejected(
'staleVersion',
'Read the current state before editing',
);
}
return _selection(command);
}
return super.execute(command, context);
}
CommandResult _selection(EditorCommand command) {
final ui = session as EditorTimelineSession;
final view = ui.view(sequence);
final query = view.version.kernelVersion.query();
if (command is SetSelection) {
if (view.isDragging) {
throw const CommandRejected('busy', 'Finish the current gesture first');
}
if (command.clipIds.length > 1024 ||
command.clipIds.toSet().length != command.clipIds.length) {
throw const CommandRejected(
'invalidArguments',
'Invalid clip selection',
);
}
final handles = <ElementHandle>[];
for (final id in command.clipIds) {
final handle = query.elementById(ElementId(id));
if (handle == null || query.ownerOf(handle) == null) {
throw const CommandRejected(
'missingClip',
'Selected clip does not exist',
);
}
handles.add(handle);
}
view.setSelection([
for (final handle in handles)
session.captionComponentFor(sequence, handle) ??
(query.connectionForTarget(handle) == null
? handle
: LayoutBodyId.element(handle)),
]);
}
final selected = <String>{};
for (final identity in view.selectedIdentities) {
final handle = switch (identity) {
ElementHandle value => value,
LayoutBodyId value => view.elementForIdentity(value),
_ => null,
};
if (handle != null && query.ownerOf(handle) != null) {
selected.add(query.element(handle).id.value);
}
}
final keyframe = view.selectedKeyframe;
return CommandResult(
status: CommandStatus.succeeded,
message: 'UI selection',
version: session.version,
data: {
'sequenceId': sequence.value,
'active': ui.activeSequenceId == sequence,
'clipIds': selected.toList(),
'keyframe': keyframe == null
? null
: {
'clipId': query.element(keyframe.element).id.value,
'offset': _time(keyframe.offset),
},
},
);
}
}
Map<String, Object?> _time(int ticks) {
final value = TimelineClock.standard.fromTicks(ticks);
return {'numerator': '${value.numerator}', 'denominator': value.denominator};
}