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.
- package/build/smoosic.js +171 -78
- package/package.json +82 -77
- package/release/smoosic.js +171 -78
- package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
- 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
package/src/ui/menus/edit.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SuiMenuBase, SuiMenuParams, SuiConfiguredMenuOption, SuiConfiguredMenu } from './menu';
|
|
2
|
+
import { PasteBuffer } from '../../smo/xform/copypaste';
|
|
2
3
|
|
|
3
4
|
declare var $: any;
|
|
4
5
|
/**
|
|
@@ -55,6 +56,104 @@ const pasteChordsMenuOption: SuiConfiguredMenuOption = {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* One choice of the Copy Voices submenu: a single voice, or all of them. A choice is only
|
|
61
|
+
* shown if the selected measures have that voice.
|
|
62
|
+
* @category SuiMenu
|
|
63
|
+
*/
|
|
64
|
+
const copyVoiceChoice = (voice: number | 'all'): SuiConfiguredMenuOption => ({
|
|
65
|
+
handler: async (menu: SuiMenuBase) => {
|
|
66
|
+
await menu.view.copyVoices(voice);
|
|
67
|
+
},
|
|
68
|
+
display: (menu: SuiMenuBase) =>
|
|
69
|
+
PasteBuffer.copyVoiceChoices(menu.view.getSelectionVoiceCount()).indexOf(voice) >= 0,
|
|
70
|
+
menuChoice: {
|
|
71
|
+
icon: '',
|
|
72
|
+
text: voice === 'all' ? 'All Voices' : `Voice ${voice + 1}`,
|
|
73
|
+
value: voice === 'all' ? 'copyVoiceAll' : `copyVoice${voice}`
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Copy one voice or all voices, in whole measures
|
|
78
|
+
* @category SuiMenu
|
|
79
|
+
*/
|
|
80
|
+
const copyVoicesMenuOption: SuiConfiguredMenuOption = {
|
|
81
|
+
handler: async () => { }, // unreachable -- subMenu takes precedence over handler
|
|
82
|
+
display: (menu: SuiMenuBase) => PasteBuffer.copyVoiceChoices(menu.view.getSelectionVoiceCount()).length > 0,
|
|
83
|
+
subMenu: [0, 1, 2, 3, 'all'].map((v) => copyVoiceChoice(v as number | 'all')),
|
|
84
|
+
menuChoice: {
|
|
85
|
+
icon: 'icon-copy',
|
|
86
|
+
text: 'Copy Voices',
|
|
87
|
+
value: 'copyVoicesAction'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The voices that can be pasted at the selected measure, given what was copied
|
|
92
|
+
*/
|
|
93
|
+
const pasteVoiceChoices = (menu: SuiMenuBase) =>
|
|
94
|
+
PasteBuffer.pasteVoiceChoices(menu.view.storePaste.copiedVoiceNumbers(), menu.view.getDestinationVoiceCount());
|
|
95
|
+
/**
|
|
96
|
+
* One choice of the Paste Voice submenu: an existing voice (replacing it), a new voice after the
|
|
97
|
+
* existing ones, or all the copied voices.
|
|
98
|
+
* @category SuiMenu
|
|
99
|
+
*/
|
|
100
|
+
const pasteVoiceChoice = (voice: number | 'all' | 'new'): SuiConfiguredMenuOption => ({
|
|
101
|
+
handler: async (menu: SuiMenuBase) => {
|
|
102
|
+
await menu.view.pasteVoices(voice);
|
|
103
|
+
},
|
|
104
|
+
display: (menu: SuiMenuBase) => pasteVoiceChoices(menu).indexOf(voice) >= 0,
|
|
105
|
+
menuChoice: {
|
|
106
|
+
icon: '',
|
|
107
|
+
text: voice === 'all' ? 'All Voices' : (voice === 'new' ? 'New Voice' : `Voice ${voice + 1}`),
|
|
108
|
+
value: voice === 'all' ? 'pasteVoiceAll' : (voice === 'new' ? 'pasteVoiceNew' : `pasteVoice${voice}`)
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Paste copied voices at the start of the selected measure
|
|
113
|
+
* @category SuiMenu
|
|
114
|
+
*/
|
|
115
|
+
const pasteVoiceMenuOption: SuiConfiguredMenuOption = {
|
|
116
|
+
handler: async () => { }, // unreachable -- subMenu takes precedence over handler
|
|
117
|
+
display: (menu: SuiMenuBase) => pasteVoiceChoices(menu).length > 0,
|
|
118
|
+
subMenu: [0, 1, 2, 3, 'new', 'all'].map((v) => pasteVoiceChoice(v as number | 'all' | 'new')),
|
|
119
|
+
menuChoice: {
|
|
120
|
+
icon: 'icon-paste',
|
|
121
|
+
text: 'Paste Voice',
|
|
122
|
+
value: 'pasteVoiceAction'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* One choice of the Select Voice submenu. Shown only if the selected measures have that voice,
|
|
128
|
+
* and only when there is more than one voice to choose between.
|
|
129
|
+
* @category SuiMenu
|
|
130
|
+
*/
|
|
131
|
+
const selectVoiceChoice = (voice: number): SuiConfiguredMenuOption => ({
|
|
132
|
+
handler: async (menu: SuiMenuBase) => {
|
|
133
|
+
await menu.view.selectVoice(voice);
|
|
134
|
+
},
|
|
135
|
+
display: (menu: SuiMenuBase) => menu.view.getSelectVoiceChoices().indexOf(voice) >= 0,
|
|
136
|
+
menuChoice: {
|
|
137
|
+
icon: '',
|
|
138
|
+
text: `Voice ${voice + 1}`,
|
|
139
|
+
value: `selectVoice${voice}`
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* Select all the notes of one voice in the measures that are selected
|
|
144
|
+
* @category SuiMenu
|
|
145
|
+
*/
|
|
146
|
+
const selectVoiceMenuOption: SuiConfiguredMenuOption = {
|
|
147
|
+
handler: async () => { }, // unreachable -- subMenu takes precedence over handler
|
|
148
|
+
display: (menu: SuiMenuBase) => menu.view.getSelectVoiceChoices().length > 0,
|
|
149
|
+
subMenu: [0, 1, 2, 3].map((v) => selectVoiceChoice(v)),
|
|
150
|
+
menuChoice: {
|
|
151
|
+
icon: '',
|
|
152
|
+
text: 'Select Voice',
|
|
153
|
+
value: 'selectVoiceAction'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
58
157
|
/**
|
|
59
158
|
* Copy Ctrl^C action
|
|
60
159
|
* @category SuiMenu
|
|
@@ -75,5 +174,5 @@ const undoMenuOption: SuiConfiguredMenuOption = {
|
|
|
75
174
|
* @category SuiMenu
|
|
76
175
|
*/
|
|
77
176
|
const SuiEditMenuOptions: SuiConfiguredMenuOption[] = [
|
|
78
|
-
copyMenuOption, pasteMenuOption, pasteChordsMenuOption, undoMenuOption
|
|
177
|
+
copyMenuOption, pasteMenuOption, pasteChordsMenuOption, copyVoicesMenuOption, pasteVoiceMenuOption, selectVoiceMenuOption, undoMenuOption
|
|
79
178
|
];
|
package/src/ui/menus/file.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { createAndDisplayDialog } from '../dialogs/dialog';
|
|
|
3
3
|
import {
|
|
4
4
|
SuiFileSaveDialog ,
|
|
5
5
|
SuiFileUploadDialog,
|
|
6
|
-
SuiPrintDialog
|
|
6
|
+
SuiPrintDialog,
|
|
7
|
+
confirmReplaceScore
|
|
7
8
|
} from '../dialogs/fileDialogs';
|
|
8
9
|
import { SmoScore } from '../../smo/data/score';
|
|
9
10
|
|
|
@@ -12,8 +13,23 @@ declare var $: any;
|
|
|
12
13
|
|
|
13
14
|
const systemNewScoreOption: SuiConfiguredMenuOption = {
|
|
14
15
|
handler: async (menu: SuiMenuBase) => {
|
|
15
|
-
|
|
16
|
-
await
|
|
16
|
+
// Ask about unsaved changes first. The prompt waits for this menu to close, and the menu
|
|
17
|
+
// closes only after this handler returns, so don't await the prompt here.
|
|
18
|
+
confirmReplaceScore({
|
|
19
|
+
ctor: 'SuiNewScoreDialog',
|
|
20
|
+
id: 'newScore',
|
|
21
|
+
modifier: null,
|
|
22
|
+
completeNotifier: menu.completeNotifier,
|
|
23
|
+
tracker: menu.tracker,
|
|
24
|
+
eventSource: menu.eventSource,
|
|
25
|
+
view: menu.view,
|
|
26
|
+
startPromise: menu.closePromise
|
|
27
|
+
}).then(async (proceed) => {
|
|
28
|
+
if (proceed) {
|
|
29
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
30
|
+
await menu.view.changeScore(score);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
17
33
|
}, display: (menu: SuiMenuBase) => true,
|
|
18
34
|
menuChoice: {
|
|
19
35
|
icon: 'mi create',
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for computeDivisions/findDivision, the pure region math behind SvgPage's
|
|
3
|
+
* modifier filing and lookup. Cases D1-D17 are listed in
|
|
4
|
+
* specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md.
|
|
5
|
+
*
|
|
6
|
+
* Run with: npm run test:page-divisions
|
|
7
|
+
*/
|
|
8
|
+
import { computeDivisions, findDivision, PageDivision } from '../src/render/sui/pageDivisions';
|
|
9
|
+
|
|
10
|
+
let failures = 0;
|
|
11
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
12
|
+
if (condition) {
|
|
13
|
+
console.log(`PASS ${name}`);
|
|
14
|
+
} else {
|
|
15
|
+
failures += 1;
|
|
16
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** The formula SvgPage.divIndex used before this fix, kept to document the bug. */
|
|
21
|
+
const legacyIndex = (pos: number, start: number, extent: number) => Math.round((pos - start) / (extent / 8));
|
|
22
|
+
|
|
23
|
+
const table = computeDivisions(0, 1000, 8);
|
|
24
|
+
|
|
25
|
+
// --- D1-D3: shape of the table ---
|
|
26
|
+
check('D1 eight divisions', table.length === 8, `got ${table.length}`);
|
|
27
|
+
check('D2 first start and last end are exact', table[0].start === 0 && table[7].end === 1000,
|
|
28
|
+
`${table[0].start}, ${table[7].end}`);
|
|
29
|
+
{
|
|
30
|
+
let contiguous = true;
|
|
31
|
+
for (let i = 0; i < 7; ++i) {
|
|
32
|
+
contiguous = contiguous && table[i].end === table[i + 1].start;
|
|
33
|
+
}
|
|
34
|
+
check('D3 divisions are contiguous', contiguous);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// --- D4: midpoints ---
|
|
38
|
+
for (let i = 0; i < 8; ++i) {
|
|
39
|
+
const got = findDivision(62.5 + 125 * i, table);
|
|
40
|
+
check(`D4 midpoint of division ${i}`, got === i, `got ${got}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// --- D5: lower half of the last division (the original bug) ---
|
|
44
|
+
check('D5 legacy formula dropped 950 (index 8)', legacyIndex(950, 0, 1000) === 8);
|
|
45
|
+
check('D5 950 is in the last division', findDivision(950, table) === 7, `got ${findDivision(950, table)}`);
|
|
46
|
+
|
|
47
|
+
// --- D6-D7: page edges ---
|
|
48
|
+
check('D6 top edge is division 0', findDivision(0, table) === 0);
|
|
49
|
+
check('D7 bottom edge is the last division', findDivision(1000, table) === 7, `got ${findDivision(1000, table)}`);
|
|
50
|
+
|
|
51
|
+
// --- D8-D9: boundaries ---
|
|
52
|
+
check('D8 interior boundary belongs to the later division', findDivision(125, table) === 1);
|
|
53
|
+
check('D8 boundary result is stable', findDivision(125, table) === findDivision(125, table));
|
|
54
|
+
check('D9 just below a boundary', findDivision(124.999, table) === 0);
|
|
55
|
+
check('D9 just above a boundary', findDivision(125.001, table) === 1);
|
|
56
|
+
|
|
57
|
+
// --- D10-D12: outside the page ---
|
|
58
|
+
check('D10 before the page', findDivision(-0.001, table) === -1);
|
|
59
|
+
check('D11 after the page', findDivision(1000.001, table) === -1);
|
|
60
|
+
check('D12 NaN', findDivision(NaN, table) === -1);
|
|
61
|
+
check('D12 Infinity', findDivision(Infinity, table) === -1);
|
|
62
|
+
check('D12 -Infinity', findDivision(-Infinity, table) === -1);
|
|
63
|
+
|
|
64
|
+
// --- D13: a page that does not start at 0 ---
|
|
65
|
+
{
|
|
66
|
+
const page3 = computeDivisions(2000, 1000, 8);
|
|
67
|
+
check('D13 page start', findDivision(2000, page3) === 0);
|
|
68
|
+
check('D13 just inside the bottom', findDivision(2999, page3) === 7);
|
|
69
|
+
// 3000 is page 3's trailing edge (and page 4's top). SvgPageMap routes that coordinate to
|
|
70
|
+
// the next page before this lookup runs, so treating it as the last division here is harmless.
|
|
71
|
+
check('D13 trailing edge is the last division', findDivision(3000, page3) === 7);
|
|
72
|
+
check('D13 before the page', findDivision(1999.5, page3) === -1);
|
|
73
|
+
check('D13 first start and last end are exact', page3[0].start === 2000 && page3[7].end === 3000);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// --- D14: other page sizes ---
|
|
77
|
+
for (const extent of [800, 1056, 1123]) {
|
|
78
|
+
const t = computeDivisions(0, extent, 8);
|
|
79
|
+
let ok = true;
|
|
80
|
+
let monotonic = true;
|
|
81
|
+
let prev = -1;
|
|
82
|
+
let hitLast = false;
|
|
83
|
+
for (let p = 0; p <= extent; p += extent / 64) {
|
|
84
|
+
const ix = findDivision(p, t);
|
|
85
|
+
ok = ok && ix >= 0 && ix <= 7;
|
|
86
|
+
monotonic = monotonic && ix >= prev;
|
|
87
|
+
prev = ix;
|
|
88
|
+
hitLast = hitLast || ix === 7;
|
|
89
|
+
}
|
|
90
|
+
check(`D14 extent ${extent}: every position maps to a division`, ok);
|
|
91
|
+
check(`D14 extent ${extent}: indices never decrease`, monotonic);
|
|
92
|
+
check(`D14 extent ${extent}: last division is reached`, hitLast);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// --- D15: exhaustive sweep ---
|
|
96
|
+
{
|
|
97
|
+
let noneOutside = true;
|
|
98
|
+
let monotonic = true;
|
|
99
|
+
let prev = 0;
|
|
100
|
+
const seen = new Set<number>();
|
|
101
|
+
for (let p = 0; p <= 1000; p += 0.5) {
|
|
102
|
+
const ix = findDivision(p, table);
|
|
103
|
+
noneOutside = noneOutside && ix >= 0 && ix <= 7;
|
|
104
|
+
monotonic = monotonic && ix >= prev;
|
|
105
|
+
prev = ix;
|
|
106
|
+
seen.add(ix);
|
|
107
|
+
}
|
|
108
|
+
check('D15 no position is outside a division', noneOutside);
|
|
109
|
+
check('D15 indices never decrease', monotonic);
|
|
110
|
+
check('D15 all eight divisions are hit', seen.size === 8 && [0, 1, 2, 3, 4, 5, 6, 7].every((i) => seen.has(i)));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// --- D16: filing and lookup agree ---
|
|
114
|
+
{
|
|
115
|
+
// Mimic SvgPage.modifierTabDivs: file a tab per sampled position, then look it up.
|
|
116
|
+
const filed: Record<number, string[]> = {};
|
|
117
|
+
const positions: number[] = [];
|
|
118
|
+
for (let p = 0; p <= 1000; p += 1) {
|
|
119
|
+
positions.push(p);
|
|
120
|
+
}
|
|
121
|
+
table.forEach((d: PageDivision) => positions.push(d.start, d.end));
|
|
122
|
+
positions.forEach((p) => {
|
|
123
|
+
const ix = findDivision(p, table);
|
|
124
|
+
if (ix >= 0) {
|
|
125
|
+
filed[ix] = filed[ix] ?? [];
|
|
126
|
+
filed[ix].push(`tab-${p}`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const allFound = positions.every((p) => {
|
|
130
|
+
const ix = findDivision(p, table);
|
|
131
|
+
return ix >= 0 && !!filed[ix] && filed[ix].indexOf(`tab-${p}`) >= 0;
|
|
132
|
+
});
|
|
133
|
+
check('D16 a tab filed at a position is found by a lookup at that position', allFound);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// --- D17: nothing that could be filed before is lost ---
|
|
137
|
+
{
|
|
138
|
+
let nothingLost = true;
|
|
139
|
+
let closeToLegacy = true;
|
|
140
|
+
for (let p = 0; p < 937.5; p += 1) {
|
|
141
|
+
// below the old cutoff, the legacy formula produced a valid index (0-7)
|
|
142
|
+
const old = legacyIndex(p, 0, 1000);
|
|
143
|
+
const now = findDivision(p, table);
|
|
144
|
+
nothingLost = nothingLost && now >= 0;
|
|
145
|
+
closeToLegacy = closeToLegacy && Math.abs(now - old) <= 1;
|
|
146
|
+
}
|
|
147
|
+
check('D17 every position that was filed before is still filed', nothingLost);
|
|
148
|
+
check('D17 new index is within one of the legacy index', closeToLegacy);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (failures > 0) {
|
|
152
|
+
console.log(`${failures} check(s) failed`);
|
|
153
|
+
process.exitCode = 1;
|
|
154
|
+
} else {
|
|
155
|
+
console.log('all checks passed');
|
|
156
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards for the removal of PromiseHelpers from the application (cases P1-P9 in
|
|
3
|
+
* specs/029-remove-promise-helpers/contracts/public-api-contract.md):
|
|
4
|
+
* - the application source does not use the helper, except for its own file and the export file
|
|
5
|
+
* - the helper class is still exported and still behaves as before, for external applications
|
|
6
|
+
*
|
|
7
|
+
* Run with: npm run test:promise-helpers
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { PromiseHelpers, TEmptyPromise } from '../src/common/promiseHelpers';
|
|
12
|
+
|
|
13
|
+
let failures = 0;
|
|
14
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
15
|
+
if (condition) {
|
|
16
|
+
console.log(`PASS ${name}`);
|
|
17
|
+
} else {
|
|
18
|
+
failures += 1;
|
|
19
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const srcRoot = path.resolve(__dirname, '..', 'src');
|
|
24
|
+
const allowed = [
|
|
25
|
+
path.join(srcRoot, 'common', 'promiseHelpers.ts'),
|
|
26
|
+
path.join(srcRoot, 'application', 'exports.ts')
|
|
27
|
+
];
|
|
28
|
+
const extensions = ['.ts', '.vue', '.js'];
|
|
29
|
+
|
|
30
|
+
/** All source files under dir with a checked extension */
|
|
31
|
+
const listFiles = (dir: string): string[] => {
|
|
32
|
+
let rv: string[] = [];
|
|
33
|
+
fs.readdirSync(dir, { withFileTypes: true }).forEach((entry) => {
|
|
34
|
+
const full = path.join(dir, entry.name);
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
rv = rv.concat(listFiles(full));
|
|
37
|
+
} else if (extensions.indexOf(path.extname(entry.name)) >= 0) {
|
|
38
|
+
rv.push(full);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return rv;
|
|
42
|
+
};
|
|
43
|
+
const rel = (file: string) => path.relative(srcRoot, file).replace(/\\/g, '/');
|
|
44
|
+
|
|
45
|
+
// --- P1, P2: the application does not use the helpers ---
|
|
46
|
+
{
|
|
47
|
+
const usingHelper: string[] = [];
|
|
48
|
+
const usingMethods: string[] = [];
|
|
49
|
+
listFiles(srcRoot).forEach((file) => {
|
|
50
|
+
if (allowed.indexOf(file) >= 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
54
|
+
if (text.indexOf('PromiseHelpers') >= 0) {
|
|
55
|
+
usingHelper.push(rel(file));
|
|
56
|
+
}
|
|
57
|
+
if (/\b(emptyPromise|makePromise)\(/.test(text)) {
|
|
58
|
+
usingMethods.push(rel(file));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
check('P1 no application file mentions PromiseHelpers', usingHelper.length === 0, usingHelper.join(', '));
|
|
62
|
+
check('P2 no application file calls emptyPromise or makePromise', usingMethods.length === 0, usingMethods.join(', '));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- P3: still part of the public exports ---
|
|
66
|
+
{
|
|
67
|
+
const exportsText = fs.readFileSync(path.join(srcRoot, 'application', 'exports.ts'), 'utf8');
|
|
68
|
+
check('P3 exports.ts re-exports the module', exportsText.indexOf("export * from '../common/promiseHelpers'") >= 0);
|
|
69
|
+
check('P3 exports.ts lists PromiseHelpers', /[\s,]PromiseHelpers\s*,/.test(exportsText));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- P4: methods exist ---
|
|
73
|
+
for (const method of ['makePromise', 'makePromiseObj', 'promiseChainThen', 'emptyPromise']) {
|
|
74
|
+
check(`P4 PromiseHelpers.${method} is a function`, typeof (PromiseHelpers as any)[method] === 'function');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const main = async () => {
|
|
78
|
+
// --- P5: emptyPromise ---
|
|
79
|
+
{
|
|
80
|
+
const value = await PromiseHelpers.emptyPromise();
|
|
81
|
+
check('P5 emptyPromise resolves', value === undefined);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --- P6: makePromise, condition true on the 3rd poll ---
|
|
85
|
+
{
|
|
86
|
+
let polls = 0;
|
|
87
|
+
let pollCalls = 0;
|
|
88
|
+
let preResolveCalls = 0;
|
|
89
|
+
await PromiseHelpers.makePromise(
|
|
90
|
+
() => { polls += 1; return polls >= 3; },
|
|
91
|
+
() => { preResolveCalls += 1; },
|
|
92
|
+
() => { pollCalls += 1; },
|
|
93
|
+
5
|
|
94
|
+
);
|
|
95
|
+
check('P6 makePromise tests the condition until it is true', polls === 3, `polls=${polls}`);
|
|
96
|
+
check('P6 pre-resolve method is called once', preResolveCalls === 1, `calls=${preResolveCalls}`);
|
|
97
|
+
check('P6 poll method is called once per failed test', pollCalls === 2, `calls=${pollCalls}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// --- P7: makePromise, condition already true: still waits one poll interval before testing ---
|
|
101
|
+
{
|
|
102
|
+
let pollCalls = 0;
|
|
103
|
+
let preResolveCalls = 0;
|
|
104
|
+
let tested = false;
|
|
105
|
+
const start = Date.now();
|
|
106
|
+
await PromiseHelpers.makePromise(
|
|
107
|
+
() => { tested = true; return true; },
|
|
108
|
+
() => { preResolveCalls += 1; },
|
|
109
|
+
() => { pollCalls += 1; },
|
|
110
|
+
30
|
|
111
|
+
);
|
|
112
|
+
const elapsed = Date.now() - start;
|
|
113
|
+
check('P7 makePromise waits one interval before the first test', tested && elapsed >= 20, `elapsed=${elapsed}`);
|
|
114
|
+
check('P7 pre-resolve called once, poll method never', preResolveCalls === 1 && pollCalls === 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// --- P8: promiseChainThen runs the sets in order ---
|
|
118
|
+
{
|
|
119
|
+
const order: string[] = [];
|
|
120
|
+
let first = 0;
|
|
121
|
+
let second = 0;
|
|
122
|
+
await PromiseHelpers.promiseChainThen([
|
|
123
|
+
PromiseHelpers.makePromiseObj(() => { first += 1; return first >= 2; }, () => { order.push('first'); }, null, 5),
|
|
124
|
+
PromiseHelpers.makePromiseObj(() => { second += 1; return second >= 2; }, () => { order.push('second'); }, null, 5)
|
|
125
|
+
]);
|
|
126
|
+
check('P8 promiseChainThen reaches both end conditions in order', order.join(',') === 'first,second', order.join(','));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// --- P9: TEmptyPromise ---
|
|
130
|
+
{
|
|
131
|
+
const value = await TEmptyPromise('x');
|
|
132
|
+
check('P9 TEmptyPromise resolves with its value', value === 'x');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (failures > 0) {
|
|
136
|
+
console.log(`${failures} check(s) failed`);
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
} else {
|
|
139
|
+
console.log('all checks passed');
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
main();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for the pure pieces of the unsaved-changes indicator: the UndoBuffer
|
|
3
|
+
* listener, the full-save-format policy, the title formatter, and the post-save decision.
|
|
4
|
+
* Cases S1-S14 are listed in specs/028-unsaved-changes-indicator/contracts/score-change-contract.md.
|
|
5
|
+
*
|
|
6
|
+
* Run with: npm run test:score-change-state
|
|
7
|
+
*/
|
|
8
|
+
import { UndoBuffer } from '../src/smo/xform/undo';
|
|
9
|
+
import { SmoSelector } from '../src/smo/xform/selections';
|
|
10
|
+
import { isFullSaveFormat, formatScoreTitle, nextStepAfterSave } from '../src/render/sui/scoreChangeState';
|
|
11
|
+
|
|
12
|
+
let failures = 0;
|
|
13
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
14
|
+
if (condition) {
|
|
15
|
+
console.log(`PASS ${name}`);
|
|
16
|
+
} else {
|
|
17
|
+
failures += 1;
|
|
18
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Record the simplest kind of undo step: a score modifier, whose payload is stored as is. */
|
|
23
|
+
const record = (buffer: UndoBuffer) => {
|
|
24
|
+
buffer.addBuffer('test edit', UndoBuffer.bufferTypes.SCORE_MODIFIER, SmoSelector.default,
|
|
25
|
+
{ ctor: 'test' }, UndoBuffer.bufferSubtypes.NONE);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// --- S1: no listener set ---
|
|
29
|
+
{
|
|
30
|
+
const buffer = new UndoBuffer();
|
|
31
|
+
let threw = false;
|
|
32
|
+
try {
|
|
33
|
+
record(buffer);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
threw = true;
|
|
36
|
+
}
|
|
37
|
+
check('S1 addBuffer works with no listener', !threw && buffer.opCount === 1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- S2: one call, one notification ---
|
|
41
|
+
{
|
|
42
|
+
const buffer = new UndoBuffer();
|
|
43
|
+
let calls = 0;
|
|
44
|
+
buffer.onAddBuffer = () => { calls += 1; };
|
|
45
|
+
record(buffer);
|
|
46
|
+
check('S2 listener called once per addBuffer', calls === 1, `calls=${calls}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- S3: many calls, including while grouping ---
|
|
50
|
+
{
|
|
51
|
+
const buffer = new UndoBuffer();
|
|
52
|
+
let calls = 0;
|
|
53
|
+
buffer.onAddBuffer = () => { calls += 1; };
|
|
54
|
+
record(buffer);
|
|
55
|
+
buffer.grouping = true;
|
|
56
|
+
record(buffer);
|
|
57
|
+
record(buffer);
|
|
58
|
+
buffer.grouping = false;
|
|
59
|
+
record(buffer);
|
|
60
|
+
check('S3 listener called for every addBuffer, grouped or not', calls === 4, `calls=${calls}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// --- S4: reset does not drop the listener ---
|
|
64
|
+
{
|
|
65
|
+
const buffer = new UndoBuffer();
|
|
66
|
+
let calls = 0;
|
|
67
|
+
buffer.onAddBuffer = () => { calls += 1; };
|
|
68
|
+
record(buffer);
|
|
69
|
+
buffer.reset();
|
|
70
|
+
record(buffer);
|
|
71
|
+
check('S4 listener survives reset()', calls === 2, `calls=${calls}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// --- S5-S7: isFullSaveFormat ---
|
|
75
|
+
check('S5 .json is a full save', isFullSaveFormat('.json') === true);
|
|
76
|
+
for (const ext of ['.xml', '.mid', '.midi', '.js']) {
|
|
77
|
+
check(`S6 ${ext} is lossy`, isFullSaveFormat(ext) === false);
|
|
78
|
+
}
|
|
79
|
+
check('S7 empty extension is not a full save', isFullSaveFormat('') === false);
|
|
80
|
+
check('S7 unknown extension is not a full save', isFullSaveFormat('.pdf') === false);
|
|
81
|
+
check('S7 .JSON matches case-insensitively', isFullSaveFormat('.JSON') === true);
|
|
82
|
+
check('S7 non-string input is not a full save', isFullSaveFormat(undefined as any) === false);
|
|
83
|
+
|
|
84
|
+
// --- S8-S11: formatScoreTitle ---
|
|
85
|
+
check('S8 unchanged score shows its name', formatScoreTitle('My Song', false) === 'My Song');
|
|
86
|
+
check('S9 changed score has a trailing asterisk', formatScoreTitle('My Song', true) === 'My Song*');
|
|
87
|
+
check('S10 empty name shows Untitled', formatScoreTitle('', false) === 'Untitled');
|
|
88
|
+
check('S10 blank name shows Untitled', formatScoreTitle(' ', false) === 'Untitled');
|
|
89
|
+
check('S11 empty name and changed is Untitled*', formatScoreTitle('', true) === 'Untitled*');
|
|
90
|
+
check('S11 name is trimmed', formatScoreTitle(' Song ', true) === 'Song*');
|
|
91
|
+
|
|
92
|
+
// --- S12-S14: nextStepAfterSave ---
|
|
93
|
+
check('S12 saved loads the new score', nextStepAfterSave('saved') === 'load');
|
|
94
|
+
check('S13 lossy export asks again', nextStepAfterSave('exported') === 'prompt');
|
|
95
|
+
check('S14 cancelled aborts the load', nextStepAfterSave('cancelled') === 'abort');
|
|
96
|
+
|
|
97
|
+
if (failures > 0) {
|
|
98
|
+
console.log(`${failures} check(s) failed`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
} else {
|
|
101
|
+
console.log('all checks passed');
|
|
102
|
+
}
|