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,353 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/runtime/processing_contracts.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/runtime/processing_resource_repository.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import '../../shared/widgets/confirm_resource_download_cancel.dart';
|
||||
import '../../shared/widgets/processing_resource_download_dialog.dart';
|
||||
import '../../workspace/timeline_session.dart';
|
||||
|
||||
import 'processing_targets.dart';
|
||||
import 'subtitle_download.dart';
|
||||
export 'processing_targets.dart';
|
||||
|
||||
class TranscriptionDialog extends ConsumerStatefulWidget {
|
||||
const TranscriptionDialog({
|
||||
super.key,
|
||||
required this.session,
|
||||
this.asset,
|
||||
this.target,
|
||||
}) : assert(asset == null || target == null);
|
||||
const TranscriptionDialog.forCurrentTask({
|
||||
super.key,
|
||||
required this.session,
|
||||
this.asset,
|
||||
this.target,
|
||||
}) : assert(asset == null || target == null);
|
||||
final EditorTimelineSession session;
|
||||
final AssetDocument? asset;
|
||||
final TranscriptionClipTarget? target;
|
||||
@override
|
||||
ConsumerState<TranscriptionDialog> createState() =>
|
||||
_TranscriptionDialogState();
|
||||
}
|
||||
|
||||
class _TranscriptionDialogState extends ConsumerState<TranscriptionDialog> {
|
||||
String _translationSource = 'auto';
|
||||
String _translationTarget = 'none';
|
||||
bool _closing = false;
|
||||
late final VoidCallback _release;
|
||||
SubtitleStartProvider get _startProvider =>
|
||||
subtitleStartProvider(widget.session);
|
||||
SubtitleDownloadState get _download {
|
||||
final global = ref.read(subtitleDownloadProvider);
|
||||
final local = ref.read(_startProvider);
|
||||
if (identical(global.request?.session, widget.session) && global.running) {
|
||||
return global;
|
||||
}
|
||||
return local is SubtitleIdle ? global : local;
|
||||
}
|
||||
|
||||
bool get _ownsDownload =>
|
||||
identical(_download.request?.session, widget.session);
|
||||
bool get _installingResource =>
|
||||
_ownsDownload && _download is SubtitleDownloading;
|
||||
bool get _picking => _ownsDownload && _download is SubtitleStarting;
|
||||
bool get _resourcePaused => _ownsDownload
|
||||
? switch (_download) {
|
||||
SubtitleDownloading(:final paused) => paused,
|
||||
_ => false,
|
||||
}
|
||||
: false;
|
||||
double? get _resourceProgress => _ownsDownload
|
||||
? switch (_download) {
|
||||
SubtitleDownloading(:final progress) => progress,
|
||||
_ => null,
|
||||
}
|
||||
: null;
|
||||
ProcessingCapability get _resourceStage => _ownsDownload
|
||||
? switch (_download) {
|
||||
SubtitleDownloading(:final stage) => stage,
|
||||
_ => ProcessingCapability.transcription,
|
||||
}
|
||||
: ProcessingCapability.transcription;
|
||||
ProcessingResourceRepository? get _resourceRepository => _ownsDownload
|
||||
? switch (_download) {
|
||||
SubtitleDownloading(:final repository) => repository,
|
||||
_ => null,
|
||||
}
|
||||
: null;
|
||||
TranscriptionClipTarget? get _target =>
|
||||
_installingResource ? _download.request?.target : widget.target;
|
||||
AssetDocument? get _asset =>
|
||||
_installingResource ? _download.request?.asset : widget.asset;
|
||||
String? get _mediaId => _target?.mediaId ?? _asset?.id;
|
||||
String? get _error => !_ownsDownload
|
||||
? null
|
||||
: switch (_download) {
|
||||
SubtitleFailed(:final failure) => switch (failure) {
|
||||
SubtitleStartFailure.start => context.l10n.startTranscriptionFailed,
|
||||
SubtitleStartFailure.download =>
|
||||
context.l10n.processingResourceDownloadFailed,
|
||||
SubtitleStartFailure.engine =>
|
||||
context.l10n.subtitleEngineUnavailable,
|
||||
},
|
||||
_ => null,
|
||||
};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_release = widget.session.retainViews();
|
||||
if (_ownsDownload && _download.running) {
|
||||
_translationSource = _download.request!.language;
|
||||
_translationTarget = _download.request!.targetLanguage;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_release();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _dismissDialog() {
|
||||
if (!mounted) return;
|
||||
final route = ModalRoute.of(context);
|
||||
if (route == null) return;
|
||||
final navigator = Navigator.of(context);
|
||||
if (route.isCurrent) {
|
||||
navigator.pop();
|
||||
} else {
|
||||
navigator.removeRoute(route);
|
||||
}
|
||||
}
|
||||
|
||||
SubtitleRequest _request() => SubtitleRequest(
|
||||
session: widget.session,
|
||||
sequence: _target?.sequence ?? widget.session.activeSequenceId,
|
||||
target: _target,
|
||||
asset: _asset,
|
||||
language: _translationSource,
|
||||
targetLanguage: _translationTarget,
|
||||
);
|
||||
Future<void> _start() => ref.read(_startProvider.notifier).start(_request());
|
||||
Future<void> _downloadResourceAndStart() {
|
||||
ref.read(_startProvider.notifier).reset();
|
||||
return ref
|
||||
.read(subtitleDownloadProvider.notifier)
|
||||
.start(_request(), download: true);
|
||||
}
|
||||
|
||||
void _toggleResourceDownload() =>
|
||||
ref.read(subtitleDownloadProvider.notifier).togglePause();
|
||||
void _cancelResourceDownload() =>
|
||||
ref.read(subtitleDownloadProvider.notifier).cancel();
|
||||
|
||||
String _translationLanguageLabel(String code) =>
|
||||
context.l10n.subtitleLanguageName(code);
|
||||
|
||||
Widget _translationLanguageMenu({
|
||||
required String label,
|
||||
required String value,
|
||||
required String other,
|
||||
required ValueChanged<String> onChanged,
|
||||
bool source = false,
|
||||
bool enabled = true,
|
||||
}) => AppField(
|
||||
label: label,
|
||||
child: AppSelect<String>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
label: label,
|
||||
value: value,
|
||||
searchable: true,
|
||||
searchHint: context.l10n.searchOptions(label),
|
||||
onChanged: enabled ? onChanged : null,
|
||||
options: [
|
||||
if (source) ...[
|
||||
AppSelectOption('auto', context.l10n.autoDetect),
|
||||
] else
|
||||
AppSelectOption('none', context.l10n.noTranslation),
|
||||
for (final code in [
|
||||
'zh',
|
||||
'en',
|
||||
'ja',
|
||||
'ko',
|
||||
if (source) 'yue',
|
||||
...m2m100LanguageNames.keys.where(
|
||||
(code) => !const {'zh', 'en', 'ja', 'ko'}.contains(code),
|
||||
),
|
||||
])
|
||||
AppSelectOption(
|
||||
code,
|
||||
_translationLanguageLabel(code),
|
||||
enabled: code != other,
|
||||
searchTerms: [
|
||||
code,
|
||||
?subtitleNativeLanguageNames[code],
|
||||
?m2m100LanguageNames[code],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildModelDownloadDialog() {
|
||||
final packages =
|
||||
_resourceRepository?.catalog ?? defaultProcessingResourceCatalog;
|
||||
final service = widget.session.transcriptions;
|
||||
final downloadBytes = packages
|
||||
.where(
|
||||
(package) =>
|
||||
ProcessingResourceRepository.subtitleCapabilities.contains(
|
||||
package.capability,
|
||||
) &&
|
||||
!(package.capability == ProcessingCapability.transcription &&
|
||||
service?.recognitionAvailable == true) &&
|
||||
!(package.capability == ProcessingCapability.translation &&
|
||||
service?.translationAvailable == true),
|
||||
)
|
||||
.fold<int>(0, (total, package) => total + package.bytes);
|
||||
final totalBytes = packages
|
||||
.where(
|
||||
(package) => ProcessingResourceRepository.subtitleCapabilities
|
||||
.contains(package.capability),
|
||||
)
|
||||
.fold<int>(0, (total, package) => total + package.bytes);
|
||||
final progressTotal = _resourceRepository?.subtitleTotalBytes ?? totalBytes;
|
||||
final downloadedBytes =
|
||||
_resourceRepository?.subtitleDownloadedBytes ??
|
||||
((_resourceProgress ?? 0) * progressTotal).round();
|
||||
return ProcessingResourceDownloadDialog(
|
||||
title: context.l10n.subtitleResourceDownloadTask,
|
||||
description: context.l10n.subtitleResourcesRequired,
|
||||
resourceName: _resourceStage == ProcessingCapability.transcription
|
||||
? context.l10n.speechResourceStage
|
||||
: context.l10n.translationResourceStage,
|
||||
downloadSize: context.l10n.subtitleResourcesDownloadSize(
|
||||
formatResourceBytes(downloadBytes),
|
||||
),
|
||||
downloading: _installingResource,
|
||||
paused: _resourcePaused,
|
||||
downloadedBytes: downloadedBytes,
|
||||
totalBytes: progressTotal,
|
||||
bytesPerSecond: _resourceRepository?.subtitleDownloadBytesPerSecond ?? 0,
|
||||
error: _error,
|
||||
downloadButtonKey: const Key('download-transcription-resource'),
|
||||
pauseButtonKey: const Key('download-transcription-resource'),
|
||||
backgroundButtonKey: const Key('background-transcription-resource'),
|
||||
onCancel: () async {
|
||||
if (_installingResource &&
|
||||
!await confirmResourceDownloadCancellation(context)) {
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
_cancelResourceDownload();
|
||||
_dismissDialog();
|
||||
},
|
||||
onDownload: _downloadResourceAndStart,
|
||||
onTogglePause: _toggleResourceDownload,
|
||||
onBackground: _dismissDialog,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.watch(subtitleDownloadProvider);
|
||||
ref.watch(_startProvider);
|
||||
void handleResult(SubtitleDownloadState next) {
|
||||
if (_closing || !identical(next.request?.session, widget.session)) return;
|
||||
if (next is SubtitleStarted || next is SubtitleCancelled) {
|
||||
_closing = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
final message = context.l10n.subtitleTaskStarted;
|
||||
_dismissDialog();
|
||||
if (next is SubtitleStarted) {
|
||||
messenger?.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ref.listen(subtitleDownloadProvider, (_, next) => handleResult(next));
|
||||
ref.listen(_startProvider, (_, next) => handleResult(next));
|
||||
return ListenableBuilder(
|
||||
listenable: widget.session,
|
||||
builder: (context, _) {
|
||||
final service = widget.session.transcriptions;
|
||||
if (service?.recognitionAvailable != true ||
|
||||
service?.translationAvailable != true ||
|
||||
_installingResource) {
|
||||
return _buildModelDownloadDialog();
|
||||
}
|
||||
final busy =
|
||||
(service?.tasks.any((task) => !task.terminal) ?? false) ||
|
||||
(service?.translationTasks.any((task) => !task.terminal) ?? false);
|
||||
return AppDialog(
|
||||
title: _target == null
|
||||
? context.l10n.transcribe
|
||||
: context.l10n.generateCaptions,
|
||||
withShadow: true,
|
||||
width: 560,
|
||||
actions: [
|
||||
if (_mediaId != null && service != null)
|
||||
FilledButton(
|
||||
onPressed: busy || _picking || !widget.session.acceptsEdits
|
||||
? null
|
||||
: _start,
|
||||
child: Text(context.l10n.generateCaptions),
|
||||
),
|
||||
],
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_translationLanguageMenu(
|
||||
label: context.l10n.sourceLanguage,
|
||||
value: _translationSource,
|
||||
other: _translationTarget,
|
||||
source: true,
|
||||
enabled: !busy && !_picking,
|
||||
onChanged: (value) =>
|
||||
setState(() => _translationSource = value),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.compact),
|
||||
_translationLanguageMenu(
|
||||
label: context.l10n.translationLanguage,
|
||||
value: _translationTarget,
|
||||
other: _translationSource,
|
||||
enabled:
|
||||
service?.translationAvailable == true &&
|
||||
!busy &&
|
||||
!_picking,
|
||||
onChanged: (value) =>
|
||||
setState(() => _translationTarget = value),
|
||||
),
|
||||
if (service?.translationAvailable != true)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppSpacing.small),
|
||||
child: Text(context.l10n.translationNotConfigured),
|
||||
),
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppSpacing.compact),
|
||||
child: Text(_error!),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user