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:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,205 @@
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'background_task_registry.dart';
|
||||
import 'timeline_session.dart';
|
||||
|
||||
part 'background_task_state.g.dart';
|
||||
part 'background_task_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class SubtitleTaskEntry with _$SubtitleTaskEntry {
|
||||
const factory SubtitleTaskEntry({
|
||||
required BackgroundTaskSession owner,
|
||||
required SubtitleBackgroundTask job,
|
||||
required TranscriptionStatus status,
|
||||
required bool terminal,
|
||||
required bool followingUp,
|
||||
required String name,
|
||||
required String sourceLanguage,
|
||||
required String targetLanguage,
|
||||
required bool hasTranslation,
|
||||
required bool recognitionTerminal,
|
||||
required bool recognitionAvailable,
|
||||
required bool translationAvailable,
|
||||
@Default([]) List<String> recentCues,
|
||||
@Default([]) List<String> resultCues,
|
||||
int? completed,
|
||||
int? total,
|
||||
String? error,
|
||||
@Default(0) int recognizedCues,
|
||||
@Default(0) int translatedCues,
|
||||
}) = _SubtitleTaskEntry;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class RemovalTaskEntry with _$RemovalTaskEntry {
|
||||
const factory RemovalTaskEntry({
|
||||
required BackgroundTaskSession owner,
|
||||
required BackgroundRemovalTask task,
|
||||
required BackgroundRemovalStatus status,
|
||||
required String name,
|
||||
required bool terminal,
|
||||
int? completed,
|
||||
int? total,
|
||||
String? error,
|
||||
}) = _RemovalTaskEntry;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class BackgroundTasksSnapshot with _$BackgroundTasksSnapshot {
|
||||
const factory BackgroundTasksSnapshot({
|
||||
@Default([]) List<SubtitleTaskEntry> subtitles,
|
||||
@Default([]) List<RemovalTaskEntry> removals,
|
||||
@Default(0) int runningCount,
|
||||
}) = _BackgroundTasksSnapshot;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class BackgroundTasks extends _$BackgroundTasks {
|
||||
final _observed = <EditorTimelineSession>{};
|
||||
@override
|
||||
BackgroundTasksSnapshot build({
|
||||
BackgroundTaskRegistry? registry,
|
||||
EditorTimelineSession? session,
|
||||
}) {
|
||||
assert(registry != null || session != null);
|
||||
registry?.addListener(_changed);
|
||||
ref.onDispose(() {
|
||||
registry?.removeListener(_changed);
|
||||
for (final owner in _observed) {
|
||||
owner.removeListener(_changed);
|
||||
}
|
||||
_observed.clear();
|
||||
});
|
||||
return _snapshot();
|
||||
}
|
||||
|
||||
void _changed() {
|
||||
if (ref.mounted) state = _snapshot();
|
||||
}
|
||||
|
||||
BackgroundTasksSnapshot _snapshot() {
|
||||
final owners =
|
||||
registry?.entries ??
|
||||
[
|
||||
BackgroundTaskSession(
|
||||
projectId: '',
|
||||
projectName: '',
|
||||
timelineId: session!.document.id,
|
||||
timelineName: session!.document.name,
|
||||
session: session!,
|
||||
),
|
||||
];
|
||||
// Registry already observes its sessions; a standalone task view needs its own listener.
|
||||
final next = registry == null
|
||||
? owners.map((owner) => owner.session).toSet()
|
||||
: <EditorTimelineSession>{};
|
||||
for (final owner in _observed.difference(next)) {
|
||||
owner.removeListener(_changed);
|
||||
}
|
||||
for (final owner in next.difference(_observed)) {
|
||||
owner.addListener(_changed);
|
||||
}
|
||||
_observed
|
||||
..clear()
|
||||
..addAll(next);
|
||||
final subtitles = <SubtitleTaskEntry>[];
|
||||
final removals = <RemovalTaskEntry>[];
|
||||
var runningCount = 0;
|
||||
for (final owner in owners) {
|
||||
final timeline = owner.session;
|
||||
runningCount +=
|
||||
timeline.subtitleWorkflows.runningCount +
|
||||
timeline.backgroundRemovals.runningCount;
|
||||
final jobs = timeline.subtitleWorkflows.tasks;
|
||||
final ids = jobs.map((job) => job.recognition.id).toSet();
|
||||
final sequence = timeline.activeSequenceId;
|
||||
if (sequence != null) {
|
||||
for (final task
|
||||
in timeline.transcriptions?.tasks ?? <EditorTranscriptionTask>[]) {
|
||||
if (ids.contains(task.id)) continue;
|
||||
final translation = timeline.transcriptions?.translationTasks
|
||||
.where(
|
||||
(item) =>
|
||||
item.command.source == task.result?.subtitles.toFilePath(),
|
||||
)
|
||||
.lastOrNull;
|
||||
subtitles.add(
|
||||
_subtitle(
|
||||
owner,
|
||||
SubtitleBackgroundTask(
|
||||
id: task.id,
|
||||
sequence: sequence,
|
||||
name: task.command.mediaId,
|
||||
recognition: task,
|
||||
targetLanguage: translation?.command.targetLanguage ?? 'none',
|
||||
translation: translation,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
subtitles.addAll(jobs.map((job) => _subtitle(owner, job)));
|
||||
removals.addAll(
|
||||
timeline.backgroundRemovals.tasks.reversed.map(
|
||||
(task) => RemovalTaskEntry(
|
||||
owner: owner,
|
||||
task: task,
|
||||
status: task.status,
|
||||
name: task.name,
|
||||
terminal: task.terminal,
|
||||
completed: task.progress?.completed,
|
||||
total: task.progress?.total,
|
||||
error: task.error,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return BackgroundTasksSnapshot(
|
||||
subtitles: subtitles,
|
||||
removals: removals,
|
||||
runningCount: runningCount,
|
||||
);
|
||||
}
|
||||
|
||||
SubtitleTaskEntry _subtitle(
|
||||
BackgroundTaskSession owner,
|
||||
SubtitleBackgroundTask job,
|
||||
) => SubtitleTaskEntry(
|
||||
owner: owner,
|
||||
job: job,
|
||||
status: job.status,
|
||||
terminal: job.terminal,
|
||||
followingUp: job.followingUp,
|
||||
name: job.name,
|
||||
sourceLanguage: job.recognition.command.language,
|
||||
targetLanguage: job.targetLanguage,
|
||||
hasTranslation: job.translation != null,
|
||||
recognitionTerminal: job.recognition.terminal,
|
||||
recognitionAvailable: job.recognition.result != null,
|
||||
translationAvailable: job.translation?.result != null,
|
||||
recentCues: job.recognition.timelineCues.reversed
|
||||
.take(3)
|
||||
.toList()
|
||||
.reversed
|
||||
.map((cue) => cue.text)
|
||||
.toList(),
|
||||
resultCues:
|
||||
job.translation?.result?.document.cues
|
||||
.map((cue) => cue.text)
|
||||
.toList() ??
|
||||
job.recognition.result?.cues.map((cue) => cue.text).toList() ??
|
||||
[],
|
||||
completed:
|
||||
job.translation?.progress?.completed ??
|
||||
job.recognition.progress?.completed,
|
||||
total: job.translation?.progress?.total ?? job.recognition.progress?.total,
|
||||
error: job.error ?? job.translation?.error ?? job.recognition.error,
|
||||
recognizedCues:
|
||||
job.recognition.result?.cues.length ??
|
||||
job.recognition.timelineCues.length,
|
||||
translatedCues: job.translation?.result?.document.cues.length ?? 0,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user