Feature: Add option to keep unused patterns during export
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<number>();
|
||||
const usedSoundIds = new Set<number>();
|
||||
@@ -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[] = [];
|
||||
|
||||
Reference in New Issue
Block a user