Update template loading to support multiple Ableton versions (v10)
This commit is contained in:
@@ -53,19 +53,42 @@ const templateMap: Record<string, () => Promise<any>> = {
|
||||
effectCompressor: () => import('./templates/effectCompressor.xml?raw'),
|
||||
};
|
||||
|
||||
export async function loadTemplate<T>(templateName: string): Promise<T> {
|
||||
if (templateCache[templateName]) {
|
||||
return templateCache[templateName];
|
||||
const live10TemplateMap: Record<string, () => Promise<any>> = {
|
||||
midiClip: () => import('./templates/live10/midiClip.xml?raw'),
|
||||
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) {
|
||||
throw new Error(`Unknown template: ${templateName}`);
|
||||
}
|
||||
|
||||
const templateModule = await importFn();
|
||||
const parsed = create(templateModule.default).toObject();
|
||||
templateCache[templateName] = parsed;
|
||||
templateCache[cacheKey] = parsed;
|
||||
return parsed as T;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user