gmf-js
Version:
Generic Module Format (GMF) core library for Node.js
56 lines (45 loc) • 1.63 kB
JavaScript
const fs = require("fs");
const path = require("path");
class GMF {
constructor(folderPath) {
this.folderPath = folderPath;
this.gmfJson = null;
this.samples = {};
this.patterns = [];
}
load() {
const gmfJsonPath = path.join(this.folderPath, "gmf.json");
if (!fs.existsSync(gmfJsonPath)) throw new Error(`gmf.json not found in ${this.folderPath}`);
this.gmfJson = JSON.parse(fs.readFileSync(gmfJsonPath, "utf8"));
// Load samples
const sampleFolder = path.join(this.folderPath, "samples");
if (fs.existsSync(sampleFolder)) {
fs.readdirSync(sampleFolder).forEach(file => {
if (file.endsWith(".wav") || file.endsWith(".raw") || file.endsWith(".json")) {
this.samples[file] = path.join(sampleFolder, file);
}
});
}
// Load patterns
const patternFolder = path.join(this.folderPath, "patterns");
if (fs.existsSync(patternFolder)) {
fs.readdirSync(patternFolder).forEach(file => {
if (file.endsWith(".json")) {
const patternData = JSON.parse(fs.readFileSync(path.join(patternFolder, file), "utf8"));
this.patterns.push(patternData);
}
});
}
return this;
}
getInfo() {
return this.gmfJson?.info || {};
}
getSamples() {
return this.samples;
}
getPatterns() {
return this.patterns;
}
}
module.exports = GMF;