smoosic 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/build/smoosic.js +171 -78
  2. package/package.json +82 -77
  3. package/release/smoosic.js +171 -78
  4. package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/src/application/application.ts +464 -459
  48. package/src/common/promiseHelpers.ts +2 -2
  49. package/src/render/audio/samples.ts +117 -118
  50. package/src/render/sui/pageDivisions.ts +58 -0
  51. package/src/render/sui/renderState.ts +469 -464
  52. package/src/render/sui/scoreChangeState.ts +62 -0
  53. package/src/render/sui/scoreView.ts +30 -0
  54. package/src/render/sui/scoreViewOperations.ts +2555 -2380
  55. package/src/render/sui/svgPageMap.ts +16 -17
  56. package/src/render/sui/textEdit.ts +310 -311
  57. package/src/render/sui/tracker.ts +40 -0
  58. package/src/render/vex/vxNote.ts +3 -1
  59. package/src/smo/xform/copypaste.ts +304 -4
  60. package/src/smo/xform/selections.ts +68 -0
  61. package/src/smo/xform/undo.ts +9 -0
  62. package/src/styles/menus.css +26 -0
  63. package/src/ui/buttons/ribbon.ts +3 -1
  64. package/src/ui/components/buttons/sidebar.vue +15 -6
  65. package/src/ui/components/dialogs/library.vue +3 -1
  66. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  67. package/src/ui/dialogs/adapter.ts +181 -183
  68. package/src/ui/dialogs/addMeasure.ts +97 -97
  69. package/src/ui/dialogs/annotationVue.ts +56 -56
  70. package/src/ui/dialogs/audioSettings.ts +121 -123
  71. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  72. package/src/ui/dialogs/clefChange.ts +53 -53
  73. package/src/ui/dialogs/customTuplets.ts +95 -96
  74. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  75. package/src/ui/dialogs/dialog.ts +627 -620
  76. package/src/ui/dialogs/durations.ts +34 -34
  77. package/src/ui/dialogs/dynamics.ts +140 -142
  78. package/src/ui/dialogs/factory.ts +198 -198
  79. package/src/ui/dialogs/fileDialogs.ts +245 -179
  80. package/src/ui/dialogs/fonts.ts +93 -93
  81. package/src/ui/dialogs/globalLayout.ts +40 -40
  82. package/src/ui/dialogs/gracenote.ts +31 -31
  83. package/src/ui/dialogs/hairpin.ts +108 -110
  84. package/src/ui/dialogs/hairpinVue.ts +51 -51
  85. package/src/ui/dialogs/instrument.ts +111 -111
  86. package/src/ui/dialogs/keySignature.ts +175 -176
  87. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  88. package/src/ui/dialogs/library.ts +207 -207
  89. package/src/ui/dialogs/libraryVue.ts +62 -48
  90. package/src/ui/dialogs/lyricVue.ts +46 -46
  91. package/src/ui/dialogs/measureFormat.ts +78 -78
  92. package/src/ui/dialogs/microtones.ts +147 -147
  93. package/src/ui/dialogs/noteHead.ts +319 -319
  94. package/src/ui/dialogs/pageLayout.ts +61 -61
  95. package/src/ui/dialogs/partInfo.ts +60 -60
  96. package/src/ui/dialogs/pedalMarking.ts +117 -117
  97. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  98. package/src/ui/dialogs/pitch.ts +352 -352
  99. package/src/ui/dialogs/preferences.ts +40 -40
  100. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  101. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  102. package/src/ui/dialogs/scoreId.ts +35 -36
  103. package/src/ui/dialogs/scoreView.ts +42 -42
  104. package/src/ui/dialogs/slur.ts +308 -310
  105. package/src/ui/dialogs/slurVue.ts +91 -91
  106. package/src/ui/dialogs/staffGroup.ts +112 -112
  107. package/src/ui/dialogs/tabNote.ts +84 -84
  108. package/src/ui/dialogs/tabStave.ts +182 -182
  109. package/src/ui/dialogs/tempo.ts +261 -263
  110. package/src/ui/dialogs/tempoVue.ts +73 -73
  111. package/src/ui/dialogs/textBlockVue.ts +127 -127
  112. package/src/ui/dialogs/textBracket.ts +114 -116
  113. package/src/ui/dialogs/textBracketVue.ts +56 -56
  114. package/src/ui/dialogs/tie.ts +140 -142
  115. package/src/ui/dialogs/timeSignature.ts +65 -66
  116. package/src/ui/dialogs/transposeScore.ts +39 -39
  117. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  118. package/src/ui/dialogs/volta.ts +120 -122
  119. package/src/ui/dialogs/voltaVue.ts +51 -51
  120. package/src/ui/fileio/library.ts +110 -111
  121. package/src/ui/menus/edit.ts +100 -1
  122. package/src/ui/menus/file.ts +19 -3
  123. package/tests/pageDivisions.ts +156 -0
  124. package/tests/promiseHelpersUsage.ts +142 -0
  125. package/tests/scoreChangeState.ts +102 -0
  126. package/tests/selectVoice.ts +189 -0
  127. package/tests/voiceCopyPaste.ts +417 -0
