midi-audio-player 2.0.0 → 2.0.2
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.
- package/dist/index.js +54 -53
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +3 -3
- package/dist/midi-audio-player.js +54 -53
- package/dist/midi-audio-player.min.js +4 -4
- package/package.json +12 -5
- package/src/midiaudioplayer.js +25 -23
- package/CHANGELOG.md +0 -26
package/src/midiaudioplayer.js
CHANGED
|
@@ -170,13 +170,18 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
|
|
173
|
-
async loadPreset(presetId, channel) {
|
|
173
|
+
async loadPreset(presetId, channel, nonblocking = false) {
|
|
174
174
|
const presetInfo = await this.findPreset(presetId);
|
|
175
175
|
if(!presetInfo) throw new Error(`Invalid preset: ${presetId}`);
|
|
176
176
|
this.#presetMap[presetInfo.program] = presetInfo;
|
|
177
177
|
const preset = await this.getPreset(presetId);
|
|
178
|
-
this.#players[channel].preset
|
|
179
|
-
this.#setupChange();
|
|
178
|
+
// this.#players[channel].setPreset(preset).then(() => this.#setupChange());
|
|
179
|
+
if(nonblocking) this.#players[channel].setPreset(preset, nonblocking).then(() => this.#setupChange());
|
|
180
|
+
else {
|
|
181
|
+
await this.#players[channel].setPreset(preset, nonblocking);
|
|
182
|
+
this.#setupChange();
|
|
183
|
+
}
|
|
184
|
+
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
|
|
@@ -207,6 +212,17 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
207
212
|
await this.loadArrayBuffer(await this.#repairMidi(content));
|
|
208
213
|
}
|
|
209
214
|
|
|
215
|
+
if(this.#opts.karaoke) {
|
|
216
|
+
this.#log('Generating karaoke frames...');
|
|
217
|
+
this.#lyrics = null;
|
|
218
|
+
await this.#generateKaraokeFrames();
|
|
219
|
+
if(this.#title) this.#sendKaraokeFrame('title', this.#title);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.#log(`Trim midi events...`);
|
|
223
|
+
this.#trimMidiEvents();
|
|
224
|
+
queueMicrotask(() => this.triggerPlayerEvent('computed'));
|
|
225
|
+
|
|
210
226
|
this.#log('Loading instruments...');
|
|
211
227
|
this.#channels = await this.#getInstruments();
|
|
212
228
|
this.#channelStates = Object.keys(this.#channels).reduce((acc, key) => ({ ...acc, [key]: false }), {});
|
|
@@ -218,8 +234,8 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
218
234
|
}));
|
|
219
235
|
}
|
|
220
236
|
|
|
221
|
-
const setupPrograms = new Set();
|
|
222
237
|
const setupPresets = {};
|
|
238
|
+
const setupPrograms = new Set();
|
|
223
239
|
if(setup?.presets !== undefined) {
|
|
224
240
|
await Promise.all(Object.keys(setup.presets).map(async channel => {
|
|
225
241
|
const presetInfo = await this.findPreset(setup.presets[channel]);
|
|
@@ -231,7 +247,7 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
231
247
|
|
|
232
248
|
const uniqueInstruments = await this.#getUniqueInstruments();
|
|
233
249
|
if(!Object.values(this.#channels).length) this.#log("Error: no instrument found");
|
|
234
|
-
|
|
250
|
+
await Promise.all([...uniqueInstruments].map(async program => {
|
|
235
251
|
if(setupPrograms.has(program)) return;
|
|
236
252
|
let preset = null;
|
|
237
253
|
if(this.#presetMap[program] !== undefined) preset = await this.getPreset(this.#presetMap[program].id);
|
|
@@ -240,18 +256,6 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
240
256
|
this.#instruments[program] = preset;
|
|
241
257
|
}));
|
|
242
258
|
|
|
243
|
-
if(this.#opts.karaoke) {
|
|
244
|
-
this.#log('Generating karaoke frames...');
|
|
245
|
-
this.#lyrics = null;
|
|
246
|
-
await this.#generateKaraokeFrames();
|
|
247
|
-
if(this.#title) this.#sendKaraokeFrame('title', this.#title);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this.#log(`Trim midi events...`);
|
|
251
|
-
this.#trimMidiEvents();
|
|
252
|
-
queueMicrotask(() => this.triggerPlayerEvent('computed'));
|
|
253
|
-
|
|
254
|
-
await presets;
|
|
255
259
|
await Promise.all(Object.keys(this.#channels).map(async channel => {
|
|
256
260
|
if(this.#players[channel]) this.#players[channel].close();
|
|
257
261
|
if(setupPresets[channel] !== undefined) this.#players[channel] = await this.#createPlayer(setupPresets[channel]);
|
|
@@ -263,7 +267,6 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
263
267
|
await this.triggerPlayerEvent('presetsLoaded', this.#instruments);
|
|
264
268
|
await this.#setupChange();
|
|
265
269
|
this.#log("Player ready");
|
|
266
|
-
|
|
267
270
|
}
|
|
268
271
|
|
|
269
272
|
|
|
@@ -676,12 +679,11 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
676
679
|
break;
|
|
677
680
|
case 'Program Change':
|
|
678
681
|
if (
|
|
679
|
-
// (this.#opts.presetAuto || this.#opts.presetRandom) &&
|
|
680
682
|
event.value >= 0 && event.value <= 127 &&
|
|
681
683
|
this.#instruments[event.value + 1] !== undefined &&
|
|
682
684
|
event.channel != 10) {
|
|
683
685
|
if (this.#players[channel].preset?.program !== (event.value + 1)) {
|
|
684
|
-
this.#players[channel].
|
|
686
|
+
this.#players[channel].setPreset(this.#instruments[event.value + 1]);
|
|
685
687
|
}
|
|
686
688
|
}
|
|
687
689
|
break;
|
|
@@ -761,8 +763,8 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
761
763
|
}
|
|
762
764
|
|
|
763
765
|
|
|
764
|
-
|
|
765
|
-
return
|
|
766
|
+
#createPlayer(preset) {
|
|
767
|
+
return WebAudioFontPlayer.load(preset, this.#audioCtx, this.#compressor);
|
|
766
768
|
}
|
|
767
769
|
|
|
768
770
|
|
|
@@ -799,7 +801,7 @@ export default class MidiAudioPlayer extends MidiPlayer.Player {
|
|
|
799
801
|
if(!this.#players[event.channel]) return;
|
|
800
802
|
if(event.channel == 10 || event.value > 127 || event.value < 0) break;
|
|
801
803
|
if(this.#players[event.channel] !== undefined && this.#players[event.channel].preset.program != (event.value + 1))
|
|
802
|
-
this.#players[event.channel].
|
|
804
|
+
this.#players[event.channel].setPreset(this.#instruments[event.value + 1]);
|
|
803
805
|
break;
|
|
804
806
|
case 'Karaoke Event':
|
|
805
807
|
if (event.tick < (this.tick - this.secondsToTicks(10))) return;
|
package/CHANGELOG.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
## Changelog
|
|
2
|
-
|
|
3
|
-
### [2.0.0] - Unreleased
|
|
4
|
-
|
|
5
|
-
#### Changed
|
|
6
|
-
* Complete refactor
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### [1.1.2] - 2026-05-10 00:19:40
|
|
10
|
-
|
|
11
|
-
#### Changed
|
|
12
|
-
* load() method now public
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### [1.1.1] - 2026-05-09 19:45:23
|
|
16
|
-
|
|
17
|
-
#### Added
|
|
18
|
-
* index.js in the root
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### [1.1.0] - 2026-05-09 17:16:45
|
|
22
|
-
|
|
23
|
-
#### Added
|
|
24
|
-
* Complete refactor
|
|
25
|
-
* Optimized WebAudioFont handling
|
|
26
|
-
* Change instrument option to preset
|