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
package/src/smo/data/music.ts
CHANGED
|
@@ -129,17 +129,6 @@ export interface VexNoteValue {
|
|
|
129
129
|
root_index: number,
|
|
130
130
|
int_val: number
|
|
131
131
|
};
|
|
132
|
-
/**
|
|
133
|
-
* Describe the music theory role of an accidental vs. the key signature.
|
|
134
|
-
* Used to determine default enharmonic spelling.
|
|
135
|
-
* @category SmoTransform
|
|
136
|
-
*/
|
|
137
|
-
export interface KeySignatureRole {
|
|
138
|
-
letter: PitchLetter,
|
|
139
|
-
accidental: string,
|
|
140
|
-
role: string
|
|
141
|
-
};
|
|
142
|
-
|
|
143
132
|
/**
|
|
144
133
|
* Helper functions that build on the VX music theory routines, and other
|
|
145
134
|
* utilities I wish were in VF.Music but aren't
|
|
@@ -519,333 +508,189 @@ export class SmoMusic {
|
|
|
519
508
|
'subbass': 7,
|
|
520
509
|
'french': -1
|
|
521
510
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Spelling is computed on the 'line of fifths': every spelling has an integer position,
|
|
513
|
+
* F=-1, C=0, G=1, D=2, A=3, E=4, B=5, plus 7 for each sharp and minus 7 for each flat.
|
|
514
|
+
* Neighbors are a fifth apart, and enharmonic spellings differ by 12. A major key is
|
|
515
|
+
* identified by its number of sharps (+) or flats (-), which is also the position of its tonic.
|
|
516
|
+
* The 7 tones of key `k` are the positions `k - 1` through `k + 5`.
|
|
517
|
+
*/
|
|
518
|
+
static get letterFifths(): Record<PitchLetter, number> {
|
|
519
|
+
return { f: -1, c: 0, g: 1, d: 2, a: 3, e: 4, b: 5 };
|
|
520
|
+
}
|
|
521
|
+
/** letters in line-of-fifths order, starting with position -1 */
|
|
522
|
+
static get fifthsLetters(): PitchLetter[] {
|
|
523
|
+
return ['f', 'c', 'g', 'd', 'a', 'e', 'b'];
|
|
524
|
+
}
|
|
525
|
+
/** semitones above c for the natural letters */
|
|
526
|
+
static get naturalValues(): Record<PitchLetter, number> {
|
|
527
|
+
return { c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11 };
|
|
528
|
+
}
|
|
529
|
+
/** the lowest and highest line-of-fifths positions that need no more than a double accidental */
|
|
530
|
+
static get minFifths(): number {
|
|
531
|
+
return -15;
|
|
532
|
+
}
|
|
533
|
+
static get maxFifths(): number {
|
|
534
|
+
return 19;
|
|
535
|
+
}
|
|
536
|
+
/** sharps (positive) minus flats, from an accidental string like '#', 'bb' or 'n' */
|
|
537
|
+
static accidentalCount(accidental: string | undefined): number {
|
|
538
|
+
let rv = 0;
|
|
539
|
+
for (const ch of accidental ?? '') {
|
|
540
|
+
rv += ch === '#' ? 1 : (ch === 'b' ? -1 : 0);
|
|
541
|
+
}
|
|
542
|
+
return rv;
|
|
543
|
+
}
|
|
544
|
+
/** inverse of accidentalCount, 'n' for natural */
|
|
545
|
+
static accidentalFromCount(count: number): string {
|
|
546
|
+
if (count === 0) {
|
|
547
|
+
return 'n';
|
|
532
548
|
}
|
|
549
|
+
return count > 0 ? '#'.repeat(count) : 'b'.repeat(-count);
|
|
550
|
+
}
|
|
551
|
+
/** position of the pitch on the line of fifths */
|
|
552
|
+
static pitchFifths(pitch: Pitch): number {
|
|
553
|
+
return SmoMusic.letterFifths[pitch.letter.toLowerCase() as PitchLetter] +
|
|
554
|
+
7 * SmoMusic.accidentalCount(pitch.accidental);
|
|
555
|
+
}
|
|
556
|
+
/** the pitch at the given line-of-fifths position. The octave is not adjusted. */
|
|
557
|
+
static fifthsToPitch(fifths: number, octave: number): Pitch {
|
|
558
|
+
const accidentalCount = Math.floor((fifths + 1) / 7);
|
|
559
|
+
const letter = SmoMusic.fifthsLetters[fifths - 7 * accidentalCount + 1];
|
|
560
|
+
return { letter, accidental: SmoMusic.accidentalFromCount(accidentalCount), octave };
|
|
561
|
+
}
|
|
533
562
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* as an augmented chord, the spelling is the same. It does not show a preference
|
|
538
|
-
* for notes that don't have an obvious purpose in the key, e.g. it does not try to compute the
|
|
539
|
-
* equivalent to 'e#' in the key of 'c'. The computation of the 'intended key area' is
|
|
540
|
-
* beyond the scope of a music program to interpret.
|
|
563
|
+
* Sharps (positive) or flats (negative) in a major key signature, which is also the
|
|
564
|
+
* position of its tonic on the line of fifths. Unknown keys are treated as C.
|
|
565
|
+
* @param keySignature a key like 'c', 'F#', 'Bb'
|
|
541
566
|
*/
|
|
542
|
-
static
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
{ letter: 'd', accidental: '#', role: '7/3'},
|
|
550
|
-
{ letter: 'e', accidental: 'b', role: 'b3'},
|
|
551
|
-
{ letter: 'e', accidental: 'n', role: '3'},
|
|
552
|
-
{ letter: 'f', accidental: 'n', role: '4'},
|
|
553
|
-
{ letter: 'f', accidental: '#', role: '#11'},
|
|
554
|
-
{ letter: 'g', accidental: 'b', role: 'b5'},
|
|
555
|
-
{ letter: 'g', accidental: 'n', role: '5'},
|
|
556
|
-
{ letter: 'g', accidental: '#', role: '7/6'},
|
|
557
|
-
{ letter: 'a', accidental: 'b', role: 'b6'},
|
|
558
|
-
{ letter: 'a', accidental: 'n', role: '6'},
|
|
559
|
-
{ letter: 'a', accidental: '#', role: '7/7'},
|
|
560
|
-
{ letter: 'b', accidental: 'b', role: 'b7'},
|
|
561
|
-
{ letter: 'b', accidental: 'n', role: '7'}
|
|
562
|
-
], 'c#': [
|
|
563
|
-
{ letter: 'c', accidental: '#', role: 'tonic' },
|
|
564
|
-
{ letter: 'c', accidental: '##', role: '7/2' },
|
|
565
|
-
{ letter: 'd', accidental: 'n', role: 'b9' },
|
|
566
|
-
{ letter: 'd', accidental: '#', role: '2' },
|
|
567
|
-
{ letter: 'd', accidental: '##', role: '#2'},
|
|
568
|
-
{ letter: 'f', accidental: 'b', role: 'b3'},
|
|
569
|
-
{ letter: 'e', accidental: '#', role: '3'},
|
|
570
|
-
{ letter: 'f', accidental: '#', role: '4'},
|
|
571
|
-
{ letter: 'f', accidental: '##', role: '#11'},
|
|
572
|
-
{ letter: 'g', accidental: 'n', role: 'b5'},
|
|
573
|
-
{ letter: 'g', accidental: '#', role: '5'},
|
|
574
|
-
{ letter: 'g', accidental: '##', role: '7/6'},
|
|
575
|
-
{ letter: 'a', accidental: 'n', role: 'b6'},
|
|
576
|
-
{ letter: 'a', accidental: '#', role: '6'},
|
|
577
|
-
{ letter: 'a', accidental: '##', role: '7/7'},
|
|
578
|
-
{ letter: 'b', accidental: 'n', role: 'b7'},
|
|
579
|
-
{ letter: 'b', accidental: '#', role: '7'}
|
|
580
|
-
], 'db': [
|
|
581
|
-
{ letter: 'd', accidental: 'b', role: 'tonic' },
|
|
582
|
-
{ letter: 'd', accidental: 'n', role: '7/2' },
|
|
583
|
-
{ letter: 'e', accidental: 'bb', role: 'b9' },
|
|
584
|
-
{ letter: 'e', accidental: 'b', role: '2' },
|
|
585
|
-
{ letter: 'e', accidental: 'n', role: '7/3'},
|
|
586
|
-
{ letter: 'f', accidental: 'b', role: 'b3'},
|
|
587
|
-
{ letter: 'f', accidental: 'n', role: '3'},
|
|
588
|
-
{ letter: 'g', accidental: 'b', role: '4'},
|
|
589
|
-
{ letter: 'g', accidental: 'n', role: '#11'},
|
|
590
|
-
{ letter: 'a', accidental: 'bb', role: 'b5'},
|
|
591
|
-
{ letter: 'a', accidental: 'b', role: '5'},
|
|
592
|
-
{ letter: 'a', accidental: 'n', role: '7/6'},
|
|
593
|
-
{ letter: 'b', accidental: 'bb', role: 'b6'},
|
|
594
|
-
{ letter: 'b', accidental: 'b', role: '6'},
|
|
595
|
-
{ letter: 'b', accidental: 'n', role: '7/7'},
|
|
596
|
-
{ letter: 'c', accidental: 'b', role: 'b7'},
|
|
597
|
-
{ letter: 'c', accidental: 'n', role: '7'}
|
|
598
|
-
], 'd': [
|
|
599
|
-
{ letter: 'd', accidental: 'n', role: 'tonic' },
|
|
600
|
-
{ letter: 'd', accidental: '#', role: '7/2' },
|
|
601
|
-
{ letter: 'e', accidental: 'b', role: 'b9' },
|
|
602
|
-
{ letter: 'e', accidental: 'n', role: '2' },
|
|
603
|
-
{ letter: 'e', accidental: '#', role: '7/3'},
|
|
604
|
-
{ letter: 'f', accidental: 'n', role: 'b3'},
|
|
605
|
-
{ letter: 'f', accidental: '#', role: '3'},
|
|
606
|
-
{ letter: 'g', accidental: 'n', role: '4'},
|
|
607
|
-
{ letter: 'g', accidental: '#', role: '#11'},
|
|
608
|
-
{ letter: 'a', accidental: 'b', role: 'b5'},
|
|
609
|
-
{ letter: 'a', accidental: 'n', role: '5'},
|
|
610
|
-
{ letter: 'a', accidental: '#', role: '7/6'},
|
|
611
|
-
{ letter: 'b', accidental: 'b', role: 'b6'},
|
|
612
|
-
{ letter: 'b', accidental: 'n', role: '6'},
|
|
613
|
-
{ letter: 'b', accidental: '#', role: '7/7'},
|
|
614
|
-
{ letter: 'c', accidental: 'n', role: 'b7'},
|
|
615
|
-
{ letter: 'c', accidental: '#', role: '7'}
|
|
616
|
-
], 'eb': [
|
|
617
|
-
{ letter: 'e', accidental: 'b', role: 'tonic' },
|
|
618
|
-
{ letter: 'e', accidental: 'n', role: '7/2' },
|
|
619
|
-
{ letter: 'f', accidental: 'b', role: 'b9' },
|
|
620
|
-
{ letter: 'f', accidental: 'n', role: '2' },
|
|
621
|
-
{ letter: 'f', accidental: '#', role: '7/3'},
|
|
622
|
-
{ letter: 'g', accidental: 'b', role: 'b3'},
|
|
623
|
-
{ letter: 'g', accidental: 'n', role: '3'},
|
|
624
|
-
{ letter: 'a', accidental: 'b', role: '4'},
|
|
625
|
-
{ letter: 'a', accidental: 'n', role: '#11'},
|
|
626
|
-
{ letter: 'b', accidental: 'bb', role: 'b5'},
|
|
627
|
-
{ letter: 'b', accidental: 'b', role: '5'},
|
|
628
|
-
{ letter: 'b', accidental: 'n', role: '7/6'},
|
|
629
|
-
{ letter: 'c', accidental: 'b', role: 'b6'},
|
|
630
|
-
{ letter: 'c', accidental: 'n', role: '6'},
|
|
631
|
-
{ letter: 'c', accidental: '#', role: '7/7'},
|
|
632
|
-
{ letter: 'd', accidental: 'b', role: 'b7'},
|
|
633
|
-
{ letter: 'd', accidental: 'n', role: '7'}
|
|
634
|
-
], 'e': [
|
|
635
|
-
{ letter: 'e', accidental: 'n', role: 'tonic' },
|
|
636
|
-
{ letter: 'e', accidental: '#', role: '7/2' },
|
|
637
|
-
{ letter: 'f', accidental: 'n', role: 'b9' },
|
|
638
|
-
{ letter: 'f', accidental: '#', role: '2' },
|
|
639
|
-
{ letter: 'f', accidental: '##', role: '7/3'},
|
|
640
|
-
{ letter: 'g', accidental: 'n', role: 'b3'},
|
|
641
|
-
{ letter: 'g', accidental: '#', role: '3'},
|
|
642
|
-
{ letter: 'a', accidental: 'n', role: '4'},
|
|
643
|
-
{ letter: 'a', accidental: '#', role: '#11'},
|
|
644
|
-
{ letter: 'b', accidental: 'b', role: 'b5'},
|
|
645
|
-
{ letter: 'b', accidental: 'n', role: '5'},
|
|
646
|
-
{ letter: 'b', accidental: '#', role: '7/6'},
|
|
647
|
-
{ letter: 'c', accidental: 'n', role: 'b6'},
|
|
648
|
-
{ letter: 'c', accidental: '#', role: '6'},
|
|
649
|
-
{ letter: 'c', accidental: '##', role: '7/7'},
|
|
650
|
-
{ letter: 'd', accidental: 'n', role: 'b7'},
|
|
651
|
-
{ letter: 'd', accidental: '#', role: '7'}
|
|
652
|
-
], 'f': [
|
|
653
|
-
{ letter: 'f', accidental: 'n', role: 'tonic' },
|
|
654
|
-
{ letter: 'f', accidental: '#', role: '7/2' },
|
|
655
|
-
{ letter: 'g', accidental: 'b', role: 'b9' },
|
|
656
|
-
{ letter: 'g', accidental: 'n', role: '2' },
|
|
657
|
-
{ letter: 'g', accidental: '#', role: '7/3'},
|
|
658
|
-
{ letter: 'a', accidental: 'b', role: 'b3'},
|
|
659
|
-
{ letter: 'a', accidental: 'n', role: '3'},
|
|
660
|
-
{ letter: 'b', accidental: 'b', role: '4'},
|
|
661
|
-
{ letter: 'b', accidental: 'n', role: '#11'},
|
|
662
|
-
{ letter: 'c', accidental: 'b', role: 'b5'},
|
|
663
|
-
{ letter: 'c', accidental: 'n', role: '5'},
|
|
664
|
-
{ letter: 'c', accidental: '#', role: '7/6'},
|
|
665
|
-
{ letter: 'd', accidental: 'b', role: 'b6'},
|
|
666
|
-
{ letter: 'd', accidental: 'n', role: '6'},
|
|
667
|
-
{ letter: 'd', accidental: '#', role: '7/7'},
|
|
668
|
-
{ letter: 'e', accidental: 'b', role: 'b7'},
|
|
669
|
-
{ letter: 'e', accidental: 'n', role: '7'}
|
|
670
|
-
], 'f#': [
|
|
671
|
-
{ letter: 'f', accidental: '#', role: 'tonic' },
|
|
672
|
-
{ letter: 'f', accidental: '##', role: '7/2' },
|
|
673
|
-
{ letter: 'g', accidental: 'n', role: 'b9' },
|
|
674
|
-
{ letter: 'g', accidental: '#', role: '2' },
|
|
675
|
-
{ letter: 'g', accidental: '##', role: '#2'},
|
|
676
|
-
{ letter: 'a', accidental: 'n', role: 'b3'},
|
|
677
|
-
{ letter: 'a', accidental: '#', role: '3'},
|
|
678
|
-
{ letter: 'b', accidental: 'n', role: '4'},
|
|
679
|
-
{ letter: 'b', accidental: '#', role: '#11'},
|
|
680
|
-
{ letter: 'c', accidental: 'n', role: 'b5'},
|
|
681
|
-
{ letter: 'c', accidental: '#', role: '5'},
|
|
682
|
-
{ letter: 'c', accidental: '##', role: '7/6'},
|
|
683
|
-
{ letter: 'd', accidental: 'n', role: 'b6'},
|
|
684
|
-
{ letter: 'd', accidental: '#', role: '6'},
|
|
685
|
-
{ letter: 'd', accidental: '##', role: '7/7'},
|
|
686
|
-
{ letter: 'e', accidental: 'n', role: 'b7'},
|
|
687
|
-
{ letter: 'e', accidental: '#', role: '7'}
|
|
688
|
-
], 'gb': [
|
|
689
|
-
{ letter: 'g', accidental: 'b', role: 'tonic' },
|
|
690
|
-
{ letter: 'g', accidental: 'n', role: '7/2' },
|
|
691
|
-
{ letter: 'a', accidental: 'bb', role: 'b9' },
|
|
692
|
-
{ letter: 'a', accidental: 'b', role: '2' },
|
|
693
|
-
{ letter: 'a', accidental: 'n', role: '7/3'},
|
|
694
|
-
{ letter: 'a', accidental: 'bb', role: 'b3'},
|
|
695
|
-
{ letter: 'b', accidental: 'b', role: '3'},
|
|
696
|
-
{ letter: 'c', accidental: 'b', role: '4'},
|
|
697
|
-
{ letter: 'c', accidental: 'n', role: '#11'},
|
|
698
|
-
{ letter: 'd', accidental: 'bb', role: 'b5'},
|
|
699
|
-
{ letter: 'd', accidental: 'b', role: '5'},
|
|
700
|
-
{ letter: 'd', accidental: 'n', role: '7/6'},
|
|
701
|
-
{ letter: 'e', accidental: 'bb', role: 'b6'},
|
|
702
|
-
{ letter: 'e', accidental: 'b', role: '6'},
|
|
703
|
-
{ letter: 'e', accidental: 'n', role: '7/7'},
|
|
704
|
-
{ letter: 'f', accidental: 'b', role: 'b7'},
|
|
705
|
-
{ letter: 'f', accidental: 'n', role: '7'}
|
|
706
|
-
], 'g': [
|
|
707
|
-
{ letter: 'g', accidental: 'n', role: 'tonic' },
|
|
708
|
-
{ letter: 'g', accidental: '#', role: '7/2' },
|
|
709
|
-
{ letter: 'g', accidental: 'b', role: 'b9' },
|
|
710
|
-
{ letter: 'a', accidental: 'n', role: '2' },
|
|
711
|
-
{ letter: 'a', accidental: '#', role: '7/3'},
|
|
712
|
-
{ letter: 'b', accidental: 'b', role: 'b3'},
|
|
713
|
-
{ letter: 'b', accidental: 'n', role: '3'},
|
|
714
|
-
{ letter: 'c', accidental: 'n', role: '4'},
|
|
715
|
-
{ letter: 'c', accidental: '#', role: '#11'},
|
|
716
|
-
{ letter: 'd', accidental: 'b', role: 'b5'},
|
|
717
|
-
{ letter: 'd', accidental: 'n', role: '5'},
|
|
718
|
-
{ letter: 'd', accidental: '#', role: '7/6'},
|
|
719
|
-
{ letter: 'e', accidental: 'b', role: 'b6'},
|
|
720
|
-
{ letter: 'e', accidental: 'n', role: '6'},
|
|
721
|
-
{ letter: 'e', accidental: '#', role: '7/7'},
|
|
722
|
-
{ letter: 'f', accidental: 'n', role: 'b7'},
|
|
723
|
-
{ letter: 'f', accidental: '#', role: '7'}
|
|
724
|
-
],'ab': [
|
|
725
|
-
{ letter: 'a', accidental: 'b', role: 'tonic' },
|
|
726
|
-
{ letter: 'a', accidental: 'n', role: '7/2' },
|
|
727
|
-
{ letter: 'b', accidental: 'bb', role: 'b9' },
|
|
728
|
-
{ letter: 'b', accidental: 'b', role: '2' },
|
|
729
|
-
{ letter: 'b', accidental: 'n', role: '7/3' },
|
|
730
|
-
{ letter: 'b', accidental: 'bb', role: 'b3' },
|
|
731
|
-
{ letter: 'c', accidental: 'n', role: '3' },
|
|
732
|
-
{ letter: 'd', accidental: 'b', role: '4' },
|
|
733
|
-
{ letter: 'd', accidental: 'n', role: '#11' },
|
|
734
|
-
{ letter: 'e', accidental: 'bb', role: 'b5' },
|
|
735
|
-
{ letter: 'e', accidental: 'b', role: '5' },
|
|
736
|
-
{ letter: 'e', accidental: 'n', role: '7/6' },
|
|
737
|
-
{ letter: 'f', accidental: 'b', role: 'b6' },
|
|
738
|
-
{ letter: 'f', accidental: 'n', role: '6' },
|
|
739
|
-
{ letter: 'f', accidental: '#', role: '7/7' },
|
|
740
|
-
{ letter: 'g', accidental: 'b', role: 'b7' },
|
|
741
|
-
{ letter: 'g', accidental: 'n', role: '7' }
|
|
742
|
-
], 'a': [
|
|
743
|
-
{ letter: 'a', accidental: 'n', role: 'tonic' },
|
|
744
|
-
{ letter: 'a', accidental: '#', role: '7/2' },
|
|
745
|
-
{ letter: 'b', accidental: 'b', role: 'b9' },
|
|
746
|
-
{ letter: 'b', accidental: 'n', role: '2' },
|
|
747
|
-
{ letter: 'b', accidental: '#', role: '7/3'},
|
|
748
|
-
{ letter: 'c', accidental: 'n', role: 'b3'},
|
|
749
|
-
{ letter: 'c', accidental: '#', role: '3'},
|
|
750
|
-
{ letter: 'd', accidental: 'n', role: '4'},
|
|
751
|
-
{ letter: 'd', accidental: '#', role: '#11'},
|
|
752
|
-
{ letter: 'e', accidental: 'b', role: 'b5'},
|
|
753
|
-
{ letter: 'e', accidental: 'n', role: '5'},
|
|
754
|
-
{ letter: 'e', accidental: '#', role: '7/6'},
|
|
755
|
-
{ letter: 'f', accidental: 'n', role: 'b6'},
|
|
756
|
-
{ letter: 'f', accidental: '#', role: '6'},
|
|
757
|
-
{ letter: 'f', accidental: '##', role: '7/7'},
|
|
758
|
-
{ letter: 'g', accidental: 'n', role: 'b7'},
|
|
759
|
-
{ letter: 'g', accidental: '#', role: '7'}
|
|
760
|
-
], 'bb': [
|
|
761
|
-
{ letter: 'b', accidental: 'b', role: 'tonic' },
|
|
762
|
-
{ letter: 'b', accidental: 'n', role: '7/2' },
|
|
763
|
-
{ letter: 'c', accidental: 'b', role: 'b9' },
|
|
764
|
-
{ letter: 'c', accidental: 'n', role: '2' },
|
|
765
|
-
{ letter: 'c', accidental: '#', role: '7/3'},
|
|
766
|
-
{ letter: 'd', accidental: 'b', role: 'b3'},
|
|
767
|
-
{ letter: 'd', accidental: 'n', role: '3'},
|
|
768
|
-
{ letter: 'e', accidental: 'b', role: '4'},
|
|
769
|
-
{ letter: 'e', accidental: 'n', role: '#11'},
|
|
770
|
-
{ letter: 'f', accidental: 'b', role: 'b5'},
|
|
771
|
-
{ letter: 'f', accidental: 'n', role: '5'},
|
|
772
|
-
{ letter: 'f', accidental: '#', role: '7/6'},
|
|
773
|
-
{ letter: 'g', accidental: 'b', role: 'b6'},
|
|
774
|
-
{ letter: 'g', accidental: 'n', role: '6'},
|
|
775
|
-
{ letter: 'g', accidental: '#', role: '7/7'},
|
|
776
|
-
{ letter: 'a', accidental: 'b', role: 'b7'},
|
|
777
|
-
{ letter: 'a', accidental: 'n', role: '7'}
|
|
778
|
-
], 'b': [
|
|
779
|
-
{ letter: 'b', accidental: 'n', role: 'tonic' },
|
|
780
|
-
{ letter: 'b', accidental: '#', role: '7/2' },
|
|
781
|
-
{ letter: 'c', accidental: 'n', role: 'b9' },
|
|
782
|
-
{ letter: 'c', accidental: '#', role: '2' },
|
|
783
|
-
{ letter: 'c', accidental: '##', role: '7/3'},
|
|
784
|
-
{ letter: 'd', accidental: 'n', role: 'b3'},
|
|
785
|
-
{ letter: 'd', accidental: '#', role: '3'},
|
|
786
|
-
{ letter: 'e', accidental: 'n', role: '4'},
|
|
787
|
-
{ letter: 'e', accidental: '#', role: '#11'},
|
|
788
|
-
{ letter: 'f', accidental: 'n', role: 'b5'},
|
|
789
|
-
{ letter: 'f', accidental: '#', role: '5'},
|
|
790
|
-
{ letter: 'f', accidental: '##', role: '7/6'},
|
|
791
|
-
{ letter: 'g', accidental: 'n', role: 'b6'},
|
|
792
|
-
{ letter: 'g', accidental: '#', role: '6'},
|
|
793
|
-
{ letter: 'g', accidental: '##', role: '7/7'},
|
|
794
|
-
{ letter: 'a', accidental: 'n', role: 'b7'},
|
|
795
|
-
{ letter: 'a', accidental: '#', role: '7'}
|
|
796
|
-
]};
|
|
797
|
-
return tbl;
|
|
567
|
+
static keyFifths(keySignature: string): number {
|
|
568
|
+
const key = (keySignature ?? '').toLowerCase();
|
|
569
|
+
const base = SmoMusic.letterFifths[key[0] as PitchLetter];
|
|
570
|
+
if (typeof (base) === 'undefined') {
|
|
571
|
+
return 0;
|
|
572
|
+
}
|
|
573
|
+
return base + 7 * SmoMusic.accidentalCount(key.substring(1));
|
|
798
574
|
}
|
|
799
575
|
/**
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
576
|
+
* The signed 'distance' of a pitch from a key: the number of sharps (positive) or flats
|
|
577
|
+
* (negative) that must be added to the key signature for the pitch to be in the key.
|
|
578
|
+
* It is the number of steps around the circle of fifths to the nearest key containing the
|
|
579
|
+
* pitch, e.g. from C major, Bb is -1 (F major) and A# is 5 (B major).
|
|
804
580
|
*/
|
|
805
|
-
static
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
581
|
+
static distanceFromKey(pitch: Pitch, keySignature: string): number {
|
|
582
|
+
return SmoMusic.fifthsDistance(SmoMusic.pitchFifths(pitch), SmoMusic.keyFifths(keySignature));
|
|
583
|
+
}
|
|
584
|
+
static fifthsDistance(fifths: number, keyFifths: number): number {
|
|
585
|
+
if (fifths > keyFifths + 5) {
|
|
586
|
+
return fifths - (keyFifths + 5);
|
|
809
587
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
return '';
|
|
588
|
+
if (fifths < keyFifths - 1) {
|
|
589
|
+
return fifths - (keyFifths - 1);
|
|
813
590
|
}
|
|
814
|
-
return
|
|
591
|
+
return 0;
|
|
815
592
|
}
|
|
816
593
|
/**
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
* @param role
|
|
820
|
-
* @param keySignature
|
|
821
|
-
* @param transposedPitch
|
|
822
|
-
* @returns
|
|
594
|
+
* The number of half steps above c0 that the pitch sounds. Unlike smoPitchToInt, this is correct
|
|
595
|
+
* for every spelling, e.g. b#3 sounds the same as c4 and cb4 the same as b3.
|
|
823
596
|
*/
|
|
824
|
-
static
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
597
|
+
static soundingValue(pitch: Pitch): number {
|
|
598
|
+
return (pitch.octave ?? 0) * 12 + SmoMusic.naturalValues[pitch.letter.toLowerCase() as PitchLetter] +
|
|
599
|
+
SmoMusic.accidentalCount(pitch.accidental);
|
|
600
|
+
}
|
|
601
|
+
/** the pitch spelled at the given line-of-fifths position that sounds `value` half steps above c0 */
|
|
602
|
+
static pitchForSounding(fifths: number, value: number): Pitch {
|
|
603
|
+
const pitch = SmoMusic.fifthsToPitch(fifths, 0);
|
|
604
|
+
pitch.octave = Math.round((value - SmoMusic.soundingValue(pitch)) / 12);
|
|
605
|
+
return pitch;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Choose a spelling for a sounding pitch that is closest to the key: the one that needs the fewest
|
|
609
|
+
* sharps or flats added to the key signature. If sharp and flat spellings are equally far, use the flat.
|
|
610
|
+
* @param value half steps above c0
|
|
611
|
+
* @param keySignature
|
|
612
|
+
*/
|
|
613
|
+
static spellSoundingValue(value: number, keySignature: string): Pitch {
|
|
614
|
+
const key = SmoMusic.keyFifths(keySignature);
|
|
615
|
+
const pitchClass = ((value % 12) + 12) % 12;
|
|
616
|
+
const start = (7 * pitchClass) % 12;
|
|
617
|
+
let best = start;
|
|
618
|
+
let bestDistance = Infinity;
|
|
619
|
+
for (let candidate = start - 24; candidate <= start + 12; candidate += 12) {
|
|
620
|
+
if (candidate < SmoMusic.minFifths || candidate > SmoMusic.maxFifths) {
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
// candidates are in ascending order, so on a tie the lower (flat side) one stays
|
|
624
|
+
const distance = Math.abs(SmoMusic.fifthsDistance(candidate, key));
|
|
625
|
+
if (distance < bestDistance) {
|
|
626
|
+
best = candidate;
|
|
627
|
+
bestDistance = distance;
|
|
628
|
+
}
|
|
828
629
|
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
630
|
+
return SmoMusic.pitchForSounding(best, value);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The destination key when a key is transposed by a number of half steps. Of the 2 or 3 enharmonic
|
|
634
|
+
* keys, the one with the fewest sharps/flats is used, and flats if there is a tie. With no offset
|
|
635
|
+
* the key is unchanged.
|
|
636
|
+
* @param keySignature the starting key
|
|
637
|
+
* @param offset half steps, may be negative
|
|
638
|
+
* @returns a key in the same case convention as keySignature (e.g. 'Bb' or 'bb')
|
|
639
|
+
*/
|
|
640
|
+
static keyForOffset(keySignature: string, offset: number): string {
|
|
641
|
+
if (offset === 0) {
|
|
642
|
+
return keySignature;
|
|
832
643
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
644
|
+
const residue = (((SmoMusic.keyFifths(keySignature) + 7 * offset) % 12) + 12) % 12;
|
|
645
|
+
const pitch = SmoMusic.fifthsToPitch(residue < 6 ? residue : residue - 12, 0);
|
|
646
|
+
let rv = pitch.letter + (pitch.accidental === 'n' ? '' : pitch.accidental);
|
|
647
|
+
if (keySignature.length > 0 && keySignature[0] === keySignature[0].toUpperCase()) {
|
|
648
|
+
rv = rv[0].toUpperCase() + rv.substring(1);
|
|
836
649
|
}
|
|
837
|
-
return
|
|
650
|
+
return rv;
|
|
651
|
+
}
|
|
652
|
+
static scaleTones: string[] = ['tonic', '2', '3', '4', '5', '6', '7'];
|
|
653
|
+
/**
|
|
654
|
+
* The tones of the key, by letter, e.g. for 'g' f is 'f#' and c is 'cn'.
|
|
655
|
+
* @param keySignature
|
|
656
|
+
*/
|
|
657
|
+
static getScaleTonesForKey(keySignature: string): Record<string, string> {
|
|
658
|
+
const key = SmoMusic.keyFifths(keySignature);
|
|
659
|
+
const rv: Record<string, string> = {};
|
|
660
|
+
SmoMusic.fifthsLetters.forEach((letter) => {
|
|
661
|
+
const accidentalCount = Math.floor((key + 5 - SmoMusic.letterFifths[letter]) / 7);
|
|
662
|
+
rv[letter] = letter + SmoMusic.accidentalFromCount(accidentalCount);
|
|
663
|
+
});
|
|
664
|
+
return rv;
|
|
838
665
|
}
|
|
839
666
|
static rawTranspose(pitch: Pitch, offset: number) {
|
|
840
667
|
return SmoMusic.smoIntToPitch(SmoMusic.smoPitchToInt(pitch) + offset);
|
|
841
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Transpose a pitch from one key to another, keeping its relationship to the key. Every pitch
|
|
671
|
+
* moves by the same number of steps around the circle of fifths as the key does, so a note that
|
|
672
|
+
* was in the key stays in the key, and a note that was N sharps/flats outside the key is still
|
|
673
|
+
* N sharps/flats outside the key (c# in C becomes d# in D). The sounding pitch is always
|
|
674
|
+
* `offset` half steps from the original, even if the keys and offset don't agree.
|
|
675
|
+
* @param pitch
|
|
676
|
+
* @param originalKey key signature of the pitch
|
|
677
|
+
* @param destinationKey key signature to spell the pitch for
|
|
678
|
+
* @param offset half steps
|
|
679
|
+
*/
|
|
842
680
|
static transposePitchForKey(pitch: Pitch, originalKey: string, destinationKey: string, offset: number): Pitch {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
681
|
+
let shift = SmoMusic.keyFifths(destinationKey) - SmoMusic.keyFifths(originalKey);
|
|
682
|
+
// 7 steps around the circle of fifths is 1 half step (mod 12)
|
|
683
|
+
let error = ((7 * offset - shift) % 12 + 12) % 12;
|
|
684
|
+
if (error > 6) {
|
|
685
|
+
error -= 12;
|
|
686
|
+
}
|
|
687
|
+
shift += error;
|
|
688
|
+
const value = SmoMusic.soundingValue(pitch) + offset;
|
|
689
|
+
const fifths = SmoMusic.pitchFifths(pitch) + shift;
|
|
690
|
+
if (fifths < SmoMusic.minFifths || fifths > SmoMusic.maxFifths) {
|
|
691
|
+
return SmoMusic.spellSoundingValue(value, destinationKey);
|
|
847
692
|
}
|
|
848
|
-
return
|
|
693
|
+
return SmoMusic.pitchForSounding(fifths, value);
|
|
849
694
|
}
|
|
850
695
|
|
|
851
696
|
/**
|
|
@@ -1199,7 +1044,10 @@ export class SmoMusic {
|
|
|
1199
1044
|
}
|
|
1200
1045
|
|
|
1201
1046
|
/**
|
|
1202
|
-
* When transposing, get the enharmonic that most closely fits the key
|
|
1047
|
+
* When transposing, get the enharmonic that most closely fits the key. If the pitch is not in
|
|
1048
|
+
* the key, this is the spelling that needs the fewest sharps/flats added to the key signature
|
|
1049
|
+
* to include it (Bb rather than A# in C, since F major is 1 flat away and B major 5 sharps),
|
|
1050
|
+
* and the flat spelling if the sharp and flat spellings are equally far.
|
|
1203
1051
|
* `getEnharmonicInKey` returns an alternate to the given pitch, or the same pitch.
|
|
1204
1052
|
* `getKeyFriendlyEnharmonic` return a pitch for a given key, given the letter name only
|
|
1205
1053
|
* @param smoPitch
|
|
@@ -1207,48 +1055,10 @@ export class SmoMusic {
|
|
|
1207
1055
|
* @returns
|
|
1208
1056
|
*/
|
|
1209
1057
|
static getEnharmonicInKey(smoPitch: Pitch, keySignature: string): Pitch {
|
|
1210
|
-
let match = false;
|
|
1211
|
-
let rv = '';
|
|
1212
1058
|
if (typeof (smoPitch.octave) === 'undefined') {
|
|
1213
1059
|
smoPitch.octave = 1;
|
|
1214
1060
|
}
|
|
1215
|
-
|
|
1216
|
-
const flatKey = keySignature.indexOf('b') >= 0;
|
|
1217
|
-
const ar = SmoMusic.getEnharmonics(SmoMusic.pitchToVexKey(smoPitch));
|
|
1218
|
-
rv = SmoMusic.stripVexOctave(SmoMusic.pitchToVexKey(smoPitch));
|
|
1219
|
-
const scaleMap: Record<string, string> = SmoMusic.getScaleTonesForKey(keySignature);
|
|
1220
|
-
// new VF.Music().createScaleMap(keySignature);
|
|
1221
|
-
ar.forEach((vexKey) => {
|
|
1222
|
-
if (vexKey.length === 1) {
|
|
1223
|
-
vexKey += 'n';
|
|
1224
|
-
}
|
|
1225
|
-
if (vexKey === scaleMap[vexKey[0]]) {
|
|
1226
|
-
rv = vexKey;
|
|
1227
|
-
match = true;
|
|
1228
|
-
} else if (!match) {
|
|
1229
|
-
// In the absence of a match of a key tone, we bias towards more
|
|
1230
|
-
// 'common', like Bb is more common than A#, esp. as a chord. This maybe
|
|
1231
|
-
// just be my horn player bias towards flat keys
|
|
1232
|
-
if (vexKey === 'a#' && !sharpKey) {
|
|
1233
|
-
rv = 'bb';
|
|
1234
|
-
} else if (vexKey === 'g#' && !sharpKey) {
|
|
1235
|
-
rv = 'ab';
|
|
1236
|
-
} else if (vexKey === 'c#' && !sharpKey) {
|
|
1237
|
-
rv = 'db';
|
|
1238
|
-
} else if (vexKey === 'd#' && !sharpKey) {
|
|
1239
|
-
rv = 'eb';
|
|
1240
|
-
} else if (vexKey === 'f#' && flatKey) {
|
|
1241
|
-
rv = 'gb';
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
const smoRv: Pitch = SmoMusic.pitchKeyToPitch(SmoMusic.vexToSmoKey(rv));
|
|
1246
|
-
smoRv.octave = smoPitch.octave;
|
|
1247
|
-
const rvi = SmoMusic.smoPitchToInt(smoRv);
|
|
1248
|
-
const ori = SmoMusic.smoPitchToInt(smoPitch);
|
|
1249
|
-
// handle the case of c0 < b0, pitch-wise
|
|
1250
|
-
smoRv.octave += Math.sign(ori - rvi);
|
|
1251
|
-
return smoRv;
|
|
1061
|
+
return SmoMusic.spellSoundingValue(SmoMusic.soundingValue(smoPitch), keySignature);
|
|
1252
1062
|
}
|
|
1253
1063
|
/**
|
|
1254
1064
|
* fix the enharmonic to match the key, if possible
|
|
@@ -1470,7 +1280,7 @@ export class SmoMusic {
|
|
|
1470
1280
|
'F#': 6,
|
|
1471
1281
|
'Bb': 2,
|
|
1472
1282
|
'Ab': 4,
|
|
1473
|
-
'
|
|
1283
|
+
'Gb': 6,
|
|
1474
1284
|
'G': 1,
|
|
1475
1285
|
'F': 1,
|
|
1476
1286
|
'Eb': 3,
|
package/src/smo/data/note.ts
CHANGED
|
@@ -585,7 +585,7 @@ export class SmoNote implements Transposable {
|
|
|
585
585
|
}
|
|
586
586
|
removeAllAnnotations() {
|
|
587
587
|
const tms = this.textModifiers.filter((mod: SmoNoteModifierBase) =>
|
|
588
|
-
mod.attrs.type !== 'SmoLyric'
|
|
588
|
+
mod.attrs.type !== 'SmoLyric' || (mod as SmoLyric).parser !== SmoLyric.parsers.annotation
|
|
589
589
|
);
|
|
590
590
|
this.textModifiers = tms;
|
|
591
591
|
}
|
|
@@ -1210,6 +1210,18 @@ export class SmoDynamicText extends SmoNoteModifierBase {
|
|
|
1210
1210
|
rv.push('selector');
|
|
1211
1211
|
return rv;
|
|
1212
1212
|
}
|
|
1213
|
+
/** the smallest font size a dynamic marking can be given */
|
|
1214
|
+
static readonly minFontSize: number = 1;
|
|
1215
|
+
/** the largest font size a dynamic marking can be given */
|
|
1216
|
+
static readonly maxFontSize: number = 99;
|
|
1217
|
+
/**
|
|
1218
|
+
* True if the value can be used as the font size of a dynamic marking: a whole number from
|
|
1219
|
+
* {@link minFontSize} to {@link maxFontSize}.
|
|
1220
|
+
*/
|
|
1221
|
+
static isValidFontSize(value: number): boolean {
|
|
1222
|
+
return typeof (value) === 'number' && Number.isInteger(value)
|
|
1223
|
+
&& value >= SmoDynamicText.minFontSize && value <= SmoDynamicText.maxFontSize;
|
|
1224
|
+
}
|
|
1213
1225
|
text: string = '';
|
|
1214
1226
|
yOffsetLine: number = 11;
|
|
1215
1227
|
yOffsetPixels: number = 0;
|