@marmooo/midy 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/esm/deps/cdn.jsdelivr.net/npm/@marmooo/{soundfont-parser@0.0.4 → soundfont-parser@0.0.6}/+esm.d.ts +16 -20
  2. package/esm/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.6/+esm.d.ts.map +1 -0
  3. package/esm/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.6/+esm.js +180 -0
  4. package/esm/midy-GM1.d.ts +29 -1
  5. package/esm/midy-GM1.d.ts.map +1 -1
  6. package/esm/midy-GM1.js +27 -32
  7. package/esm/midy-GM2.d.ts +53 -1
  8. package/esm/midy-GM2.d.ts.map +1 -1
  9. package/esm/midy-GM2.js +81 -79
  10. package/esm/midy-GMLite.d.ts +29 -1
  11. package/esm/midy-GMLite.d.ts.map +1 -1
  12. package/esm/midy-GMLite.js +27 -32
  13. package/esm/midy.d.ts +73 -1
  14. package/esm/midy.d.ts.map +1 -1
  15. package/esm/midy.js +104 -97
  16. package/package.json +1 -1
  17. package/script/deps/cdn.jsdelivr.net/npm/@marmooo/{soundfont-parser@0.0.4 → soundfont-parser@0.0.6}/+esm.d.ts +16 -20
  18. package/script/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.6/+esm.d.ts.map +1 -0
  19. package/script/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.6/+esm.js +190 -0
  20. package/script/midy-GM1.d.ts +29 -1
  21. package/script/midy-GM1.d.ts.map +1 -1
  22. package/script/midy-GM1.js +27 -32
  23. package/script/midy-GM2.d.ts +53 -1
  24. package/script/midy-GM2.d.ts.map +1 -1
  25. package/script/midy-GM2.js +81 -79
  26. package/script/midy-GMLite.d.ts +29 -1
  27. package/script/midy-GMLite.d.ts.map +1 -1
  28. package/script/midy-GMLite.js +27 -32
  29. package/script/midy.d.ts +73 -1
  30. package/script/midy.d.ts.map +1 -1
  31. package/script/midy.js +104 -97
  32. package/esm/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.d.ts.map +0 -1
  33. package/esm/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.js +0 -162
  34. package/script/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.d.ts.map +0 -1
  35. package/script/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.js +0 -169
package/script/midy.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Midy = void 0;
4
4
  const _esm_js_1 = require("./deps/cdn.jsdelivr.net/npm/midi-file@1.2.4/+esm.js");
