Comparing version 0.6.0 to 0.7.0
{ | ||
"name": "webmscore", | ||
"version": "0.6.0", | ||
"description": "MuseScore's libmscore in WebAssembly! Read mscz data, and generate MIDI/MusicXML/SVG/PNG/PDF sheets right in browsers", | ||
"version": "0.7.0", | ||
"description": "MuseScore's libmscore in WebAssembly! Read mscz data, and generate audio/MIDI/MusicXML/SVG/PNG/PDF sheets right in browsers", | ||
"type": "module", | ||
@@ -50,4 +50,4 @@ "types": "global.d.ts", | ||
"clean": "cd ../ && make clean", | ||
"prepack": "cp ../README.md ." | ||
"prepack": "cp ../README.md . && cp ../CHANGELOG.md ." | ||
} | ||
} |
@@ -10,4 +10,7 @@ | ||
* Get score metadata | ||
* Export part score | ||
* Generate music sheets in SVG/PNG/PDF formats | ||
* Generate MIDI | ||
* Generate audio files in WAV, OGG, or FLAC formats | ||
* Synthesize raw audio frames, can be used in the Web Audio API | ||
* Export as MusicXML compressed/uncompressed | ||
@@ -63,2 +66,52 @@ * Generate position information of measures or segments on the generated sheets | ||
### Load extra fonts | ||
If your score sheet contains characters out of the range of the bundled [FreeFont](https://www.gnu.org/software/freefont/), those characters will be shown as tofu characters (`□` or `�`) in SVG/PNG/PDF files. Loading extra fonts is required. | ||
webmscore can load any font format supported by [FreeType](https://www.freetype.org/freetype2/docs/index.html). | ||
```js | ||
const score = await WebMscore.load('mscz', msczdata, [...arrOfFontData]) | ||
``` | ||
> CJK fonts are no longer bundled inside webmscore since v0.6.0 | ||
### Load soundfont files | ||
Loading a soudfont (sf2/sf3) file is required before generating/synthesizing audio. | ||
```js | ||
await score.setSoundFont(soudfontData) | ||
``` | ||
Soudfonts can be found on [musescore.org website](https://musescore.org/en/handbook/soundfonts-and-sfz-files#list). | ||
Example: (`FluidR3Mono_GM.sf3`) | ||
```js | ||
const soudfontData = new Uint8Array( | ||
await ( | ||
await fetch('https://cdn.jsdelivr.net/gh/musescore/MuseScore@2.1/share/sound/FluidR3Mono_GM.sf3') | ||
).arrayBuffer() | ||
) | ||
``` | ||
### Boost Mode | ||
Sometimes you only want to process a bunch of score metadata, so drawing sheet images internally is a waste of time and system resource. | ||
You can enable the Boost Mode by setting the `doLayout` parameter in `WebMscore.load` to `false`. | ||
Example: | ||
```js | ||
const score = await WebMscore.load('mscz', msczdata, [], false) | ||
const metadata = await score.metadata() | ||
score.destroy() | ||
``` | ||
webmscore's Boost Mode is about 3x faster than the batch converter feature (`-j`) of the musescore software, according to the [benchmark](./web-example/benchmark.js) result. | ||
WebAssembly vs native C++ program! | ||
### Note: | ||
@@ -65,0 +118,0 @@ |
@@ -38,8 +38,9 @@ | ||
* @param {Uint8Array[]} fonts load extra font files (CJK characters support) | ||
* @param {boolean} doLayout set to false if you only need the score metadata or the midi file (Super Fast, 3x faster than the musescore software) | ||
*/ | ||
static async load(filetype, data, fonts = []) { | ||
static async load(filetype, data, fonts = [], doLayout = true) { | ||
await WebMscore.ready | ||
for (const f of fonts) { | ||
await this.addFont(f) | ||
await WebMscore.addFont(f) | ||
} | ||
@@ -53,4 +54,4 @@ | ||
'number', // return type | ||
['number', 'number', 'number'], // argument types | ||
[filetypeptr, dataptr, data.byteLength] // arguments | ||
['number', 'number', 'number', 'boolean'], // argument types | ||
[filetypeptr, dataptr, data.byteLength, doLayout] // arguments | ||
) | ||
@@ -196,2 +197,12 @@ | ||
/** | ||
* Save part score as MSCZ/MSCX file | ||
* @param {'mscz' | 'mscx'} filetype | ||
* @returns {Promise<Uint8Array>} | ||
*/ | ||
async saveMsc(filetype = 'mscz') { | ||
const dataptr = Module.ccall('saveMsc', 'number', ['number', 'boolean', 'number'], [this.scoreptr, filetype == 'mscz', this.excerptId]) | ||
return readData(dataptr) | ||
} | ||
/** | ||
* Export score as the SVG file of one page | ||
@@ -198,0 +209,0 @@ * @param {number} pageNumber integer |
@@ -52,7 +52,8 @@ // @ts-check | ||
* @param {Uint8Array[]} fonts load extra font files (CJK characters support) | ||
* @param {boolean} doLayout set to false if you only need the score metadata or the midi file (Super Fast, 3x faster than the musescore software) | ||
*/ | ||
static async load(filetype, data, fonts = []) { | ||
static async load(filetype, data, fonts = [], doLayout = true) { | ||
const instance = new WebMscoreW() | ||
await instance.rpc('ready') | ||
await instance.rpc('load', [filetype, data, fonts], [data.buffer, /** ...fonts.map(f => f.buffer) */]) | ||
await instance.rpc('load', [filetype, data, fonts, doLayout], [data.buffer, /** ...fonts.map(f => f.buffer) */]) | ||
return instance | ||
@@ -181,2 +182,11 @@ } | ||
/** | ||
* Save part score as MSCZ/MSCX file | ||
* @param {'mscz' | 'mscx'} filetype | ||
* @returns {Promise<Uint8Array>} | ||
*/ | ||
async saveMsc(filetype = 'mscz') { | ||
return this.rpc('saveMsc', [filetype]) | ||
} | ||
/** | ||
* Export score as the SVG file of one page | ||
@@ -183,0 +193,0 @@ * @param {number} pageNumber integer |
@@ -51,5 +51,4 @@ | ||
case 'load': | ||
const [filetype, filedata, fonts] = params | ||
await WebMscore.ready | ||
score = await WebMscore.load(filetype, filedata, fonts) | ||
score = await WebMscore.load.apply(undefined, params) | ||
rpcRes(id, 'done') | ||
@@ -56,0 +55,0 @@ break; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29229106
17
5463
189
19