@@ -1,7 +1,5 @@
1
1
  // [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
2
2
  // Copyright (c) Aaron David Newman 2021.
3
- import { SuiRenderState } from "../render/sui/renderState";
4
-
5
3
  export type promiseFunction = () => void;
6
4
  export type promiseCondition = () => boolean;
7
5
  export type promiseInstance = () => Promise<any>;
@@ -22,6 +20,8 @@ export function TEmptyPromise<T>(obj: T): Promise<T> {
22
20
  });
23
21
  }
24
22
  /**
23
+ * Helpers from before async/await was available. The application itself no longer uses
24
+ * them; this class is kept, unchanged, for external applications that call it.
25
25
  * @internal
26
26
  */
27
27
  export class PromiseHelpers {
@@ -1,118 +1,117 @@
1
- // [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
2
- // Copyright (c) Aaron David Newman 2021.
3
- import { SmoAudioPitch } from '../../smo/data/music';
4
- import { PromiseHelpers } from '../../common/promiseHelpers';
5
- import { Ref } from 'vue';
6
- import { SmoOscillatorInfo, SmoInstrument, SmoOscillatorInfoAllTypes,
7
- SmoOscillatorInfoNumberType, SmoOscillatorInfoNumberArType, SmoOscillatorInfoStringType, SmoOscillatorInfoStringNullType,
8
- SmoOscillatorInfoWaveformType, SmoOscillatorInfoSustainType, SmoOscillatorInfoOptionsType } from '../../smo/data/staffModifiers';
9
- import {
10
- getSoundfontKits,
11
- Soundfont,
12
- getSoundfontNames,
13
- Reverb,
14
- Soundfont2Sampler,
15
- } from 'smplr';
16
-
17
- export const instrumentSampleMap: Record<string, string> = {
18
- 'piano':'acoustic_grand_piano',
19
- 'accordion': 'accordion',
20
- 'electricPiano':'electric_piano_1',
21
- 'bass':'acoustic_bass',
22
- 'jazzBass': 'electric_bass_finger',
23
- 'eGuitar': 'electric_guitar_jazz',
24
- 'cello': 'cello',
25
- 'violin': 'violin',
26
- 'trumpet':'trumpet',
27
- 'horn': 'french_horn',
28
- 'trombone':'trombone',
29
- 'tuba': 'tuba',
30
- 'clarinet':'clarinet',
31
- 'flute':'flute',
32
- 'altoSax':'alto_sax',
33
- 'tenorSax':'tenor_sax',
34
- 'bariSax':'baritone_sax',
35
- 'pad': 'pad_3_polysynth',
36
- 'percussion':'timpani'
37
- };
38
- export const loadedSoundfonts: Record<string, Soundfont> = {};
39
-
40
- /**
41
- * A set of parameters from the instrument interface used to create audio from samples.
42
- * @category SuiAudio
43
- */
44
- export interface SampleChooserParams {
45
- family?: string,
46
- instrument: string,
47
- frequency: number,
48
- duration: number,
49
- gain: number,
50
- articulation?: string
51
- }
52
- /**
53
- * A function prototype that chooses from among samples to return the correct one for that note
54
- */
55
- export type SampleChooser = (params: SampleChooserParams, samples: SmoOscillatorInfo[]) => AudioSample | null;
56
- /**
57
- * A specific audio sample that can be converted into an audio node
58
- * @category SuiAudio
59
- */
60
- export interface AudioSample {
61
- sample: AudioBuffer,
62
- frequency: number,
63
- patch: string,
64
- gain: number
65
- }
66
- /**
67
- * Interface for a chooser function and a set of samples
68
- * @category SuiAudio
69
- */
70
- export interface InstrumentSampleChooser {
71
- instrument: string,
72
- sampleChooser: SampleChooser,
73
- samples: SmoOscillatorInfo[]
74
- }
75
-
76
- /**
77
- * Logic to create audio nodes out of HTML5 media elements
78
- * @category SuiAudio
79
- */
80
- export class SuiSampleMedia {
81
- static sampleFiles: SmoOscillatorInfo[] = [];
82
- static sampleBufferMap: Record<string, AudioBuffer> = {};
83
- static sampleOscMap: Record<string, SmoOscillatorInfo[]> = {};
84
- static instrumentChooser: Record<string, InstrumentSampleChooser> = {};
85
- static receivedBuffer: boolean = false;
86
- static getFamilyForInstrument(instKey: string): string {
87
- const sound = SuiSampleMedia.instrumentChooser[instKey];
88
- if (sound && sound.samples.length) {
89
- return sound.samples[0].family;
90
- }
91
- return 'keyboard';
92
- }
93
- /**
94
- * Load samples so we can play the music
95
- * @returns - promise, resolved when loaded
96
- */
97
- static async samplePromise(audio: AudioContext, setProgress: (percent: number) => void): Promise<any> {
98
- let i = 0;
99
- const instrumentKeys = Object.keys(instrumentSampleMap);
100
- const context = new AudioContext() as unknown as AudioContext;
101
- for (let i = 0; i < instrumentKeys.length; ++i) {
102
- const key = instrumentKeys[i];
103
- const sampler = instrumentSampleMap[key];
104
- const obj: any = {};
105
- if (key === 'percussion') {
106
- obj['instrumentUrl'] = 'https://smoosic.github.io/SmoSounds/drumfont/percussion-ogg.js';
107
- } else {
108
- obj['instrument'] = sampler;
109
- }
110
- const instrument = new Soundfont(context, obj);
111
- // instrument.output.addEffect("reverb", new Reverb(context), 0.9);
112
- await instrument.load;
113
- instrument.output.addEffect("reverb", new Reverb(context), 0.1);
114
- loadedSoundfonts[key] = instrument;
115
- setProgress(Math.round(((i + 1) / instrumentKeys.length) * 100));
116
- }
117
- }
118
- }
1
+ // [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
2
+ // Copyright (c) Aaron David Newman 2021.
3
+ import { SmoAudioPitch } from '../../smo/data/music';
4
+ import { Ref } from 'vue';
5
+ import { SmoOscillatorInfo, SmoInstrument, SmoOscillatorInfoAllTypes,
6
+ SmoOscillatorInfoNumberType, SmoOscillatorInfoNumberArType, SmoOscillatorInfoStringType, SmoOscillatorInfoStringNullType,
7
+ SmoOscillatorInfoWaveformType, SmoOscillatorInfoSustainType, SmoOscillatorInfoOptionsType } from '../../smo/data/staffModifiers';
8
+ import {
9
+ getSoundfontKits,
10
+ Soundfont,
11
+ getSoundfontNames,
12
+ Reverb,
13
+ Soundfont2Sampler,
14
+ } from 'smplr';
15
+
16
+ export const instrumentSampleMap: Record<string, string> = {
17
+ 'piano':'acoustic_grand_piano',
18
+ 'accordion': 'accordion',
19
+ 'electricPiano':'electric_piano_1',
20
+ 'bass':'acoustic_bass',
21
+ 'jazzBass': 'electric_bass_finger',
22
+ 'eGuitar': 'electric_guitar_jazz',
23
+ 'cello': 'cello',
24
+ 'violin': 'violin',
25
+ 'trumpet':'trumpet',
26
+ 'horn': 'french_horn',
27
+ 'trombone':'trombone',
28
+ 'tuba': 'tuba',
29
+ 'clarinet':'clarinet',
30
+ 'flute':'flute',
31
+ 'altoSax':'alto_sax',
32
+ 'tenorSax':'tenor_sax',
33
+ 'bariSax':'baritone_sax',
34
+ 'pad': 'pad_3_polysynth',
35
+ 'percussion':'timpani'
36
+ };
37
+ export const loadedSoundfonts: Record<string, Soundfont> = {};
38
+
39
+ /**
40
+ * A set of parameters from the instrument interface used to create audio from samples.
41
+ * @category SuiAudio
42
+ */
43
+ export interface SampleChooserParams {
44
+ family?: string,
45
+ instrument: string,
46
+ frequency: number,
47
+ duration: number,
48
+ gain: number,
49
+ articulation?: string
50
+ }
51
+ /**
52
+ * A function prototype that chooses from among samples to return the correct one for that note
53
+ */
54
+ export type SampleChooser = (params: SampleChooserParams, samples: SmoOscillatorInfo[]) => AudioSample | null;
55
+ /**
56
+ * A specific audio sample that can be converted into an audio node
57
+ * @category SuiAudio
58
+ */
59
+ export interface AudioSample {
60
+ sample: AudioBuffer,
61
+ frequency: number,
62
+ patch: string,
63
+ gain: number
64
+ }
65
+ /**
66
+ * Interface for a chooser function and a set of samples
67
+ * @category SuiAudio
68
+ */
69
+ export interface InstrumentSampleChooser {
70
+ instrument: string,
71
+ sampleChooser: SampleChooser,
72
+ samples: SmoOscillatorInfo[]
73
+ }
74
+
75
+ /**
76
+ * Logic to create audio nodes out of HTML5 media elements
77
+ * @category SuiAudio
78
+ */
79
+ export class SuiSampleMedia {
80
+ static sampleFiles: SmoOscillatorInfo[] = [];
81
+ static sampleBufferMap: Record<string, AudioBuffer> = {};
82
+ static sampleOscMap: Record<string, SmoOscillatorInfo[]> = {};
83
+ static instrumentChooser: Record<string, InstrumentSampleChooser> = {};
84
+ static receivedBuffer: boolean = false;
85
+ static getFamilyForInstrument(instKey: string): string {
86
+ const sound = SuiSampleMedia.instrumentChooser[instKey];
87
+ if (sound && sound.samples.length) {
88
+ return sound.samples[0].family;
89
+ }
90
+ return 'keyboard';
91
+ }
92
+ /**
93
+ * Load samples so we can play the music
94
+ * @returns - promise, resolved when loaded
95
+ */
96
+ static async samplePromise(audio: AudioContext, setProgress: (percent: number) => void): Promise<any> {
97
+ let i = 0;
98
+ const instrumentKeys = Object.keys(instrumentSampleMap);
99
+ const context = new AudioContext() as unknown as AudioContext;
100
+ for (let i = 0; i < instrumentKeys.length; ++i) {
101
+ const key = instrumentKeys[i];
102
+ const sampler = instrumentSampleMap[key];
103
+ const obj: any = {};
104
+ if (key === 'percussion') {
105
+ obj['instrumentUrl'] = 'https://smoosic.github.io/SmoSounds/drumfont/percussion-ogg.js';
106
+ } else {
107
+ obj['instrument'] = sampler;
108
+ }
109
+ const instrument = new Soundfont(context, obj);
110
+ // instrument.output.addEffect("reverb", new Reverb(context), 0.9);
111
+ await instrument.load;
112
+ instrument.output.addEffect("reverb", new Reverb(context), 0.1);
113
+ loadedSoundfonts[key] = instrument;
114
+ setProgress(Math.round(((i + 1) / instrumentKeys.length) * 100));
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,58 @@
1
+ // [Smoosic](https://github.com/AaronDavidNewman/Smoosic)
2
+ // Copyright (c) Aaron David Newman 2021.
3
+ /**
4
+ * Pure helpers that split a page into contiguous divisions along its flow dimension, and find
5
+ * the division that contains a position. SvgPage uses them to file and look up modifiers.
6
+ * This module has no imports so it can be tested without a DOM or VexFlow.
7
+ * @module /render/sui/pageDivisions
8
+ */
9
+
10
+ /**
11
+ * A band of a page. A division contains positions from `start` (inclusive) to `end`
12
+ * (exclusive), except the last division of a page, which also contains `end`.
13
+ * @category SuiRender
14
+ */
15
+ export interface PageDivision {
16
+ start: number,
17
+ end: number
18
+ }
19
+
20
+ /**
21
+ * Split `[pageStart, pageStart + pageExtent]` into `count` contiguous divisions. Each division
22
+ * ends exactly where the next begins, and the last ends exactly at the page edge.
23
+ * @param pageStart position of the leading edge of the page
24
+ * @param pageExtent size of the page along the flow dimension
25
+ * @param count number of divisions
26
+ * @returns the divisions, in increasing order
27
+ */
28
+ export function computeDivisions(pageStart: number, pageExtent: number, count: number): PageDivision[] {
29
+ const rv: PageDivision[] = [];
30
+ const edge = (i: number) => (i === count ? pageStart + pageExtent : pageStart + (pageExtent * i) / count);
31
+ for (let i = 0; i < count; ++i) {
32
+ rv.push({ start: edge(i), end: edge(i + 1) });
33
+ }
34
+ return rv;
35
+ }
36
+
37
+ /**
38
+ * Find the division containing `position`. A position on a boundary between two divisions
39
+ * belongs to the later one; the page's trailing edge belongs to the last division.
40
+ * @param position position along the flow dimension
41
+ * @param divisions the page's divisions, from {@link computeDivisions}
42
+ * @returns the index of the division, or -1 if the position is outside the page
43
+ */
44
+ export function findDivision(position: number, divisions: PageDivision[]): number {
45
+ if (!Number.isFinite(position) || divisions.length === 0) {
46
+ return -1;
47
+ }
48
+ const last = divisions.length - 1;
49
+ if (position < divisions[0].start || position > divisions[last].end) {
50
+ return -1;
51
+ }
52
+ for (let i = 0; i < last; ++i) {
53
+ if (position < divisions[i].end) {
54
+ return i;
55
+ }
56
+ }
57
+ return last;
58
+ }