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,362 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex/features/properties/audio_gain_scale.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import '../../workspace/timeline_session.dart';
|
||||
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
|
||||
export 'package:cutdex_sdk/editor.dart' show ClipAudioGain;
|
||||
|
||||
class AudioProperties extends StatefulWidget {
|
||||
const AudioProperties({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.sequence,
|
||||
required this.clip,
|
||||
required this.hasAudio,
|
||||
});
|
||||
final EditorTimelineSession session;
|
||||
final SequenceId sequence;
|
||||
final ElementRecord clip;
|
||||
final bool hasAudio;
|
||||
|
||||
@override
|
||||
State<AudioProperties> createState() => _AudioPropertiesState();
|
||||
}
|
||||
|
||||
class _AudioPropertiesState extends State<AudioProperties> {
|
||||
final _text = TextEditingController();
|
||||
final _focus = FocusNode();
|
||||
ClipAudioGain? _timeline;
|
||||
Object? _editVersion;
|
||||
int? _editTick;
|
||||
String? _error;
|
||||
bool _dirty = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focus.addListener(_focusChanged);
|
||||
}
|
||||
|
||||
void _focusChanged() {
|
||||
if (_focus.hasFocus) {
|
||||
_beginEdit();
|
||||
} else if (_dirty) {
|
||||
_submit(_text.text);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.session.clearAudioGainPreview(widget.clip.id);
|
||||
_focus.removeListener(_focusChanged);
|
||||
_focus.dispose();
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _beginEdit() {
|
||||
final view = widget.session.view(widget.sequence);
|
||||
_editVersion = view.version.kernelVersion;
|
||||
_editTick = view.playheadTick;
|
||||
}
|
||||
|
||||
bool get _editValid {
|
||||
final view = widget.session.view(widget.sequence);
|
||||
return widget.session.activeSequenceId == widget.sequence &&
|
||||
(_editVersion == null ||
|
||||
identical(_editVersion, view.version.kernelVersion)) &&
|
||||
(_editTick == null || _editTick == view.playheadTick);
|
||||
}
|
||||
|
||||
bool _commit(ClipAudioGain value) {
|
||||
widget.session.clearAudioGainPreview(widget.clip.id);
|
||||
final view = widget.session.view(widget.sequence);
|
||||
final query = view.version.kernelVersion.query();
|
||||
final handle = query.elementById(widget.clip.id);
|
||||
if (handle == null || !_editValid) {
|
||||
setState(() {
|
||||
_timeline = null;
|
||||
_dirty = false;
|
||||
_error = null;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
widget.session.commands.setAudio(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip.id,
|
||||
tick: _editTick ?? view.playheadTick,
|
||||
db: value.db,
|
||||
muted: value.muted,
|
||||
);
|
||||
setState(() {
|
||||
_timeline = null;
|
||||
_dirty = false;
|
||||
_editVersion = null;
|
||||
_editTick = null;
|
||||
_error = null;
|
||||
});
|
||||
return true;
|
||||
} catch (_) {
|
||||
setState(() => _error = context.l10n.updateVolumeFailed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _submit(String text) {
|
||||
final db = double.tryParse(text.trim());
|
||||
if (db == null || !db.isFinite || db < -90 || db > 12) {
|
||||
setState(() => _error = context.l10n.invalidGain);
|
||||
return false;
|
||||
}
|
||||
return _commit(ClipAudioGain(AudioGainScale.quantizeDb(db)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final view = widget.session.view(widget.sequence);
|
||||
return ListenableBuilder(
|
||||
listenable: view,
|
||||
builder: (context, _) {
|
||||
final query = view.version.kernelVersion.query();
|
||||
final handle = query.elementById(widget.clip.id);
|
||||
final record = handle == null ? widget.clip : query.element(handle);
|
||||
final localTick = handle == null
|
||||
? 0
|
||||
: view.playheadTick - query.absoluteStart(handle);
|
||||
final sourceTick = TimelineSourceClock(record).nearestSourceTick(
|
||||
localTick.clamp(0, record.duration > 0 ? record.duration - 1 : 0),
|
||||
);
|
||||
final saved = ClipAudioGain.fromRecord(record, sourceTick: sourceTick);
|
||||
final keyed =
|
||||
record.parameters?[ClipAudioGain.gainId]?.keyframeAt(sourceTick) !=
|
||||
null;
|
||||
final value = _editValid ? _timeline ?? saved : saved;
|
||||
final enabled = widget.hasAudio && handle != null;
|
||||
if (!_dirty) {
|
||||
final text = value.muted ? '-∞' : AudioGainScale.formatDb(value.db);
|
||||
if (_text.text != text) _text.text = text;
|
||||
}
|
||||
if (ClipAudioGain.isDetached(record)) {
|
||||
return Padding(
|
||||
padding: AppSpacing.panelSection,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.audioDetached,
|
||||
style: AppTheme.propertySectionTitleStyle(context),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
OutlinedButton.icon(
|
||||
key: const Key('audio-restore'),
|
||||
icon: const Icon(Icons.volume_up_outlined),
|
||||
label: Text(context.l10n.restoreAudio),
|
||||
onPressed: !enabled || !widget.session.acceptsEdits
|
||||
? null
|
||||
: () {
|
||||
try {
|
||||
widget.session.commands.setAudio(
|
||||
sequence: widget.sequence,
|
||||
clip: record.id,
|
||||
muted: false,
|
||||
);
|
||||
setState(() {
|
||||
_timeline = null;
|
||||
_dirty = false;
|
||||
_editVersion = null;
|
||||
_error = null;
|
||||
});
|
||||
} catch (_) {
|
||||
setState(
|
||||
() => _error = context.l10n.updateVolumeFailed,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_error != null) Text(_error!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: AppSpacing.panelSection,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.hasAudio
|
||||
? context.l10n.volume
|
||||
: context.l10n.unboundAudio,
|
||||
style: AppTheme.propertySectionTitleStyle(context),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('audio-key'),
|
||||
tooltip: context.l10n.toggleKeyframe(
|
||||
keyed
|
||||
? context.l10n.delete
|
||||
: context.l10n.addKeyframeAction,
|
||||
context.l10n.volume,
|
||||
),
|
||||
isSelected: keyed,
|
||||
icon: Transform.rotate(
|
||||
angle: 0.7853981633974483,
|
||||
child: Icon(
|
||||
keyed ? Icons.square : Icons.crop_square,
|
||||
size: 12,
|
||||
),
|
||||
),
|
||||
onPressed: !enabled
|
||||
? null
|
||||
: () {
|
||||
if (_dirty && !_submit(_text.text)) return;
|
||||
_focus.unfocus();
|
||||
FocusManager.instance
|
||||
.applyFocusChangesIfNeeded();
|
||||
try {
|
||||
widget.session.commands.editKeyframeChannel(
|
||||
sequence: widget.sequence,
|
||||
clip: widget.clip.id,
|
||||
tick: view.playheadTick,
|
||||
parameterIds: [ClipAudioGain.gainId],
|
||||
);
|
||||
} catch (_) {
|
||||
setState(
|
||||
() => _error =
|
||||
context.l10n.updateKeyframesFailed,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('audio-mute'),
|
||||
tooltip: value.muted
|
||||
? context.l10n.unmute
|
||||
: context.l10n.mute,
|
||||
isSelected: value.muted,
|
||||
icon: Icon(
|
||||
value.muted ? Icons.volume_off : Icons.volume_up,
|
||||
),
|
||||
onPressed: !enabled
|
||||
? null
|
||||
: () {
|
||||
_editVersion = null;
|
||||
_editTick = null;
|
||||
_commit(
|
||||
ClipAudioGain(saved.db, muted: !saved.muted),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('audio-reset'),
|
||||
tooltip: context.l10n.resetVolume,
|
||||
icon: const Icon(Icons.restart_alt),
|
||||
onPressed: !enabled
|
||||
? null
|
||||
: () {
|
||||
_editVersion = null;
|
||||
_editTick = null;
|
||||
_commit(const ClipAudioGain(0));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppSlider(
|
||||
key: const Key('audio-slider'),
|
||||
value: value.muted
|
||||
? 0
|
||||
: AudioGainScale.positionAt(value.db),
|
||||
semanticFormatterCallback: (p) => p == 0
|
||||
? context.l10n.mute
|
||||
: '${AudioGainScale.formatDb(AudioGainScale.dbAt(p))} dB',
|
||||
onChangeStart: !enabled
|
||||
? null
|
||||
: (_) {
|
||||
_focus.unfocus();
|
||||
FocusManager.instance
|
||||
.applyFocusChangesIfNeeded();
|
||||
_beginEdit();
|
||||
},
|
||||
onChanged: !enabled
|
||||
? null
|
||||
: (p) => setState(() {
|
||||
if (!_editValid) {
|
||||
widget.session.clearAudioGainPreview(
|
||||
widget.clip.id,
|
||||
);
|
||||
_timeline = null;
|
||||
return;
|
||||
}
|
||||
_dirty = false;
|
||||
_timeline = p == 0
|
||||
? ClipAudioGain(saved.db, muted: true)
|
||||
: ClipAudioGain(
|
||||
AudioGainScale.quantizeDb(
|
||||
AudioGainScale.dbAt(p),
|
||||
),
|
||||
);
|
||||
widget.session.previewAudioGain(
|
||||
widget.sequence,
|
||||
widget.clip.id,
|
||||
_timeline!,
|
||||
);
|
||||
}),
|
||||
onChangeEnd: !enabled
|
||||
? null
|
||||
: (_) => _commit(_timeline ?? saved),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
SizedBox(
|
||||
width: 84,
|
||||
child: AppTextField(
|
||||
key: const Key('audio-db'),
|
||||
controller: _text,
|
||||
focusNode: _focus,
|
||||
label: null,
|
||||
unit: 'dB',
|
||||
enabled: enabled,
|
||||
errorText: _error,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
signed: true,
|
||||
decimal: true,
|
||||
),
|
||||
onChanged: (_) {
|
||||
if (!_dirty) {
|
||||
_beginEdit();
|
||||
}
|
||||
_dirty = true;
|
||||
},
|
||||
onSubmitted: _submit,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user