keepClipRanges method
Rebuilds the timeline so each clip in rangesByClipId only keeps the
listed file-time ranges (silence removal). Clips not listed, or listed
with no ranges, stay as they are unless dropUnlisted (AI Shorts keeps
only the picked moments). One undo step. Returns how much project time
was removed.
Implementation
Duration keepClipRanges(
Map<String, List<TimeRange>> rangesByClipId, {
bool dropUnlisted = false,
}) {
final before = totalDuration;
final stamp = DateTime.now().microsecondsSinceEpoch;
final rebuilt = <VideoEditorClip>[];
for (final clip in clips) {
final ranges = rangesByClipId[clip.id];
if (clip.isImage || ranges == null || ranges.isEmpty) {
if (!dropUnlisted) rebuilt.add(clip);
continue;
}
for (var n = 0; n < ranges.length; n++) {
rebuilt.add(clip.copyWith(
id: n == 0 ? clip.id : '${clip.id}_talk_${stamp}_$n',
startTime: ranges[n].start,
endTime: ranges[n].end,
)..markEdited());
}
}
clipController.restore(rebuilt);
if (_currentGlobalTime.value > totalDuration) {
_currentGlobalTime.value = totalDuration;
}
_saveState();
notifyListeners();
_updateVideoPlayerForCurrentClip();
final removed = before - totalDuration;
return removed < Duration.zero ? Duration.zero : removed;
}