diff --git a/src/lib/exporters/ableton/index.ts b/src/lib/exporters/ableton/index.ts index 51dc379..2a8c3fe 100644 --- a/src/lib/exporters/ableton/index.ts +++ b/src/lib/exporters/ableton/index.ts @@ -41,6 +41,7 @@ async function exportAbleton( progressCallback, abortSignal, exporterParams.exportAllPadsWithSamples, + exporterParams.keepUnusedPatterns, ); samples.forEach((s) => { zippedProject.file(`${projectName} Project/Samples/Imported/${s.name}`, s.data); diff --git a/src/lib/exporters/utils.ts b/src/lib/exporters/utils.ts index 7d0f35f..c46eb78 100644 --- a/src/lib/exporters/utils.ts +++ b/src/lib/exporters/utils.ts @@ -219,7 +219,11 @@ export function getSampleName(name: string | undefined, soundId: number, extensi return extension ? `${n}.wav` : n; } -function getSoundsInfoFromProject(data: ProjectRawData, exportAllPadsWithSamples = false) { +function getSoundsInfoFromProject( + data: ProjectRawData, + exportAllPadsWithSamples = false, + keepUnusedPatterns = false, +) { const snds: SoundInfo[] = []; const existingSounds = new Set(); const usedSoundIds = new Set(); @@ -235,6 +239,23 @@ function getSoundsInfoFromProject(data: ProjectRawData, exportAllPadsWithSamples } } + if (keepUnusedPatterns) { + for (const pattern of data.groupPatterns) { + for (const [source, notes] of Object.entries(pattern.notes)) { + if (notes.length === 0) { + continue; + } + + const pad = data.pads[pattern.group]?.find( + (candidate) => candidate.pad === Number(source) + 1, + ); + if (pad?.soundId) { + usedSoundIds.add(pad.soundId); + } + } + } + } + for (const group in data.pads) { for (const pad of data.pads[group]) { if (pad.soundId <= 0) { @@ -267,8 +288,13 @@ export async function collectSamples( progressCallback: ({ progress, status }: ExportStatus) => void, abortSignal: AbortSignal, exportAllPadsWithSamples = false, + keepUnusedPatterns = false, ) { - const projectSounds = getSoundsInfoFromProject(data, exportAllPadsWithSamples); + const projectSounds = getSoundsInfoFromProject( + data, + exportAllPadsWithSamples, + keepUnusedPatterns, + ); const samples: { name: string; data: Blob }[] = []; const downloaded: string[] = [];