smoosic 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/smoosic.js +167 -74
- package/package.json +82 -77
- package/release/smoosic.js +171 -78
- package/release/styles/menus.css +26 -0
- package/specs/022-text-reposition-on-resize/spec.md +1 -0
- package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
- package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
- package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
- package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
- package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
- package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
- package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
- package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
- package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
- package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
- package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
- package/specs/028-unsaved-changes-indicator/plan.md +96 -0
- package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
- package/specs/028-unsaved-changes-indicator/research.md +68 -0
- package/specs/028-unsaved-changes-indicator/spec.md +135 -0
- package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
- package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
- package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
- package/specs/029-remove-promise-helpers/data-model.md +45 -0
- package/specs/029-remove-promise-helpers/plan.md +86 -0
- package/specs/029-remove-promise-helpers/quickstart.md +53 -0
- package/specs/029-remove-promise-helpers/research.md +71 -0
- package/specs/029-remove-promise-helpers/spec.md +107 -0
- package/specs/029-remove-promise-helpers/tasks.md +164 -0
- package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
- package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
- package/specs/030-copy-paste-voices/data-model.md +63 -0
- package/specs/030-copy-paste-voices/plan.md +80 -0
- package/specs/030-copy-paste-voices/quickstart.md +50 -0
- package/specs/030-copy-paste-voices/research.md +80 -0
- package/specs/030-copy-paste-voices/spec.md +124 -0
- package/specs/030-copy-paste-voices/tasks.md +183 -0
- package/specs/031-select-voice/checklists/requirements.md +39 -0
- package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
- package/specs/031-select-voice/data-model.md +47 -0
- package/specs/031-select-voice/plan.md +79 -0
- package/specs/031-select-voice/quickstart.md +43 -0
- package/specs/031-select-voice/research.md +55 -0
- package/specs/031-select-voice/spec.md +113 -0
- package/specs/031-select-voice/tasks.md +171 -0
- package/src/application/application.ts +464 -459
- package/src/common/promiseHelpers.ts +2 -2
- package/src/render/audio/samples.ts +117 -118
- package/src/render/sui/pageDivisions.ts +58 -0
- package/src/render/sui/renderState.ts +469 -464
- package/src/render/sui/scoreChangeState.ts +62 -0
- package/src/render/sui/scoreView.ts +30 -0
- package/src/render/sui/scoreViewOperations.ts +2555 -2380
- package/src/render/sui/svgPageMap.ts +16 -17
- package/src/render/sui/textEdit.ts +310 -311
- package/src/render/sui/tracker.ts +40 -0
- package/src/render/vex/vxNote.ts +3 -1
- package/src/smo/xform/copypaste.ts +304 -4
- package/src/smo/xform/selections.ts +68 -0
- package/src/smo/xform/undo.ts +9 -0
- package/src/styles/menus.css +26 -0
- package/src/ui/buttons/ribbon.ts +3 -1
- package/src/ui/components/buttons/sidebar.vue +15 -6
- package/src/ui/components/dialogs/library.vue +3 -1
- package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
- package/src/ui/dialogs/adapter.ts +181 -183
- package/src/ui/dialogs/addMeasure.ts +97 -97
- package/src/ui/dialogs/annotationVue.ts +56 -56
- package/src/ui/dialogs/audioSettings.ts +121 -123
- package/src/ui/dialogs/chordChangeVue.ts +46 -46
- package/src/ui/dialogs/clefChange.ts +53 -53
- package/src/ui/dialogs/customTuplets.ts +95 -96
- package/src/ui/dialogs/customTupletsVue.ts +47 -47
- package/src/ui/dialogs/dialog.ts +627 -620
- package/src/ui/dialogs/durations.ts +34 -34
- package/src/ui/dialogs/dynamics.ts +140 -142
- package/src/ui/dialogs/factory.ts +198 -198
- package/src/ui/dialogs/fileDialogs.ts +245 -179
- package/src/ui/dialogs/fonts.ts +93 -93
- package/src/ui/dialogs/globalLayout.ts +40 -40
- package/src/ui/dialogs/gracenote.ts +31 -31
- package/src/ui/dialogs/hairpin.ts +108 -110
- package/src/ui/dialogs/hairpinVue.ts +51 -51
- package/src/ui/dialogs/instrument.ts +111 -111
- package/src/ui/dialogs/keySignature.ts +175 -176
- package/src/ui/dialogs/keySignatureVue.ts +47 -47
- package/src/ui/dialogs/library.ts +207 -207
- package/src/ui/dialogs/libraryVue.ts +62 -48
- package/src/ui/dialogs/lyricVue.ts +46 -46
- package/src/ui/dialogs/measureFormat.ts +78 -78
- package/src/ui/dialogs/microtones.ts +147 -147
- package/src/ui/dialogs/noteHead.ts +319 -319
- package/src/ui/dialogs/pageLayout.ts +61 -61
- package/src/ui/dialogs/partInfo.ts +60 -60
- package/src/ui/dialogs/pedalMarking.ts +117 -117
- package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
- package/src/ui/dialogs/pitch.ts +352 -352
- package/src/ui/dialogs/preferences.ts +40 -40
- package/src/ui/dialogs/rehearsalMark.ts +64 -64
- package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
- package/src/ui/dialogs/scoreId.ts +35 -36
- package/src/ui/dialogs/scoreView.ts +42 -42
- package/src/ui/dialogs/slur.ts +308 -310
- package/src/ui/dialogs/slurVue.ts +91 -91
- package/src/ui/dialogs/staffGroup.ts +112 -112
- package/src/ui/dialogs/tabNote.ts +84 -84
- package/src/ui/dialogs/tabStave.ts +182 -182
- package/src/ui/dialogs/tempo.ts +261 -263
- package/src/ui/dialogs/tempoVue.ts +73 -73
- package/src/ui/dialogs/textBlockVue.ts +127 -127
- package/src/ui/dialogs/textBracket.ts +114 -116
- package/src/ui/dialogs/textBracketVue.ts +56 -56
- package/src/ui/dialogs/tie.ts +140 -142
- package/src/ui/dialogs/timeSignature.ts +65 -66
- package/src/ui/dialogs/transposeScore.ts +39 -39
- package/src/ui/dialogs/unsavedChanges.ts +43 -0
- package/src/ui/dialogs/volta.ts +120 -122
- package/src/ui/dialogs/voltaVue.ts +51 -51
- package/src/ui/fileio/library.ts +110 -111
- package/src/ui/menus/edit.ts +100 -1
- package/src/ui/menus/file.ts +19 -3
- package/tests/pageDivisions.ts +156 -0
- package/tests/promiseHelpersUsage.ts +142 -0
- package/tests/scoreChangeState.ts +102 -0
- package/tests/selectVoice.ts +189 -0
- package/tests/voiceCopyPaste.ts +417 -0
|
@@ -1,179 +1,245 @@
|
|
|
1
|
-
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
-
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
-
import { SuiDialogBase, SuiDialogParams, DialogDefinition, InstallDialog } from './dialog';
|
|
4
|
-
import { SmoScore } from '../../smo/data/score';
|
|
5
|
-
import { XmlToSmo } from '../../smo/mxml/xmlToSmo';
|
|
6
|
-
import { SmoToXml } from '../../smo/mxml/smoToXml';
|
|
7
|
-
import { SuiScoreViewOperations } from '../../render/sui/scoreViewOperations';
|
|
8
|
-
import { SuiFileDownloadComponent } from './components/fileDownload';
|
|
9
|
-
import { SuiDialogAdapterBase, SuiComponentAdapter } from './adapter';
|
|
10
|
-
import { addFileLink } from '../../common/htmlHelpers';
|
|
11
|
-
import { SmoToMidi } from '../../smo/midi/smoToMidi';
|
|
12
|
-
import { MidiToSmo } from '../../smo/midi/midiToSmo';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { default as
|
|
20
|
-
import { default as
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
let
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
1
|
+
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
+
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
+
import { SuiDialogBase, SuiDialogParams, DialogDefinition, InstallDialog } from './dialog';
|
|
4
|
+
import { SmoScore } from '../../smo/data/score';
|
|
5
|
+
import { XmlToSmo } from '../../smo/mxml/xmlToSmo';
|
|
6
|
+
import { SmoToXml } from '../../smo/mxml/smoToXml';
|
|
7
|
+
import { SuiScoreViewOperations } from '../../render/sui/scoreViewOperations';
|
|
8
|
+
import { SuiFileDownloadComponent } from './components/fileDownload';
|
|
9
|
+
import { SuiDialogAdapterBase, SuiComponentAdapter } from './adapter';
|
|
10
|
+
import { addFileLink } from '../../common/htmlHelpers';
|
|
11
|
+
import { SmoToMidi } from '../../smo/midi/smoToMidi';
|
|
12
|
+
import { MidiToSmo } from '../../smo/midi/midiToSmo';
|
|
13
|
+
import { SmoToVex } from '../../render/vex/toVex';
|
|
14
|
+
import { parseMidi } from '../../common/midi-parser.js';
|
|
15
|
+
import { replaceVueRoot, modalContainerId } from '../common';
|
|
16
|
+
import { createApp, ref, Ref, watch } from 'vue';
|
|
17
|
+
import { SuiFileInput } from '../fileio/fileInput';
|
|
18
|
+
import { default as messageDialog } from '../components/dialogs/modalMessage.vue';
|
|
19
|
+
import { default as fileUploadApp } from '../components/dialogs/fileUpload.vue';
|
|
20
|
+
import { default as saveFileApp } from '../components/dialogs/save.vue';
|
|
21
|
+
import { SuiNavigationDom } from '../navigation';
|
|
22
|
+
import { SaveOutcome, nextStepAfterSave } from '../../render/sui/scoreChangeState';
|
|
23
|
+
import { askUnsavedChoice } from './unsavedChanges';
|
|
24
|
+
declare var $: any;
|
|
25
|
+
|
|
26
|
+
export const SuiFileUploadDialog = async (parameters: SuiDialogParams) => {
|
|
27
|
+
const enable: Ref<boolean> = ref(false);
|
|
28
|
+
let filename = '';
|
|
29
|
+
let uploadedFile: any | null = null;
|
|
30
|
+
let quantizeValue: number = 1024;
|
|
31
|
+
const quantizeCb = (val: string) => {
|
|
32
|
+
quantizeValue = parseInt(val, 10);
|
|
33
|
+
}
|
|
34
|
+
const uploadCb = async (evt: any) => {
|
|
35
|
+
if (evt.target.files.length > 0) {
|
|
36
|
+
filename = evt.target.files[0].name;
|
|
37
|
+
}
|
|
38
|
+
const localFile = new SuiFileInput(evt);
|
|
39
|
+
await localFile.loadAsync();
|
|
40
|
+
uploadedFile = localFile.value;
|
|
41
|
+
enable.value = true;
|
|
42
|
+
};
|
|
43
|
+
// The score read from the file. It replaces the open score only after the user has been
|
|
44
|
+
// asked about unsaved changes, which has to wait until this dialog has closed.
|
|
45
|
+
let pendingScore: SmoScore | null = null;
|
|
46
|
+
const convertMidi = (): SmoScore | null => {
|
|
47
|
+
try {
|
|
48
|
+
// midi parser expects data in UintArray form
|
|
49
|
+
const ar = new Uint8Array(uploadedFile);
|
|
50
|
+
const midi: any = parseMidi(ar);
|
|
51
|
+
const midiParser = new MidiToSmo(midi, quantizeValue);
|
|
52
|
+
return midiParser.convert();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.warn('unable to score ' + e);
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const convertXml = (): SmoScore | null => {
|
|
59
|
+
try {
|
|
60
|
+
const parser = new DOMParser();
|
|
61
|
+
const xml = parser.parseFromString(uploadedFile, 'text/xml');
|
|
62
|
+
const score = XmlToSmo.convert(xml);
|
|
63
|
+
score.layoutManager!.zoomToWidth($('body').width());
|
|
64
|
+
return score;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.warn('unable to score ' + e);
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const convertJson = (): SmoScore | null => {
|
|
71
|
+
if (uploadedFile && uploadedFile.length > 0) {
|
|
72
|
+
try {
|
|
73
|
+
return SmoScore.deserialize(uploadedFile);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.warn('unable to score ' + e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const commitCb = async () => {
|
|
81
|
+
pendingScore = null;
|
|
82
|
+
if (filename.endsWith('.mid') || filename.endsWith('.midi')) {
|
|
83
|
+
pendingScore = convertMidi();
|
|
84
|
+
}
|
|
85
|
+
else if (filename.endsWith('.xml') || filename.endsWith('.mxml') || filename.endsWith('.mxl')) {
|
|
86
|
+
pendingScore = convertXml();
|
|
87
|
+
}
|
|
88
|
+
else if (filename.endsWith('.json')) {
|
|
89
|
+
pendingScore = convertJson();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const afterCloseCb = async () => {
|
|
93
|
+
if (pendingScore && await confirmReplaceScore(parameters)) {
|
|
94
|
+
await parameters.view.changeScore(pendingScore);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const cancelCb = async () => {
|
|
98
|
+
}
|
|
99
|
+
const rootId = replaceVueRoot(modalContainerId);
|
|
100
|
+
const appParams: any = { enable, uploadCb, domId: rootId };
|
|
101
|
+
if (parameters.id === 'importMidi') {
|
|
102
|
+
appParams['quantizeCb'] = quantizeCb;
|
|
103
|
+
}
|
|
104
|
+
InstallDialog({
|
|
105
|
+
root: rootId,
|
|
106
|
+
app: fileUploadApp,
|
|
107
|
+
appParams,
|
|
108
|
+
dialogParams: parameters,
|
|
109
|
+
commitCb,
|
|
110
|
+
cancelCb,
|
|
111
|
+
afterCloseCb
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Call before replacing the open score with another (New, Open, Import, Library). If the score
|
|
117
|
+
* has unsaved changes, ask the user whether to save first. If they save in a lossy format
|
|
118
|
+
* (MusicXML, MIDI...) the score is still unsaved, so ask again. Must be called after any dialog
|
|
119
|
+
* used to choose the new score has closed.
|
|
120
|
+
* @param parameters dialog parameters, including the view
|
|
121
|
+
* @returns true if it is OK to replace the score, false if the user cancelled
|
|
122
|
+
*/
|
|
123
|
+
export const confirmReplaceScore = async (parameters: SuiDialogParams): Promise<boolean> => {
|
|
124
|
+
while (parameters.view.scoreChanged.value) {
|
|
125
|
+
const choice = await askUnsavedChoice(parameters);
|
|
126
|
+
if (choice === 'discard') {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
if (choice === 'cancel') {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const outcome = await new Promise<SaveOutcome>((resolve) => {
|
|
133
|
+
SuiFileSaveDialog(parameters, (result: SaveOutcome) => resolve(result));
|
|
134
|
+
});
|
|
135
|
+
const next = nextStepAfterSave(outcome);
|
|
136
|
+
if (next === 'load') {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (next === 'abort') {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Save the score to a file.
|
|
148
|
+
* @param parameters dialog parameters
|
|
149
|
+
* @param onClosed optional, called when the dialog closes with how it ended: the score was saved
|
|
150
|
+
* in full, exported to a lossy format, or the dialog was cancelled.
|
|
151
|
+
*/
|
|
152
|
+
export const SuiFileSaveDialog = async (parameters: SuiDialogParams, onClosed?: (outcome: SaveOutcome) => void) => {
|
|
153
|
+
const page = 0;
|
|
154
|
+
const contents: Ref<any> = ref('');
|
|
155
|
+
const getSmoContent = () => {
|
|
156
|
+
const json = parameters.view.storeScore.serialize();
|
|
157
|
+
const jsonText = JSON.stringify(json);
|
|
158
|
+
return jsonText;
|
|
159
|
+
}
|
|
160
|
+
const getSmoValidationContent = () => {
|
|
161
|
+
const json = parameters.view.storeScore.serialize({ useDictionary: false, skipStaves: false, preserveStaffIds: false });
|
|
162
|
+
const jsonText = JSON.stringify(json);
|
|
163
|
+
return jsonText;
|
|
164
|
+
}
|
|
165
|
+
const getMusicXmlContent = () => {
|
|
166
|
+
const dom = SmoToXml.convert(parameters.view.storeScore);
|
|
167
|
+
const ser = new XMLSerializer();
|
|
168
|
+
const xmlText = ser.serializeToString(dom);
|
|
169
|
+
return xmlText;
|
|
170
|
+
}
|
|
171
|
+
const getMidiContent = () => {
|
|
172
|
+
const bytes = SmoToMidi.convert(parameters.view.storeScore);
|
|
173
|
+
return bytes;
|
|
174
|
+
}
|
|
175
|
+
const getVexContent = () => {
|
|
176
|
+
const vexText = SmoToVex.convert(parameters.view.storeScore, { div: 'smoo', page });
|
|
177
|
+
return vexText;
|
|
178
|
+
};
|
|
179
|
+
contents.value = getSmoContent();
|
|
180
|
+
const extension: Ref<string> = ref('.json');
|
|
181
|
+
const suggestedName = parameters.view.score.scoreInfo.name;
|
|
182
|
+
const changeExtensionCb = (ext: string) => {
|
|
183
|
+
if (ext === '.json') {
|
|
184
|
+
contents.value = getSmoContent();
|
|
185
|
+
} else if (ext === '.xml') {
|
|
186
|
+
contents.value = getMusicXmlContent();
|
|
187
|
+
} else if (ext === '.mid' || ext === '.midi') {
|
|
188
|
+
contents.value = getMidiContent();
|
|
189
|
+
} else if (ext === '.js') {
|
|
190
|
+
contents.value = getVexContent();
|
|
191
|
+
} else if (ext === '.smojson') {
|
|
192
|
+
contents.value = getSmoValidationContent();
|
|
193
|
+
extension.value = '.json';
|
|
194
|
+
return;
|
|
195
|
+
} else {
|
|
196
|
+
contents.value = getSmoContent();
|
|
197
|
+
}
|
|
198
|
+
extension.value = ext;
|
|
199
|
+
}
|
|
200
|
+
let committedOutcome: SaveOutcome = 'cancelled';
|
|
201
|
+
const commitCb = async () => {
|
|
202
|
+
// The view knows which formats hold the whole score, and clears the changed flag only for those.
|
|
203
|
+
committedOutcome = parameters.view.recordSave(extension.value) ? 'saved' : 'exported';
|
|
204
|
+
}
|
|
205
|
+
const cancelCb = async () => {
|
|
206
|
+
if (onClosed) {
|
|
207
|
+
onClosed('cancelled');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Report a committed save only after the dialog has closed, so a caller can open another dialog.
|
|
211
|
+
const afterCloseCb = async () => {
|
|
212
|
+
if (onClosed) {
|
|
213
|
+
onClosed(committedOutcome);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const rootId = replaceVueRoot(modalContainerId);
|
|
217
|
+
const appParams = { suggestedName, contents, extension, changeExtensionCb, domId: rootId };
|
|
218
|
+
InstallDialog({
|
|
219
|
+
root: rootId,
|
|
220
|
+
app: saveFileApp,
|
|
221
|
+
appParams,
|
|
222
|
+
dialogParams: parameters,
|
|
223
|
+
commitCb,
|
|
224
|
+
cancelCb,
|
|
225
|
+
afterCloseCb
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
export const SuiPrintDialog = async (parameters: SuiDialogParams) => {
|
|
229
|
+
await parameters.view.renderer.renderForPrintPromise();
|
|
230
|
+
window.print();
|
|
231
|
+
$('body').removeClass('printing');
|
|
232
|
+
const okCb = async () => {
|
|
233
|
+
parameters.view.renderer.restoreLayoutAfterPrint();
|
|
234
|
+
window.dispatchEvent(new Event('resize'));
|
|
235
|
+
}
|
|
236
|
+
const rootId = replaceVueRoot(modalContainerId);
|
|
237
|
+
const appParams = { domId: rootId, okCb, message: 'Print complete!', headline: 'Printing' };
|
|
238
|
+
InstallDialog({
|
|
239
|
+
root: rootId,
|
|
240
|
+
app: messageDialog,
|
|
241
|
+
dialogParams: parameters,
|
|
242
|
+
appParams,
|
|
243
|
+
commitCb: okCb, cancelCb: okCb});
|
|
244
|
+
}
|
|
245
|
+
|
package/src/ui/dialogs/fonts.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
-
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
-
import { FontInfo } from '../../common/vex';
|
|
4
|
-
import { SmoScore, isEngravingFont, engravingFontType } from '../../smo/data/score';
|
|
5
|
-
import { FontPurpose } from '../../smo/data/scoreModifiers';
|
|
6
|
-
import { SuiDialogParams, InstallDialog } from './dialog';
|
|
7
|
-
import { replaceVueRoot, modalContainerId } from '../common';
|
|
8
|
-
import { reactive, watch, ref } from 'vue';
|
|
9
|
-
import scoreFontsApp from '../components/dialogs/scoreFonts.vue';
|
|
10
|
-
|
|
11
|
-
declare var $: any;
|
|
12
|
-
export const SuiScoreFontDialogVue = (parameters: SuiDialogParams) => {
|
|
13
|
-
const currentFonts = parameters.view.score.fonts;
|
|
14
|
-
const backupFonts: FontPurpose[] = JSON.parse(JSON.stringify(currentFonts));
|
|
15
|
-
let changed = false;
|
|
16
|
-
const engravingFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.ENGRAVING);
|
|
17
|
-
if (!engravingFontInfo) {
|
|
18
|
-
throw new Error('No engraving font found in score');
|
|
19
|
-
}
|
|
20
|
-
const chordFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.CHORDS);
|
|
21
|
-
if (!chordFontInfo) {
|
|
22
|
-
throw new Error('No chord font found in score');
|
|
23
|
-
}
|
|
24
|
-
const lyricFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.LYRICS);
|
|
25
|
-
if (!lyricFontInfo) {
|
|
26
|
-
throw new Error('No lyric font found in score');
|
|
27
|
-
}
|
|
28
|
-
const engravingFont = ref(engravingFontInfo.family ?? 'Bravura');
|
|
29
|
-
const lyricFontCb = async (fontInfo: FontInfo) => {
|
|
30
|
-
changed = true;
|
|
31
|
-
await parameters.view.setLyricFont(fontInfo);
|
|
32
|
-
}
|
|
33
|
-
const chordFontCb = async (fontInfo: FontInfo) => {
|
|
34
|
-
changed = true;
|
|
35
|
-
await parameters.view.setChordFont(fontInfo);
|
|
36
|
-
}
|
|
37
|
-
watch(engravingFont, async (newVal) => {
|
|
38
|
-
changed = true;
|
|
39
|
-
if (isEngravingFont(newVal)) {
|
|
40
|
-
await parameters.view.setEngravingFontFamily(newVal);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const getFonts = () => {
|
|
44
|
-
return {
|
|
45
|
-
engravingFont,
|
|
46
|
-
lyricFont: lyricFontInfo,
|
|
47
|
-
chordFont: chordFontInfo
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const commitCb = async () => {
|
|
51
|
-
if (changed) {
|
|
52
|
-
parameters.view.resetPartView();
|
|
53
|
-
}
|
|
54
|
-
await parameters.view.refreshViewport();
|
|
55
|
-
}
|
|
56
|
-
const cancelCb = async () => {
|
|
57
|
-
if (changed) {
|
|
58
|
-
const currentEngraving = backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.ENGRAVING)?.family ?? 'Bravura';
|
|
59
|
-
if (!isEngravingFont(currentEngraving)) {
|
|
60
|
-
throw new Error('Invalid engraving font in backup');
|
|
61
|
-
}
|
|
62
|
-
await parameters.view.setEngravingFontFamily(currentEngraving);
|
|
63
|
-
await parameters.view.setChordFont({
|
|
64
|
-
weight: 'normal',
|
|
65
|
-
style: 'normal',
|
|
66
|
-
...backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.CHORDS)
|
|
67
|
-
});
|
|
68
|
-
await parameters.view.setLyricFont({
|
|
69
|
-
weight: 'normal',
|
|
70
|
-
style: 'normal',
|
|
71
|
-
...backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.LYRICS)
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const rootId = replaceVueRoot(modalContainerId);
|
|
76
|
-
const appParams = {
|
|
77
|
-
domId: rootId,
|
|
78
|
-
label: 'Score Fonts',
|
|
79
|
-
getFonts,
|
|
80
|
-
updateLyricFontCb: lyricFontCb,
|
|
81
|
-
updateChordFontCb: chordFontCb,
|
|
82
|
-
};
|
|
83
|
-
InstallDialog({
|
|
84
|
-
app: scoreFontsApp,
|
|
85
|
-
appParams,
|
|
86
|
-
root: rootId,
|
|
87
|
-
dialogParams: parameters,
|
|
88
|
-
commitCb,
|
|
89
|
-
cancelCb
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
1
|
+
// [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
|
|
2
|
+
// Copyright (c) Aaron David Newman 2021.
|
|
3
|
+
import { FontInfo } from '../../common/vex';
|
|
4
|
+
import { SmoScore, isEngravingFont, engravingFontType } from '../../smo/data/score';
|
|
5
|
+
import { FontPurpose } from '../../smo/data/scoreModifiers';
|
|
6
|
+
import { SuiDialogParams, InstallDialog } from './dialog';
|
|
7
|
+
import { replaceVueRoot, modalContainerId } from '../common';
|
|
8
|
+
import { reactive, watch, ref } from 'vue';
|
|
9
|
+
import scoreFontsApp from '../components/dialogs/scoreFonts.vue';
|
|
10
|
+
|
|
11
|
+
declare var $: any;
|
|
12
|
+
export const SuiScoreFontDialogVue = (parameters: SuiDialogParams) => {
|
|
13
|
+
const currentFonts = parameters.view.score.fonts;
|
|
14
|
+
const backupFonts: FontPurpose[] = JSON.parse(JSON.stringify(currentFonts));
|
|
15
|
+
let changed = false;
|
|
16
|
+
const engravingFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.ENGRAVING);
|
|
17
|
+
if (!engravingFontInfo) {
|
|
18
|
+
throw new Error('No engraving font found in score');
|
|
19
|
+
}
|
|
20
|
+
const chordFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.CHORDS);
|
|
21
|
+
if (!chordFontInfo) {
|
|
22
|
+
throw new Error('No chord font found in score');
|
|
23
|
+
}
|
|
24
|
+
const lyricFontInfo = currentFonts.find((ff: any) => ff.purpose === SmoScore.fontPurposes.LYRICS);
|
|
25
|
+
if (!lyricFontInfo) {
|
|
26
|
+
throw new Error('No lyric font found in score');
|
|
27
|
+
}
|
|
28
|
+
const engravingFont = ref(engravingFontInfo.family ?? 'Bravura');
|
|
29
|
+
const lyricFontCb = async (fontInfo: FontInfo) => {
|
|
30
|
+
changed = true;
|
|
31
|
+
await parameters.view.setLyricFont(fontInfo);
|
|
32
|
+
}
|
|
33
|
+
const chordFontCb = async (fontInfo: FontInfo) => {
|
|
34
|
+
changed = true;
|
|
35
|
+
await parameters.view.setChordFont(fontInfo);
|
|
36
|
+
}
|
|
37
|
+
watch(engravingFont, async (newVal) => {
|
|
38
|
+
changed = true;
|
|
39
|
+
if (isEngravingFont(newVal)) {
|
|
40
|
+
await parameters.view.setEngravingFontFamily(newVal);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const getFonts = () => {
|
|
44
|
+
return {
|
|
45
|
+
engravingFont,
|
|
46
|
+
lyricFont: lyricFontInfo,
|
|
47
|
+
chordFont: chordFontInfo
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const commitCb = async () => {
|
|
51
|
+
if (changed) {
|
|
52
|
+
parameters.view.resetPartView();
|
|
53
|
+
}
|
|
54
|
+
await parameters.view.refreshViewport();
|
|
55
|
+
}
|
|
56
|
+
const cancelCb = async () => {
|
|
57
|
+
if (changed) {
|
|
58
|
+
const currentEngraving = backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.ENGRAVING)?.family ?? 'Bravura';
|
|
59
|
+
if (!isEngravingFont(currentEngraving)) {
|
|
60
|
+
throw new Error('Invalid engraving font in backup');
|
|
61
|
+
}
|
|
62
|
+
await parameters.view.setEngravingFontFamily(currentEngraving);
|
|
63
|
+
await parameters.view.setChordFont({
|
|
64
|
+
weight: 'normal',
|
|
65
|
+
style: 'normal',
|
|
66
|
+
...backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.CHORDS)
|
|
67
|
+
});
|
|
68
|
+
await parameters.view.setLyricFont({
|
|
69
|
+
weight: 'normal',
|
|
70
|
+
style: 'normal',
|
|
71
|
+
...backupFonts.find((ff: FontPurpose) => ff.purpose === SmoScore.fontPurposes.LYRICS)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const rootId = replaceVueRoot(modalContainerId);
|
|
76
|
+
const appParams = {
|
|
77
|
+
domId: rootId,
|
|
78
|
+
label: 'Score Fonts',
|
|
79
|
+
getFonts,
|
|
80
|
+
updateLyricFontCb: lyricFontCb,
|
|
81
|
+
updateChordFontCb: chordFontCb,
|
|
82
|
+
};
|
|
83
|
+
InstallDialog({
|
|
84
|
+
app: scoreFontsApp,
|
|
85
|
+
appParams,
|
|
86
|
+
root: rootId,
|
|
87
|
+
dialogParams: parameters,
|
|
88
|
+
commitCb,
|
|
89
|
+
cancelCb
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|