5
- const _esm_js_2 = require("./deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.js");
5
+ const _esm_js_2 = require("./deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.6/+esm.js");
6
6
  class Note {
7
7
  constructor(noteNumber, velocity, startTime, instrumentKey) {
8
8
  Object.defineProperty(this, "bufferSource", {
@@ -233,6 +233,7 @@ class Midy {
233
233
  this.audioContext = audioContext;
234
234
  this.options = { ...this.defaultOptions, ...options };
235
235
  this.masterGain = new GainNode(audioContext);
236
+ this.controlChangeHandlers = this.createControlChangeHandlers();
236
237
  this.channels = this.createChannels(audioContext);
237
238
  this.reverbEffect = this.options.reverbAlgorithm(audioContext);
238
239
  this.chorusEffect = this.createChorusEffect(audioContext);
@@ -934,7 +935,7 @@ class Midy {
934
935
  return;
935
936
  const soundFont = this.soundFonts[soundFontIndex];
936
937
  const isSF3 = soundFont.parsed.info.version.major === 3;
937
- const instrumentKey = soundFont.getInstrumentKey(bankNumber, channel.program, noteNumber);
938
+ const instrumentKey = soundFont.getInstrumentKey(bankNumber, channel.program, noteNumber, velocity);
938
939
  if (!instrumentKey)
939
940
  return;
940
941
  const note = await this.createNote(channel, instrumentKey, noteNumber, velocity, startTime, isSF3);
@@ -957,10 +958,12 @@ class Midy {
957
958
  }
958
959
  scheduleNoteRelease(channelNumber, noteNumber, _velocity, stopTime, stopPedal = false) {
959
960
  const channel = this.channels[channelNumber];
960
- if (stopPedal && channel.sustainPedal)
961
- return;
962
- if (stopPedal && channel.sostenutoNotes.has(noteNumber))
963
- return;
961
+ if (stopPedal) {
962
+ if (channel.sustainPedal)
963
+ return;
964
+ if (channel.sostenutoNotes.has(noteNumber))
965
+ return;
966
+ }
964
967
  if (!channel.scheduledNotes.has(noteNumber))
965
968
  return;
966
969
  const scheduledNotes = channel.scheduledNotes.get(noteNumber);
@@ -989,16 +992,15 @@ class Midy {
989
992
  note.bufferSource.disconnect();
990
993
  note.volumeNode.disconnect();
991
994
  note.filterNode.disconnect();
992
- if (note.volumeDepth)
995
+ if (note.modulationDepth) {
993
996
  note.volumeDepth.disconnect();
994
- if (note.modulationDepth)
995
997
  note.modulationDepth.disconnect();
996
- if (note.modulationLFO)
997
998
  note.modulationLFO.stop();
998
- if (note.vibratoDepth)
999
+ }
1000
+ if (note.vibratoDepth) {
999
1001
  note.vibratoDepth.disconnect();
1000
- if (note.vibratoLFO)
1001
1002
  note.vibratoLFO.stop();
1003
+ }
1002
1004
  resolve();
1003
1005
  };
1004
1006
  note.bufferSource.stop(volEndTime);
@@ -1108,78 +1110,51 @@ class Midy {
1108
1110
  channel.pitchBendRange * 100;
1109
1111
  this.updateDetune(channel, detuneChange);
1110
1112
  }
1113
+ createControlChangeHandlers() {
1114
+ return {
1115
+ 0: this.setBankMSB,
1116
+ 1: this.setModulationDepth,
1117
+ 5: this.setPortamentoTime,
1118
+ 6: this.dataEntryMSB,
1119
+ 7: this.setVolume,
1120
+ 10: this.setPan,
1121
+ 11: this.setExpression,
1122
+ 32: this.setBankLSB,
1123
+ 38: this.dataEntryLSB,
1124
+ 64: this.setSustainPedal,
1125
+ 65: this.setPortamento,
1126
+ 66: this.setSostenutoPedal,
1127
+ 67: this.setSoftPedal,
1128
+ 71: this.setFilterResonance,
1129
+ 72: this.setReleaseTime,
1130
+ 73: this.setAttackTime,
1131
+ 74: this.setBrightness,
1132
+ 75: this.setDecayTime,
1133
+ 76: this.setVibratoRate,
1134
+ 77: this.setVibratoDepth,
1135
+ 78: this.setVibratoDelay,
1136
+ 91: this.setReverbSendLevel,
1137
+ 93: this.setChorusSendLevel,
1138
+ 96: this.dataIncrement,
1139
+ 97: this.dataDecrement,
1140
+ 100: this.setRPNLSB,
1141
+ 101: this.setRPNMSB,
1142
+ 120: this.allSoundOff,
1143
+ 121: this.resetAllControllers,
1144
+ 123: this.allNotesOff,
1145
+ 124: this.omniOff,
1146
+ 125: this.omniOn,
1147
+ 126: this.monoOn,
1148
+ 127: this.polyOn,
1149
+ };
1150
+ }
1111
1151
  handleControlChange(channelNumber, controller, value) {
1112
- switch (controller) {
1113
- case 0:
1114
- return this.setBankMSB(channelNumber, value);
1115
- case 1:
1116
- return this.setModulationDepth(channelNumber, value);
1117
- case 5:
1118
- return this.setPortamentoTime(channelNumber, value);
1119
- case 6:
1120
- return this.dataEntryMSB(channelNumber, value);
1121
- case 7:
1122
- return this.setVolume(channelNumber, value);
1123
- case 10:
1124
- return this.setPan(channelNumber, value);
1125
- case 11:
1126
- return this.setExpression(channelNumber, value);
1127
- case 32:
1128
- return this.setBankLSB(channelNumber, value);
1129
- case 38:
1130
- return this.dataEntryLSB(channelNumber, value);
1131
- case 64:
1132
- return this.setSustainPedal(channelNumber, value);
1133
- case 65:
1134
- return this.setPortamento(channelNumber, value);
1135
- case 66:
1136
- return this.setSostenutoPedal(channelNumber, value);
1137
- case 67:
1138
- return this.setSoftPedal(channelNumber, value);
1139
- case 71:
1140
- return this.setFilterResonance(channelNumber, value);
1141
- case 72:
1142
- return this.setReleaseTime(channelNumber, value);
1143
- case 73:
1144
- return this.setAttackTime(channelNumber, value);
1145
- case 74:
1146
- return this.setBrightness(channelNumber, value);
1147
- case 75:
1148
- return this.setDecayTime(channelNumber, value);
1149
- case 76:
1150
- return this.setVibratoRate(channelNumber, value);
1151
- case 77:
1152
- return this.setVibratoDepth(channelNumber, value);
1153
- case 78:
1154
- return this.setVibratoDelay(channelNumber, value);
1155
- case 91:
1156
- return this.setReverbSendLevel(channelNumber, value);
1157
- case 93:
1158
- return this.setChorusSendLevel(channelNumber, value);
1159
- case 96: // https://amei.or.jp/midistandardcommittee/Recommended_Practice/e/rp18.pdf
1160
- return this.dataIncrement(channelNumber);
1161
- case 97: // https://amei.or.jp/midistandardcommittee/Recommended_Practice/e/rp18.pdf
1162
- return this.dataDecrement(channelNumber);
1163
- case 100:
1164
- return this.setRPNLSB(channelNumber, value);
1165
- case 101:
1166
- return this.setRPNMSB(channelNumber, value);
1167
- case 120:
1168
- return this.allSoundOff(channelNumber);
1169
- case 121:
1170
- return this.resetAllControllers(channelNumber);
1171
- case 123:
1172
- return this.allNotesOff(channelNumber);
1173
- case 124:
1174
- return this.omniOff();
1175
- case 125:
1176
- return this.omniOn();
1177
- case 126:
1178
- return this.monoOn();
1179
- case 127:
1180
- return this.polyOn();
1181
- default:
1182
- console.warn(`Unsupported Control change: controller=${controller} value=${value}`);
1152
+ const handler = this.controlChangeHandlers[controller];
1153
+ if (handler) {
1154
+ handler.call(this, channelNumber, value);
1155
+ }
1156
+ else {
1157
+ console.warn(`Unsupported Control change: controller=${controller} value=${value}`);
1183
1158
  }
1184
1159
  }
1185
1160
  setBankMSB(channelNumber, msb) {
@@ -1264,28 +1239,49 @@ class Midy {
1264
1239
  }
1265
1240
  setReverbSendLevel(channelNumber, reverbSendLevel) {
1266
1241
  const channel = this.channels[channelNumber];
1267
- const reverbEffect = this.reverbEffect;
1268
- if (0 < reverbSendLevel) {
1269
- const now = this.audioContext.currentTime;
1270
- channel.reverbSendLevel = reverbSendLevel / 127;
1271
- reverbEffect.output.gain.cancelScheduledValues(now);
1272
- reverbEffect.output.gain.setValueAtTime(channel.reverbSendLevel, now);
1242
+ if (0 < channel.reverbSendLevel) {
1243
+ if (0 < reverbSendLevel) {
1244
+ const now = this.audioContext.currentTime;
1245
+ channel.reverbSendLevel = reverbSendLevel / 127;
1246
+ reverbEffect.output.gain.cancelScheduledValues(now);
1247
+ reverbEffect.output.gain.setValueAtTime(channel.reverbSendLevel, now);
1248
+ }
1249
+ else {
1250
+ channel.merger.disconnect(reverbEffect.input);
1251
+ }
1273
1252
  }
1274
- else if (channel.reverbSendLevel !== 0) {
1275
- channel.merger.disconnect(reverbEffect.input);
1253
+ else {
1254
+ if (0 < reverbSendLevel) {
1255
+ channel.merger.connect(reverbEffect.input);
1256
+ const now = this.audioContext.currentTime;
1257
+ channel.reverbSendLevel = reverbSendLevel / 127;
1258
+ reverbEffect.output.gain.cancelScheduledValues(now);
1259
+ reverbEffect.output.gain.setValueAtTime(channel.reverbSendLevel, now);
1260
+ }
1276
1261
  }
1277
1262
  }
1278
1263
  setChorusSendLevel(channelNumber, chorusSendLevel) {
1279
1264
  const channel = this.channels[channelNumber];
1280
1265
  const chorusEffect = this.chorusEffect;
1281
- if (0 < chorusSendLevel) {
1282
- const now = this.audioContext.currentTime;
1283
- channel.chorusSendLevel = chorusSendLevel / 127;
1284
- chorusEffect.output.gain.cancelScheduledValues(now);
1285
- chorusEffect.output.gain.setValueAtTime(channel.chorusSendLevel, now);
1266
+ if (0 < channel.chorusSendLevel) {
1267
+ if (0 < chorusSendLevel) {
1268
+ const now = this.audioContext.currentTime;
1269
+ channel.chorusSendLevel = chorusSendLevel / 127;
1270
+ chorusEffect.output.gain.cancelScheduledValues(now);
1271
+ chorusEffect.output.gain.setValueAtTime(channel.chorusSendLevel, now);
1272
+ }
1273
+ else {
1274
+ channel.merger.disconnect(chorusEffect.input);
1275
+ }
1286
1276
  }
1287
- else if (channel.chorusSendLevel !== 0) {
1288
- channel.merger.disconnect(chorusEffect.input);
1277
+ else {
1278
+ if (0 < chorusSendLevel) {
1279
+ channel.merger.connect(chorusEffect.input);
1280
+ const now = this.audioContext.currentTime;
1281
+ channel.chorusSendLevel = chorusSendLevel / 127;
1282
+ chorusEffect.output.gain.cancelScheduledValues(now);
1283
+ chorusEffect.output.gain.setValueAtTime(channel.chorusSendLevel, now);
1284
+ }
1289
1285
  }
1290
1286
  }
1291
1287
  setSostenutoPedal(channelNumber, value) {
@@ -1366,6 +1362,15 @@ class Midy {
1366
1362
  setVibratoRate(channelNumber, vibratoRate) {
1367
1363
  const channel = this.channels[channelNumber];
1368
1364
  channel.vibratoRate = vibratoRate / 64;
1365
+ if (channel.vibratoDepth <= 0)
1366
+ return;
1367
+ const now = this.audioContext.currentTime;
1368
+ const activeNotes = this.getActiveNotes(channel, now);
1369
+ activeNotes.forEach((activeNote) => {
1370
+ activeNote.vibratoLFO.frequency
1371
+ .cancelScheduledValues(now)
1372
+ .setValueAtTime(channel.vibratoRate, now);
1373
+ });
1369
1374
  }
1370
1375
  setVibratoDepth(channelNumber, vibratoDepth) {
1371
1376
  const channel = this.channels[channelNumber];
@@ -1425,9 +1430,11 @@ class Midy {
1425
1430
  console.warn(`Channel ${channelNumber}: Unsupported RPN MSB=${channel.rpnMSB} LSB=${channel.rpnLSB}`);
1426
1431
  }
1427
1432
  }
1433
+ // https://amei.or.jp/midistandardcommittee/Recommended_Practice/e/rp18.pdf
1428
1434
  dataIncrement(channelNumber) {
1429
1435
  this.handleRPN(channelNumber, 1);
1430
1436
  }
1437
+ // https://amei.or.jp/midistandardcommittee/Recommended_Practice/e/rp18.pdf
1431
1438
  dataDecrement(channelNumber) {
1432
1439
  this.handleRPN(channelNumber, -1);
1433
1440
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"+esm.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.js"],"names":[],"mappings":";;AAMi9Z;IAAQ,oBAA2H;IAAd,YAAa;IAAC,qDAAoJ;IAAA,mCAAoP;IAAA,uCAAwQ;IAAA,+DAAqP;IAAA,gDAAuX;IAAA,mCAAiL;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAA03E;IAAA,qBAA0I;CAAC;AAAj6L,+BAAmL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAniE;;;;;;;;;;;;;;;;EAA27B;AAAs1N,mCAAwC;AAA3sQ;IAAQ,oCAAyU;IAAnC,SAAU;IAAC,WAAY;IAAC,SAAU;IAAC,gBAAgE;CAAC;AAApyH;IAAqQ,wBAAwD;IAArT,4BAAyN;IAApB,QAAS;IAAC,QAAS;IAAC,oBAAoC;CAAyD;AAAllG;IAAwjC,gCAA8d;CAAC"}
@@ -1,162 +0,0 @@
1
- /**
2
- * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.
3
- * Original file: /npm/@marmooo/soundfont-parser@0.0.4/esm/mod.js
4
- *
5
- * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
6
- */
7
- class e {
8
- constructor(e, t) { Object.defineProperty(this, "data", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "ip", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), this.data = e, this.ip = t; }
9
- readString(e) { const t = this.data.subarray(this.ip, this.ip += e), n = String.fromCharCode(...Array.from(t)), r = n.indexOf("\0"); return r > 0 ? n.substring(0, r) : n; }
10
- readWORD() { return this.data[this.ip++] | this.data[this.ip++] << 8; }
11
- readDWORD(e = !1) { return e ? (this.data[this.ip++] << 24 | this.data[this.ip++] << 16 | this.data[this.ip++] << 8 | this.data[this.ip++]) >>> 0 : (this.data[this.ip++] | this.data[this.ip++] << 8 | this.data[this.ip++] << 16 | this.data[this.ip++] << 24) >>> 0; }
12
- readByte() { return this.data[this.ip++]; }
13
- readAt(e) { return this.data[this.ip + e]; }
14
- readUInt8() { return this.readByte(); }
15
- readInt8() { return this.readByte() << 24 >> 24; }
16
- readUInt16() { return this.readWORD(); }
17
- readInt16() { return this.readWORD() << 16 >> 16; }
18
- readUInt32() { return this.readDWORD(); }
19
- }
20
- function t(t, n, a) { const i = new e(t, n), o = i.readString(4), s = i.readDWORD(a); return new r(o, s, i.ip); }
21
- function n(e, n = 0, r, { padding: a = !0, bigEndian: i = !1 } = {}) { const o = [], s = r + n; let l = n; for (; l < s;) {
22
- const r = t(e, l, i);
23
- l = r.offset + r.size, a && 1 == (l - n & 1) && l++, o.push(r);
24
- } return o; }
25
- class r {
26
- constructor(e, t, n) { Object.defineProperty(this, "type", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "size", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "offset", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), this.type = e, this.size = t, this.offset = n; }
27
- }
28
- const a = ["startAddrsOffset", "endAddrsOffset", "startloopAddrsOffset", "endloopAddrsOffset", "startAddrsCoarseOffset", "modLfoToPitch", "vibLfoToPitch", "modEnvToPitch", "initialFilterFc", "initialFilterQ", "modLfoToFilterFc", "modEnvToFilterFc", "endAddrsCoarseOffset", "modLfoToVolume", void 0, "chorusEffectsSend", "reverbEffectsSend", "pan", void 0, void 0, void 0, "delayModLFO", "freqModLFO", "delayVibLFO", "freqVibLFO", "delayModEnv", "attackModEnv", "holdModEnv", "decayModEnv", "sustainModEnv", "releaseModEnv", "keynumToModEnvHold", "keynumToModEnvDecay", "delayVolEnv", "attackVolEnv", "holdVolEnv", "decayVolEnv", "sustainVolEnv", "releaseVolEnv", "keynumToVolEnvHold", "keynumToVolEnvDecay", "instrument", void 0, "keyRange", "velRange", "startloopAddrsCoarseOffset", "keynum", "velocity", "initialAttenuation", void 0, "endloopAddrsCoarseOffset", "coarseTune", "fineTune", "sampleID", "sampleModes", void 0, "scaleTuning", "exclusiveClass", "overridingRootKey"];
29
- class i {
30
- constructor() { Object.defineProperty(this, "major", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "minor", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
31
- static parse(e) { const t = new i; return t.major = e.readInt8(), t.minor = e.readInt8(), t; }
32
- }
33
- class o {
34
- constructor() { Object.defineProperty(this, "comment", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "copyright", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "creationDate", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "engineer", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "name", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "product", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "software", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "version", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "soundEngine", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "romName", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "romVersion", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
35
- static parse(t, n) { function r(e) { return n.find((t => t.type === e)); } function a(n) { return new e(t, n.offset); } function s(e) { const t = r(e); return t ? a(t).readString(t.size) : null; } function l(e) { const t = r(e); return t ? i.parse(a(t)) : null; } const d = new o; return d.comment = s("ICMT"), d.copyright = s("ICOP"), d.creationDate = s("ICRD"), d.engineer = s("IENG"), d.name = s("INAM"), d.product = s("IPRD"), d.software = s("ISFT"), d.version = l("ifil"), d.soundEngine = s("isng"), d.romName = s("irom"), d.romVersion = l("iver"), d; }
36
- }
37
- class s {
38
- constructor() { Object.defineProperty(this, "generatorIndex", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "modulatorIndex", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
39
- static parse(e) { const t = new s; return t.generatorIndex = e.readWORD(), t.modulatorIndex = e.readWORD(), t; }
40
- }
41
- class l {
42
- constructor() { Object.defineProperty(this, "presetName", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "preset", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "bank", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "presetBagIndex", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "library", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "genre", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "morphology", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
43
- get isEnd() { return "EOP" === this.presetName; }
44
- static parse(e) { const t = new l; return t.presetName = e.readString(20), t.preset = e.readWORD(), t.bank = e.readWORD(), t.presetBagIndex = e.readWORD(), t.library = e.readDWORD(), t.genre = e.readDWORD(), t.morphology = e.readDWORD(), t; }
45
- }
46
- class d {
47
- constructor(e, t) { Object.defineProperty(this, "lo", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "hi", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), this.lo = e, this.hi = t; }
48
- in(e) { return this.lo <= e && e <= this.hi; }
49
- static parse(e) { return new d(e.readByte(), e.readByte()); }
50
- }
51
- class u {
52
- constructor() { Object.defineProperty(this, "sourceOper", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "destinationOper", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "value", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "amountSourceOper", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "transOper", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
53
- get type() { return a[this.destinationOper]; }
54
- get isEnd() { return 0 === this.sourceOper && 0 === this.destinationOper && 0 === this.value && 0 === this.amountSourceOper && 0 === this.transOper; }
55
- static parse(e) { const t = new u; switch (t.sourceOper = e.readWORD(), t.destinationOper = e.readWORD(), t.type) {
56
- case "keyRange":
57
- case "velRange":
58
- t.value = d.parse(e);
59
- break;
60
- default: t.value = e.readInt16();
61
- } return t.amountSourceOper = e.readWORD(), t.transOper = e.readWORD(), t; }
62
- }
63
- class c {
64
- constructor() { Object.defineProperty(this, "code", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "value", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
65
- get type() { return a[this.code]; }
66
- get isEnd() { return 0 === this.code && 0 === this.value; }
67
- static parse(e) { const t = new c; switch (t.code = e.readWORD(), t.type) {
68
- case "keyRange":
69
- case "velRange":
70
- t.value = d.parse(e);
71
- break;
72
- default: t.value = e.readInt16();
73
- } return t; }
74
- }
75
- class f {
76
- constructor() { Object.defineProperty(this, "instrumentName", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "instrumentBagIndex", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
77
- get isEnd() { return "EOI" === this.instrumentName; }
78
- static parse(e) { const t = new f; return t.instrumentName = e.readString(20), t.instrumentBagIndex = e.readWORD(), t; }
79
- }
80
- class p {
81
- constructor() { Object.defineProperty(this, "sampleName", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "start", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "end", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "loopStart", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "loopEnd", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "sampleRate", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "originalPitch", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "pitchCorrection", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "sampleLink", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "sampleType", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }); }
82
- get isEnd() { return "EOS" === this.sampleName; }
83
- static parse(e, t) { const n = new p; return n.sampleName = e.readString(20), n.start = e.readDWORD(), n.end = e.readDWORD(), n.loopStart = e.readDWORD(), n.loopEnd = e.readDWORD(), n.sampleRate = e.readDWORD(), n.originalPitch = e.readByte(), n.pitchCorrection = e.readInt8(), n.sampleLink = e.readWORD(), n.sampleType = e.readWORD(), t || (n.loopStart -= n.start, n.loopEnd -= n.start), n; }
84
- }
85
- class m {
86
- constructor(e, t, n) { Object.defineProperty(this, "min", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "max", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), Object.defineProperty(this, "value", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), this.min = e, this.value = t, this.max = n; }
87
- clamp() { return Math.max(this.min, Math.min(this.value, this.max)); }
88
- }
89
- function b(e, r = {}) { const a = n(e, 0, e.length, r); if (1 !== a.length)
90
- throw new Error("wrong chunk length"); const i = a[0]; if (null === i)
91
- throw new Error("chunk not found"); function s(e, t, n) { const r = v(e, t, "LIST", "pdta"); if (9 !== r.length)
92
- throw new Error("invalid pdta chunk"); return { presetHeaders: g(r[0], t), presetZone: w(r[1], t), presetModulators: P(r[2], t), presetGenerators: k(r[3], t), instruments: O(r[4], t), instrumentZone: E(r[5], t), instrumentModulators: R(r[6], t), instrumentGenerators: D(r[7], t), sampleHeaders: j(r[8], t, n) }; } const l = function (e, n, r = {}) { const a = v(e, n, "RIFF", "sfbk", r); if (3 !== a.length)
93
- throw new Error("invalid sfbk structure"); const i = function (e, t) { const n = v(e, t, "LIST", "INFO"); return o.parse(t, n); }(a[0], n), l = 3 === i.version.major; return l && "LIST" !== a[2].type && (a[2] = t(n, a[2].offset - 9, !1)), { info: i, samplingData: h(a[1], n), ...s(a[2], n, l) }; }(i, e, r), d = 3 === l.info.version.major; return { ...l, samples: T(l.sampleHeaders, l.samplingData.offsetMSB, l.samplingData.offsetLSB, e, d) }; }
94
- function v(t, r, a, i, o = {}) { if (t.type !== a)
95
- throw new Error("invalid chunk type:" + t.type); const s = new e(r, t.offset), l = s.readString(4); if (l !== i)
96
- throw new Error("invalid signature:" + l); return n(r, s.ip, t.size - 4, o); }
97
- function h(e, t) { const n = v(e, t, "LIST", "sdta"); return { offsetMSB: n[0].offset, offsetLSB: n[1]?.offset }; }
98
- function y(t, n, r, a, i, o) { const s = []; if (t.type !== r)
99
- throw new Error("invalid chunk type:" + t.type); const l = new e(n, t.offset), d = t.offset + t.size; for (; l.ip < d;) {
100
- const e = a.parse(l, o);
101
- if (i && i(e))
102
- break;
103
- s.push(e);
104
- } return s; }
105
- const g = (e, t) => y(e, t, "phdr", l, (e => e.isEnd)), w = (e, t) => y(e, t, "pbag", s), O = (e, t) => y(e, t, "inst", f, (e => e.isEnd)), E = (e, t) => y(e, t, "ibag", s), P = (e, t) => y(e, t, "pmod", u, (e => e.isEnd)), R = (e, t) => y(e, t, "imod", u, (e => e.isEnd)), k = (e, t) => y(e, t, "pgen", c, (e => e.isEnd)), D = (e, t) => y(e, t, "igen", c), j = (e, t, n) => y(e, t, "shdr", p, (e => e.isEnd), n);
106
- function T(e, t, n, r, a) { return e.map((e => { let { start: n, end: i } = e; return a || (n *= 2, i *= 2), new Uint8Array(r.subarray(t + n, t + i)); })); }
107
- function I(e) { const t = {}; for (const n of e) {
108
- const e = n.type;
109
- if (void 0 !== e)
110
- if ("keyRange" === e || "velRange" === e)
111
- t[e] = n.value;
112
- else {
113
- const r = L[e];
114
- t[e] = new m(r.min, n.value, r.max);
115
- }
116
- } return t; }
117
- const M = -32768, F = 32767, L = { startAddrsOffset: new m(0, 0, F), endAddrsOffset: new m(M, 0, 0), startloopAddrsOffset: new m(M, 0, F), endloopAddrsOffset: new m(M, 0, F), startAddrsCoarseOffset: new m(0, 0, F), modLfoToPitch: new m(-12e3, 0, 12e3), vibLfoToPitch: new m(-12e3, 0, 12e3), modEnvToPitch: new m(-12e3, 0, 12e3), initialFilterFc: new m(1500, 13500, 13500), initialFilterQ: new m(0, 0, 960), modLfoToFilterFc: new m(-12e3, 0, 12e3), modEnvToFilterFc: new m(-12e3, 0, 12e3), endAddrsCoarseOffset: new m(M, 0, 0), modLfoToVolume: new m(-960, 0, 960), chorusEffectsSend: new m(0, 0, 1e3), reverbEffectsSend: new m(0, 0, 1e3), pan: new m(-500, 0, 500), delayModLFO: new m(-12e3, -12e3, 5e3), freqModLFO: new m(-16e3, 0, 4500), delayVibLFO: new m(-12e3, -12e3, 5e3), freqVibLFO: new m(-16e3, 0, 4500), delayModEnv: new m(-12e3, -12e3, 5e3), attackModEnv: new m(-12e3, -12e3, 8e3), holdModEnv: new m(-12e3, -12e3, 5e3), decayModEnv: new m(-12e3, -12e3, 8e3), sustainModEnv: new m(0, 0, 1e3), releaseModEnv: new m(-12e3, -12e3, 8e3), keynumToModEnvHold: new m(-1200, 0, 1200), keynumToModEnvDecay: new m(-1200, 0, 1200), delayVolEnv: new m(-12e3, -12e3, 5e3), attackVolEnv: new m(-12e3, -12e3, 8e3), holdVolEnv: new m(-12e3, -12e3, 5e3), decayVolEnv: new m(-12e3, -12e3, 8e3), sustainVolEnv: new m(0, 0, 1440), releaseVolEnv: new m(-12e3, -12e3, 8e3), keynumToVolEnvHold: new m(-1200, 0, 1200), keynumToVolEnvDecay: new m(-1200, 0, 1200), instrument: new m(-1, -1, F), keyRange: new d(0, 127), velRange: new d(0, 127), startloopAddrsCoarseOffset: new m(M, 0, F), keynum: new m(-1, -1, 127), velocity: new m(-1, -1, 127), initialAttenuation: new m(0, 0, 1440), endloopAddrsCoarseOffset: new m(M, 0, F), coarseTune: new m(-120, 0, 120), fineTune: new m(-99, 0, 99), sampleID: new m(-1, -1, F), sampleModes: new m(0, 0, 3), scaleTuning: new m(0, 100, 100), exclusiveClass: new m(0, 0, 127), overridingRootKey: new m(-1, -1, 127) };
118
- class V {
119
- constructor(e) { Object.defineProperty(this, "parsed", { enumerable: !0, configurable: !0, writable: !0, value: void 0 }), this.parsed = e; }
120
- getGenerators(e, t, n, r) { const a = new Array(r - n); for (let i = n; i < r; i++) {
121
- const r = t[i].generatorIndex, o = t[i + 1].generatorIndex;
122
- a[i - n] = e.slice(r, o);
123
- } return a; }
124
- getPresetGenerators(e) { const t = this.parsed.presetHeaders[e], n = this.parsed.presetHeaders[e + 1], r = n ? n.presetBagIndex : this.parsed.presetZone.length - 1; return this.getGenerators(this.parsed.presetGenerators, this.parsed.presetZone, t.presetBagIndex, r); }
125
- getInstrumentGenerators(e) { const t = this.parsed.instruments[e], n = this.parsed.instruments[e + 1], r = n ? n.instrumentBagIndex : this.parsed.instrumentZone.length - 1; return this.getGenerators(this.parsed.instrumentGenerators, this.parsed.instrumentZone, t.instrumentBagIndex, r); }
126
- findInstrumentZone(e, t, n = 100) { const r = this.getInstrumentGenerators(e); let a; for (let e = 0; e < r.length; e++) {
127
- const i = I(r[e]);
128
- if (void 0 !== i.sampleID) {
129
- if ((!i.keyRange || i.keyRange.in(t)) && (!i.velRange || i.velRange.in(n)))
130
- return a ? { ...a, ...i } : i;
131
- }
132
- else
133
- a = i;
134
- } }
135
- findInstrument(e, t, n = 100) { const r = this.getPresetGenerators(e); let a; for (let e = 0; e < r.length; e++) {
136
- const i = I(r[e]);
137
- if (void 0 === i.instrument) {
138
- a = i;
139
- continue;
140
- }
141
- if (i.keyRange && !i.keyRange.in(t))
142
- continue;
143
- if (i.velRange && !i.velRange.in(n))
144
- continue;
145
- const o = this.findInstrumentZone(i.instrument.value, t, n);
146
- if (o)
147
- return a ? this.getInstrument({ ...a, ...i }, o) : this.getInstrument(i, o);
148
- } return null; }
149
- getInstrument(e, t) { const n = { ...L, ...t }, r = Object.keys(e); for (const t of r)
150
- if ("keyRange" !== t && "velRange" !== t) {
151
- const r = n[t], a = e[t];
152
- n[t] = new m(r.min, r.value + a.value, r.max);
153
- } return n; }
154
- getInstrumentKey(e, t, n, r = 100) { const a = this.parsed.presetHeaders.findIndex((n => n.preset === t && n.bank === e)); if (a < 0)
155
- return console.warn("preset not found: bank=%s instrument=%s", e, t), null; const i = this.findInstrument(a, n, r); if (!i)
156
- return console.warn("instrument not found: bank=%s instrument=%s", e, t), null; const o = this.parsed.samples[i.sampleID.value], s = this.parsed.sampleHeaders[i.sampleID.value], l = i.coarseTune.clamp() + i.fineTune.clamp() / 100, d = -1 === i.overridingRootKey.value ? s.originalPitch : i.overridingRootKey.clamp(), u = l + s.pitchCorrection / 100 - d, c = i.scaleTuning.clamp() / 100; return { start: 32768 * i.startAddrsCoarseOffset.clamp() + i.startAddrsOffset.clamp(), end: 32768 * i.endAddrsCoarseOffset.clamp() + i.endAddrsOffset.clamp(), loopStart: s.loopStart + 32768 * i.startloopAddrsCoarseOffset.clamp() + i.startloopAddrsOffset.clamp(), loopEnd: s.loopEnd + 32768 * i.endloopAddrsCoarseOffset.clamp() + i.endloopAddrsOffset.clamp(), modLfoToPitch: i.modLfoToPitch.clamp(), vibLfoToPitch: i.vibLfoToPitch.clamp(), modEnvToPitch: i.modEnvToPitch.clamp(), initialFilterFc: i.initialFilterFc.clamp(), initialFilterQ: i.initialFilterQ.clamp(), modLfoToFilterFc: i.modLfoToFilterFc.clamp(), modEnvToFilterFc: i.modEnvToFilterFc.clamp(), modLfoToVolume: i.modLfoToVolume.clamp(), chorusEffectsSend: i.chorusEffectsSend.clamp() / 1e3, reverbEffectsSend: i.reverbEffectsSend.clamp() / 1e3, pan: i.pan.clamp(), delayModLFO: S(i.delayModLFO.clamp()), freqModLFO: i.freqModLFO.clamp(), delayVibLFO: S(i.delayVibLFO.clamp()), freqVibLFO: i.freqVibLFO.clamp(), modDelay: S(i.delayModEnv.clamp()), modAttack: S(i.attackModEnv.clamp()), modHold: S(i.holdModEnv.clamp()), modDecay: S(i.decayModEnv.clamp()), modSustain: i.sustainModEnv.clamp() / 1e3, modRelease: S(i.releaseModEnv.clamp()), keynumToModEnvHold: i.keynumToModEnvHold.clamp(), keynumToModEnvDecay: i.keynumToModEnvDecay.clamp(), volDelay: S(i.delayVolEnv.clamp()), volAttack: S(i.attackVolEnv.clamp()), volHold: S(i.holdVolEnv.clamp()), volDecay: S(i.decayVolEnv.clamp()), volSustain: i.sustainVolEnv.clamp() / 1e3, volRelease: S(i.releaseVolEnv.clamp()), keynumToVolEnvHold: i.keynumToVolEnvHold.clamp(), keynumToVolEnvDecay: i.keynumToVolEnvDecay.clamp(), keyRange: i.keyRange, velRange: i.velRange, keynum: i.keynum.clamp(), velocity: i.velocity.clamp(), initialAttenuation: i.initialAttenuation.clamp(), playbackRate: e => Math.pow(Math.pow(2, 1 / 12), (e + u) * c), sample: o, sampleRate: s.sampleRate, sampleName: s.sampleName, sampleModes: i.sampleModes.clamp(), exclusiveClass: i.exclusiveClass.clamp() }; }
157
- getPresetNames() { const e = {}; return this.parsed.presetHeaders.forEach((t => { e[t.bank] || (e[t.bank] = {}), e[t.bank][t.preset] = t.presetName; })), e; }
158
- }
159
- function S(e) { return Math.pow(2, e / 1200); }
160
- export { V as SoundFont, I as createGeneratorObject, L as defaultInstrumentZone, b as parse, S as timecentToSecond };
161
- export default null;
162
- //# sourceMappingURL=/sm/2e6aae3211f3eeb8dde2dd5dcc4214014a112db10099ab21cf37b9a7d590cd62.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"+esm.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/cdn.jsdelivr.net/npm/@marmooo/soundfont-parser@0.0.4/+esm.js"],"names":[],"mappings":";;AAMi9Z;IAAQ,oBAA2H;IAAd,YAAa;IAAC,qDAAoJ;IAAA,mCAAoP;IAAA,uCAAwQ;IAAA,+DAAqP;IAAA,gDAAuX;IAAA,mCAAiL;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAA03E;IAAA,qBAA0I;CAAC;AAAj6L,+BAAmL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAniE;;;;;;;;;;;;;;;;EAA27B;AAAs1N,mCAAwC;AAA3sQ;IAAQ,oCAAyU;IAAnC,SAAU;IAAC,WAAY;IAAC,SAAU;IAAC,gBAAgE;CAAC;AAApyH;IAAqQ,wBAAwD;IAArT,4BAAyN;IAApB,QAAS;IAAC,QAAS;IAAC,oBAAoC;CAAyD;AAAllG;IAAwjC,gCAA8d;CAAC"}