feat: implemented track level automation
This commit is contained in:
@@ -8,6 +8,7 @@ import { upgradeToV6 } from './upgradeToV6';
|
||||
import { upgradeToV7 } from './upgradeToV7';
|
||||
import { upgradeToV8 } from './upgradeToV8';
|
||||
import { upgradeToV9 } from './upgradeToV9';
|
||||
import { upgradeToV10 } from './upgradeToV10';
|
||||
|
||||
/**
|
||||
* Upgrade the given project to the latest structure version, one version at a time.
|
||||
@@ -63,6 +64,10 @@ export function upgradeProjectToLatest(project: KGProject): KGProject {
|
||||
workingProject = upgradeToV9(workingProject);
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
workingProject = upgradeToV10(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}`);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { KGProject } from '../KGProject';
|
||||
import { KGTrack } from '../track/KGTrack';
|
||||
import { KGTrackAutomationPoint } from '../track/KGTrackAutomationPoint';
|
||||
import { upgradeProjectToLatest } from './KGProjectUpgrader';
|
||||
import { upgradeToV10 } from './upgradeToV10';
|
||||
|
||||
describe('upgradeToV10', () => {
|
||||
it('initializes missing track automation arrays on legacy tracks', () => {
|
||||
const track = new KGTrack('Legacy Track', 1);
|
||||
delete (track as unknown as { volumeAutomation?: unknown }).volumeAutomation;
|
||||
delete (track as unknown as { panAutomation?: unknown }).panAutomation;
|
||||
const project = new KGProject('Test', 32, 0, 125, undefined, undefined, undefined, undefined, undefined, 1, [track], 9);
|
||||
|
||||
upgradeToV10(project);
|
||||
|
||||
expect(track.getVolumeAutomation()).toEqual([]);
|
||||
expect(track.getPanAutomation()).toEqual([]);
|
||||
expect(project.getProjectStructureVersion()).toBe(10);
|
||||
});
|
||||
|
||||
it('preserves existing track automation points through the main upgrader path', () => {
|
||||
const track = new KGTrack('Legacy Track', 1);
|
||||
track.setVolumeAutomation([new KGTrackAutomationPoint('point-1', 1, -3)]);
|
||||
const project = new KGProject('Test', 32, 0, 125, undefined, undefined, undefined, undefined, undefined, 1, [track], 9);
|
||||
|
||||
const upgraded = upgradeProjectToLatest(project);
|
||||
|
||||
expect(upgraded.getProjectStructureVersion()).toBe(10);
|
||||
expect(upgraded.getTracks()[0].getVolumeAutomation()).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { KGProject } from '../KGProject';
|
||||
|
||||
export function upgradeToV10(project: KGProject): KGProject {
|
||||
try {
|
||||
for (const track of project.getTracks()) {
|
||||
const volumeAutomation = (track as unknown as { volumeAutomation?: unknown }).volumeAutomation;
|
||||
if (!Array.isArray(volumeAutomation)) {
|
||||
track.setVolumeAutomation([]);
|
||||
}
|
||||
|
||||
const panAutomation = (track as unknown as { panAutomation?: unknown }).panAutomation;
|
||||
if (!Array.isArray(panAutomation)) {
|
||||
track.setPanAutomation([]);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
project.setProjectStructureVersion(10);
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ describe('upgradeToV8', () => {
|
||||
|
||||
const upgraded = upgradeProjectToLatest(project);
|
||||
|
||||
expect(upgraded.getProjectStructureVersion()).toBe(9);
|
||||
expect(upgraded.getProjectStructureVersion()).toBe(10);
|
||||
expect((upgraded.getTracks()[0].getRegions()[0] as KGMidiRegion).getPitchBends()).toEqual([]);
|
||||
expect((upgraded.getTracks()[0].getRegions()[0] as KGMidiRegion).getControllerEventsByType()).toHaveLength(128);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user