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