36 lines
886 B
JavaScript
36 lines
886 B
JavaScript
var CONSTANTS = require("./constants");
|
|
|
|
var FILL_SIZE = 4;
|
|
var PRESET_LENGTH = 257;
|
|
|
|
function creator(data) {
|
|
var buffer = [];
|
|
for (var i = 0; i < CONSTANTS.HEADER.length; i++) {
|
|
buffer.push(CONSTANTS.HEADER.charCodeAt(i));
|
|
}
|
|
buffer.push(26); // <ctrl-z>
|
|
var ending = "!--";
|
|
for (var i = 0; i < ending.length; i++) {
|
|
buffer.push(ending.charCodeAt(i));
|
|
}
|
|
if (!data.presets) {
|
|
throw new Error("Eqf data is missing presets");
|
|
}
|
|
data.presets.forEach(function(preset) {
|
|
var k = 0;
|
|
for (; k < preset.name.length; k++) {
|
|
buffer.push(preset.name.charCodeAt(k));
|
|
}
|
|
for (; k < PRESET_LENGTH; k++) {
|
|
buffer.push(0);
|
|
}
|
|
|
|
CONSTANTS.PRESET_VALUES.forEach(function(valueName) {
|
|
buffer.push(64 - preset[valueName]); // Adjust for inverse values
|
|
});
|
|
});
|
|
return new Uint8Array(buffer).buffer;
|
|
}
|
|
|
|
module.exports = creator;
|