refactor: individual downloads

This commit is contained in:
Xmader 2020-11-24 06:03:46 -05:00
parent 40d1ddbab8
commit caba1c041a
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 43 additions and 39 deletions

View File

@ -4,7 +4,7 @@ import { waitForDocumentLoaded, saveAs, console } from './utils'
import { downloadPDF } from './pdf'
import { downloadMscz } from './mscz'
import { getFileUrl } from './file'
import { WebMscore, loadSoundFont } from './mscore'
import { INDV_DOWNLOADS } from './mscore'
import { BtnList, BtnAction, BtnListMode } from './btn'
import { ScoreInfoInPage, SheetInfoInPage } from './scoreinfo'
import i18n from './i18n'
@ -65,44 +65,7 @@ const main = (): void => {
const fieldset = w.document.createElement('fieldset')
w.document.body.append(fieldset)
interface IndividualDownload {
name: string;
fileExt: string;
action (score: WebMscore): Promise<Uint8Array>;
}
const downloads: IndividualDownload[] = [
{
name: i18n('DOWNLOAD')('PDF'),
fileExt: 'pdf',
action: (score) => score.savePdf(),
},
{
name: i18n('DOWNLOAD')('MSCZ'),
fileExt: 'mscz',
action: (score) => score.saveMsc('mscz'),
},
{
name: i18n('DOWNLOAD')('MusicXML'),
fileExt: 'mxl',
action: (score) => score.saveMxl(),
},
{
name: i18n('DOWNLOAD')('MIDI'),
fileExt: 'mid',
action: (score) => score.saveMidi(true, true),
},
{
name: i18n('DOWNLOAD_AUDIO')('FLAC'),
fileExt: 'flac',
action: (score) => loadSoundFont(score).then(() => score.saveAudio('flac')),
},
{
name: i18n('DOWNLOAD_AUDIO')('OGG'),
fileExt: 'ogg',
action: (score) => loadSoundFont(score).then(() => score.saveAudio('ogg')),
},
]
const downloads = INDV_DOWNLOADS
// part selection
const DEFAULT_PART = -1 // initially select "full score"

View File

@ -1,9 +1,11 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { fetchMscz } from './mscz'
import { fetchData } from './utils'
import { ScoreInfo } from './scoreinfo'
import isNodeJs from 'detect-node'
import i18n from './i18n'
const WEBMSCORE_URL = 'https://cdn.jsdelivr.net/npm/webmscore@0.10/webmscore.js'
@ -88,3 +90,42 @@ export const loadMscore = async (scoreinfo: ScoreInfo, w?: Window): Promise<WebM
return score
}
export interface IndividualDownload {
name: string;
fileExt: string;
action (score: WebMscore): Promise<Uint8Array>;
}
export const INDV_DOWNLOADS: IndividualDownload[] = [
{
name: i18n('DOWNLOAD')('PDF'),
fileExt: 'pdf',
action: (score) => score.savePdf(),
},
{
name: i18n('DOWNLOAD')('MSCZ'),
fileExt: 'mscz',
action: (score) => score.saveMsc('mscz'),
},
{
name: i18n('DOWNLOAD')('MusicXML'),
fileExt: 'mxl',
action: (score) => score.saveMxl(),
},
{
name: i18n('DOWNLOAD')('MIDI'),
fileExt: 'mid',
action: (score) => score.saveMidi(true, true),
},
{
name: i18n('DOWNLOAD_AUDIO')('FLAC'),
fileExt: 'flac',
action: (score) => loadSoundFont(score).then(() => score.saveAudio('flac')),
},
{
name: i18n('DOWNLOAD_AUDIO')('OGG'),
fileExt: 'ogg',
action: (score) => loadSoundFont(score).then(() => score.saveAudio('ogg')),
},
]