feat: load soundfont in nodejs

This commit is contained in:
Xmader 2020-11-24 05:22:56 -05:00
parent c96a6b69dd
commit 36a05aac75
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4

View file

@ -56,8 +56,18 @@ const initFonts = () => {
export const loadSoundFont = (score: WebMscore): Promise<void> => { export const loadSoundFont = (score: WebMscore): Promise<void> => {
if (!score[SOUND_FONT_LOADED]) { if (!score[SOUND_FONT_LOADED]) {
const loadPromise = (async () => { const loadPromise = (async () => {
let data: Uint8Array
if (isNodeJs) {
// module.exports.FluidR3Mono = ...
const SF3 = Object.values(require('@librescore/sf3'))[0]
const fs = require('fs')
data = await fs.promises.readFile(SF3)
} else {
data = await fetchData(SF3_URL)
}
await score.setSoundFont( await score.setSoundFont(
await fetchData(SF3_URL), data,
) )
})() })()
score[SOUND_FONT_LOADED] = loadPromise score[SOUND_FONT_LOADED] = loadPromise