Play midi via AlphaSynth does not work in node environment. #1606
-
Running in Electron, I tried several api, but none worked. There must be something wrong with the way I use it. There are some refer: code: playMidi = async () => {
const soundFontResponse = await fetch(
"https://barba828.github.io/buitar-editor/soundfont/sonivox.sf2"
);
const midiFile = new alphaTab.midi.MidiFile();
const soundFont = new Uint8Array(await soundFontResponse.arrayBuffer());
// test_1
const player = new alphaTab.synth.AlphaSynth(
new alphaTab.synth.AlphaSynthAudioWorkletOutput(this.alphaTabSettings),
99999999
);
// test_2
// const player = new alphaTab.synth.AlphaSynthWebWorkerApi(
// new alphaTab.synth.AlphaSynthAudioWorkletOutput(this.alphaTabSettings),
// this.alphaTabSettings
// );
// test_3
// const player = new alphaTab.synth.AlphaSynthWebWorkerApi(
// new alphaTab.synth.AlphaSynthScriptProcessorOutput(),
// this.alphaTabSettings
// );
player.loadSoundFont(soundFont, false);
player.loadMidiFile(midiFile);
player.play();
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think we might be mixing things here a bit.
The If you just want to collect the raw audio samples yourself a implementation of an output can look like this: https://github.com/CoderLine/alphaTab/blob/develop/test/audio/TestOutput.ts
Electron is generally using the Chromium render engine. Assuming you use alphaTab in the "browser" part of Electron, you can follow most parts of using alphaTab as from a web application. To load the SoundFont and input files you would use the electron bits to either get blobs (Blob,ArrayBuffer,Uint8Array) to pass to alphaTab. 1 There might be some projects providing Web Audio in Node.js scopes. The challenge is that node.js is single threaded and alphaTab in the browser mode launches background workers to handle the multi-threading aspects. These platform aspects are not available in node.js either. If you use electron, my recommendation would be to stay on the browser level for alphaTab display and playback. You might use alphaTab also on node.js level for some organizational bits (e.g. reading song details from files for a media library). Footnotes |
Beta Was this translation helpful? Give feedback.
I think we might be mixing things here a bit.
The
AlphaSynthAudioWorkletOutput
is not supported on Node. As the name implies: This "output" is using Audio Worklets which are a Browser API unavailable in Node. We currently have no output which would work on node.js. As node.js doesn't ship a platform API itself for audio, some third party library would have to be used.If you just want to collect the raw audio samples yourself a implementation of an output can look like this: https://github.com/CoderLine/alphaTab/blob/develop/test/audio/TestOutput.ts
Electron is generally using the Chrom…