Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
1288 lines
45 KiB
Dart
1288 lines
45 KiB
Dart
import '../../shared/widgets/presentation_list.dart';
|
|
|
|
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
|
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:cutdex_core/timeline/engine.dart';
|
|
import 'package:cutdex_core/timeline/layout.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_core/project.dart';
|
|
|
|
import 'package:cutdex_timeline_ui/cutdex_timeline_ui.dart';
|
|
|
|
import '../../shared/widgets/listenable_selector.dart';
|
|
import '../../workspace/timeline_provider.dart';
|
|
import '../../workspace/projects.dart';
|
|
import '../../workspace/project_state.dart';
|
|
|
|
import '../../integrations/runtime/timeline_thumbnails.dart';
|
|
import '../../integrations/runtime/timeline_waveforms.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:cutdex_ui/icons.dart';
|
|
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
import '../editor/editor_panel_defaults.dart';
|
|
import '../editor/timeline_operation_region.dart';
|
|
import '../media/transcription_dialog.dart';
|
|
import '../media/media_browser_controller.dart';
|
|
import '../media/background_removal_dialog.dart';
|
|
import '../projects/widgets/name_dialog.dart';
|
|
import '../../workspace/timeline_session.dart';
|
|
import '../../workspace/preview_target.dart';
|
|
import 'timeline_asset_drop_target.dart';
|
|
import 'editor_timeline_viewport.dart';
|
|
import 'timeline_speed_editor.dart';
|
|
|
|
class EditorTimelinePanel extends StatelessWidget {
|
|
const EditorTimelinePanel({
|
|
super.key,
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
this.pending = false,
|
|
this.timelineLoading = false,
|
|
this.rulerTimecodeLayout,
|
|
});
|
|
final String projectId;
|
|
final String timelineId;
|
|
final bool pending;
|
|
|
|
/// Keeps the active surface visible while disabling edits during navigation.
|
|
final bool timelineLoading;
|
|
|
|
/// An override of the desktop ruler layout selected in settings.
|
|
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Theme(
|
|
data: AppTheme.timelinePanelTheme(Theme.of(context)),
|
|
child: pending
|
|
? const EditorTimelineDefaults()
|
|
: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_TimelineTabsContent(
|
|
projectId: projectId,
|
|
timelineId: timelineId,
|
|
),
|
|
const Divider(height: 1),
|
|
Expanded(
|
|
child: TimelineOperationRegion(
|
|
projectId: projectId,
|
|
loading: timelineLoading,
|
|
child: _TimelineSessionContent(
|
|
projectId: projectId,
|
|
timelineId: timelineId,
|
|
rulerTimecodeLayout: rulerTimecodeLayout,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class _TimelineTabsContent extends ConsumerWidget {
|
|
const _TimelineTabsContent({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
});
|
|
final String projectId;
|
|
final String timelineId;
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final tabs = ref.watch(
|
|
projectsProvider.select((value) {
|
|
final state = value.asData?.value;
|
|
final active = state?.activeProject?.id == projectId;
|
|
return (
|
|
active
|
|
? PresentationList(
|
|
state!.timelines.map(
|
|
(timeline) => (timeline.id, timeline.name, timeline.pinned),
|
|
),
|
|
)
|
|
: PresentationList<(String, String, bool)>(const []),
|
|
active ? state?.visibleTimelineId : null,
|
|
active && state?.creatingTimeline == true,
|
|
active ? state?.openingTimelineId : null,
|
|
);
|
|
}),
|
|
);
|
|
return _TimelineTabsBar(
|
|
projectId: projectId,
|
|
timelineId: tabs.$2 ?? timelineId,
|
|
timelines:
|
|
ref.read(projectsProvider).asData?.value.activeProject?.id ==
|
|
projectId
|
|
? ref.read(projectsProvider).asData!.value.timelines
|
|
: const <TimelineSummary>[],
|
|
creating: tabs.$3,
|
|
openingTimelineId: tabs.$4,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TimelineSessionContent extends ConsumerWidget {
|
|
const _TimelineSessionContent({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
required this.rulerTimecodeLayout,
|
|
});
|
|
final String projectId;
|
|
final String timelineId;
|
|
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
|
|
|
|
void _activateTimeline(WidgetRef ref) {
|
|
ref.read(mediaBrowserProvider(projectId)).selectedAssetId = null;
|
|
ref
|
|
.read(previewNavigationProvider(projectId, timelineId).notifier)
|
|
.showTimeline();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final provider = editorTimelineProvider(projectId, timelineId);
|
|
final watched = ref.watch(provider);
|
|
final cached = watched.isLoading && !watched.hasError
|
|
? ref
|
|
.read(projectsProvider.notifier)
|
|
.cachedTimelineSession(projectId, timelineId)
|
|
: null;
|
|
final timeline = cached == null ? watched : AsyncData(cached);
|
|
return timeline.when(
|
|
loading: () => const EditorTimelineDefaults(
|
|
key: Key('timeline-pending'),
|
|
showTabs: false,
|
|
),
|
|
error: (_, _) => WorkspacePanel(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
primary: false,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
context.l10n.openTimelineFailed,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
TextButton(
|
|
onPressed: () => ref.invalidate(provider),
|
|
child: Text(context.l10n.retry),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
data: (session) => Listener(
|
|
behavior: HitTestBehavior.translucent,
|
|
onPointerDown: (_) {
|
|
if (const bool.fromEnvironment('CUTDEX_PREVIEW_TRACE')) {
|
|
debugPrint(
|
|
'CUTDEX_PREVIEW '
|
|
'${DateTime.now().millisecondsSinceEpoch} '
|
|
'dart pointer-down',
|
|
);
|
|
}
|
|
_activateTimeline(ref);
|
|
},
|
|
child: _TimelineEditor(
|
|
session: session,
|
|
projectId: projectId,
|
|
rulerTimecodeLayout: rulerTimecodeLayout,
|
|
onSelectionActivated: () => _activateTimeline(ref),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TimelineTabsBar extends ConsumerStatefulWidget {
|
|
const _TimelineTabsBar({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
required this.timelines,
|
|
required this.creating,
|
|
required this.openingTimelineId,
|
|
});
|
|
|
|
final String projectId;
|
|
final String timelineId;
|
|
final List<TimelineSummary> timelines;
|
|
final bool creating;
|
|
final String? openingTimelineId;
|
|
|
|
@override
|
|
ConsumerState<_TimelineTabsBar> createState() => _TimelineTabsBarState();
|
|
}
|
|
|
|
class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
|
|
double get _barHeight =>
|
|
AppTheme.isDesktop(context) ? AppDesktopMetrics.timelineTabs : 26.0;
|
|
double get _tabHeight =>
|
|
AppTheme.isDesktop(context) ? AppDesktopMetrics.timelineTabControl : 20;
|
|
static const _menuWidth = 220.0;
|
|
final _scrollController = ScrollController();
|
|
final _selectedMenuItemKey = GlobalKey();
|
|
final _selectedTabKey = GlobalKey();
|
|
|
|
bool get _operationsBusy =>
|
|
widget.creating ||
|
|
widget.openingTimelineId != null ||
|
|
(ref.read(projectsProvider).value?.projectBusy ?? false);
|
|
|
|
Future<void> _openTimeline(TimelineSummary timeline) async {
|
|
if (widget.creating ||
|
|
(ref.read(projectsProvider).value?.projectBusy ?? false) ||
|
|
timeline.id == widget.timelineId) {
|
|
return;
|
|
}
|
|
await ref
|
|
.read(projectsProvider.notifier)
|
|
.openTimeline(widget.projectId, timeline.id);
|
|
}
|
|
|
|
Future<void> _setTimelinePinned(TimelineSummary timeline) async {
|
|
if (_operationsBusy) return;
|
|
await ref
|
|
.read(projectsProvider.notifier)
|
|
.setTimelinePinned(timeline.id, !timeline.pinned);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_showSelectedTab();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant _TimelineTabsBar oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.timelineId != widget.timelineId) {
|
|
_showSelectedTab();
|
|
}
|
|
}
|
|
|
|
void _showSelectedTab() {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final selected = _selectedTabKey.currentContext;
|
|
if (selected != null) {
|
|
Scrollable.ensureVisible(
|
|
selected,
|
|
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
|
|
);
|
|
Scrollable.ensureVisible(
|
|
selected,
|
|
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
void _showSelectedMenuItem() {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final selected = _selectedMenuItemKey.currentContext;
|
|
if (selected != null) {
|
|
Scrollable.ensureVisible(selected, alignment: 0.5);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> _renameTimeline(TimelineSummary timeline) async {
|
|
if (_operationsBusy) return;
|
|
final project = ref.read(projectsProvider).value?.activeProject;
|
|
if (project?.id != widget.projectId) return;
|
|
final name = await askName(
|
|
context,
|
|
title: context.l10n.rename,
|
|
label: context.l10n.name,
|
|
initialValue: timeline.name,
|
|
submitLabel: context.l10n.rename,
|
|
);
|
|
if (name == null || !mounted || name == timeline.name) return;
|
|
await ref
|
|
.read(projectsProvider.notifier)
|
|
.renameTimeline(project!, timeline.id, name);
|
|
}
|
|
|
|
Future<void> _deleteTimeline(TimelineSummary timeline) async {
|
|
if (_operationsBusy || widget.timelines.length <= 1) return;
|
|
final confirmed = await showAppDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) => AppDialog(
|
|
title: context.l10n.delete,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, false),
|
|
child: Text(context.l10n.cancel),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(dialogContext, true),
|
|
child: Text(context.l10n.delete),
|
|
),
|
|
],
|
|
child: Text(context.l10n.deleteTimelineConfirmation(timeline.name)),
|
|
),
|
|
);
|
|
if (confirmed == true && mounted) {
|
|
await ref.read(projectsProvider.notifier).deleteTimeline(timeline.id);
|
|
}
|
|
}
|
|
|
|
Future<void> _createTimeline() async {
|
|
if (_operationsBusy) return;
|
|
if (widget.timelines.length >= Projects.maxTimelineCount) {
|
|
ErrorNotificationHost.maybeOf(context)?.show(
|
|
ErrorNotification(
|
|
content: Text(
|
|
context.l10n.timelineLimitReached(Projects.maxTimelineCount),
|
|
),
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
await ref
|
|
.read(projectsProvider.notifier)
|
|
.createTimeline(name: _nextName(context));
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_scrollController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
String _nextName(BuildContext context) {
|
|
final names = widget.timelines.map((timeline) => timeline.name).toSet();
|
|
for (var index = 1; ; index++) {
|
|
final candidate = context.l10n.defaultTimelineName(index);
|
|
if (!names.contains(candidate)) return candidate;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final desktop = AppTheme.isDesktop(context);
|
|
final actionHeight = desktop ? _tabHeight : _barHeight;
|
|
final actionStyle = desktop ? AppTheme.timelineTabActionStyle : null;
|
|
final addButton = SizedBox.square(
|
|
dimension: actionHeight,
|
|
child: IconButton(
|
|
key: const Key('timeline-add-button'),
|
|
tooltip: context.l10n.createTimelineHint,
|
|
onPressed: _createTimeline,
|
|
style: actionStyle,
|
|
padding: EdgeInsets.zero,
|
|
constraints: BoxConstraints.tightFor(
|
|
width: actionHeight,
|
|
height: actionHeight,
|
|
),
|
|
icon: const Icon(AppIcons.add, size: AppIconSize.small),
|
|
),
|
|
);
|
|
final tabList = ScrollEdgeFade(
|
|
controller: _scrollController,
|
|
axis: Axis.horizontal,
|
|
child: Listener(
|
|
onPointerSignal: (event) {
|
|
if (event is! PointerScrollEvent || !_scrollController.hasClients) {
|
|
return;
|
|
}
|
|
final delta = event.scrollDelta.dy != 0
|
|
? event.scrollDelta.dy
|
|
: event.scrollDelta.dx;
|
|
if (delta == 0) return;
|
|
final position = _scrollController.position;
|
|
_scrollController.jumpTo(
|
|
(position.pixels + delta).clamp(
|
|
position.minScrollExtent,
|
|
position.maxScrollExtent,
|
|
),
|
|
);
|
|
},
|
|
child: SingleChildScrollView(
|
|
key: const Key('timeline-tabs-list'),
|
|
controller: _scrollController,
|
|
scrollDirection: Axis.horizontal,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
|
child: Row(
|
|
children: [
|
|
for (
|
|
var index = 0;
|
|
index < widget.timelines.length;
|
|
index++
|
|
) ...[
|
|
if (index > 0) const SizedBox(width: AppSpacing.tiny),
|
|
_buildTab(context, widget.timelines[index]),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final listButton = SizedBox.square(
|
|
dimension: actionHeight,
|
|
child: AppPopover(
|
|
width: _menuWidth,
|
|
maxHeight: 320,
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
child: SingleChildScrollView(
|
|
primary: false,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final timeline in widget.timelines)
|
|
KeyedSubtree(
|
|
key: timeline.id == widget.timelineId
|
|
? _selectedMenuItemKey
|
|
: null,
|
|
child: AppMenuItem(
|
|
key: ValueKey('timeline-menu-${timeline.id}'),
|
|
label: timeline.name,
|
|
selected: timeline.id == widget.timelineId,
|
|
selectOption: true,
|
|
onPressed: () => _openTimeline(timeline),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
builder: (context, toggle) => IconButton(
|
|
key: const Key('timeline-list-button'),
|
|
tooltip: context.l10n.timelines,
|
|
onPressed: () {
|
|
toggle();
|
|
_showSelectedMenuItem();
|
|
},
|
|
padding: EdgeInsets.zero,
|
|
style: actionStyle,
|
|
constraints: BoxConstraints.tightFor(
|
|
width: actionHeight,
|
|
height: actionHeight,
|
|
),
|
|
icon: const Icon(AppIcons.more, size: AppIconSize.small),
|
|
),
|
|
),
|
|
);
|
|
return ColoredBox(
|
|
key: const Key('timeline-tabs-background'),
|
|
color: AppTheme.timelineTabsBackground(context),
|
|
child: SizedBox(
|
|
key: const Key('timeline-tabs-bar'),
|
|
height: _barHeight,
|
|
child: Row(
|
|
children: [
|
|
if (!desktop) addButton,
|
|
Expanded(
|
|
child: desktop
|
|
? Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Flexible(child: tabList),
|
|
addButton,
|
|
],
|
|
),
|
|
)
|
|
: tabList,
|
|
),
|
|
Padding(
|
|
padding: EdgeInsetsDirectional.only(
|
|
end: desktop ? AppSpacing.small : 0,
|
|
),
|
|
child: listButton,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTab(BuildContext context, TimelineSummary timeline) {
|
|
final selected = timeline.id == widget.timelineId;
|
|
return KeyedSubtree(
|
|
key: selected ? _selectedTabKey : null,
|
|
child: AppContextMenu(
|
|
itemsBuilder: (context) => [
|
|
AppMenuItem(
|
|
key: ValueKey('timeline-pin-${timeline.id}'),
|
|
label: timeline.pinned
|
|
? context.l10n.unpinTimeline
|
|
: context.l10n.pinTimeline,
|
|
icon: AppIcons.pin,
|
|
onPressed: () => _setTimelinePinned(timeline),
|
|
),
|
|
AppMenuItem(
|
|
key: ValueKey('timeline-rename-${timeline.id}'),
|
|
label: context.l10n.rename,
|
|
icon: AppIcons.rename,
|
|
onPressed: () => _renameTimeline(timeline),
|
|
),
|
|
AppMenuItem(
|
|
key: ValueKey('timeline-delete-${timeline.id}'),
|
|
label: context.l10n.delete,
|
|
icon: AppIcons.delete,
|
|
destructive: true,
|
|
onPressed: widget.timelines.length <= 1
|
|
? null
|
|
: () => _deleteTimeline(timeline),
|
|
),
|
|
],
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Semantics(
|
|
selected: selected,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: AppTheme.isDesktop(context) ? 180 : double.infinity,
|
|
),
|
|
child: TextButton(
|
|
key: ValueKey('timeline-tab-${timeline.id}'),
|
|
onPressed: () => _openTimeline(timeline),
|
|
style: AppTheme.timelineTabStyle(context, selected: selected),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (timeline.pinned) ...[
|
|
const Icon(AppIcons.pinFilled, size: 10),
|
|
const SizedBox(width: AppSpacing.tiny),
|
|
],
|
|
Flexible(
|
|
child: Text(
|
|
timeline.name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TimelineEditor extends StatefulWidget {
|
|
const _TimelineEditor({
|
|
required this.session,
|
|
required this.projectId,
|
|
required this.onSelectionActivated,
|
|
required this.rulerTimecodeLayout,
|
|
});
|
|
final String projectId;
|
|
final EditorTimelineSession session;
|
|
final VoidCallback onSelectionActivated;
|
|
final TimelineRulerTimecodeLayout? rulerTimecodeLayout;
|
|
|
|
@override
|
|
State<_TimelineEditor> createState() => _TimelineEditorState();
|
|
}
|
|
|
|
class _TimelineEditorState extends State<_TimelineEditor> {
|
|
EditorTimelineSession get session => widget.session;
|
|
String get projectId => widget.projectId;
|
|
RuntimeTimelineThumbnails get _thumbnails => session.thumbnails;
|
|
RuntimeTimelineWaveforms get _waveforms => session.waveforms;
|
|
TimelineViewController? _selectionView;
|
|
Set<Object> _lastSelection = {};
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
session.addListener(_bindSelectionView);
|
|
_bindSelectionView();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant _TimelineEditor oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (!identical(oldWidget.session, session)) {
|
|
oldWidget.session.removeListener(_bindSelectionView);
|
|
session.addListener(_bindSelectionView);
|
|
_bindSelectionView();
|
|
}
|
|
}
|
|
|
|
void _bindSelectionView() {
|
|
final sequence = session.activeSequenceId;
|
|
final next = sequence == null ? null : session.view(sequence);
|
|
if (identical(next, _selectionView)) return;
|
|
_selectionView?.editingChanges.removeListener(_selectionChanged);
|
|
_selectionView = next;
|
|
_lastSelection = next?.selectedIdentities.toSet() ?? {};
|
|
next?.editingChanges.addListener(_selectionChanged);
|
|
}
|
|
|
|
void _selectionChanged() {
|
|
final selected = _selectionView?.selectedIdentities.toSet() ?? {};
|
|
if (setEquals(selected, _lastSelection)) return;
|
|
_lastSelection = selected;
|
|
if (selected.isNotEmpty) widget.onSelectionActivated();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
session.removeListener(_bindSelectionView);
|
|
_selectionView?.editingChanges.removeListener(_selectionChanged);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ListenableSelector(
|
|
listenable: session,
|
|
select: () => session.activeSequenceId,
|
|
builder: (context, _) => _build(context),
|
|
);
|
|
|
|
TranscriptionClipTarget? _captionTarget(
|
|
TimelineViewController controller,
|
|
SequenceId sequence,
|
|
) {
|
|
if (!session.acceptsEdits ||
|
|
controller.isDragging ||
|
|
controller.selectedIdentities.length != 1) {
|
|
return null;
|
|
}
|
|
final handle = switch (controller.selectedIdentities.single) {
|
|
ElementHandle value => value,
|
|
LayoutBodyId value => controller.elementForIdentity(value),
|
|
_ => null,
|
|
};
|
|
final query = controller.version.kernelVersion.query();
|
|
if (handle == null || query.ownerOf(handle) == null) return null;
|
|
final clip = query.element(handle);
|
|
final binding = clip.payloadRef == null
|
|
? null
|
|
: session.mediaBinding(clip.payloadRef!);
|
|
if (binding == null ||
|
|
binding.audioTrackIndex == null ||
|
|
session.unavailableAssets.containsKey(binding.media.id)) {
|
|
return null;
|
|
}
|
|
return TranscriptionClipTarget(
|
|
sequence: sequence,
|
|
clipId: clip.id.value,
|
|
mediaId: binding.media.id,
|
|
name: clip.name ?? context.l10n.clip,
|
|
audioStream: binding.audioTrackIndex!,
|
|
);
|
|
}
|
|
|
|
BackgroundRemovalClipTarget? _backgroundRemovalTarget(
|
|
TimelineViewController controller,
|
|
SequenceId sequence,
|
|
) {
|
|
if (!session.acceptsEdits ||
|
|
controller.isDragging ||
|
|
controller.selectedIdentities.length != 1) {
|
|
return null;
|
|
}
|
|
final handle = controller.elementForIdentity(
|
|
controller.selectedIdentities.single,
|
|
);
|
|
final query = controller.version.kernelVersion.query();
|
|
if (handle == null || query.ownerOf(handle) == null) return null;
|
|
final clip = query.element(handle);
|
|
final binding = clip.payloadRef == null
|
|
? null
|
|
: session.mediaBinding(clip.payloadRef!);
|
|
if (binding?.videoTrackIndex == null ||
|
|
session.unavailableAssets.containsKey(binding!.media.id)) {
|
|
return null;
|
|
}
|
|
return BackgroundRemovalClipTarget(
|
|
sequence: sequence,
|
|
clipId: clip.id.value,
|
|
mediaId: binding.media.id,
|
|
name: clip.name ?? context.l10n.clip,
|
|
);
|
|
}
|
|
|
|
List<ElementHandle> _selectedCaptionCues(TimelineViewController controller) {
|
|
final query = controller.version.kernelVersion.query();
|
|
final result = <ElementHandle>[];
|
|
for (final identity in controller.selectedIdentities) {
|
|
final handle = controller.elementForIdentity(identity);
|
|
if (handle == null || query.ownerOf(handle) == null) return [];
|
|
final ref = query.element(handle).payloadRef;
|
|
if (ref == null || session.payloadFor(ref)?.type != 'caption') {
|
|
return [];
|
|
}
|
|
result.add(handle);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool _canSplitCaption(
|
|
TimelineViewController controller,
|
|
List<ElementHandle> cues,
|
|
) {
|
|
if (cues.length != 1 || controller.isDragging) return false;
|
|
final query = controller.version.kernelVersion.query();
|
|
final start = query.absoluteStart(cues.single);
|
|
return controller.playheadTick > start &&
|
|
controller.playheadTick < start + query.element(cues.single).duration;
|
|
}
|
|
|
|
void _splitCaption(
|
|
SequenceId sequence,
|
|
TimelineViewController controller,
|
|
ElementHandle cue,
|
|
) {
|
|
final query = controller.version.kernelVersion.query();
|
|
final offset = controller.playheadTick - query.absoluteStart(cue);
|
|
session.splitCaption(
|
|
sequence,
|
|
SplitCaption(
|
|
captionId: query.element(cue).id.value,
|
|
offset: CommandTime(offset, TimelineClock.ticksPerSecond),
|
|
expectedVersion: session.version,
|
|
),
|
|
);
|
|
}
|
|
|
|
void _runCaptionEdit(BuildContext context, void Function() edit) {
|
|
try {
|
|
edit();
|
|
} on CommandRejected catch (error) {
|
|
ErrorNotificationHost.maybeOf(context)?.show(
|
|
ErrorNotification(
|
|
content: Text(
|
|
error.code == 'staleVersion'
|
|
? context.l10n.captionChanged
|
|
: context.l10n.editCaptionError(
|
|
context.l10n.errorMessage(error),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _toolbarButton({
|
|
Key? key,
|
|
required String tooltip,
|
|
required VoidCallback? onPressed,
|
|
required IconData icon,
|
|
String? semanticLabel,
|
|
}) => IconButton(
|
|
key: key,
|
|
tooltip: tooltip,
|
|
onPressed: onPressed,
|
|
iconSize: AppIconSize.header,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints.tightFor(
|
|
width: AppControlSize.headerButton,
|
|
height: AppControlSize.headerButton,
|
|
),
|
|
style: IconButton.styleFrom(
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
icon: Icon(icon, semanticLabel: semanticLabel),
|
|
);
|
|
|
|
Widget _build(BuildContext context) {
|
|
final sequenceId = session.activeSequenceId;
|
|
if (sequenceId == null) {
|
|
return WorkspacePanel(
|
|
child: Center(child: Text(context.l10n.noTimelineSequence)),
|
|
);
|
|
}
|
|
final controller = session.view(sequenceId);
|
|
return WorkspacePanel(
|
|
headerHeight: AppTheme.isDesktop(context)
|
|
? AppDesktopMetrics.timelineToolbar
|
|
: 32,
|
|
headerPadding: EdgeInsets.zero,
|
|
controls: ListenableSelector(
|
|
listenable: Listenable.merge([
|
|
controller.contentChanges,
|
|
controller.playheadChanges,
|
|
session,
|
|
]),
|
|
select: () => (
|
|
controller.canUndo,
|
|
controller.canRedo,
|
|
controller.canCutSelection,
|
|
controller.canDeleteSelection,
|
|
controller.commandRejection,
|
|
_canSplitCaption(controller, _selectedCaptionCues(controller)),
|
|
_selectedCaptionCues(controller).singleOrNull,
|
|
controller.version.kernelVersion,
|
|
),
|
|
builder: (context, _) {
|
|
final captionCues = _selectedCaptionCues(controller);
|
|
final canSplitCaption = _canSplitCaption(controller, captionCues);
|
|
if (!AppTheme.isDesktop(context)) {
|
|
return SizedBox(
|
|
key: const Key('timeline-toolbar'),
|
|
height: 32,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.gap),
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
minWidth: constraints.maxWidth,
|
|
),
|
|
child: IntrinsicWidth(
|
|
child: Row(
|
|
children: [
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
spacing: AppSpacing.tiny,
|
|
children: [
|
|
_toolbarButton(
|
|
tooltip: context.l10n.undo,
|
|
onPressed: controller.canUndo
|
|
? controller.undo
|
|
: null,
|
|
icon: AppIcons.undo,
|
|
),
|
|
_toolbarButton(
|
|
tooltip: context.l10n.redo,
|
|
onPressed: controller.canRedo
|
|
? controller.redo
|
|
: null,
|
|
icon: AppIcons.redo,
|
|
),
|
|
_toolbarButton(
|
|
tooltip: context.l10n.splitAtPlayhead,
|
|
onPressed: canSplitCaption
|
|
? () => _runCaptionEdit(
|
|
context,
|
|
() => _splitCaption(
|
|
sequenceId,
|
|
controller,
|
|
captionCues.single,
|
|
),
|
|
)
|
|
: controller.canCutSelection
|
|
? controller.cutSelectionAtPlayhead
|
|
: null,
|
|
icon: AppIcons.cut,
|
|
),
|
|
_toolbarButton(
|
|
key: const ValueKey('timeline-trim-left'),
|
|
tooltip: context.l10n.trimLeftTooltip,
|
|
onPressed: controller.canCutSelection
|
|
? controller.trimLeftAtPlayhead
|
|
: null,
|
|
icon: AppIcons.alignLeft,
|
|
semanticLabel: context.l10n.trimLeft,
|
|
),
|
|
_toolbarButton(
|
|
key: const ValueKey('timeline-trim-right'),
|
|
tooltip: context.l10n.trimRightTooltip,
|
|
onPressed: controller.canCutSelection
|
|
? controller.trimRightAtPlayhead
|
|
: null,
|
|
icon: AppIcons.alignRight,
|
|
semanticLabel: context.l10n.trimRight,
|
|
),
|
|
_toolbarButton(
|
|
key: const ValueKey(
|
|
'timeline-delete-selection',
|
|
),
|
|
tooltip: context.l10n.deleteSelectedClips,
|
|
onPressed: () {
|
|
if (!controller.canDeleteSelection) return;
|
|
controller.deleteSelection();
|
|
},
|
|
icon: AppIcons.delete,
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
_toolbarButton(
|
|
key: const ValueKey('timeline-fit'),
|
|
tooltip: context.l10n.fitTimeline,
|
|
semanticLabel: context.l10n.fitTimeline,
|
|
onPressed: controller.fitTimeline,
|
|
icon: AppIcons.fitContent,
|
|
),
|
|
if (controller.commandRejection != null)
|
|
Tooltip(
|
|
message: controller.commandRejection!,
|
|
child: const Icon(AppIcons.info),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return SizedBox(
|
|
key: const Key('timeline-toolbar'),
|
|
height: AppTheme.isDesktop(context)
|
|
? AppDesktopMetrics.timelineToolbar
|
|
: 32,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.medium,
|
|
),
|
|
child: AppCommandToolbar(
|
|
groups: [
|
|
[
|
|
AppToolbarCommand(
|
|
label: context.l10n.undo,
|
|
onPressed: controller.canUndo ? controller.undo : null,
|
|
icon: AppIcons.undo,
|
|
),
|
|
AppToolbarCommand(
|
|
label: context.l10n.redo,
|
|
onPressed: controller.canRedo ? controller.redo : null,
|
|
icon: AppIcons.redo,
|
|
),
|
|
],
|
|
[
|
|
AppToolbarCommand(
|
|
label: context.l10n.splitAtPlayhead,
|
|
onPressed: canSplitCaption
|
|
? () => _runCaptionEdit(
|
|
context,
|
|
() => _splitCaption(
|
|
sequenceId,
|
|
controller,
|
|
captionCues.single,
|
|
),
|
|
)
|
|
: controller.canCutSelection
|
|
? controller.cutSelectionAtPlayhead
|
|
: null,
|
|
icon: AppIcons.cut,
|
|
),
|
|
AppToolbarCommand(
|
|
key: const ValueKey('timeline-trim-left'),
|
|
label: context.l10n.trimLeftTooltip,
|
|
semanticLabel: context.l10n.trimLeft,
|
|
onPressed: controller.canCutSelection
|
|
? controller.trimLeftAtPlayhead
|
|
: null,
|
|
icon: AppIcons.alignLeft,
|
|
),
|
|
AppToolbarCommand(
|
|
key: const ValueKey('timeline-trim-right'),
|
|
label: context.l10n.trimRightTooltip,
|
|
semanticLabel: context.l10n.trimRight,
|
|
onPressed: controller.canCutSelection
|
|
? controller.trimRightAtPlayhead
|
|
: null,
|
|
icon: AppIcons.alignRight,
|
|
),
|
|
AppToolbarCommand(
|
|
key: const ValueKey('timeline-delete-selection'),
|
|
label: context.l10n.deleteSelectedClips,
|
|
onPressed: controller.canDeleteSelection
|
|
? controller.deleteSelection
|
|
: null,
|
|
icon: AppIcons.delete,
|
|
),
|
|
],
|
|
],
|
|
trailing: [
|
|
AppToolbarCommand(
|
|
key: const ValueKey('timeline-fit'),
|
|
label: context.l10n.fitTimeline,
|
|
semanticLabel: context.l10n.fitTimeline,
|
|
onPressed: controller.fitTimeline,
|
|
icon: AppIcons.fitContent,
|
|
),
|
|
],
|
|
status: controller.commandRejection == null
|
|
? null
|
|
: Tooltip(
|
|
message: controller.commandRejection!,
|
|
child: const Icon(AppIcons.info, size: 16),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
child: ListenableBuilder(
|
|
listenable: controller.contentChanges,
|
|
builder: (context, child) => AppContextMenu(
|
|
itemsBuilder: (_) {
|
|
final target = _captionTarget(controller, sequenceId);
|
|
final backgroundRemovalTarget = _backgroundRemovalTarget(
|
|
controller,
|
|
sequenceId,
|
|
);
|
|
final query = controller.version.kernelVersion.query();
|
|
final handle =
|
|
!controller.isDragging &&
|
|
controller.selectedIdentities.length == 1
|
|
? controller.elementForIdentity(
|
|
controller.selectedIdentities.single,
|
|
)
|
|
: null;
|
|
final clip = handle == null || query.ownerOf(handle) == null
|
|
? null
|
|
: query.element(handle);
|
|
final detachTarget = clip?.id;
|
|
final restoreAudio =
|
|
clip != null &&
|
|
clip.payloadRef != null &&
|
|
session.payloadFor(clip.payloadRef!)?.type == 'video' &&
|
|
(ClipAudioGain.isDetached(clip) ||
|
|
ClipAudioGain.fromRecord(clip).muted);
|
|
return [
|
|
AppMenuItem(
|
|
label: restoreAudio
|
|
? context.l10n.restoreAudio
|
|
: context.l10n.detachAudio,
|
|
icon: restoreAudio ? AppIcons.volume : AppIcons.audioFile,
|
|
onPressed:
|
|
session.acceptsEdits &&
|
|
detachTarget != null &&
|
|
(restoreAudio ||
|
|
session.canDetachAudio(sequenceId, detachTarget))
|
|
? () {
|
|
try {
|
|
if (restoreAudio) {
|
|
session.commands.setAudio(
|
|
sequence: sequenceId,
|
|
clip: detachTarget,
|
|
muted: false,
|
|
);
|
|
} else {
|
|
session.detachAudio(sequenceId, detachTarget);
|
|
}
|
|
} catch (error) {
|
|
ErrorNotificationHost.of(context).show(
|
|
ErrorNotification(
|
|
content: Text(context.l10n.errorMessage(error)),
|
|
details: error.toString(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
: null,
|
|
),
|
|
AppMenuItem(
|
|
label: context.l10n.separateVocals,
|
|
icon: AppIcons.audioWaveform,
|
|
onPressed: null,
|
|
),
|
|
AppMenuItem(
|
|
label: context.l10n.removeBackground,
|
|
icon: AppIcons.removeBackground,
|
|
onPressed: backgroundRemovalTarget == null
|
|
? null
|
|
: () => showAppDialog<void>(
|
|
context: context,
|
|
builder: (_) => BackgroundRemovalDialog(
|
|
session: session,
|
|
target: backgroundRemovalTarget,
|
|
),
|
|
),
|
|
),
|
|
AppMenuItem(
|
|
label: context.l10n.generateCaptions,
|
|
icon: AppIcons.subtitles,
|
|
onPressed: target == null
|
|
? null
|
|
: () => showAppDialog<void>(
|
|
context: context,
|
|
builder: (_) => TranscriptionDialog.forCurrentTask(
|
|
session: session,
|
|
target: target,
|
|
),
|
|
),
|
|
),
|
|
AppMenuItem(
|
|
label: context.l10n.deleteSelectedClips,
|
|
icon: AppIcons.delete,
|
|
destructive: true,
|
|
onPressed: controller.canDeleteSelection
|
|
? controller.deleteSelection
|
|
: null,
|
|
),
|
|
];
|
|
},
|
|
child: child!,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: EditorTimelineViewport(
|
|
leadingPadding: AppSpacing.medium,
|
|
controller: controller,
|
|
rulerTimecodeLayout: widget.rulerTimecodeLayout,
|
|
child: TimelineAssetDropTarget(
|
|
projectId: projectId,
|
|
session: session,
|
|
sequenceId: sequenceId,
|
|
child: TimelineInteractionRegion(
|
|
controller: controller,
|
|
keyframes: true,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
TimelineView(
|
|
key: const Key('editor-timeline-surface'),
|
|
controller: controller,
|
|
classifyContent: session.classify,
|
|
contentStatus: session.mediaStatus,
|
|
contentTitle: session.contentTitle,
|
|
contentStatusChanges: session,
|
|
thumbnails: _thumbnails,
|
|
waveforms: _waveforms,
|
|
showKeyframes: true,
|
|
paintClipHeader: TimelineSpeedEditor.headerPainter(
|
|
context,
|
|
session: session,
|
|
sequence: sequenceId,
|
|
),
|
|
overlay: TimelineSpeedEditor(
|
|
session: session,
|
|
sequence: sequenceId,
|
|
controller: controller,
|
|
),
|
|
),
|
|
ListenableSelector<Object>(
|
|
listenable: controller.contentChanges,
|
|
select: () => (
|
|
controller.contentEndTick == 0,
|
|
controller.isDragging,
|
|
controller.geometry.primaryTop,
|
|
controller.geometry.primaryHeight,
|
|
controller.camera.verticalOffset,
|
|
),
|
|
builder: (context, _) =>
|
|
controller.contentEndTick == 0 &&
|
|
!controller.isDragging
|
|
? TimelineEmptyDropZone(
|
|
primaryTop: controller.geometry.primaryTop
|
|
.toDouble(),
|
|
primaryHeight: controller
|
|
.geometry
|
|
.primaryHeight
|
|
.toDouble(),
|
|
verticalOffset:
|
|
controller.camera.verticalOffset,
|
|
)
|
|
: const SizedBox.shrink(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class TimelineEmptyDropZone extends StatelessWidget {
|
|
const TimelineEmptyDropZone({
|
|
super.key,
|
|
required this.primaryTop,
|
|
required this.primaryHeight,
|
|
required this.verticalOffset,
|
|
});
|
|
|
|
final double primaryTop;
|
|
final double primaryHeight;
|
|
final double verticalOffset;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => IgnorePointer(
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final height = primaryHeight
|
|
.clamp(0.0, constraints.maxHeight)
|
|
.toDouble();
|
|
final top = (primaryTop - verticalOffset)
|
|
.clamp(0.0, constraints.maxHeight - height)
|
|
.toDouble();
|
|
return Stack(
|
|
children: [
|
|
Positioned(
|
|
top: top,
|
|
left: AppSpacing.medium,
|
|
right: AppSpacing.medium,
|
|
height: height,
|
|
child: CustomPaint(
|
|
key: const ValueKey('timeline-empty-drop-zone'),
|
|
painter: _DashedDropZonePainter(
|
|
color: AppTheme.sidebarDividerColor(context),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
context.l10n.timelineDropToStart,
|
|
style: Theme.of(context).textTheme.labelLarge?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
class _DashedDropZonePainter extends CustomPainter {
|
|
const _DashedDropZonePainter({required this.color});
|
|
|
|
final Color color;
|
|
static const _radius = Radius.circular(8);
|
|
static const _dash = 5.0;
|
|
static const _gap = 3.0;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
if (size.isEmpty) return;
|
|
final rect = RRect.fromRectAndRadius(
|
|
Rect.fromLTWH(1, 1, size.width - 2, size.height - 2),
|
|
_radius,
|
|
);
|
|
final path = Path()..addRRect(rect);
|
|
final paint = Paint()
|
|
..color = color
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 2;
|
|
for (final metric in path.computeMetrics()) {
|
|
var start = 0.0;
|
|
while (start < metric.length) {
|
|
canvas.drawPath(
|
|
metric.extractPath(start, (start + _dash).clamp(0, metric.length)),
|
|
paint,
|
|
);
|
|
start += _dash + _gap;
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(_DashedDropZonePainter oldDelegate) =>
|
|
color != oldDelegate.color;
|
|
}
|