| import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js"; |
| import { writeDword, writeWord } from "../../../utils/byte_functions/little_endian.js"; |
| import { generatorTypes } from "../generator.js"; |
| import { writeRIFFOddSize } from "../riff_chunk.js"; |
| import { writeWavesample } from "./wsmp.js"; |
| import { writeArticulator } from "./art2.js"; |
|
|
| |
| |
| |
| |
| |
| |
| export function writeDLSRegion(zone, globalZone) |
| { |
| |
| const rgnhData = new IndexedByteArray(12); |
| |
| writeWord(rgnhData, Math.max(zone.keyRange.min, 0)); |
| writeWord(rgnhData, zone.keyRange.max); |
| |
| writeWord(rgnhData, Math.max(zone.velRange.min, 0)); |
| writeWord(rgnhData, zone.velRange.max); |
| |
| writeWord(rgnhData, 0); |
| |
| const exclusive = zone.getGeneratorValue(generatorTypes.exclusiveClass, 0); |
| writeWord(rgnhData, exclusive); |
| |
| writeWord(rgnhData, 0); |
| const rgnh = writeRIFFOddSize( |
| "rgnh", |
| rgnhData |
| ); |
| |
| let rootKey = zone.getGeneratorValue(generatorTypes.overridingRootKey, zone.sample.samplePitch); |
| |
| |
| |
| |
| const scaleTuning = zone.getGeneratorValue( |
| generatorTypes.scaleTuning, |
| globalZone.getGeneratorValue(generatorTypes.scaleTuning, 100) |
| ); |
| if (scaleTuning === 0 && zone.keyRange.max - zone.keyRange.min === 0) |
| { |
| rootKey = zone.keyRange.min; |
| } |
| |
| |
| const wsmp = writeWavesample( |
| zone.sample, |
| rootKey, |
| zone.getGeneratorValue( |
| generatorTypes.fineTune, |
| 0 |
| ) + zone.getGeneratorValue(generatorTypes.coarseTune, 0) * 100 |
| + zone.sample.samplePitchCorrection, |
| zone.getGeneratorValue(generatorTypes.initialAttenuation, 0), |
| |
| zone.sample.sampleLoopStartIndex |
| + zone.getGeneratorValue(generatorTypes.startloopAddrsOffset, 0) |
| + zone.getGeneratorValue(generatorTypes.startloopAddrsCoarseOffset, 0) * 32768, |
| zone.sample.sampleLoopEndIndex |
| + zone.getGeneratorValue(generatorTypes.endloopAddrsOffset, 0) |
| + zone.getGeneratorValue(generatorTypes.endloopAddrsCoarseOffset, 0) * 32768, |
| zone.getGeneratorValue(generatorTypes.sampleModes, 0) |
| ); |
| |
| |
| const wlnkData = new IndexedByteArray(12); |
| writeWord(wlnkData, 0); |
| writeWord(wlnkData, 0); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| writeDword(wlnkData, 1); |
| writeDword(wlnkData, this.samples.indexOf(zone.sample)); |
| const wlnk = writeRIFFOddSize( |
| "wlnk", |
| wlnkData |
| ); |
| |
| |
| let lar2 = new IndexedByteArray(0); |
| if (zone.modulators.length + zone.generators.length > 0) |
| { |
| const art2 = writeArticulator(zone); |
| |
| lar2 = writeRIFFOddSize( |
| "lar2", |
| art2, |
| false, |
| true |
| ); |
| } |
| |
| return writeRIFFOddSize( |
| "rgn2", |
| combineArrays([ |
| rgnh, |
| wsmp, |
| wlnk, |
| lar2 |
| ]), |
| false, |
| true |
| ); |
| } |