smoosic 2.0.3 → 2.0.5
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 +408 -69
- package/changes.md +95 -0
- package/package.json +19 -1
- package/release/smoosic.js +408 -69
- package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
- package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
- package/specs/032-split-multimeasure-rests/data-model.md +70 -0
- package/specs/032-split-multimeasure-rests/plan.md +81 -0
- package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
- package/specs/032-split-multimeasure-rests/research.md +63 -0
- package/specs/032-split-multimeasure-rests/spec.md +127 -0
- package/specs/032-split-multimeasure-rests/tasks.md +174 -0
- package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
- package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
- package/specs/033-key-distance-transposition/data-model.md +49 -0
- package/specs/033-key-distance-transposition/plan.md +87 -0
- package/specs/033-key-distance-transposition/quickstart.md +40 -0
- package/specs/033-key-distance-transposition/research.md +82 -0
- package/specs/033-key-distance-transposition/spec.md +132 -0
- package/specs/033-key-distance-transposition/tasks.md +139 -0
- package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
- package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
- package/specs/034-smz-compressed-scores/data-model.md +48 -0
- package/specs/034-smz-compressed-scores/plan.md +89 -0
- package/specs/034-smz-compressed-scores/quickstart.md +44 -0
- package/specs/034-smz-compressed-scores/research.md +86 -0
- package/specs/034-smz-compressed-scores/spec.md +137 -0
- package/specs/034-smz-compressed-scores/tasks.md +148 -0
- package/specs/035-paste-special/checklists/requirements.md +35 -0
- package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
- package/specs/035-paste-special/data-model.md +47 -0
- package/specs/035-paste-special/plan.md +83 -0
- package/specs/035-paste-special/quickstart.md +51 -0
- package/specs/035-paste-special/research.md +97 -0
- package/specs/035-paste-special/spec.md +170 -0
- package/specs/035-paste-special/tasks.md +149 -0
- package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
- package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
- package/specs/036-autosave-recovery/data-model.md +70 -0
- package/specs/036-autosave-recovery/plan.md +87 -0
- package/specs/036-autosave-recovery/quickstart.md +65 -0
- package/specs/036-autosave-recovery/research.md +105 -0
- package/specs/036-autosave-recovery/spec.md +143 -0
- package/specs/036-autosave-recovery/tasks.md +165 -0
- package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
- package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
- package/specs/037-fix-new-part-dialog/data-model.md +68 -0
- package/specs/037-fix-new-part-dialog/plan.md +83 -0
- package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
- package/specs/037-fix-new-part-dialog/research.md +86 -0
- package/specs/037-fix-new-part-dialog/spec.md +144 -0
- package/specs/037-fix-new-part-dialog/tasks.md +174 -0
- package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
- package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
- package/specs/038-per-measure-beam-groups/data-model.md +75 -0
- package/specs/038-per-measure-beam-groups/plan.md +84 -0
- package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
- package/specs/038-per-measure-beam-groups/research.md +72 -0
- package/specs/038-per-measure-beam-groups/spec.md +146 -0
- package/specs/038-per-measure-beam-groups/tasks.md +132 -0
- package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
- package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
- package/specs/039-measure-fill-submenu/data-model.md +79 -0
- package/specs/039-measure-fill-submenu/plan.md +81 -0
- package/specs/039-measure-fill-submenu/quickstart.md +62 -0
- package/specs/039-measure-fill-submenu/research.md +68 -0
- package/specs/039-measure-fill-submenu/spec.md +153 -0
- package/specs/039-measure-fill-submenu/tasks.md +121 -0
- package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
- package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
- package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
- package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
- package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
- package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
- package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
- package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
- package/specs/041-delete-special/checklists/requirements.md +35 -0
- package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
- package/specs/041-delete-special/data-model.md +40 -0
- package/specs/041-delete-special/plan.md +93 -0
- package/specs/041-delete-special/quickstart.md +41 -0
- package/specs/041-delete-special/research.md +75 -0
- package/specs/041-delete-special/spec.md +136 -0
- package/specs/041-delete-special/tasks.md +106 -0
- package/specs/042-preserve-music-time-signature/checklists/requirements.md +35 -0
- package/specs/042-preserve-music-time-signature/contracts/rebar-api.md +66 -0
- package/specs/042-preserve-music-time-signature/data-model.md +73 -0
- package/specs/042-preserve-music-time-signature/plan.md +93 -0
- package/specs/042-preserve-music-time-signature/quickstart.md +37 -0
- package/specs/042-preserve-music-time-signature/research.md +102 -0
- package/specs/042-preserve-music-time-signature/spec.md +153 -0
- package/specs/042-preserve-music-time-signature/tasks.md +104 -0
- package/src/application/application.ts +13 -2
- package/src/application/exports.ts +402 -395
- package/src/application/generateVexTests.ts +2 -2
- package/src/render/sui/NoteEntryCaret.ts +117 -16
- package/src/render/sui/autosave.ts +265 -0
- package/src/render/sui/formatter.ts +12 -2
- package/src/render/sui/renderState.ts +4 -4
- package/src/render/sui/scoreChangeState.ts +8 -3
- package/src/render/sui/scoreView.ts +47 -2
- package/src/render/sui/scoreViewOperations.ts +2761 -2555
- package/src/render/sui/staffLineGeometry.ts +82 -0
- package/src/render/sui/tracker.ts +18 -23
- package/src/render/vex/vxMeasure.ts +22 -8
- package/src/render/vex/vxNote.ts +2 -4
- package/src/smo/data/measure.ts +58 -1
- package/src/smo/data/measureModifiers.ts +81 -1
- package/src/smo/data/music.ts +169 -359
- package/src/smo/data/note.ts +1 -1
- package/src/smo/data/noteModifiers.ts +12 -0
- package/src/smo/data/score.ts +179 -7
- package/src/smo/data/scoreModifiers.ts +46 -1
- package/src/smo/data/systemStaff.ts +43 -0
- package/src/smo/xform/beamers.ts +80 -6
- package/src/smo/xform/copypaste.ts +207 -47
- package/src/smo/xform/measureFill.ts +89 -0
- package/src/smo/xform/operations.ts +452 -61
- package/src/smo/xform/rebar.ts +490 -0
- package/src/smo/xform/selections.ts +73 -0
- package/src/ui/components/dialogs/beamGroups.vue +106 -0
- package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
- package/src/ui/components/dialogs/dynamics.vue +16 -3
- package/src/ui/components/dialogs/fileUpload.vue +2 -2
- package/src/ui/components/dialogs/hairpin.vue +3 -3
- package/src/ui/components/dialogs/newPart.vue +148 -184
- package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
- package/src/ui/components/dialogs/recovery.vue +66 -0
- package/src/ui/components/dialogs/save.vue +11 -4
- package/src/ui/components/dialogs/scorePreferences.vue +23 -1
- package/src/ui/components/dialogs/slur.vue +6 -6
- package/src/ui/components/dialogs/tempo.vue +11 -3
- package/src/ui/components/dialogs/timeSignature.vue +18 -3
- package/src/ui/components/dialogs/volta.vue +3 -3
- package/src/ui/dialogs/annotationVue.ts +1 -1
- package/src/ui/dialogs/beamGroupsVue.ts +69 -0
- package/src/ui/dialogs/createPartHelpers.ts +68 -0
- package/src/ui/dialogs/deleteSpecial.ts +57 -0
- package/src/ui/dialogs/dynamicsVue.ts +87 -60
- package/src/ui/dialogs/factory.ts +0 -2
- package/src/ui/dialogs/fileDialogs.ts +63 -22
- package/src/ui/dialogs/instrument.ts +37 -30
- package/src/ui/dialogs/pasteSpecial.ts +59 -0
- package/src/ui/dialogs/preferences.ts +41 -40
- package/src/ui/dialogs/recovery.ts +49 -0
- package/src/ui/dialogs/timeSignature.ts +27 -39
- package/src/ui/fileio/fileInput.ts +12 -3
- package/src/ui/fileio/scoreArchive.ts +151 -0
- package/src/ui/fileio/xhrLoader.ts +26 -0
- package/src/ui/i18n/language.ts +1 -1
- package/src/ui/menus/beams.ts +181 -112
- package/src/ui/menus/edit.ts +44 -6
- package/src/ui/menus/file.ts +21 -1
- package/src/ui/menus/measure.ts +40 -1
- package/tests/autosave.ts +332 -0
- package/tests/beamDotted.ts +56 -0
- package/tests/beamGroups.ts +338 -0
- package/tests/createPart.ts +292 -0
- package/tests/deleteSpecial.ts +350 -0
- package/tests/dynamicsFontSize.ts +132 -0
- package/tests/keyDistanceTransposition.ts +351 -0
- package/tests/measureFill.ts +295 -0
- package/tests/movePart.ts +94 -0
- package/tests/multimeasureRest.ts +338 -0
- package/tests/pasteIntoMeasure.ts +103 -0
- package/tests/pasteSpecial.ts +541 -0
- package/tests/quickBeam.ts +126 -0
- package/tests/rebarMeasures.ts +492 -0
- package/tests/scoreArchive.ts +218 -0
- package/tests/scoreChangeState.ts +2 -0
- package/tests/staffLineGeometry.ts +179 -0
- package/tests/timeRangeSelect.ts +111 -0
- package/tests/timeSignatureDisplay.ts +58 -0
- package/tools/smoosic-schema.json +37 -0
- package/typedoc.ts +2 -1
- package/types/src/application/exports.d.ts +454 -447
- package/types/src/common/promiseHelpers.d.ts +30 -30
- package/types/src/common/vex.d.ts +224 -224
- package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
- package/types/src/render/sui/autosave.d.ts +99 -0
- package/types/src/render/sui/scoreView.d.ts +23 -0
- package/types/src/render/sui/scoreViewOperations.d.ts +776 -639
- package/types/src/render/sui/svgHelpers.d.ts +88 -88
- package/types/src/render/sui/svgPageMap.d.ts +344 -344
- package/types/src/render/sui/textEdit.d.ts +96 -96
- package/types/src/render/sui/textRender.d.ts +199 -199
- package/types/src/render/vex/smoAdapter.d.ts +47 -47
- package/types/src/render/vex/vxMeasure.d.ts +97 -97
- package/types/src/render/vex/vxNote.d.ts +56 -56
- package/types/src/render/vex/vxSystem.d.ts +71 -71
- package/types/src/smo/data/measure.d.ts +30 -0
- package/types/src/smo/data/measureModifiers.d.ts +568 -513
- package/types/src/smo/data/music.d.ts +74 -32
- package/types/src/smo/data/note.d.ts +498 -498
- package/types/src/smo/data/noteModifiers.d.ts +615 -606
- package/types/src/smo/data/score.d.ts +479 -421
- package/types/src/smo/data/scoreModifiers.d.ts +30 -0
- package/types/src/smo/data/scoreText.d.ts +334 -334
- package/types/src/smo/data/systemStaff.d.ts +14 -0
- package/types/src/smo/xform/beamers.d.ts +23 -1
- package/types/src/smo/xform/copypaste.d.ts +138 -2
- package/types/src/smo/xform/measureFill.d.ts +21 -0
- package/types/src/smo/xform/operations.d.ts +269 -129
- package/types/src/smo/xform/rebar.d.ts +53 -0
- package/types/src/smo/xform/selections.d.ts +168 -154
- package/types/src/smo/xform/undo.d.ts +142 -142
- package/types/src/ui/buttons/button.d.ts +100 -100
- package/types/src/ui/buttons/ribbon.d.ts +70 -70
- package/types/src/ui/common.d.ts +76 -76
- package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
- package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
- package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
- package/types/src/ui/composable/draggable.d.ts +15 -15
- package/types/src/ui/dialogs/adapter.d.ts +120 -120
- package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
- package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
- package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
- package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
- package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
- package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
- package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/dialog.d.ts +203 -203
- package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
- package/types/src/ui/dialogs/factory.d.ts +15 -15
- package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
- package/types/src/ui/dialogs/hairpin.d.ts +35 -35
- package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
- package/types/src/ui/dialogs/instrument.d.ts +3 -3
- package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
- package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
- package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
- package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
- package/types/src/ui/dialogs/recovery.d.ts +8 -0
- package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
- package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
- package/types/src/ui/dialogs/slur.d.ts +57 -57
- package/types/src/ui/dialogs/slurVue.d.ts +7 -7
- package/types/src/ui/dialogs/tempo.d.ts +50 -50
- package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
- package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
- package/types/src/ui/dialogs/textBracket.d.ts +35 -35
- package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
- package/types/src/ui/dialogs/tie.d.ts +41 -41
- package/types/src/ui/dialogs/volta.d.ts +40 -40
- package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
- package/types/src/ui/fileio/fileInput.d.ts +7 -1
- package/types/src/ui/fileio/library.d.ts +40 -40
- package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
- package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
- package/types/src/ui/menus/file.d.ts +8 -8
- package/types/src/ui/menus/language.d.ts +7 -7
- package/types/src/ui/menus/manager.d.ts +58 -58
- package/types/src/ui/menus/menu.d.ts +159 -159
- package/types/src/ui/menus/partSelection.d.ts +14 -14
- package/types/src/ui/menus/score.d.ts +8 -8
- package/types/src/ui/menus/staffModifier.d.ts +17 -17
- package/types/typedoc.d.ts +148 -147
- package/src/ui/dialogs/dynamics.ts +0 -141
- package/types/src/ui/dialogs/dynamics.d.ts +0 -37
|
@@ -7,7 +7,7 @@ import { SmoScore } from '../data/score';
|
|
|
7
7
|
import { SmoMeasureParams, SmoMeasure, SmoVoice } from '../data/measure';
|
|
8
8
|
import { SmoSystemStaff, SmoSystemStaffParams } from '../data/systemStaff';
|
|
9
9
|
import { SmoArticulation, SmoGraceNote, SmoLyric, SmoMicrotone, SmoOrnament,
|
|
10
|
-
SmoDynamicText,
|
|
10
|
+
SmoDynamicText, SmoNoteModifierBase,
|
|
11
11
|
SmoTabNote} from '../data/noteModifiers';
|
|
12
12
|
import {
|
|
13
13
|
SmoRehearsalMark, SmoMeasureText, SmoVolta, SmoMeasureFormat, SmoTempo, SmoBarline,
|
|
@@ -17,10 +17,13 @@ import { SmoStaffHairpin, SmoSlur, SmoTie, StaffModifierBase, SmoTieParams, SmoI
|
|
|
17
17
|
SmoSlurParams, SmoInstrumentMeasure, SmoStaffTextBracket, SmoStaffTextBracketParams,
|
|
18
18
|
SmoTabStave } from '../data/staffModifiers';
|
|
19
19
|
import { SmoSystemGroup } from '../data/scoreModifiers';
|
|
20
|
+
import { SmoPartInfo } from '../data/partInfo';
|
|
20
21
|
import { SmoTextGroup } from '../data/scoreText';
|
|
21
22
|
import { SmoSelection, SmoSelector, ModifierTab } from './selections';
|
|
22
23
|
import { SmoContractNoteActor, SmoStretchNoteActor, SmoMakeTupletActor, SmoUnmakeTupletActor, SmoStretchNoteParams, SmoContractNoteParams, SmoMakeTupletParams} from './tickDuration';
|
|
23
24
|
import { SmoBeamer } from './beamers';
|
|
25
|
+
import { fillRestDurations, MeasureFillType } from './measureFill';
|
|
26
|
+
import { rebarMeasures, RebarResult } from './rebar';
|
|
24
27
|
import { SmoTupletTree } from '../data/tuplet';
|
|
25
28
|
/**
|
|
26
29
|
* supported operations for {@link SmoOperation.batchSelectionOperation} to change a note's duration
|
|
@@ -41,7 +44,120 @@ export type createStaffModifierType<T> = (fromSelection: SmoSelection, toSelecti
|
|
|
41
44
|
* take the score, a selection or selection array, and the parameters of the operation.
|
|
42
45
|
* @category SmoTransform
|
|
43
46
|
*/
|
|
47
|
+
/**
|
|
48
|
+
* What is needed to create a part: where it goes, its instrument, and what it is called.
|
|
49
|
+
* @category SmoOperation
|
|
50
|
+
*/
|
|
51
|
+
export interface AddPartParams {
|
|
52
|
+
/** where the new part goes, counting from 1; N + 1 is after the last of N staves */
|
|
53
|
+
location: number;
|
|
54
|
+
/** the sound, clef, staff lines and transposition of the (first) staff */
|
|
55
|
+
instrument: SmoInstrument;
|
|
56
|
+
/** add a second staff to the part, with the opposite clef */
|
|
57
|
+
twoStaves: boolean;
|
|
58
|
+
/** the name as typed. If it is blank, instrumentLabel is the name */
|
|
59
|
+
name: string;
|
|
60
|
+
/** the display name of the instrument, e.g. 'Bb Trumpet' */
|
|
61
|
+
instrumentLabel: string;
|
|
62
|
+
/** the abbreviation as typed; blank for none */
|
|
63
|
+
abbreviation: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The kinds of marking attached to notes that Delete Special can remove on their own
|
|
68
|
+
* @category SmoTransform
|
|
69
|
+
*/
|
|
70
|
+
export type DeleteAttributeKind = 'dynamics' | 'lyrics' | 'annotations' | 'chords' | 'articulations'
|
|
71
|
+
| 'ornaments' | 'graceNotes' | 'arpeggios' | 'microtones';
|
|
72
|
+
/** How the markings of one kind are counted on a note and cleared from it */
|
|
73
|
+
interface DeleteAttributeHandler {
|
|
74
|
+
count: (note: SmoNote) => number,
|
|
75
|
+
clear: (note: SmoNote) => void
|
|
76
|
+
}
|
|
77
|
+
const isLyricOfParser = (mod: SmoNoteModifierBase, parser: number) =>
|
|
78
|
+
mod.attrs.type === 'SmoLyric' && (mod as SmoLyric).parser === parser;
|
|
79
|
+
/** Lyrics, annotations and chords are all SmoLyric, told apart only by parser */
|
|
80
|
+
const lyricHandler = (parser: number): DeleteAttributeHandler => ({
|
|
81
|
+
count: (note) => note.textModifiers.filter((mod) => isLyricOfParser(mod, parser)).length,
|
|
82
|
+
clear: (note) => {
|
|
83
|
+
note.textModifiers = note.textModifiers.filter((mod) => !isLyricOfParser(mod, parser));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const deleteAttributeHandlers: Record<DeleteAttributeKind, DeleteAttributeHandler> = {
|
|
87
|
+
dynamics: {
|
|
88
|
+
count: (note) => note.textModifiers.filter((mod) => mod.attrs.type === 'SmoDynamicText').length,
|
|
89
|
+
clear: (note) => {
|
|
90
|
+
note.textModifiers = note.textModifiers.filter((mod) => mod.attrs.type !== 'SmoDynamicText');
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
lyrics: lyricHandler(SmoLyric.parsers.lyric),
|
|
94
|
+
annotations: lyricHandler(SmoLyric.parsers.annotation),
|
|
95
|
+
chords: lyricHandler(SmoLyric.parsers.chord),
|
|
96
|
+
articulations: {
|
|
97
|
+
count: (note) => note.articulations.length,
|
|
98
|
+
clear: (note) => { note.articulations = []; }
|
|
99
|
+
},
|
|
100
|
+
ornaments: {
|
|
101
|
+
count: (note) => note.ornaments.length,
|
|
102
|
+
clear: (note) => { note.ornaments = []; }
|
|
103
|
+
},
|
|
104
|
+
graceNotes: {
|
|
105
|
+
count: (note) => note.graceNotes.length,
|
|
106
|
+
clear: (note) => { note.graceNotes = []; }
|
|
107
|
+
},
|
|
108
|
+
arpeggios: {
|
|
109
|
+
count: (note) => note.arpeggio ? 1 : 0,
|
|
110
|
+
clear: (note) => { note.arpeggio = undefined; }
|
|
111
|
+
},
|
|
112
|
+
microtones: {
|
|
113
|
+
count: (note) => note.tones.length,
|
|
114
|
+
clear: (note) => { note.tones = []; }
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
44
118
|
export class SmoOperation {
|
|
119
|
+
/** All the kinds Delete Special can remove, in the order of its dialog */
|
|
120
|
+
static readonly deleteAttributeKinds: DeleteAttributeKind[] = ['dynamics', 'lyrics', 'annotations', 'chords',
|
|
121
|
+
'articulations', 'ornaments', 'graceNotes', 'arpeggios', 'microtones'];
|
|
122
|
+
/**
|
|
123
|
+
* How many markings of the given kinds are on the notes of the selections. Reads only. Selections with
|
|
124
|
+
* no note are skipped, and kinds that are not known are ignored.
|
|
125
|
+
* @param selections the selected notes
|
|
126
|
+
* @param kinds the kinds of marking to count
|
|
127
|
+
*/
|
|
128
|
+
static countNoteAttributes(selections: SmoSelection[], kinds: DeleteAttributeKind[]): number {
|
|
129
|
+
const handlers = SmoOperation.deleteHandlersFor(kinds);
|
|
130
|
+
let count = 0;
|
|
131
|
+
selections.forEach((selection) => {
|
|
132
|
+
const note = selection.note;
|
|
133
|
+
if (note) {
|
|
134
|
+
handlers.forEach((handler) => {
|
|
135
|
+
count += handler.count(note);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return count;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Remove every marking of the given kinds from the notes of the selections. Pitches, durations, ties and
|
|
143
|
+
* the kinds not listed are not changed. Kinds that are not known are ignored.
|
|
144
|
+
* @param selections the selected notes
|
|
145
|
+
* @param kinds the kinds of marking to remove
|
|
146
|
+
*/
|
|
147
|
+
static deleteNoteAttributes(selections: SmoSelection[], kinds: DeleteAttributeKind[]) {
|
|
148
|
+
const handlers = SmoOperation.deleteHandlersFor(kinds);
|
|
149
|
+
selections.forEach((selection) => {
|
|
150
|
+
const note = selection.note;
|
|
151
|
+
if (note) {
|
|
152
|
+
handlers.forEach((handler) => handler.clear(note));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
private static deleteHandlersFor(kinds: DeleteAttributeKind[]): DeleteAttributeHandler[] {
|
|
157
|
+
return kinds.filter((kind) => Object.prototype.hasOwnProperty.call(deleteAttributeHandlers, kind))
|
|
158
|
+
.map((kind) => deleteAttributeHandlers[kind]);
|
|
159
|
+
}
|
|
160
|
+
|
|
45
161
|
static setMeasureFormat(score: SmoScore, selection: SmoSelection, value: SmoMeasureFormat) {
|
|
46
162
|
if (!score.formattingManager) {
|
|
47
163
|
return;
|
|
@@ -82,24 +198,70 @@ export class SmoOperation {
|
|
|
82
198
|
});
|
|
83
199
|
}
|
|
84
200
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
|
|
89
|
-
|
|
201
|
+
* The staves that make up the part containing the given staff. A multi-staff part is
|
|
202
|
+
* kept together.
|
|
203
|
+
* @returns the index of the first staff of the part, and the number of staves in it
|
|
204
|
+
*/
|
|
205
|
+
static getPartBlock(score: SmoScore, staffIndex: number): { start: number, length: number } {
|
|
206
|
+
const count = score.staves.length;
|
|
207
|
+
const info = score.staves[staffIndex].partInfo;
|
|
208
|
+
const start = Math.max(0, staffIndex - info.stavesBefore);
|
|
209
|
+
const end = Math.min(count - 1, staffIndex + info.stavesAfter);
|
|
210
|
+
return { start, length: end - start + 1 };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Swap the part starting at `start` with the part just before it, keeping the staves
|
|
214
|
+
* of each part together and in order.
|
|
215
|
+
*/
|
|
216
|
+
private static swapPartWithPrevious(score: SmoScore, start: number) {
|
|
217
|
+
const prev = SmoOperation.getPartBlock(score, start - 1);
|
|
218
|
+
const cur = SmoOperation.getPartBlock(score, start);
|
|
219
|
+
for (let k = 0; k < cur.length; ++k) {
|
|
220
|
+
// bubble each staff of the current part up past the previous part
|
|
221
|
+
for (let j = 0; j < prev.length; ++j) {
|
|
222
|
+
score.swapStaves(start + k - j, start + k - j - 1);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Move a part up or down one. A part with 2 staves moves as a unit, so a single-staff part
|
|
228
|
+
* that it passes moves by 2. If last down, move to first. If first up, move to last
|
|
229
|
+
* @param score
|
|
230
|
+
* @param selection
|
|
231
|
+
* @param index direction to move, -1 for up and 1 for down
|
|
90
232
|
*/
|
|
91
233
|
static moveStaffUpDown(score: SmoScore, selection: SmoSelection, index: number) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
234
|
+
const count = score.staves.length;
|
|
235
|
+
if (count < 2 || selection.selector.staff >= count) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const block = SmoOperation.getPartBlock(score, selection.selector.staff);
|
|
239
|
+
if (block.length >= count) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
let start = block.start;
|
|
243
|
+
if (index < 0) {
|
|
244
|
+
if (start > 0) {
|
|
245
|
+
SmoOperation.swapPartWithPrevious(score, start);
|
|
246
|
+
} else {
|
|
247
|
+
// first part up: it becomes the last, by moving each part after it up past it
|
|
248
|
+
while (start + block.length < count) {
|
|
249
|
+
const next = SmoOperation.getPartBlock(score, start + block.length);
|
|
250
|
+
SmoOperation.swapPartWithPrevious(score, next.start);
|
|
251
|
+
start += next.length;
|
|
252
|
+
}
|
|
99
253
|
}
|
|
100
|
-
} else if (
|
|
101
|
-
|
|
102
|
-
|
|
254
|
+
} else if (index > 0) {
|
|
255
|
+
if (start + block.length < count) {
|
|
256
|
+
// moving down is the next part moving up
|
|
257
|
+
SmoOperation.swapPartWithPrevious(score, start + block.length);
|
|
258
|
+
} else {
|
|
259
|
+
// last part down: it becomes the first
|
|
260
|
+
while (start > 0) {
|
|
261
|
+
const prev = SmoOperation.getPartBlock(score, start - 1);
|
|
262
|
+
SmoOperation.swapPartWithPrevious(score, start);
|
|
263
|
+
start = prev.start;
|
|
264
|
+
}
|
|
103
265
|
}
|
|
104
266
|
}
|
|
105
267
|
}
|
|
@@ -139,6 +301,54 @@ export class SmoOperation {
|
|
|
139
301
|
score.staves[tabStaves[0].startSelector.staff].removeTabStaves(tabStaves);
|
|
140
302
|
}
|
|
141
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Re-bar the music of measures firstMeasure to lastMeasure (all staves) into a new time signature, adding
|
|
306
|
+
* measures if the new one holds less time. See {@link rebarMeasures}. Unlike {@link setTimeSignature}, no
|
|
307
|
+
* music is lost.
|
|
308
|
+
* @param score the score to change
|
|
309
|
+
* @param firstMeasure the first measure of the range
|
|
310
|
+
* @param lastMeasure the last measure of the range
|
|
311
|
+
* @param timeSignature the new time signature
|
|
312
|
+
*/
|
|
313
|
+
static rebarMeasures(score: SmoScore, firstMeasure: number, lastMeasure: number, timeSignature: SmoTimeSignature): RebarResult {
|
|
314
|
+
return rebarMeasures(score, firstMeasure, lastMeasure, timeSignature);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Would setting this time signature on measures firstMeasure to lastMeasure change anything? True if any
|
|
318
|
+
* of those measures, in any staff, has a time signature that is not equal to this one, display options included.
|
|
319
|
+
* Reads only.
|
|
320
|
+
*/
|
|
321
|
+
static timeSignatureChanges(score: SmoScore, firstMeasure: number, lastMeasure: number, timeSignature: SmoTimeSignature): boolean {
|
|
322
|
+
return SmoOperation.rangeMeasures(score, firstMeasure, lastMeasure).some((measure) =>
|
|
323
|
+
!SmoTimeSignature.equalIncludeAttributes(measure.timeSignature, timeSignature));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Is every measure in the range, in every staff, already as long as the new time signature would make it?
|
|
327
|
+
* (2/2 for 4/4, or only a display option changed). If so the music does not need to move. The measure
|
|
328
|
+
* k places after the first has part k of a time signature that has several parts. Reads only.
|
|
329
|
+
*/
|
|
330
|
+
static timeSignatureKeepsLength(score: SmoScore, firstMeasure: number, lastMeasure: number, timeSignature: SmoTimeSignature): boolean {
|
|
331
|
+
const measures = SmoOperation.rangeMeasures(score, firstMeasure, lastMeasure);
|
|
332
|
+
if (measures.length < 1) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
const perStaff = lastMeasure - firstMeasure + 1;
|
|
336
|
+
return measures.every((measure, ix) => {
|
|
337
|
+
const k = ix % perStaff;
|
|
338
|
+
const part = timeSignature.times[k % timeSignature.times.length];
|
|
339
|
+
const oldTicks = SmoMusic.timeSignatureToTicks(measure.timeSignature.actualBeats, measure.timeSignature.beatDuration);
|
|
340
|
+
return oldTicks === SmoMusic.timeSignatureToTicks(part.actualBeats, part.beatDuration);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
private static rangeMeasures(score: SmoScore, firstMeasure: number, lastMeasure: number): SmoMeasure[] {
|
|
344
|
+
const rv: SmoMeasure[] = [];
|
|
345
|
+
score.staves.forEach((staff) => {
|
|
346
|
+
for (let m = Math.max(firstMeasure, 0); m <= lastMeasure && m < staff.measures.length; ++m) {
|
|
347
|
+
rv.push(staff.measures[m]);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
return rv;
|
|
351
|
+
}
|
|
142
352
|
static setTimeSignature(score: SmoScore, selections: SmoSelection[], timeSignature: SmoTimeSignature) {
|
|
143
353
|
const selectors: SmoSelector[] = [];
|
|
144
354
|
let i = 0;
|
|
@@ -413,18 +623,34 @@ export class SmoOperation {
|
|
|
413
623
|
});
|
|
414
624
|
}
|
|
415
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Transpose the whole score by a number of half steps. The destination key of each measure is
|
|
628
|
+
* computed from its current key, and each pitch is spelled so that its distance from the new key
|
|
629
|
+
* matches its distance from the old key (e.g. e natural in Eb becomes g# in G).
|
|
630
|
+
* @param score
|
|
631
|
+
* @param offset half steps, may be negative
|
|
632
|
+
*/
|
|
416
633
|
static transposeScore(score: SmoScore, offset: number) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
634
|
+
if (offset === 0) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
score.staves.forEach((staff) => {
|
|
638
|
+
staff.measures.forEach((measure) => {
|
|
639
|
+
const originalKey = measure.keySignature;
|
|
640
|
+
const destinationKey = SmoMusic.keyForOffset(originalKey, offset);
|
|
641
|
+
measure.voices.forEach((voice) => {
|
|
642
|
+
voice.notes.forEach((note) => {
|
|
643
|
+
SmoNote.transpose(note, [], offset, originalKey, destinationKey);
|
|
644
|
+
note.getGraceNotes().forEach((graceNote) => {
|
|
645
|
+
SmoNote.transpose(graceNote, [], offset, originalKey, destinationKey);
|
|
646
|
+
});
|
|
426
647
|
});
|
|
427
648
|
});
|
|
649
|
+
measure.setKeySignature(destinationKey);
|
|
650
|
+
});
|
|
651
|
+
Object.keys(staff.keySignatureMap).forEach((measureIndex) => {
|
|
652
|
+
const ix = parseInt(measureIndex, 10);
|
|
653
|
+
staff.keySignatureMap[ix] = SmoMusic.keyForOffset(staff.keySignatureMap[ix], offset);
|
|
428
654
|
});
|
|
429
655
|
});
|
|
430
656
|
}
|
|
@@ -628,6 +854,14 @@ export class SmoOperation {
|
|
|
628
854
|
note.beamState = SmoNote.beamStates.auto;
|
|
629
855
|
}
|
|
630
856
|
});
|
|
857
|
+
// In a measure with its own beam grouping, every note of a hand beam except the last is marked
|
|
858
|
+
// 'continue' so that a group boundary does not break the beam after it. Otherwise the beam
|
|
859
|
+
// is as it always was.
|
|
860
|
+
if (selections[0].measure.getBeamGroups().length > 0) {
|
|
861
|
+
for (let i = 0; i < beamGroup.length - 1; ++i) {
|
|
862
|
+
beamGroup[i].beamState = SmoNote.beamStates.continue;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
631
865
|
const sn = beamGroup[beamGroup.length - 1];
|
|
632
866
|
sn.beamState = SmoNote.beamStates.end;
|
|
633
867
|
// Make sure the last note of the previous beam is the end of this beam group.
|
|
@@ -641,6 +875,59 @@ export class SmoOperation {
|
|
|
641
875
|
}
|
|
642
876
|
}
|
|
643
877
|
}
|
|
878
|
+
/**
|
|
879
|
+
* Set the beam grouping of the measures in the selections, or clear it with an empty list.
|
|
880
|
+
* Only the staves and measures in the selections change.
|
|
881
|
+
* @param score the score the selections belong to
|
|
882
|
+
* @param selections the notes or measures to change; every measure they touch is changed
|
|
883
|
+
* @param groups the longest beam group for each group in turn, whole numbers from 1 to 4
|
|
884
|
+
*/
|
|
885
|
+
static setBeamGroups(score: SmoScore, selections: SmoSelection[], groups: number[]) {
|
|
886
|
+
selections.forEach((selection) => {
|
|
887
|
+
selection.measure.setBeamGroups(groups);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Set the beam grouping of every measure in every staff of the score, or clear it with
|
|
892
|
+
* an empty list.
|
|
893
|
+
*/
|
|
894
|
+
static setAllBeamGroups(score: SmoScore, groups: number[]) {
|
|
895
|
+
score.staves.forEach((staff) => {
|
|
896
|
+
staff.measures.forEach((measure) => {
|
|
897
|
+
measure.setBeamGroups(groups);
|
|
898
|
+
});
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Fill the measures in the selections with rests, removing all the notes and voices in them. See
|
|
903
|
+
* {@link fillRestDurations} for which rests. Everything attached to the removed notes goes with them:
|
|
904
|
+
* staff modifiers that start or end in the measure (slurs, ties, hairpins) and text attached to its notes.
|
|
905
|
+
* Only the staves and measures in the selections change.
|
|
906
|
+
* @param score the score the selections belong to
|
|
907
|
+
* @param selections the notes or measures; every measure they touch is filled
|
|
908
|
+
* @param fill which rests
|
|
909
|
+
*/
|
|
910
|
+
static fillMeasures(score: SmoScore, selections: SmoSelection[], fill: MeasureFillType) {
|
|
911
|
+
const done: Record<string, boolean> = {};
|
|
912
|
+
selections.forEach((selection) => {
|
|
913
|
+
const staffIndex = selection.selector.staff;
|
|
914
|
+
const measure = selection.measure;
|
|
915
|
+
const measureIndex = measure.measureNumber.measureIndex;
|
|
916
|
+
const key = `${staffIndex}-${measureIndex}`;
|
|
917
|
+
if (done[key]) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
done[key] = true;
|
|
921
|
+
// A pickup measure is filled to the length it has
|
|
922
|
+
const total = measure.isPickup() ? measure.getTicksFromVoice(0) : undefined;
|
|
923
|
+
const durations = fillRestDurations(measure.timeSignature, fill, total);
|
|
924
|
+
const triple = measure.timeSignature.actualBeats % 3 === 0;
|
|
925
|
+
const beamBeats = triple ? score.preferences.defaultTripleDuration : score.preferences.defaultDupleDuration;
|
|
926
|
+
selection.staff.removeModifiersInMeasure(measureIndex);
|
|
927
|
+
score.removeTextAttachedToMeasure(staffIndex, measureIndex);
|
|
928
|
+
measure.fillWithRests(durations, beamBeats);
|
|
929
|
+
});
|
|
930
|
+
}
|
|
644
931
|
static clearAllBeamGroups(score: SmoScore) {
|
|
645
932
|
score.staves.forEach((ss) => {
|
|
646
933
|
ss.measures.forEach((mm) => {
|
|
@@ -665,6 +952,34 @@ export class SmoOperation {
|
|
|
665
952
|
});
|
|
666
953
|
}
|
|
667
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Put the selected notes back to automatic beaming: no hand-placed beam break or join, and the
|
|
957
|
+
* beam length for the meter from the score preferences. In a measure with its own beam grouping,
|
|
958
|
+
* that grouping applies.
|
|
959
|
+
*/
|
|
960
|
+
static autoBeamSelections(score: SmoScore, selections: SmoSelection[]) {
|
|
961
|
+
selections.forEach((selection) => {
|
|
962
|
+
const note = selection.note;
|
|
963
|
+
if (note) {
|
|
964
|
+
const triple = selection.measure.timeSignature.actualBeats % 3 === 0;
|
|
965
|
+
note.beamBeats = triple ? score.preferences.defaultTripleDuration : score.preferences.defaultDupleDuration;
|
|
966
|
+
note.beamState = SmoNote.beamStates.auto;
|
|
967
|
+
note.endBeam = false;
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Set the stem direction of the selected notes
|
|
973
|
+
* @param flagState one of {@link SmoNote.flagStates}: auto, up or down
|
|
974
|
+
*/
|
|
975
|
+
static setStemDirection(selections: SmoSelection[], flagState: number) {
|
|
976
|
+
selections.forEach((selection) => {
|
|
977
|
+
if (selection.note) {
|
|
978
|
+
selection.note.flagState = flagState;
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
|
|
668
983
|
static toggleBeamDirection(selections: SmoSelection[]) {
|
|
669
984
|
const note0 = selections[0].note as SmoNote;
|
|
670
985
|
note0.toggleFlagState();
|
|
@@ -974,6 +1289,68 @@ export class SmoOperation {
|
|
|
974
1289
|
static addStaff(score: SmoScore, parameters: SmoSystemStaffParams): SmoSystemStaff {
|
|
975
1290
|
return score.addStaff(parameters);
|
|
976
1291
|
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Create a part with one or two staves. The part goes at the requested location, but never
|
|
1294
|
+
* inside an existing part with more than one staff. Staves below it move down, and anything
|
|
1295
|
+
* that refers to them moves too. The new part keeps its text groups (preserveTextGroups), which
|
|
1296
|
+
* is not the default for a part.
|
|
1297
|
+
* @param score the full score
|
|
1298
|
+
* @param params where to put the part and what it is called
|
|
1299
|
+
* @returns the index of the first new staff
|
|
1300
|
+
*/
|
|
1301
|
+
static addPart(score: SmoScore, params: AddPartParams): number {
|
|
1302
|
+
const index = score.resolveNewPartIndex(params.location);
|
|
1303
|
+
const lastMeasure = score.staves[0].measures.length - 1;
|
|
1304
|
+
const typedName = (params.name ?? '').trim();
|
|
1305
|
+
const partName = typedName.length > 0 ? typedName : params.instrumentLabel;
|
|
1306
|
+
const abbreviation = (params.abbreviation ?? '').trim();
|
|
1307
|
+
const stavesInPart = params.twoStaves ? 2 : 1;
|
|
1308
|
+
const newStaves: SmoSystemStaff[] = [];
|
|
1309
|
+
for (let ix = 0; ix < stavesInPart; ++ix) {
|
|
1310
|
+
const instrument = new SmoInstrument(params.instrument);
|
|
1311
|
+
if (ix === 1) {
|
|
1312
|
+
instrument.clef = params.instrument.clef === 'treble' ? 'bass' : 'treble';
|
|
1313
|
+
}
|
|
1314
|
+
// the selectors are shared with the instrument we copied, and with the other new staff
|
|
1315
|
+
instrument.startSelector = JSON.parse(JSON.stringify(params.instrument.startSelector));
|
|
1316
|
+
instrument.endSelector = JSON.parse(JSON.stringify(params.instrument.endSelector));
|
|
1317
|
+
instrument.startSelector.measure = 0;
|
|
1318
|
+
instrument.endSelector.measure = lastMeasure;
|
|
1319
|
+
const partInfo = new SmoPartInfo(SmoPartInfo.defaults);
|
|
1320
|
+
partInfo.partName = partName;
|
|
1321
|
+
partInfo.partAbbreviation = abbreviation;
|
|
1322
|
+
partInfo.preserveTextGroups = true;
|
|
1323
|
+
partInfo.stavesBefore = ix;
|
|
1324
|
+
partInfo.stavesAfter = stavesInPart - ix - 1;
|
|
1325
|
+
const staffParams: SmoSystemStaffParams = SmoSystemStaff.defaults;
|
|
1326
|
+
staffParams.staffId = index + ix;
|
|
1327
|
+
staffParams.measureInstrumentMap[0] = instrument;
|
|
1328
|
+
staffParams.partInfo = partInfo;
|
|
1329
|
+
newStaves.push(score.addStaff(staffParams));
|
|
1330
|
+
}
|
|
1331
|
+
newStaves.forEach((staff) => {
|
|
1332
|
+
staff.updateInstrumentOffsets();
|
|
1333
|
+
});
|
|
1334
|
+
score.setNoteInstrumentProperties();
|
|
1335
|
+
// As for any added staff, group the new staves with the staff above them, so they are justified
|
|
1336
|
+
// and bracketed together. A group that already spans the new staff has grown to hold it.
|
|
1337
|
+
for (let ix = 0; ix < stavesInPart; ++ix) {
|
|
1338
|
+
const staffId = index + ix;
|
|
1339
|
+
if (staffId > 0) {
|
|
1340
|
+
const selection = SmoSelection.measureSelection(score, staffId - 1, 0);
|
|
1341
|
+
const grp = selection ? score.getSystemGroupForStaff(selection) : undefined;
|
|
1342
|
+
if (grp) {
|
|
1343
|
+
grp.endSelector.staff = Math.max(grp.endSelector.staff, staffId);
|
|
1344
|
+
} else {
|
|
1345
|
+
const newGroup = new SmoSystemGroup(SmoSystemGroup.defaults);
|
|
1346
|
+
newGroup.startSelector.staff = staffId - 1;
|
|
1347
|
+
newGroup.endSelector.staff = staffId;
|
|
1348
|
+
score.systemGroups.push(newGroup);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return index;
|
|
1353
|
+
}
|
|
977
1354
|
static removeStaff(score: SmoScore, index: number) {
|
|
978
1355
|
score.removeStaff(index);
|
|
979
1356
|
}
|
|
@@ -1057,52 +1434,66 @@ export class SmoOperation {
|
|
|
1057
1434
|
}
|
|
1058
1435
|
score.setNoteInstrumentProperties();
|
|
1059
1436
|
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Group runs of empty measures into multimeasure rests, for parts that show them. A landmark splits a run:
|
|
1439
|
+
* a start landmark (rehearsal mark, key, time or tempo change, Segno, Coda, instrument change, repeat
|
|
1440
|
+
* or double barline at the start of the measure) ends the rest before its measure and that measure
|
|
1441
|
+
* starts the next rest; an end landmark (D.S., D.C., To Coda, Fine, repeat or double barline at the end of
|
|
1442
|
+
* the measure) ends the rest after its measure. Measures under a volta ending are never grouped.
|
|
1443
|
+
* The result is recorded in each measure's svg record: the first measure of a rest has its length, end
|
|
1444
|
+
* barline and end symbol, the others are hidden; every other measure is reset.
|
|
1445
|
+
* @param score the score being displayed
|
|
1446
|
+
*/
|
|
1060
1447
|
static computeMultipartRest(score: SmoScore) {
|
|
1061
|
-
let i = 0;
|
|
1062
|
-
let j = 0;
|
|
1063
|
-
const measureRanges: Record<number, number> = {};
|
|
1064
1448
|
const measureCount = score.staves[0].measures.length;
|
|
1065
1449
|
if (score.staves[0].partInfo.expandMultimeasureRests === true) {
|
|
1066
1450
|
return;
|
|
1067
1451
|
}
|
|
1452
|
+
const isRestMeasure = (m: number) => {
|
|
1453
|
+
return score.staves[0].measures[m].format.forceRest || score.staves.every((staff) => staff.isRest(m));
|
|
1454
|
+
};
|
|
1455
|
+
const reset = (m: number, hide: boolean) => {
|
|
1456
|
+
score.staves.forEach((staff) => {
|
|
1457
|
+
const svg = staff.measures[m].svg;
|
|
1458
|
+
svg.multimeasureLength = 0;
|
|
1459
|
+
svg.multimeasureEndBarline = SmoBarline.barlines.singleBar;
|
|
1460
|
+
svg.multimeasureEndSymbol = null;
|
|
1461
|
+
svg.hideMultimeasure = hide;
|
|
1462
|
+
});
|
|
1463
|
+
};
|
|
1464
|
+
let i = 0;
|
|
1068
1465
|
while (i < measureCount) {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
const
|
|
1466
|
+
if (score.isMultimeasureBlocked(i) || !isRestMeasure(i)) {
|
|
1467
|
+
reset(i, false);
|
|
1468
|
+
i += 1;
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
// measure i starts a block; it may carry start landmarks. An end landmark closes the block.
|
|
1472
|
+
let j = i + 1;
|
|
1473
|
+
let closed = score.isMultimeasureEndLandmark(i);
|
|
1474
|
+
while (!closed && j < measureCount && isRestMeasure(j) && !score.isMultimeasureBlocked(j)
|
|
1475
|
+
&& !score.staves[0].measures[j].format.restBreak && !score.isMultimeasureStartLandmark(j)) {
|
|
1476
|
+
closed = score.isMultimeasureEndLandmark(j);
|
|
1477
|
+
j += 1;
|
|
1478
|
+
}
|
|
1479
|
+
if (j - i >= 2) {
|
|
1480
|
+
const last = j - 1;
|
|
1481
|
+
reset(i, false);
|
|
1084
1482
|
score.staves.forEach((staff) => {
|
|
1085
|
-
staff.measures[
|
|
1483
|
+
const svg = staff.measures[i].svg;
|
|
1484
|
+
svg.multimeasureLength = j - i;
|
|
1485
|
+
svg.multimeasureEndBarline = staff.measures[last].getEndBarline().barline;
|
|
1486
|
+
const symbol = staff.measures[last].getRepeatSymbol();
|
|
1487
|
+
svg.multimeasureEndSymbol = (symbol && SmoScore.isEndRepeatSymbol(symbol.symbol)) ? symbol : null;
|
|
1086
1488
|
});
|
|
1087
|
-
i
|
|
1489
|
+
for (let k = i + 1; k < j; ++k) {
|
|
1490
|
+
reset(k, true);
|
|
1491
|
+
}
|
|
1492
|
+
} else {
|
|
1493
|
+
reset(i, false);
|
|
1088
1494
|
}
|
|
1495
|
+
i = j;
|
|
1089
1496
|
}
|
|
1090
|
-
const multiKeys = Object.keys(measureRanges).map((x) => parseInt(x, 10));
|
|
1091
|
-
multiKeys.forEach((key) => {
|
|
1092
|
-
const endMeasure = measureRanges[key];
|
|
1093
|
-
score.staves.forEach((staff) => {
|
|
1094
|
-
const mmLength = endMeasure - key;
|
|
1095
|
-
const svg = staff.measures[key].svg;
|
|
1096
|
-
svg.multimeasureLength = mmLength;
|
|
1097
|
-
if (svg.multimeasureLength > 1) {
|
|
1098
|
-
svg.multimeasureEndBarline = staff.measures[endMeasure - 1].getEndBarline().barline;
|
|
1099
|
-
}
|
|
1100
|
-
staff.measures[key].svg.hideMultimeasure = false;
|
|
1101
|
-
for (i = key + 1; i < endMeasure; ++i) {
|
|
1102
|
-
staff.measures[i].svg.hideMultimeasure = true;
|
|
1103
|
-
}
|
|
1104
|
-
});
|
|
1105
|
-
});
|
|
1106
1497
|
}
|
|
1107
1498
|
}
|
|
1108
1499
|
|