forked from musescore/MuseScore
-
Notifications
You must be signed in to change notification settings - Fork 12
/
example.js
71 lines (52 loc) · 2.73 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import WebMscore from 'webmscore'
import fs from 'fs'
import * as FRONTS from '@librescore/fonts'
// https://musescore.com/openscore/scores/4074271
// public domain
const name = 'Aequale_No_1.mscz'
const exportedPrefix = 'exported'
const filedata = fs.readFileSync(`./${name}`)
WebMscore.ready.then(async () => {
console.log('supported file format version:', await WebMscore.version())
const score = await WebMscore.load('mscz', filedata, [
fs.readFileSync(FRONTS.CN), // only contains the CN variation (style) of Chinese characters (the range of GB18030), including traditional and simplified
fs.readFileSync(FRONTS.KR), // to support hangul syllables
])
console.log(score)
console.log()
console.log('score title:', await score.title())
console.log('number of pages:', await score.npages())
console.log()
// await score.generateExcerpts()
// await score.setExcerptId(2)
fs.writeFileSync(`./${exportedPrefix}.musicxml`, await score.saveXml())
console.log(`generated MusicXML file: ./${exportedPrefix}.musicxml`)
const n = await score.npages()
for (let index = 0; index < n; index++) {
const f = `./${exportedPrefix}-${index}.svg`
const svg = await score.saveSvg(index, true)
fs.writeFileSync(f, svg)
console.log(`generated SVG page ${index}: ${f}`)
}
const lastPage = n - 1
fs.writeFileSync(`./${exportedPrefix}-${lastPage}.png`, await score.savePng(lastPage))
console.log(`generated PNG page ${lastPage}: ./${exportedPrefix}-${lastPage}.png`)
fs.writeFileSync(`./${exportedPrefix}.pdf`, await score.savePdf())
console.log(`generated PDF file: ./${exportedPrefix}.pdf`)
fs.writeFileSync(`./${exportedPrefix}.mxl`, await score.saveMxl())
console.log(`generated compressed MusicXML file: ./${exportedPrefix}.mxl`)
fs.writeFileSync(`./${exportedPrefix}.mid`, await score.saveMidi())
console.log(`generated MIDI file: ./${exportedPrefix}.mid`)
await score.setSoundFont(fs.readFileSync('../share/sound/FluidR3Mono_GM.sf3'))
fs.writeFileSync(`./${exportedPrefix}.ogg`, await score.saveAudio('ogg'))
console.log(`generated OGG audio: ./${exportedPrefix}.ogg`)
fs.writeFileSync(`./${exportedPrefix}-mpos.json`, await score.savePositions(false))
console.log(`exported positions of measures: ./${exportedPrefix}-mpos.json`)
fs.writeFileSync(`./${exportedPrefix}-spos.json`, await score.savePositions(true))
console.log(`exported positions of segments: ./${exportedPrefix}.spos.json`)
const metadata = await score.metadata()
fs.writeFileSync(`./${exportedPrefix}-metadata.json`, JSON.stringify(metadata, null, 4))
console.log('score metadata', metadata)
score.destroy()
console.log('destroyed')
})