notula 0.0.0-stage → 0.8.0

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 (81) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -2
  4. package/README.zh-CN.md +216 -0
  5. package/THIRD_PARTY_NOTICES.md +50 -0
  6. package/assets/fonts/OFL.txt +94 -0
  7. package/dist-lib/analyze-DJ6p6BkU.js +2 -0
  8. package/dist-lib/analyze-DJ6p6BkU.js.map +1 -0
  9. package/dist-lib/audio/browser-fetch.d.ts +2 -0
  10. package/dist-lib/audio/felt-piano.d.ts +8 -0
  11. package/dist-lib/audio/highlight.d.ts +14 -0
  12. package/dist-lib/audio/index.d.ts +10 -0
  13. package/dist-lib/audio/player.d.ts +70 -0
  14. package/dist-lib/audio/sampled-piano.d.ts +31 -0
  15. package/dist-lib/audio/timeline.d.ts +45 -0
  16. package/dist-lib/audio.js +2 -0
  17. package/dist-lib/audio.js.map +1 -0
  18. package/dist-lib/core/color.d.ts +1 -0
  19. package/dist-lib/core/number.d.ts +2 -0
  20. package/dist-lib/core/rational.d.ts +20 -0
  21. package/dist-lib/core/text.d.ts +1 -0
  22. package/dist-lib/dsl/ast.d.ts +295 -0
  23. package/dist-lib/dsl/lexer.d.ts +115 -0
  24. package/dist-lib/dsl/parser.d.ts +7 -0
  25. package/dist-lib/highlight-B88FnJNW.js +2 -0
  26. package/dist-lib/highlight-B88FnJNW.js.map +1 -0
  27. package/dist-lib/index-D4SDrvs8.js +2 -0
  28. package/dist-lib/index-D4SDrvs8.js.map +1 -0
  29. package/dist-lib/index.d.ts +16 -0
  30. package/dist-lib/index.js +2 -0
  31. package/dist-lib/index.js.map +1 -0
  32. package/dist-lib/integrations/index.d.ts +1 -0
  33. package/dist-lib/integrations/markdown-dom.d.ts +8 -0
  34. package/dist-lib/integrations/markdown.d.ts +45 -0
  35. package/dist-lib/integrations/obsidian-child.d.ts +16 -0
  36. package/dist-lib/integrations/obsidian-playback.d.ts +19 -0
  37. package/dist-lib/integrations/obsidian.d.ts +86 -0
  38. package/dist-lib/integrations/panorama-scroll.d.ts +7 -0
  39. package/dist-lib/integrations/resize.d.ts +6 -0
  40. package/dist-lib/integrations.js +2 -0
  41. package/dist-lib/integrations.js.map +1 -0
  42. package/dist-lib/ir/analyze.d.ts +13 -0
  43. package/dist-lib/ir/types.d.ts +263 -0
  44. package/dist-lib/layout/accidentals.d.ts +20 -0
  45. package/dist-lib/layout/annotations.d.ts +163 -0
  46. package/dist-lib/layout/articulations.d.ts +93 -0
  47. package/dist-lib/layout/beaming.d.ts +92 -0
  48. package/dist-lib/layout/grace.d.ts +33 -0
  49. package/dist-lib/layout/layout.d.ts +3 -0
  50. package/dist-lib/layout/polyphony.d.ts +20 -0
  51. package/dist-lib/layout/spacing.d.ts +38 -0
  52. package/dist-lib/layout/staff.d.ts +60 -0
  53. package/dist-lib/layout/stems-chords.d.ts +59 -0
  54. package/dist-lib/layout/systems.d.ts +31 -0
  55. package/dist-lib/layout/ties-slurs.d.ts +59 -0
  56. package/dist-lib/layout/tuplets.d.ts +25 -0
  57. package/dist-lib/layout/types.d.ts +210 -0
  58. package/dist-lib/metrics/bravura-glyph-paths.d.ts +9 -0
  59. package/dist-lib/metrics/bravura-metrics.d.ts +52 -0
  60. package/dist-lib/micro/micro.d.ts +33 -0
  61. package/dist-lib/obsidian.js +2 -0
  62. package/dist-lib/obsidian.js.map +1 -0
  63. package/dist-lib/render.d.ts +20 -0
  64. package/dist-lib/shared.d.ts +8 -0
  65. package/dist-lib/svg/dom.d.ts +4 -0
  66. package/dist-lib/svg/emitter.d.ts +56 -0
  67. package/docs/INTEGRATIONS.md +200 -0
  68. package/docs/SYNTAX.md +74 -0
  69. package/docs/assets/cadenza-dark.svg +497 -0
  70. package/docs/assets/cadenza-light.svg +497 -0
  71. package/docs/assets/chords-dark.svg +695 -0
  72. package/docs/assets/chords-light.svg +695 -0
  73. package/docs/assets/hero-dark.svg +498 -0
  74. package/docs/assets/hero-light.svg +498 -0
  75. package/docs/assets/logo-dark.svg +12 -0
  76. package/docs/assets/logo-light.svg +12 -0
  77. package/docs/assets/wordmark-dark.svg +41 -0
  78. package/docs/assets/wordmark-light.svg +41 -0
  79. package/examples/obsidian-plugin/README.md +43 -0
  80. package/llms.txt +141 -0
  81. package/package.json +94 -4
