smoosic 2.0.1 → 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.
Files changed (127) hide show
  1. package/build/smoosic.js +171 -78
  2. package/package.json +82 -77
  3. package/release/smoosic.js +171 -78
  4. package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/src/application/application.ts +464 -459
  48. package/src/common/promiseHelpers.ts +2 -2
  49. package/src/render/audio/samples.ts +117 -118
  50. package/src/render/sui/pageDivisions.ts +58 -0
  51. package/src/render/sui/renderState.ts +469 -464
  52. package/src/render/sui/scoreChangeState.ts +62 -0
  53. package/src/render/sui/scoreView.ts +30 -0
  54. package/src/render/sui/scoreViewOperations.ts +2555 -2380
  55. package/src/render/sui/svgPageMap.ts +16 -17
  56. package/src/render/sui/textEdit.ts +310 -311
  57. package/src/render/sui/tracker.ts +40 -0
  58. package/src/render/vex/vxNote.ts +3 -1
  59. package/src/smo/xform/copypaste.ts +304 -4
  60. package/src/smo/xform/selections.ts +68 -0
  61. package/src/smo/xform/undo.ts +9 -0
  62. package/src/styles/menus.css +26 -0
  63. package/src/ui/buttons/ribbon.ts +3 -1
  64. package/src/ui/components/buttons/sidebar.vue +15 -6
  65. package/src/ui/components/dialogs/library.vue +3 -1
  66. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  67. package/src/ui/dialogs/adapter.ts +181 -183
  68. package/src/ui/dialogs/addMeasure.ts +97 -97
  69. package/src/ui/dialogs/annotationVue.ts +56 -56
  70. package/src/ui/dialogs/audioSettings.ts +121 -123
  71. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  72. package/src/ui/dialogs/clefChange.ts +53 -53
  73. package/src/ui/dialogs/customTuplets.ts +95 -96
  74. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  75. package/src/ui/dialogs/dialog.ts +627 -620
  76. package/src/ui/dialogs/durations.ts +34 -34
  77. package/src/ui/dialogs/dynamics.ts +140 -142
  78. package/src/ui/dialogs/factory.ts +198 -198
  79. package/src/ui/dialogs/fileDialogs.ts +245 -179
  80. package/src/ui/dialogs/fonts.ts +93 -93
  81. package/src/ui/dialogs/globalLayout.ts +40 -40
  82. package/src/ui/dialogs/gracenote.ts +31 -31
  83. package/src/ui/dialogs/hairpin.ts +108 -110
  84. package/src/ui/dialogs/hairpinVue.ts +51 -51
  85. package/src/ui/dialogs/instrument.ts +111 -111
  86. package/src/ui/dialogs/keySignature.ts +175 -176
  87. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  88. package/src/ui/dialogs/library.ts +207 -207
  89. package/src/ui/dialogs/libraryVue.ts +62 -48
  90. package/src/ui/dialogs/lyricVue.ts +46 -46
  91. package/src/ui/dialogs/measureFormat.ts +78 -78
  92. package/src/ui/dialogs/microtones.ts +147 -147
  93. package/src/ui/dialogs/noteHead.ts +319 -319
  94. package/src/ui/dialogs/pageLayout.ts +61 -61
  95. package/src/ui/dialogs/partInfo.ts +60 -60
  96. package/src/ui/dialogs/pedalMarking.ts +117 -117
  97. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  98. package/src/ui/dialogs/pitch.ts +352 -352
  99. package/src/ui/dialogs/preferences.ts +40 -40
  100. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  101. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  102. package/src/ui/dialogs/scoreId.ts +35 -36
  103. package/src/ui/dialogs/scoreView.ts +42 -42
  104. package/src/ui/dialogs/slur.ts +308 -310
  105. package/src/ui/dialogs/slurVue.ts +91 -91
  106. package/src/ui/dialogs/staffGroup.ts +112 -112
  107. package/src/ui/dialogs/tabNote.ts +84 -84
  108. package/src/ui/dialogs/tabStave.ts +182 -182
  109. package/src/ui/dialogs/tempo.ts +261 -263
  110. package/src/ui/dialogs/tempoVue.ts +73 -73
  111. package/src/ui/dialogs/textBlockVue.ts +127 -127
  112. package/src/ui/dialogs/textBracket.ts +114 -116
  113. package/src/ui/dialogs/textBracketVue.ts +56 -56
  114. package/src/ui/dialogs/tie.ts +140 -142
  115. package/src/ui/dialogs/timeSignature.ts +65 -66
  116. package/src/ui/dialogs/transposeScore.ts +39 -39
  117. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  118. package/src/ui/dialogs/volta.ts +120 -122
  119. package/src/ui/dialogs/voltaVue.ts +51 -51
  120. package/src/ui/fileio/library.ts +110 -111
  121. package/src/ui/menus/edit.ts +100 -1
  122. package/src/ui/menus/file.ts +19 -3
  123. package/tests/pageDivisions.ts +156 -0
  124. package/tests/promiseHelpersUsage.ts +142 -0
  125. package/tests/scoreChangeState.ts +102 -0
  126. package/tests/selectVoice.ts +189 -0
  127. 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 { PromiseHelpers } from '../../common/promiseHelpers';
