| import { combineArrays, IndexedByteArray } from "../../../utils/indexed_array.js"; |
| import { combineZones } from "./combine_zones.js"; |
| import { writeRIFFOddSize } from "../riff_chunk.js"; |
| import { writeDword } from "../../../utils/byte_functions/little_endian.js"; |
| import { writeDLSRegion } from "./rgn2.js"; |
| import { getStringBytesZero } from "../../../utils/byte_functions/string.js"; |
| import { writeArticulator } from "./art2.js"; |
| import { SpessaSynthGroupCollapsed, SpessaSynthGroupEnd } from "../../../utils/loggin.js"; |
| import { consoleColors } from "../../../utils/other.js"; |
|
|
| |
| |
| |
| |
| |
| export function writeIns(preset) |
| { |
| SpessaSynthGroupCollapsed( |
| `%cWriting %c${preset.presetName}%c...`, |
| consoleColors.info, |
| consoleColors.recognized, |
| consoleColors.info |
| ); |
| |
| const combined = combineZones(preset); |
| |
| const nonGlobalRegionsCount = combined.reduce((sum, z) => |
| { |
| if (!z.isGlobal) |
| { |
| return sum + 1; |
| } |
| return sum; |
| }, 0); |
| |
| |
| const inshData = new IndexedByteArray(12); |
| writeDword(inshData, nonGlobalRegionsCount); |
| |
| let ulBank = (preset.bank & 127) << 8; |
| |
| if (preset.bank === 128) |
| { |
| ulBank |= (1 << 31); |
| } |
| writeDword(inshData, ulBank); |
| writeDword(inshData, preset.program & 127); |
| |
| const insh = writeRIFFOddSize( |
| "insh", |
| inshData |
| ); |
| |
| |
| let lar2 = new IndexedByteArray(0); |
| const globalZone = combined.find(z => z.isGlobal === true); |
| if (globalZone) |
| { |
| const art2 = writeArticulator(globalZone); |
| lar2 = writeRIFFOddSize( |
| "lar2", |
| art2, |
| false, |
| true |
| ); |
| } |
| |
| |
| const lrgnData = combineArrays(combined.reduce((arrs, z) => |
| { |
| if (!z.isGlobal) |
| { |
| arrs.push(writeDLSRegion.apply(this, [z, globalZone])); |
| } |
| return arrs; |
| }, [])); |
| const lrgn = writeRIFFOddSize( |
| "lrgn", |
| lrgnData, |
| false, |
| true |
| ); |
| |
| |
| const inam = writeRIFFOddSize( |
| "INAM", |
| getStringBytesZero(preset.presetName) |
| ); |
| const info = writeRIFFOddSize( |
| "INFO", |
| inam, |
| false, |
| true |
| ); |
| |
| SpessaSynthGroupEnd(); |
| return writeRIFFOddSize( |
| "ins ", |
| combineArrays([insh, lrgn, lar2, info]), |
| false, |
| true |
| ); |
| } |