@@ -0,0 +1,2 @@
1
+ import type { SampleFetcher } from './sampled-piano.js';
2
+ export declare const browserSampleFetcher: SampleFetcher;
@@ -0,0 +1,8 @@
1
+ import type { AudioNoteEvent } from './timeline.js';
2
+ export interface FeltMasterBus {
3
+ readonly input: AudioNode;
4
+ readonly masterGain: GainNode;
5
+ readonly compressor: DynamicsCompressorNode;
6
+ }
7
+ export declare function buildFeltMasterBus(ctx: AudioContext, volume: number): FeltMasterBus;
8
+ export declare function scheduleFeltNote(ctx: AudioContext, dest: AudioNode, startTime: number, ev: AudioNoteEvent, rate: number, durationSec: number, safeVel: number, activeNodes: AudioScheduledSourceNode[]): void;
@@ -0,0 +1,14 @@
1
+ export interface PlaybackHighlightOptions {
2
+ readonly className?: string;
3
+ }
4
+ export interface PlaybackHighlightController {
5
+ update(activeEventIds: readonly string[]): void;
6
+ onActiveEvents(activeEventIds: readonly string[], elapsedSec: number): void;
7
+ onEvent(activeEventIds: readonly string[], elapsedSec: number): void;
8
+ onEnd(): void;
9
+ clear(): void;
10
+ dispose(): void;
11
+ }
12
+ export declare function attachPlaybackHighlight(root: {
13
+ querySelectorAll(sel: string): Iterable<Element> | ArrayLike<Element>;
14
+ }, options?: PlaybackHighlightOptions): PlaybackHighlightController;
@@ -0,0 +1,10 @@
1
+ import type { ScoreIR } from '../ir/types.js';
2
+ import { NotulaPlayer as TransportFreeNotulaPlayer, type AudioPlayerOptions, type AudioSoundMode, type AudioSoundState, type AudioVoiceBackend, type AudioVoiceNote } from './player.js';
3
+ export { buildPlaybackTimeline, midiToFrequency, type AudioNoteEvent, type GainContourPoint, type PlaybackTimeline, type PlaybackVisualSpan, type TimelineOptions, } from './timeline.js';
4
+ export { type AudioPlayerOptions, type AudioSoundMode, type AudioSoundState, type AudioVoiceBackend, type AudioVoiceNote, };
5
+ export { DEFAULT_SAMPLE_BASE_URL, type SampleFetcher, type SampleFetchResult, } from './sampled-piano.js';
6
+ export * from './highlight.js';
7
+ export declare class NotulaPlayer extends TransportFreeNotulaPlayer {
8
+ constructor(audioContext?: AudioContext);
9
+ }
10
+ export declare function playScore(scoreOrDsl: ScoreIR | string, options?: AudioPlayerOptions): NotulaPlayer;
@@ -0,0 +1,70 @@
1
+ import type { ScoreIR } from '../ir/types.js';
2
+ import { type PlaybackTimeline } from './timeline.js';
3
+ import { type SampleFetcher } from './sampled-piano.js';
4
+ export type AudioSoundMode = 'grand' | 'felt';
5
+ export type AudioSoundState = 'loading' | 'grand' | 'fallback' | 'felt';
6
+ export interface AudioVoiceNote {
7
+ readonly midi: number;
8
+ readonly frequencyHz: number;
9
+ readonly startTime: number;
10
+ readonly durationSec: number;
11
+ readonly velocity: number;
12
+ readonly sustainVelocity?: number;
13
+ readonly isGrace?: boolean;
14
+ }
15
+ export interface AudioVoiceBackend {
16
+ /** Route all voices to the session mixer when the instrument has one shared output. */
17
+ readonly sharedOutput?: boolean;
18
+ noteOn(ctx: AudioContext, dest: AudioNode, note: AudioVoiceNote): void;
19
+ stopAll?(ctx: AudioContext): void;
20
+ dispose?(): void;
21
+ }
22
+ export interface AudioPlayerOptions {
23
+ readonly bpm?: number;
24
+ readonly playbackRate?: number;
25
+ readonly expandRepeats?: boolean;
26
+ readonly sound?: AudioSoundMode;
27
+ readonly waveform?: 'piano' | 'triangle' | 'sine';
28
+ readonly volume?: number;
29
+ readonly backend?: AudioVoiceBackend;
30
+ readonly sampleBaseUrl?: string;
31
+ readonly sampleFetcher?: SampleFetcher;
32
+ readonly sampleTimeoutMs?: number;
33
+ readonly onSoundState?: (state: AudioSoundState) => void;
34
+ readonly onEvent?: (activeEventIds: readonly string[], elapsedSec: number) => void;
35
+ readonly onActiveEvents?: (activeEventIds: readonly string[], elapsedSec: number) => void;
36
+ readonly onEnd?: () => void;
37
+ }
38
+ export declare class NotulaPlayer {
39
+ private readonly audioContext?;
40
+ private readonly defaultSampleFetcher?;
41
+ private ctx;
42
+ private callerBackend?;
43
+ private sessionBackend?;
44
+ private masterGain;
45
+ private activeNodes;
46
+ private rafId;
47
+ private pollTimer;
48
+ private resumeTimer;
49
+ private pendingLoad;
50
+ private playing;
51
+ private disposing;
52
+ private sessionId;
53
+ private activeCallback;
54
+ private baseStart;
55
+ private playbackRate;
56
+ private lastElapsedSec;
57
+ private lastTotalDurationSec;
58
+ private prevActiveKey;
59
+ /** An optional caller-owned context can be shared with a sampled instrument. */
60
+ constructor(audioContext?: AudioContext | undefined, defaultSampleFetcher?: SampleFetcher | undefined);
61
+ isPlaying(): boolean;
62
+ play(scoreOrDsl: ScoreIR | string, options?: AudioPlayerOptions): PlaybackTimeline;
63
+ stop(): void;
64
+ dispose(): void;
65
+ private resetState;
66
+ private stopInternal;
67
+ private clearClockLoops;
68
+ private scheduleNote;
69
+ }
70
+ export declare function playScore(scoreOrDsl: ScoreIR | string, options?: AudioPlayerOptions): NotulaPlayer;
@@ -0,0 +1,31 @@
1
+ import type { AudioVoiceBackend } from './player.js';
2
+ export interface SampleFetchResult {
3
+ readonly status: number;
4
+ readonly contentType?: string;
5
+ readonly arrayBuffer: () => Promise<ArrayBuffer>;
6
+ }
7
+ export type SampleFetcher = (url: string, signal?: AbortSignal) => Promise<SampleFetchResult>;
8
+ export declare const DEFAULT_SAMPLE_BASE_URL = "https://smpldsnds.github.io/sfzinstruments-splendid-grand-piano/samples";
9
+ interface SampleSpec {
10
+ readonly name: string;
11
+ readonly sampleMidi: number;
12
+ readonly playbackRate: number;
13
+ readonly cutoffHz?: number;
14
+ }
15
+ export declare function normalizeSampleBaseUrl(baseUrl?: string): string;
16
+ export declare function isSamplePlaybackSupported(ctx: AudioContext): boolean;
17
+ export declare function isSampledPianoUnavailable(baseUrl: string, fetcher: SampleFetcher): boolean;
18
+ export declare function resolveSampleSpec(midi: number, velocity: number): SampleSpec;
19
+ export interface PrepareSampledPianoOptions {
20
+ readonly baseUrl: string;
21
+ readonly fetcher: SampleFetcher;
22
+ readonly timeoutMs: number;
23
+ readonly signal: AbortSignal;
24
+ }
25
+ export interface PlannedSampleNote {
26
+ readonly midi: number;
27
+ readonly velocity: number;
28
+ }
29
+ export declare function prepareSampledPiano(ctx: AudioContext, notes: readonly PlannedSampleNote[], options: PrepareSampledPianoOptions): Promise<AudioVoiceBackend>;
30
+ export declare function clearSampledPianoStateForTest(): void;
31
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { ScoreIR } from '../ir/types.js';
2
+ export interface GainContourPoint {
3
+ readonly offsetSec: number;
4
+ readonly multiplier: number;
5
+ }
6
+ export interface AudioNoteEvent {
7
+ readonly eventId: string;
8
+ readonly staffId: string;
9
+ readonly voiceId: string;
10
+ readonly midi: number;
11
+ readonly frequencyHz: number;
12
+ readonly startSec: number;
13
+ readonly durationSec: number;
14
+ readonly velocity: number;
15
+ readonly sustainVelocity?: number;
16
+ readonly gainContour?: readonly GainContourPoint[];
17
+ readonly isGrace: boolean;
18
+ readonly expression?: {
19
+ readonly downbeat: boolean;
20
+ readonly blockChord: boolean;
21
+ };
22
+ }
23
+ export interface PlaybackVisualSpan {
24
+ readonly eventId: string;
25
+ readonly startSec: number;
26
+ readonly endSec: number;
27
+ readonly staffId: string;
28
+ readonly voiceId: string;
29
+ readonly isGrace: boolean;
30
+ }
31
+ export interface PlaybackTimeline {
32
+ readonly bpm: number;
33
+ readonly totalDurationSec: number;
34
+ readonly events: readonly AudioNoteEvent[];
35
+ readonly visualSpans: readonly PlaybackVisualSpan[];
36
+ }
37
+ export interface TimelineOptions {
38
+ readonly bpm?: number;
39
+ readonly expandRepeats?: boolean;
40
+ }
41
+ export declare const MAX_PLAYBACK_OCCURRENCES = 512;
42
+ export declare const MIN_NOTE_DURATION_SEC = 0.004;
43
+ export declare const MAX_TREMOLO_SLICES = 64;
44
+ export declare function midiToFrequency(midi: number): number;
45
+ export declare function buildPlaybackTimeline(ir: ScoreIR, options?: TimelineOptions): PlaybackTimeline;
@@ -0,0 +1,2 @@
1
+ import{N as a}from"./highlight-B88FnJNW.js";import{D as t,a as r,b as e,m as s}from"./highlight-B88FnJNW.js";const o=async(a,t)=>{var r,e;const s=globalThis.fetch;if("function"!=typeof s)throw new Error("Fetch API is unavailable");const o=await s(a,{signal:t,credentials:"omit",referrerPolicy:"no-referrer"});return{status:o.status,contentType:(null==(e=null==(r=o.headers)?void 0:r.get)?void 0:e.call(r,"content-type"))??void 0,arrayBuffer:()=>o.arrayBuffer()}};class i extends a{constructor(a){super(a,o)}}function n(a,t={}){const r=new i;return r.play(a,t),r}export{t as DEFAULT_SAMPLE_BASE_URL,i as NotulaPlayer,r as attachPlaybackHighlight,e as buildPlaybackTimeline,s as midiToFrequency,n as playScore};
2
+ //# sourceMappingURL=audio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio.js","sources":["../src/audio/browser-fetch.ts","../src/audio/index.ts"],"sourcesContent":["import type { SampleFetcher } from './sampled-piano.js';\n\nexport const browserSampleFetcher: SampleFetcher = async (url, signal) => {\n const fetchFn = globalThis.fetch;\n if (typeof fetchFn !== 'function') {\n throw new Error('Fetch API is unavailable');\n }\n const response = await fetchFn(url, {\n signal,\n credentials: 'omit',\n referrerPolicy: 'no-referrer',\n });\n return {\n status: response.status,\n contentType: response.headers?.get?.('content-type') ?? undefined,\n arrayBuffer: () => response.arrayBuffer(),\n };\n};\n","import type { ScoreIR } from '../ir/types.js';\nimport { browserSampleFetcher } from './browser-fetch.js';\nimport {\n NotulaPlayer as TransportFreeNotulaPlayer,\n type AudioPlayerOptions,\n type AudioSoundMode,\n type AudioSoundState,\n type AudioVoiceBackend,\n type AudioVoiceNote,\n} from './player.js';\n\nexport {\n buildPlaybackTimeline,\n midiToFrequency,\n type AudioNoteEvent,\n type GainContourPoint,\n type PlaybackTimeline,\n type PlaybackVisualSpan,\n type TimelineOptions,\n} from './timeline.js';\nexport {\n type AudioPlayerOptions,\n type AudioSoundMode,\n type AudioSoundState,\n type AudioVoiceBackend,\n type AudioVoiceNote,\n};\nexport {\n DEFAULT_SAMPLE_BASE_URL,\n type SampleFetcher,\n type SampleFetchResult,\n} from './sampled-piano.js';\nexport * from './highlight.js';\n\nexport class NotulaPlayer extends TransportFreeNotulaPlayer {\n constructor(audioContext?: AudioContext) {\n super(audioContext, browserSampleFetcher);\n }\n}\n\nexport function playScore(\n scoreOrDsl: ScoreIR | string,\n options: AudioPlayerOptions = {},\n): NotulaPlayer {\n const player = new NotulaPlayer();\n player.play(scoreOrDsl, options);\n return player;\n}\n"],"names":["browserSampleFetcher","async","url","signal","fetchFn","globalThis","fetch","Error","response","credentials","referrerPolicy","status","contentType","_b","_a","headers","get","call","arrayBuffer","NotulaPlayer","TransportFreeNotulaPlayer","constructor","audioContext","super","playScore","scoreOrDsl","options","player","play","p","s","h","m","b","i"],"mappings":"6GAEO,MAAMA,EAAsCC,MAAOC,EAAKC,aAC7D,MAAMC,EAAUC,WAAWC,MAC3B,GAAuB,mBAAZF,EACT,MAAM,IAAIG,MAAM,4BAElB,MAAMC,QAAiBJ,EAAQF,EAAK,CAClCC,OAAAA,EACAM,YAAa,OACbC,eAAgB,gBAElB,MAAO,CACLC,OAAQH,EAASG,OACjBC,aAAa,OAAAC,EAAA,OAAAC,EAAAN,EAASO,cAAT,EAAAD,EAAkBE,UAAlB,EAAAH,EAAAI,KAAAH,EAAwB,uBAAmB,EACxDI,YAAa,IAAMV,EAASU,gBCmBzB,MAAMC,UAAqBC,EAChC,WAAAC,CAAYC,GACVC,MAAMD,EAActB,EACtB,EAGK,SAASwB,EACdC,EACAC,EAA8B,IAE9B,MAAMC,EAAS,IAAIR,EACnB,OAAAQ,EAAOC,KAAKH,EAAYC,GACjBC,CACT,QAAAE,6BAAAC,kBAAAC,6BAAAC,2BAAAC,qBAAAC"}
@@ -0,0 +1 @@
1
+ export declare function isSafeCssColor(value: unknown): value is string;
@@ -0,0 +1,2 @@
1
+ export declare function clamp(value: number, min: number, max: number): number;
2
+ export declare function clampFinite(value: number | undefined, min: number, max: number): number | undefined;
@@ -0,0 +1,20 @@
1
+ export interface Rational {
2
+ readonly num: number;
3
+ readonly den: number;
4
+ }
5
+ export declare function tryRational(num: number, den?: number): Rational | null;
6
+ export declare function rational(num: number, den?: number): Rational;
7
+ export declare const ZERO: Rational;
8
+ export declare const ONE: Rational;
9
+ export declare function tryAdd(a: Rational, b: Rational): Rational | null;
10
+ export declare function add(a: Rational, b: Rational): Rational;
11
+ export declare function trySub(a: Rational, b: Rational): Rational | null;
12
+ export declare function sub(a: Rational, b: Rational): Rational;
13
+ export declare function tryMul(a: Rational, b: Rational): Rational | null;
14
+ export declare function mul(a: Rational, b: Rational): Rational;
15
+ export declare function div(a: Rational, b: Rational): Rational;
16
+ export declare function cmp(a: Rational, b: Rational): -1 | 0 | 1;
17
+ export declare function eq(a: Rational, b: Rational): boolean;
18
+ export declare function minR(a: Rational, b: Rational): Rational;
19
+ export declare function maxR(a: Rational, b: Rational): Rational;
20
+ export declare function toNumber(r: Rational): number;
@@ -0,0 +1 @@
1
+ export declare function sanitizeXmlChars(str: string): string;
@@ -0,0 +1,295 @@
1
+ export interface Position {
2
+ readonly line: number;
3
+ readonly column: number;
4
+ readonly offset: number;
5
+ }
6
+ export interface Span {
7
+ readonly start: Position;
8
+ readonly end: Position;
9
+ }
10
+ export interface Diagnostic {
11
+ readonly severity: 'error' | 'warning';
12
+ readonly code: string;
13
+ readonly message: string;
14
+ readonly span: Span;
15
+ }
16
+ export type PitchLetter = 'c' | 'd' | 'e' | 'f' | 'g' | 'a' | 'b';
17
+ export type Alteration = -2 | -1 | 0 | 1 | 2;
18
+ export type ClefName = 'treble' | 'treble_8' | 'treble^8' | 'bass' | 'bass_8' | 'bass^8' | 'alto' | 'tenor';
19
+ export type BarlineKind = '|' | '||' | '|.' | '|:' | ':|' | ':|:';
20
+ export type BaseDurationDen = 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128;
21
+ export type FingeringDigit = 0 | 1 | 2 | 3 | 4 | 5;
22
+ export type TimeSignatureSymbol = 'numeric' | 'common' | 'cut';
23
+ export type ArticulationKind = 'staccato' | 'tenuto' | 'accent' | 'marcato' | 'fermata';
24
+ export type OrnamentKind = 'trill' | 'prall' | 'mordent' | 'turn';
25
+ export type PedalKind = 'on' | 'off';
26
+ export type ArpeggioKind = 'normal' | 'up' | 'down';
27
+ export type BreathMarkKind = 'comma' | 'caesura';
28
+ export type TremoloDiv = 8 | 16 | 32;
29
+ export type OttavaShift = -1 | 0 | 1;
30
+ export type MarkPlacement = 'auto' | 'above' | 'below';
31
+ export type DynamicKind = 'ppp' | 'pp' | 'p' | 'mp' | 'mf' | 'f' | 'ff' | 'fff' | 'sf' | 'sfz' | 'sffff' | 'fp';
32
+ export type HairpinKind = 'cresc' | 'dim' | 'stop';
33
+ export interface HairpinMarkAst {
34
+ readonly kind: HairpinKind;
35
+ readonly placement: MarkPlacement;
36
+ readonly span: Span;
37
+ }
38
+ export interface ArticulationAst {
39
+ readonly kind: ArticulationKind;
40
+ readonly placement: MarkPlacement;
41
+ readonly span: Span;
42
+ }
43
+ export interface OrnamentAst {
44
+ readonly kind: OrnamentKind;
45
+ readonly placement: MarkPlacement;
46
+ readonly span: Span;
47
+ }
48
+ export interface PedalMarkAst {
49
+ readonly kind: PedalKind;
50
+ readonly span: Span;
51
+ }
52
+ export interface ArpeggioAst {
53
+ readonly kind: ArpeggioKind;
54
+ readonly span: Span;
55
+ }
56
+ export interface BreathMarkAst {
57
+ readonly kind: BreathMarkKind;
58
+ readonly span: Span;
59
+ }
60
+ export interface TremoloAst {
61
+ readonly kind: TremoloDiv;
62
+ readonly span: Span;
63
+ }
64
+ export interface DynamicAst {
65
+ readonly kind: DynamicKind;
66
+ readonly placement: MarkPlacement;
67
+ readonly span: Span;
68
+ }
69
+ export interface FingeringAst {
70
+ readonly digit: FingeringDigit;
71
+ readonly placement: 'above' | 'below';
72
+ readonly span: Span;
73
+ }
74
+ export interface ScaleDegreeAst {
75
+ readonly degree: 1 | 2 | 3 | 4 | 5 | 6 | 7;
76
+ readonly accidental?: '#' | 'b' | 'n';
77
+ readonly placement: 'above' | 'below';
78
+ readonly span: Span;
79
+ }
80
+ export interface LeadSheetChordAst {
81
+ readonly text: string;
82
+ readonly span: Span;
83
+ }
84
+ export type BracketMarkAst = {
85
+ readonly kind: 'start';
86
+ readonly placement: 'above' | 'below';
87
+ readonly label: string;
88
+ readonly span: Span;
89
+ } | {
90
+ readonly kind: 'end';
91
+ readonly span: Span;
92
+ };
93
+ export interface ParsedLeadSheetChord {
94
+ readonly root: string;
95
+ readonly rootAccidental?: string;
96
+ readonly quality: string;
97
+ readonly bass?: string;
98
+ readonly bassAccidental?: string;
99
+ }
100
+ export declare function hasOwn(obj: object, key: PropertyKey): boolean;
101
+ export declare function parseLeadSheetChordText(raw: string): ParsedLeadSheetChord | null;
102
+ export interface AstPitch {
103
+ readonly letter: PitchLetter;
104
+ readonly alter: Alteration;
105
+ readonly octave: number;
106
+ readonly forcedAccidental?: '!' | '?';
107
+ readonly parenthesized?: true;
108
+ readonly highlight?: string;
109
+ readonly tie?: boolean;
110
+ readonly span: Span;
111
+ }
112
+ export interface AstDuration {
113
+ readonly baseDen: BaseDurationDen;
114
+ readonly dots: 0 | 1 | 2;
115
+ readonly span: Span;
116
+ }
117
+ export type DurationAst = AstDuration;
118
+ export interface TimeStatement {
119
+ readonly kind: 'time';
120
+ readonly numerator: number;
121
+ readonly denominator: number;
122
+ readonly symbol?: TimeSignatureSymbol;
123
+ readonly span: Span;
124
+ }
125
+ export interface PartialStatement {
126
+ readonly kind: 'partial';
127
+ readonly duration: DurationAst;
128
+ readonly span: Span;
129
+ }
130
+ export type AstStatement = {
131
+ readonly kind: 'clef';
132
+ readonly clef: ClefName;
133
+ readonly span: Span;
134
+ } | {
135
+ readonly kind: 'key';
136
+ readonly tonicLetter: PitchLetter;
137
+ readonly tonicAlter: Alteration;
138
+ readonly mode: 'major' | 'minor';
139
+ readonly span: Span;
140
+ } | TimeStatement | PartialStatement | {
141
+ readonly kind: 'tempo';
142
+ readonly text?: string;
143
+ readonly beatUnit?: BaseDurationDen;
144
+ readonly beatDots?: 0 | 1;
145
+ readonly bpm?: number;
146
+ readonly span: Span;
147
+ } | {
148
+ readonly kind: 'bar';
149
+ readonly barline: BarlineKind;
150
+ readonly explicit: boolean;
151
+ readonly span: Span;
152
+ } | {
153
+ readonly kind: 'note';
154
+ readonly pitch: AstPitch;
155
+ readonly duration: AstDuration | null;
156
+ readonly tie?: boolean;
157
+ readonly slurStart?: boolean;
158
+ readonly slurEnd?: boolean;
159
+ readonly highlight?: string;
160
+ readonly aboveLabels?: readonly string[];
161
+ readonly belowLabels?: readonly string[];
162
+ readonly fingerings?: readonly FingeringAst[];
163
+ readonly scaleDegrees?: readonly ScaleDegreeAst[];
164
+ readonly chordSymbol?: LeadSheetChordAst;
165
+ readonly articulations?: readonly ArticulationAst[];
166
+ readonly ornaments?: readonly OrnamentAst[];
167
+ readonly dynamics?: readonly DynamicAst[];
168
+ readonly hairpins?: readonly HairpinMarkAst[];
169
+ readonly pedals?: readonly PedalMarkAst[];
170
+ readonly arpeggios?: readonly ArpeggioAst[];
171
+ readonly breathMarks?: readonly BreathMarkAst[];
172
+ readonly tremolos?: readonly TremoloAst[];
173
+ readonly bracketMarks?: readonly BracketMarkAst[];
174
+ readonly span: Span;
175
+ } | {
176
+ readonly kind: 'rest';
177
+ readonly duration: AstDuration | null;
178
+ readonly aboveLabels?: readonly string[];
179
+ readonly belowLabels?: readonly string[];
180
+ readonly articulations?: readonly ArticulationAst[];
181
+ readonly dynamics?: readonly DynamicAst[];
182
+ readonly hairpins?: readonly HairpinMarkAst[];
183
+ readonly pedals?: readonly PedalMarkAst[];
184
+ readonly breathMarks?: readonly BreathMarkAst[];
185
+ readonly span: Span;
186
+ } | {
187
+ readonly kind: 'measureRest';
188
+ readonly aboveLabels?: readonly string[];
189
+ readonly belowLabels?: readonly string[];
190
+ readonly articulations?: readonly ArticulationAst[];
191
+ readonly dynamics?: readonly DynamicAst[];
192
+ readonly hairpins?: readonly HairpinMarkAst[];
193
+ readonly pedals?: readonly PedalMarkAst[];
194
+ readonly breathMarks?: readonly BreathMarkAst[];
195
+ readonly span: Span;
196
+ } | {
197
+ readonly kind: 'chord';
198
+ readonly pitches: readonly AstPitch[];
199
+ readonly duration: AstDuration | null;
200
+ readonly tie?: boolean;
201
+ readonly slurStart?: boolean;
202
+ readonly slurEnd?: boolean;
203
+ readonly highlight?: string;
204
+ readonly aboveLabels?: readonly string[];
205
+ readonly belowLabels?: readonly string[];
206
+ readonly fingerings?: readonly FingeringAst[];
207
+ readonly scaleDegrees?: readonly ScaleDegreeAst[];
208
+ readonly chordSymbol?: LeadSheetChordAst;
209
+ readonly articulations?: readonly ArticulationAst[];
210
+ readonly ornaments?: readonly OrnamentAst[];
211
+ readonly dynamics?: readonly DynamicAst[];
212
+ readonly hairpins?: readonly HairpinMarkAst[];
213
+ readonly pedals?: readonly PedalMarkAst[];
214
+ readonly arpeggios?: readonly ArpeggioAst[];
215
+ readonly breathMarks?: readonly BreathMarkAst[];
216
+ readonly tremolos?: readonly TremoloAst[];
217
+ readonly bracketMarks?: readonly BracketMarkAst[];
218
+ readonly span: Span;
219
+ } | {
220
+ readonly kind: 'staffSwitch';
221
+ readonly visualStaffIndex: 0 | 1;
222
+ readonly span: Span;
223
+ } | {
224
+ readonly kind: 'beamOpen';
225
+ readonly span: Span;
226
+ } | {
227
+ readonly kind: 'beamClose';
228
+ readonly span: Span;
229
+ } | {
230
+ readonly kind: 'tuplet';
231
+ readonly num: number;
232
+ readonly den: number;
233
+ readonly body: readonly AstStatement[];
234
+ readonly span: Span;
235
+ } | {
236
+ readonly kind: 'relative';
237
+ readonly refPitch: AstPitch | null;
238
+ readonly body: readonly AstStatement[];
239
+ readonly span: Span;
240
+ } | {
241
+ readonly kind: 'grace';
242
+ readonly acciaccatura: boolean;
243
+ readonly body: readonly AstStatement[];
244
+ readonly span: Span;
245
+ } | {
246
+ readonly kind: 'cadenza';
247
+ readonly on: boolean;
248
+ readonly span: Span;
249
+ } | {
250
+ readonly kind: 'highlight';
251
+ readonly colorOrRole: string;
252
+ readonly body: readonly AstStatement[];
253
+ readonly span: Span;
254
+ } | {
255
+ readonly kind: 'spacer';
256
+ readonly duration: AstDuration | null;
257
+ readonly dynamics?: readonly DynamicAst[];
258
+ readonly hairpins?: readonly HairpinMarkAst[];
259
+ readonly pedals?: readonly PedalMarkAst[];
260
+ readonly span: Span;
261
+ } | {
262
+ readonly kind: 'break';
263
+ readonly span: Span;
264
+ } | {
265
+ readonly kind: 'volta';
266
+ readonly ending: 0 | 1 | 2;
267
+ readonly span: Span;
268
+ } | {
269
+ readonly kind: 'ottava';
270
+ readonly shift: OttavaShift;
271
+ readonly span: Span;
272
+ } | {
273
+ readonly kind: 'voiceDir';
274
+ readonly dir: 'up' | 'down' | 'neutral';
275
+ readonly span: Span;
276
+ } | {
277
+ readonly kind: 'polyphony';
278
+ readonly voices: readonly (readonly AstStatement[])[];
279
+ readonly span: Span;
280
+ } | {
281
+ readonly kind: 'staff';
282
+ readonly id?: string;
283
+ readonly body: readonly AstStatement[];
284
+ readonly span: Span;
285
+ } | {
286
+ readonly kind: 'grandStaff';
287
+ readonly staves: readonly Extract<AstStatement, {
288
+ kind: 'staff';
289
+ }>[];
290
+ readonly span: Span;
291
+ };
292
+ export interface AstDocument {
293
+ readonly statements: readonly AstStatement[];
294
+ readonly diagnostics: readonly Diagnostic[];
295
+ }
@@ -0,0 +1,115 @@
1
+ import type { Alteration, BarlineKind, Diagnostic, PitchLetter, Span } from './ast.js';
2
+ export type Token = {
3
+ readonly type: 'command';
4
+ readonly name: string;
5
+ readonly span: Span;
6
+ } | {
7
+ readonly type: 'string';
8
+ readonly value: string;
9
+ readonly unclosed?: boolean;
10
+ readonly span: Span;
11
+ } | {
12
+ readonly type: 'pitch';
13
+ readonly letter: PitchLetter;
14
+ readonly alter: Alteration;
15
+ readonly octave: number;
16
+ readonly hasOctaveMarks: boolean;
17
+ readonly raw: string;
18
+ readonly span: Span;
19
+ } | {
20
+ readonly type: 'rest';
21
+ readonly span: Span;
22
+ } | {
23
+ readonly type: 'spacer';
24
+ readonly span: Span;
25
+ } | {
26
+ readonly type: 'ident';
27
+ readonly value: string;
28
+ readonly span: Span;
29
+ } | {
30
+ readonly type: 'int';
31
+ readonly value: number;
32
+ readonly raw: string;
33
+ readonly span: Span;
34
+ } | {
35
+ readonly type: 'dots';
36
+ readonly count: number;
37
+ readonly span: Span;
38
+ } | {
39
+ readonly type: 'barline';
40
+ readonly value: BarlineKind;
41
+ readonly span: Span;
42
+ } | {
43
+ readonly type: 'ldangle';
44
+ readonly span: Span;
45
+ } | {
46
+ readonly type: 'rdangle';
47
+ readonly span: Span;
48
+ } | {
49
+ readonly type: 'hairpin';
50
+ readonly value: 'cresc' | 'dim' | 'stop';
51
+ readonly span: Span;
52
+ } | {
53
+ readonly type: 'langle';
54
+ readonly span: Span;
55
+ } | {
56
+ readonly type: 'rangle';
57
+ readonly span: Span;
58
+ } | {
59
+ readonly type: 'doubleBackslash';
60
+ readonly span: Span;
61
+ } | {
62
+ readonly type: 'lbracket';
63
+ readonly span: Span;
64
+ } | {
65
+ readonly type: 'rbracket';
66
+ readonly span: Span;
67
+ } | {
68
+ readonly type: 'lbrace';
69
+ readonly span: Span;
70
+ } | {
71
+ readonly type: 'rbrace';
72
+ readonly span: Span;
73
+ } | {
74
+ readonly type: 'lparen';
75
+ readonly span: Span;
76
+ } | {
77
+ readonly type: 'rparen';
78
+ readonly span: Span;
79
+ } | {
80
+ readonly type: 'tilde';
81
+ readonly span: Span;
82
+ } | {
83
+ readonly type: 'bang';
84
+ readonly span: Span;
85
+ } | {
86
+ readonly type: 'question';
87
+ readonly span: Span;
88
+ } | {
89
+ readonly type: 'at';
90
+ readonly span: Span;
91
+ } | {
92
+ readonly type: 'caret';
93
+ readonly span: Span;
94
+ } | {
95
+ readonly type: 'underscore';
96
+ readonly span: Span;
97
+ } | {
98
+ readonly type: 'minus';
99
+ readonly span: Span;
100
+ } | {
101
+ readonly type: 'slash';
102
+ readonly span: Span;
103
+ } | {
104
+ readonly type: 'equals';
105
+ readonly span: Span;
106
+ } | {
107
+ readonly type: 'eof';
108
+ readonly span: Span;
109
+ };
110
+ export declare const MAX_INPUT_LENGTH = 65536;
111
+ export declare function tokenize(source: string): {
112
+ tokens: Token[];
113
+ diagnostics: Diagnostic[];
114
+ truncated: boolean;
115
+ };
@@ -0,0 +1,7 @@
1
+ import { type AstDocument } from './ast.js';
2
+ import { MAX_INPUT_LENGTH } from './lexer.js';
3
+ export { MAX_INPUT_LENGTH };
4
+ export declare const MAX_NESTING_DEPTH = 32;
5
+ export declare const MAX_TIME_NUMERATOR = 64;
6
+ export declare const MAX_OCTAVE_MARKS = 6;
7
+ export declare function parse(source: string): AstDocument;