@dsebastien/music-notation 0.4.0 → 0.5.1

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The tab bundle for web pages (`music-notation.tab.min.js`): draws ```tab and ```score blocks,
3
+ * now and as the page changes (Obsidian Publish swaps content as you navigate). Loads alphaTab, its
4
+ * music font and soundfont from jsDelivr the first time a page has such a block, renders on the
5
+ * main thread (web workers can't start from another origin), and gives the diagrams a soundfont
6
+ * player of their own.
7
+ */
8
+ import { type AlphaTabModule } from './index.js';
9
+ import { type NotePlayer } from '../playback/player.js';
10
+ declare global {
11
+ interface Window {
12
+ alphaTab?: AlphaTabModule;
13
+ musicNotationTabLoaded?: boolean;
14
+ musicNotationSoundfontPlayer?: NotePlayer;
15
+ }
16
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Tabs and scores (#24): ```tab and ```score blocks in alphaTex (or a Guitar Pro / MusicXML file),
3
+ * drawn and played by alphaTab (MPL-2.0, used unmodified). alphaTab isn't bundled here: the app
4
+ * passes the alphaTab module (its UMD build, `window.alphaTab`), so the app decides how it ships
5
+ * (Music Practice embeds it, Publish pages load it from jsDelivr). Also the converters and
6
+ * exporters behind imports (#25), and a soundfont player for the diagrams' playback (#23).
7
+ */
8
+ import type * as AT from '@coderline/alphatab';
9
+ import type { NotePlayer } from '../playback/player.js';
10
+ export type AlphaTabModule = typeof AT;
11
+ /** The alphaTab release these blocks are made for (Publish loads it from jsDelivr). */
12
+ export declare const ALPHATAB_VERSION = "1.8.4";
13
+ /** jsDelivr URLs of alphaTab's script, music font and soundfont, for web pages. */
14
+ export declare const alphaTabCdn: (version?: string) => {
15
+ script: string;
16
+ font: string;
17
+ soundFont: string;
18
+ };
19
+ export interface TabAssets {
20
+ /** A URL of alphaTab's script (UMD) to run it in workers; null renders on the main thread. */
21
+ scriptFile?: string | null;
22
+ /** The Bravura music font (woff2): a URL or a data URL. */
23
+ font: string;
24
+ /** The soundfont: its bytes or a URL. */
25
+ soundFont: Uint8Array | string;
26
+ }
27
+ export interface TabOptions {
28
+ alphaTab: AlphaTabModule;
29
+ assets: TabAssets;
30
+ /** The bytes of a file a block names (`file: [[Song.gp]]`); null when it can't be found. */
31
+ resolveFile?: (link: string) => Promise<Uint8Array | null>;
32
+ /** The player bar (default true). The player itself starts at the first Play. */
33
+ player?: boolean;
34
+ /** Called once alphaTab's API exists (before the score is drawn). */
35
+ onApi?: (api: AT.AlphaTabApi) => void;
36
+ }
37
+ export type Staves = 'tab' | 'score' | 'both';
38
+ export interface TabSource {
39
+ staves: Staves;
40
+ /** A file to draw instead of alphaTex (`[[Song.gp]]` or a path). */
41
+ file: string | null;
42
+ /** Tracks to draw (1-based); all by default. */
43
+ tracks: number[] | null;
44
+ /** The alphaTex itself. */
45
+ tex: string;
46
+ /** Lines of the block before the alphaTex (settings, blank lines), for error positions. */
47
+ texLine: number;
48
+ }
49
+ /**
50
+ * A tab block's own settings (lines `staves:`, `file:`, `tracks:` at the top, `//` comments
51
+ * allowed among them), then its alphaTex. ```tab blocks show tablature, ```score blocks standard
52
+ * notation, unless `staves:` says otherwise. Throws a message for the user.
53
+ */
54
+ export declare function parseTabSource(language: 'tab' | 'score', source: string): TabSource;
55
+ /** Prints a drawn score in black on white, whatever the theme. Throws when the app can't print. */
56
+ export declare function printTab(result: TabResult): void;
57
+ export interface TabResult {
58
+ el: HTMLElement;
59
+ /** Resolves once drawn (or failed, or removed), with the message shown when it failed. */
60
+ ready: Promise<{
61
+ ok: boolean;
62
+ error: string | null;
63
+ }>;
64
+ /** The alphaTab API, for exports and playback. */
65
+ api: AT.AlphaTabApi | null;
66
+ destroy(): void;
67
+ }
68
+ /**
69
+ * Draws a ```tab or ```score block into `host`, with its player bar. Never throws and `ready`
70
+ * never rejects: a mistake (in the alphaTex, a missing or unreadable file, no alphaTab) shows an
71
+ * inline message; an empty block draws nothing.
72
+ */
73
+ export declare function renderTab(language: 'tab' | 'score', source: string, host: HTMLElement, options: TabOptions): TabResult;
74
+ /**
75
+ * Diagram playback through alphaTab's synthesizer and soundfont (realistic sound): a NotePlayer
76
+ * for the `play` render option. `api` is an alphaTab API used only for this (not a score's: its
77
+ * song would stop), with its soundfont loaded.
78
+ */
79
+ export declare function soundfontPlayer(alphaTab: AlphaTabModule, api: () => AT.AlphaTabApi | null): NotePlayer;
80
+ /** A soundfont player with its own hidden alphaTab instance; `destroy` frees it. */
81
+ export interface SoundfontPlayer extends NotePlayer {
82
+ destroy(): void;
83
+ }
84
+ /**
85
+ * A soundfont player that makes its own hidden alphaTab instance on the first play (for pages
86
+ * and notes without a tab block, and so a score's song isn't stopped). The first notes wait for
87
+ * the soundfont; when it can't load, notes play through `fallback`.
88
+ */
89
+ export declare function createSoundfontPlayer(alphaTab: AlphaTabModule, assets: TabAssets, doc: Document, fallback?: NotePlayer): SoundfontPlayer;
90
+ /** A score file's alphaTex (Guitar Pro 3–8, MusicXML, Capella), for inline imports. */
91
+ export declare function scoreToAlphaTex(alphaTab: AlphaTabModule, bytes: Uint8Array): string;
92
+ /** A Guitar Pro 7 file of alphaTex or a score file. */
93
+ export declare function exportGp7(alphaTab: AlphaTabModule, music: string | Uint8Array): Uint8Array;
94
+ /** A MIDI file of alphaTex or a score file. */
95
+ export declare function exportMidi(alphaTab: AlphaTabModule, music: string | Uint8Array): Uint8Array;
96
+ export { textTabToAlphaTex } from '../convert/text-tab.js';
97
+ export { chordSheetToChordPro } from '../convert/chord-sheet.js';