Update template loading to support multiple Ableton versions (v10)

This commit is contained in:
2026-07-13 04:46:46 +02:00
parent 569865249c
commit bdeb078716

View File

@@ -53,19 +53,42 @@ const templateMap: Record<string, () => Promise<any>> = {
effectCompressor: () => import('./templates/effectCompressor.xml?raw'), effectCompressor: () => import('./templates/effectCompressor.xml?raw'),
}; };
export async function loadTemplate<T>(templateName: string): Promise<T> { const live10TemplateMap: Record<string, () => Promise<any>> = {
if (templateCache[templateName]) { midiClip: () => import('./templates/live10/midiClip.xml?raw'),
return templateCache[templateName]; midiTrack: () => import('./templates/live10/midiTrack.xml?raw'),
project: () => import('./templates/live10/project.xml?raw'),
simpler: () => import('./templates/live10/simpler.xml?raw'),
scene: () => import('./templates/live10/scene.xml?raw'),
groupTrack: () => import('./templates/live10/groupTrack.xml?raw'),
drumRack: () => import('./templates/live10/drumRack.xml?raw'),
drumBranch: () => import('./templates/live10/drumBranch.xml?raw'),
returnTrack: () => import('./templates/live10/returnTrack.xml?raw'),
trackSendHolder: () => import('./templates/live10/trackSendHolder.xml?raw'),
effectReverb: () => import('./templates/live10/effectReverb.xml?raw'),
effectDelay: () => import('./templates/live10/effectDelay.xml?raw'),
effectChorus: () => import('./templates/live10/effectChorus.xml?raw'),
effectDistortion: () => import('./templates/live10/effectDistortion.xml?raw'),
effectFilter: () => import('./templates/live10/effectFilter.xml?raw'),
effectCompressor: () => import('./templates/live10/effectCompressor.xml?raw'),
};
export async function loadTemplate<T>(
templateName: string,
abletonVersion: '10' | '11' = '11',
): Promise<T> {
const cacheKey = `${abletonVersion}:${templateName}`;
if (templateCache[cacheKey]) {
return templateCache[cacheKey];
} }
const importFn = templateMap[templateName]; const importFn = abletonVersion === '10' ? live10TemplateMap[templateName] : templateMap[templateName];
if (!importFn) { if (!importFn) {
throw new Error(`Unknown template: ${templateName}`); throw new Error(`Unknown template: ${templateName}`);
} }
const templateModule = await importFn(); const templateModule = await importFn();
const parsed = create(templateModule.default).toObject(); const parsed = create(templateModule.default).toObject();
templateCache[templateName] = parsed; templateCache[cacheKey] = parsed;
return parsed as T; return parsed as T;
} }