Skip to content

Commit

Permalink
fix: hasSoundfont mark
Browse files Browse the repository at this point in the history
The soundfont is shared across all instances, so it should be a static property of `WebMscore`.
  • Loading branch information
Xmader committed Dec 28, 2020
1 parent f63f690 commit 2b07ee9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 12 additions & 5 deletions web-public/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import {

class WebMscore {

/**
* A soundfont file is loaded
* (Audio needs soundfonts)
* @private
* @see setSoundFont and saveAudio
*/
static hasSoundfont = false;

/**
* This promise is resolved when the runtime is fully initialized
* @returns {Promise<void>}
Expand Down Expand Up @@ -307,7 +315,7 @@ class WebMscore {
* @param {Uint8Array} data
*/
async setSoundFont(data) {
if (this.hasSoundfont) {
if (WebMscore.hasSoundfont) {
// remove the old soundfont file
Module['FS_createDataFile']('/MuseScore_General.sf3')
}
Expand All @@ -316,16 +324,15 @@ class WebMscore {
// side effects: the soundfont is shared across all instances
Module['FS_createDataFile']('/', 'MuseScore_General.sf3', data, true, true)

/** @private */
this.hasSoundfont = true
WebMscore.hasSoundfont = true
}

/**
* Export score as audio file (wav/ogg/flac/mp3)
* @param {'wav' | 'ogg' | 'flac' | 'mp3'} format
*/
async saveAudio(format) {
if (!this.hasSoundfont) {
if (!WebMscore.hasSoundfont) {
throw new Error('The soundfont is not set.')
}

Expand Down Expand Up @@ -361,7 +368,7 @@ class WebMscore {
* @returns {Promise<number>} Pointer to the iterator function
*/
async _synthAudio(starttime = 0) {
if (!this.hasSoundfont) {
if (!WebMscore.hasSoundfont) {
throw new Error('The soundfont is not set.')
}

Expand Down
5 changes: 0 additions & 5 deletions web-public/src/worker-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ class WebMscoreW {
*/
async setSoundFont(data) {
await this.rpc('setSoundFont', [data], [data.buffer])
/** @private */
this.hasSoundfont = true
}

/**
Expand All @@ -261,9 +259,6 @@ class WebMscoreW {
* @returns {Promise<Uint8Array>}
*/
saveAudio(format) {
if (!this.hasSoundfont) {
throw new Error('The soundfont is not set.')
}
return this.rpc('saveAudio', [format])
}

Expand Down

0 comments on commit 2b07ee9

Please sign in to comment.