feat: add audio region trimming with non-destructive clip offset

This commit is contained in:
Xiaohan-Tian
2026-04-10 20:17:31 -07:00
parent 39401b39c6
commit 1670679c61
8 changed files with 192 additions and 60 deletions
@@ -4,6 +4,7 @@ import { upgradeToV2 } from './upgradeToV2';
import { upgradeToV3 } from './upgradeToV3';
import { upgradeToV4 } from './upgradeToV4';
import { upgradeToV5 } from './upgradeToV5';
import { upgradeToV6 } from './upgradeToV6';
/**
* Upgrade the given project to the latest structure version, one version at a time.
@@ -43,6 +44,10 @@ export function upgradeProjectToLatest(project: KGProject): KGProject {
workingProject = upgradeToV5(workingProject);
break;
}
case 6: {
workingProject = upgradeToV6(workingProject);
break;
}
default: {
// If an upgrader is missing, throw to prevent loading incompatible structures
throw new Error(`No upgrader found for project structure version ${nextVersion}`);
+21
View File
@@ -0,0 +1,21 @@
import { KGProject } from '../KGProject';
import { KGAudioRegion } from '../region/KGAudioRegion';
export function upgradeToV6(project: KGProject): KGProject {
try {
// Ensure all audio regions have clipStartOffsetSeconds initialized
for (const track of project.getTracks()) {
for (const region of track.getRegions()) {
if (region instanceof KGAudioRegion) {
const current = region.getClipStartOffsetSeconds?.();
if (current === undefined || current === null) {
region.setClipStartOffsetSeconds(0);
}
}
}
}
} finally {
project.setProjectStructureVersion(6);
}
return project;
}