|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { generatorTypes } from "./generator.js"; |
|
|
import { Modulator } from "./modulator.js"; |
|
|
import { isXGDrums } from "../../utils/xg_hacks.js"; |
|
|
|
|
|
export class BasicPreset |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parentSoundBank; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
presetName = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
program = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bank = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
presetZones = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foundSamplesAndGenerators = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
genre = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
morphology = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(parentSoundBank) |
|
|
{ |
|
|
this.parentSoundBank = parentSoundBank; |
|
|
for (let i = 0; i < 128; i++) |
|
|
{ |
|
|
this.foundSamplesAndGenerators[i] = []; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isDrumPreset(allowXG, allowSFX = false) |
|
|
{ |
|
|
const xg = allowXG && this.parentSoundBank.isXGBank; |
|
|
|
|
|
return this.bank === 128 || ( |
|
|
xg && |
|
|
(isXGDrums(this.bank) && (this.bank !== 126 || allowSFX)) |
|
|
); |
|
|
} |
|
|
|
|
|
deletePreset() |
|
|
{ |
|
|
this.presetZones.forEach(z => z.deleteZone()); |
|
|
this.presetZones.length = 0; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteZone(index) |
|
|
{ |
|
|
this.presetZones[index].deleteZone(); |
|
|
this.presetZones.splice(index, 1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preload(keyMin, keyMax) |
|
|
{ |
|
|
for (let key = keyMin; key < keyMax + 1; key++) |
|
|
{ |
|
|
for (let velocity = 0; velocity < 128; velocity++) |
|
|
{ |
|
|
this.getSamplesAndGenerators(key, velocity).forEach(samandgen => |
|
|
{ |
|
|
if (!samandgen.sample.isSampleLoaded) |
|
|
{ |
|
|
samandgen.sample.getAudioData(); |
|
|
} |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preloadSpecific(key, velocity) |
|
|
{ |
|
|
this.getSamplesAndGenerators(key, velocity).forEach(samandgen => |
|
|
{ |
|
|
if (!samandgen.sample.isSampleLoaded) |
|
|
{ |
|
|
samandgen.sample.getAudioData(); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getSamplesAndGenerators(midiNote, velocity) |
|
|
{ |
|
|
const memorized = this.foundSamplesAndGenerators[midiNote][velocity]; |
|
|
if (memorized) |
|
|
{ |
|
|
return memorized; |
|
|
} |
|
|
|
|
|
if (this.presetZones.length < 1) |
|
|
{ |
|
|
return []; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isInRange(range, number) |
|
|
{ |
|
|
return number >= range.min && number <= range.max; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addUnique(main, adder) |
|
|
{ |
|
|
main.push(...adder.filter(g => !main.find(mg => mg.generatorType === g.generatorType))); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addUniqueMods(main, adder) |
|
|
{ |
|
|
main.push(...adder.filter(m => !main.find(mm => Modulator.isIdentical(m, mm)))); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let parsedGeneratorsAndSamples = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let globalPresetGenerators = this.presetZones[0].isGlobal ? [...this.presetZones[0].generators] : []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let globalPresetModulators = this.presetZones[0].isGlobal ? [...this.presetZones[0].modulators] : []; |
|
|
const globalKeyRange = this.presetZones[0].isGlobal ? this.presetZones[0].keyRange : { min: 0, max: 127 }; |
|
|
const globalVelRange = this.presetZones[0].isGlobal ? this.presetZones[0].velRange : { min: 0, max: 127 }; |
|
|
|
|
|
|
|
|
let presetZonesInRange = this.presetZones.filter(currentZone => |
|
|
( |
|
|
isInRange( |
|
|
currentZone.hasKeyRange ? currentZone.keyRange : globalKeyRange, |
|
|
midiNote |
|
|
) |
|
|
&& |
|
|
isInRange( |
|
|
currentZone.hasVelRange ? currentZone.velRange : globalVelRange, |
|
|
velocity |
|
|
) |
|
|
) && !currentZone.isGlobal); |
|
|
|
|
|
presetZonesInRange.forEach(zone => |
|
|
{ |
|
|
|
|
|
if (zone.instrument.instrumentZones.length < 1) |
|
|
{ |
|
|
return; |
|
|
} |
|
|
let presetGenerators = zone.generators; |
|
|
let presetModulators = zone.modulators; |
|
|
const firstZone = zone.instrument.instrumentZones[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let globalInstrumentGenerators = firstZone.isGlobal ? [...firstZone.generators] : []; |
|
|
let globalInstrumentModulators = firstZone.isGlobal ? [...firstZone.modulators] : []; |
|
|
const globalKeyRange = firstZone.isGlobal ? firstZone.keyRange : { min: 0, max: 127 }; |
|
|
const globalVelRange = firstZone.isGlobal ? firstZone.velRange : { min: 0, max: 127 }; |
|
|
|
|
|
|
|
|
let instrumentZonesInRange = zone.instrument.instrumentZones |
|
|
.filter(currentZone => |
|
|
( |
|
|
isInRange( |
|
|
currentZone.hasKeyRange ? currentZone.keyRange : globalKeyRange, |
|
|
midiNote |
|
|
) |
|
|
&& |
|
|
isInRange( |
|
|
currentZone.hasVelRange ? currentZone.velRange : globalVelRange, |
|
|
velocity |
|
|
) |
|
|
) && !currentZone.isGlobal |
|
|
); |
|
|
|
|
|
instrumentZonesInRange.forEach(instrumentZone => |
|
|
{ |
|
|
let instrumentGenerators = [...instrumentZone.generators]; |
|
|
let instrumentModulators = [...instrumentZone.modulators]; |
|
|
|
|
|
addUnique( |
|
|
presetGenerators, |
|
|
globalPresetGenerators |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addUnique( |
|
|
instrumentGenerators, |
|
|
globalInstrumentGenerators |
|
|
); |
|
|
|
|
|
addUniqueMods( |
|
|
presetModulators, |
|
|
globalPresetModulators |
|
|
); |
|
|
addUniqueMods( |
|
|
instrumentModulators, |
|
|
globalInstrumentModulators |
|
|
); |
|
|
|
|
|
|
|
|
addUniqueMods( |
|
|
instrumentModulators, |
|
|
this.parentSoundBank.defaultModulators |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const finalModulatorList = [...instrumentModulators]; |
|
|
for (let i = 0; i < presetModulators.length; i++) |
|
|
{ |
|
|
let mod = presetModulators[i]; |
|
|
const identicalInstrumentModulator = finalModulatorList.findIndex( |
|
|
m => Modulator.isIdentical(mod, m)); |
|
|
if (identicalInstrumentModulator !== -1) |
|
|
{ |
|
|
|
|
|
|
|
|
finalModulatorList[identicalInstrumentModulator] = finalModulatorList[identicalInstrumentModulator].sumTransform( |
|
|
mod); |
|
|
} |
|
|
else |
|
|
{ |
|
|
finalModulatorList.push(mod); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
parsedGeneratorsAndSamples.push({ |
|
|
instrumentGenerators: instrumentGenerators, |
|
|
presetGenerators: presetGenerators, |
|
|
modulators: finalModulatorList, |
|
|
sample: instrumentZone.sample, |
|
|
sampleID: instrumentZone.generators.find( |
|
|
g => g.generatorType === generatorTypes.sampleID).generatorValue |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.foundSamplesAndGenerators[midiNote][velocity] = parsedGeneratorsAndSamples; |
|
|
return parsedGeneratorsAndSamples; |
|
|
} |
|
|
} |