14
- import { SmoToVex } from '../../render/vex/toVex';
15
- import { parseMidi } from '../../common/midi-parser.js';
16
- import { replaceVueRoot, modalContainerId } from '../common';
17
- import { createApp, ref, Ref, watch } from 'vue';
18
- import { SuiFileInput } from '../fileio/fileInput';
19
- import { default as messageDialog } from '../components/dialogs/modalMessage.vue';
20
- import { default as fileUploadApp } from '../components/dialogs/fileUpload.vue';
21
- import { default as saveFileApp } from '../components/dialogs/save.vue';
22
- import { SuiNavigationDom } from '../navigation';
23
- declare var $: any;
24
-
25
- export const SuiFileUploadDialog = async (parameters: SuiDialogParams) => {
26
- const enable: Ref<boolean> = ref(false);
27
- let filename = '';
28
- let uploadedFile: any | null = null;
29
- let quantizeValue: number = 1024;
30
- const quantizeCb = (val: string) => {
31
- quantizeValue = parseInt(val, 10);
32
- }
33
- const uploadCb = async (evt: any) => {
34
- if (evt.target.files.length > 0) {
35
- filename = evt.target.files[0].name;
36
- }
37
- const localFile = new SuiFileInput(evt);
38
- await localFile.loadAsync();
39
- uploadedFile = localFile.value;
40
- enable.value = true;
41
- };
42
- const commitMidi = async () => {
43
- try {
44
- // midi parser expects data in UintArray form
45
- const ar = new Uint8Array(uploadedFile);
46
- const midi: any = parseMidi(ar);
47
- const midiParser = new MidiToSmo(midi, quantizeValue);
48
- await parameters.view.changeScore(midiParser.convert());
49
- } catch (e) {
50
- console.warn('unable to score ' + e);
51
- }
52
- }
53
- const commitXml = async () => {
54
- try {
55
- const parser = new DOMParser();
56
- const xml = parser.parseFromString(uploadedFile, 'text/xml');
57
- const score = XmlToSmo.convert(xml);
58
- score.layoutManager!.zoomToWidth($('body').width());
59
- await parameters.view.changeScore(score);
60
- } catch (e) {
61
- console.warn('unable to score ' + e);
62
- }
63
- }
64
- const commitCb = async () => {
65
- if (filename.endsWith('.mid') || filename.endsWith('.midi')) {
66
- await commitMidi();
67
- }
68
- else if (filename.endsWith('.xml') || filename.endsWith('.mxml') || filename.endsWith('.mxl')) {
69
- await commitXml();
70
- }
71
- else if (filename.endsWith('.json')) {
72
- if (uploadedFile && uploadedFile.length > 0) {
73
- try {
74
- const score = SmoScore.deserialize(uploadedFile);
75
- await parameters.view.changeScore(score);
76
- } catch (e) {
77
- console.warn('unable to score ' + e);
78
- }
79
- }
80
- }
81
- }
82
- const cancelCb = async () => {
83
- }
84
- const rootId = replaceVueRoot(modalContainerId);
85
- const appParams: any = { enable, uploadCb, domId: rootId };
86
- if (parameters.id === 'importMidi') {
87
- appParams['quantizeCb'] = quantizeCb;
88
- }
89
- InstallDialog({
90
- root: rootId,
91
- app: fileUploadApp,
92
- appParams,
93
- dialogParams: parameters,
94
- commitCb,
95
- cancelCb
96
- });
97
- }
98
-
99
- export const SuiFileSaveDialog = async (parameters: SuiDialogParams) => {
100
- const page = 0;
101
- const contents: Ref<any> = ref('');
102
- const getSmoContent = () => {
103
- const json = parameters.view.storeScore.serialize();
104
- const jsonText = JSON.stringify(json);
105
- return jsonText;
106
- }
107
- const getSmoValidationContent = () => {
108
- const json = parameters.view.storeScore.serialize({ useDictionary: false, skipStaves: false, preserveStaffIds: false });
109
- const jsonText = JSON.stringify(json);
110
- return jsonText;
111
- }
112
- const getMusicXmlContent = () => {
113
- const dom = SmoToXml.convert(parameters.view.storeScore);
114
- const ser = new XMLSerializer();
115
- const xmlText = ser.serializeToString(dom);
116
- return xmlText;
117
- }
118
- const getMidiContent = () => {
119
- const bytes = SmoToMidi.convert(parameters.view.storeScore);
120
- return bytes;
121
- }
122
- const getVexContent = () => {
123
- const vexText = SmoToVex.convert(parameters.view.storeScore, { div: 'smoo', page });
124
- return vexText;
125
- };
126
- contents.value = getSmoContent();
127
- const extension: Ref<string> = ref('.json');
128
- const suggestedName = parameters.view.score.scoreInfo.name;
129
- const changeExtensionCb = (ext: string) => {
130
- if (ext === '.json') {
131
- contents.value = getSmoContent();
132
- } else if (ext === '.xml') {
133
- contents.value = getMusicXmlContent();
134
- } else if (ext === '.mid' || ext === '.midi') {
135
- contents.value = getMidiContent();
136
- } else if (ext === '.js') {
137
- contents.value = getVexContent();
138
- } else if (ext === '.smojson') {
139
- contents.value = getSmoValidationContent();
140
- extension.value = '.json';
141
- return;
142
- } else {
143
- contents.value = getSmoContent();
144
- }
145
- extension.value = ext;
146
- }
147
- const commitCb = async () => {
148
- }
149
- const cancelCb = async () => {
150
- }
151
- const rootId = replaceVueRoot(modalContainerId);
152
- const appParams = { suggestedName, contents, extension, changeExtensionCb, domId: rootId };
153
- InstallDialog({
154
- root: rootId,
155
- app: saveFileApp,
156
- appParams,
157
- dialogParams: parameters,
158
- commitCb,
159
- cancelCb
160
- });
161
- }
162
- export const SuiPrintDialog = async (parameters: SuiDialogParams) => {
163
- await parameters.view.renderer.renderForPrintPromise();
164
- window.print();
165
- $('body').removeClass('printing');
166
- const okCb = async () => {
167
- parameters.view.renderer.restoreLayoutAfterPrint();
168
- window.dispatchEvent(new Event('resize'));
169
- }
170
- const rootId = replaceVueRoot(modalContainerId);
171
- const appParams = { domId: rootId, okCb, message: 'Print complete!', headline: 'Printing' };
172
- InstallDialog({
173
- root: rootId,
174
- app: messageDialog,
175
- dialogParams: parameters,
176
- appParams,
177
- commitCb: okCb, cancelCb: okCb});
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
+
@@ -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
+