Implement ID management and reset functionality for Ableton export
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
||||
gzipString,
|
||||
koEnvRangeToSeconds,
|
||||
loadTemplate,
|
||||
resetIds,
|
||||
TIME_SIGNATURES,
|
||||
toNativePath,
|
||||
} from './utils';
|
||||
@@ -611,6 +612,7 @@ async function buildReturnTrack(projectData: ProjectRawData, trackId: number = 0
|
||||
}
|
||||
|
||||
export async function buildProject(projectData: ProjectRawData, exporterParams: ExporterParams) {
|
||||
resetIds();
|
||||
const transformedData = abletonTransformer(projectData, exporterParams);
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
|
||||
@@ -31,6 +31,7 @@ const MIN_ID = 22000;
|
||||
const START_ID = 22000;
|
||||
|
||||
let _id = START_ID;
|
||||
let assignedNodes = new WeakSet<object>();
|
||||
const templateCache: Record<string, any> = {};
|
||||
|
||||
const templateMap: Record<string, () => Promise<any>> = {
|
||||
@@ -80,27 +81,34 @@ export function fixIds(node: any): any {
|
||||
return node.map((n) => fixIds(n));
|
||||
}
|
||||
|
||||
if (!node || typeof node !== 'object') {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node?.['@Id']) {
|
||||
const idNum = parseInt(String(node['@Id']), 10);
|
||||
|
||||
if (idNum > MIN_ID) {
|
||||
if (idNum > MIN_ID && !assignedNodes.has(node)) {
|
||||
node['@Id'] = _id;
|
||||
|
||||
assignedNodes.add(node);
|
||||
_id++;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof node === 'object') {
|
||||
Object.keys(node).forEach((key) => {
|
||||
if (!key.startsWith('@')) {
|
||||
node[key] = fixIds(node[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
export function resetIds() {
|
||||
_id = START_ID;
|
||||
assignedNodes = new WeakSet<object>();
|
||||
}
|
||||
|
||||
export function getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user