@dsebastien/music-notation 0.17.0 → 0.18.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.
- package/README.md +1 -1
- package/dist/chord/fingering-words.d.ts +7 -0
- package/dist/chord/transitions.d.ts +5 -0
- package/dist/index.js +37 -40
- package/dist/index.js.map +9 -9
- package/dist/music-notation.css +3 -15
- package/dist/music-notation.publish.min.js +31 -43
- package/dist/music-notation.tab.min.js +10 -22
- package/dist/playback/bar-parts.d.ts +1 -0
- package/dist/publish/index.js +34 -25
- package/dist/publish/index.js.map +9 -9
- package/dist/tab/auto.d.ts +1 -0
- package/dist/tab/index.d.ts +5 -0
- package/dist/tab/index.js +167 -83
- package/dist/tab/index.js.map +6 -4
- package/package.json +1 -1
package/dist/tab/auto.d.ts
CHANGED
package/dist/tab/index.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ export interface TabOptions {
|
|
|
46
46
|
onKeepView?: (staves: Staves) => void;
|
|
47
47
|
/** The view of a block with no `staves:` line (default: the block's language). */
|
|
48
48
|
defaultStaves?: Staves;
|
|
49
|
+
/**
|
|
50
|
+
* The app's volume, 0 to 1 (a number, or a function read at each Play and on `volumeChanged`,
|
|
51
|
+
* #85); 0.8 by default. The bar has no volume of its own (#82).
|
|
52
|
+
*/
|
|
53
|
+
volume?: number | (() => number);
|
|
49
54
|
}
|
|
50
55
|
export type Staves = 'tab' | 'score' | 'both';
|
|
51
56
|
export interface TabSource {
|
package/dist/tab/index.js
CHANGED
|
@@ -1769,6 +1769,138 @@ function textTabToAlphaTex(text) {
|
|
|
1769
1769
|
return [...header, ...ts, texOf(bars, meter)].join(`
|
|
1770
1770
|
`);
|
|
1771
1771
|
}
|
|
1772
|
+
|
|
1773
|
+
// src/playback/bar-parts.ts
|
|
1774
|
+
var ICONS = {
|
|
1775
|
+
play: "M4 2.5v11l9-5.5z",
|
|
1776
|
+
pause: "M4 3h3v10H4zM9 3h3v10H9z",
|
|
1777
|
+
stop: "M4 4h8v8H4z",
|
|
1778
|
+
all: "M1.5 2.5v11l6.5-5.5zM8 2.5v11l6.5-5.5z",
|
|
1779
|
+
loop: "M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",
|
|
1780
|
+
count: "M5.5 14h5L9 2.5H7zM8 11.5l4.5-7",
|
|
1781
|
+
click: "M3 5v6M8 5v6M13 5v6"
|
|
1782
|
+
};
|
|
1783
|
+
var STROKED = new Set(["loop", "count", "click"]);
|
|
1784
|
+
function icon(doc, name) {
|
|
1785
|
+
const root = svg(doc, "svg", {
|
|
1786
|
+
class: `mn-play-icon mn-play-icon-${name}${STROKED.has(name) ? " mn-play-icon-line" : ""}`,
|
|
1787
|
+
viewBox: "0 0 16 16",
|
|
1788
|
+
width: 12,
|
|
1789
|
+
height: 12,
|
|
1790
|
+
"aria-hidden": "true"
|
|
1791
|
+
});
|
|
1792
|
+
root.appendChild(svg(doc, "path", { d: ICONS[name] }));
|
|
1793
|
+
return root;
|
|
1794
|
+
}
|
|
1795
|
+
function playBar(doc, cls, label) {
|
|
1796
|
+
const bar = html(doc, "div", `mn-play mn-play-static ${cls}`);
|
|
1797
|
+
bar.addEventListener("mousedown", (event) => event.stopPropagation());
|
|
1798
|
+
bar.setAttribute("role", "group");
|
|
1799
|
+
bar.setAttribute("aria-label", label);
|
|
1800
|
+
return bar;
|
|
1801
|
+
}
|
|
1802
|
+
function iconButton(doc, cls, label, name) {
|
|
1803
|
+
const button = html(doc, "button", cls);
|
|
1804
|
+
button.type = "button";
|
|
1805
|
+
button.appendChild(icon(doc, name));
|
|
1806
|
+
button.title = label;
|
|
1807
|
+
button.setAttribute("aria-label", label);
|
|
1808
|
+
return button;
|
|
1809
|
+
}
|
|
1810
|
+
function pressedButton(doc, cls, label, name, on, set) {
|
|
1811
|
+
const button = iconButton(doc, cls, label, name);
|
|
1812
|
+
const show = () => {
|
|
1813
|
+
button.setAttribute("aria-pressed", String(on));
|
|
1814
|
+
button.classList.toggle("mn-on", on);
|
|
1815
|
+
};
|
|
1816
|
+
button.addEventListener("click", () => {
|
|
1817
|
+
on = !on;
|
|
1818
|
+
set(on);
|
|
1819
|
+
show();
|
|
1820
|
+
});
|
|
1821
|
+
show();
|
|
1822
|
+
return button;
|
|
1823
|
+
}
|
|
1824
|
+
function valueSlider(doc, label, unit, min, max, value, set, hint) {
|
|
1825
|
+
const field = html(doc, "label", "mn-play-field");
|
|
1826
|
+
const input = html(doc, "input");
|
|
1827
|
+
input.type = "range";
|
|
1828
|
+
input.min = String(min);
|
|
1829
|
+
input.max = String(max);
|
|
1830
|
+
input.setAttribute("aria-label", label);
|
|
1831
|
+
if (hint)
|
|
1832
|
+
input.setAttribute("aria-description", hint);
|
|
1833
|
+
const text = html(doc, "span", "mn-play-value");
|
|
1834
|
+
text.setAttribute("aria-hidden", "true");
|
|
1835
|
+
const show = (n) => {
|
|
1836
|
+
input.value = String(n);
|
|
1837
|
+
const written = `${n} ${unit}`;
|
|
1838
|
+
text.textContent = written;
|
|
1839
|
+
input.setAttribute("aria-valuetext", written);
|
|
1840
|
+
field.title = `${label}: ${written}${hint ? ` (${hint})` : ""}`;
|
|
1841
|
+
};
|
|
1842
|
+
input.addEventListener("input", () => {
|
|
1843
|
+
const n = Number(input.value);
|
|
1844
|
+
set(n);
|
|
1845
|
+
show(n);
|
|
1846
|
+
});
|
|
1847
|
+
show(value);
|
|
1848
|
+
field.append(input, text);
|
|
1849
|
+
return { field, input, show };
|
|
1850
|
+
}
|
|
1851
|
+
function choice(doc, cls, label, values, chosen, names, set) {
|
|
1852
|
+
const el = html(doc, "select", cls);
|
|
1853
|
+
el.setAttribute("aria-label", label);
|
|
1854
|
+
el.title = label;
|
|
1855
|
+
for (const value of values) {
|
|
1856
|
+
const option = html(doc, "option", undefined, names[value]);
|
|
1857
|
+
option.value = value;
|
|
1858
|
+
option.selected = value === chosen;
|
|
1859
|
+
el.appendChild(option);
|
|
1860
|
+
}
|
|
1861
|
+
el.addEventListener("change", () => set(el.value));
|
|
1862
|
+
return el;
|
|
1863
|
+
}
|
|
1864
|
+
var DEFAULT_VOLUME = 0.8;
|
|
1865
|
+
function volumeOf(volume) {
|
|
1866
|
+
let value = volume;
|
|
1867
|
+
if (typeof volume === "function") {
|
|
1868
|
+
try {
|
|
1869
|
+
value = volume();
|
|
1870
|
+
} catch {
|
|
1871
|
+
value = undefined;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_VOLUME;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
// src/playback/live-volume.ts
|
|
1878
|
+
var REGISTRY = Symbol.for("@dsebastien/music-notation/volume");
|
|
1879
|
+
var shared = globalThis;
|
|
1880
|
+
var listeners = shared[REGISTRY] ??= new Set;
|
|
1881
|
+
var level = (value) => typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : null;
|
|
1882
|
+
function volumeChanged() {
|
|
1883
|
+
for (const listener of [...listeners]) {
|
|
1884
|
+
try {
|
|
1885
|
+
listener();
|
|
1886
|
+
} catch {}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
function followVolume(read, handles, start) {
|
|
1890
|
+
let last = level(start);
|
|
1891
|
+
const listener = () => {
|
|
1892
|
+
const now = level(read());
|
|
1893
|
+
if (now === null || now === last)
|
|
1894
|
+
return;
|
|
1895
|
+
last = now;
|
|
1896
|
+
for (const h of handles())
|
|
1897
|
+
h.setVolume?.(now);
|
|
1898
|
+
};
|
|
1899
|
+
listeners.add(listener);
|
|
1900
|
+
return () => {
|
|
1901
|
+
listeners.delete(listener);
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1772
1904
|
// src/convert/chord-sheet.ts
|
|
1773
1905
|
function chordsOf(line) {
|
|
1774
1906
|
const found = [];
|
|
@@ -2001,37 +2133,14 @@ var local = (doc) => {
|
|
|
2001
2133
|
}
|
|
2002
2134
|
};
|
|
2003
2135
|
};
|
|
2004
|
-
var ICONS = {
|
|
2005
|
-
play: "M4 2.5v11l9-5.5z",
|
|
2006
|
-
pause: "M4 3h3v10H4zM9 3h3v10H9z",
|
|
2007
|
-
stop: "M4 4h8v8H4z",
|
|
2008
|
-
loop: "M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",
|
|
2009
|
-
metronome: "M6 2h4l3 12H3zM8 11l3-7",
|
|
2010
|
-
countIn: "M3 13h10M5 13V9M8 13V6M11 13V3",
|
|
2011
|
-
volume: "M2 6h3l4-3v10l-4-3H2zM11 5.5a3.5 3.5 0 0 1 0 5"
|
|
2012
|
-
};
|
|
2013
|
-
function icon(doc, name) {
|
|
2014
|
-
const filled = name === "play" || name === "pause" || name === "stop";
|
|
2015
|
-
const root = svg(doc, "svg", {
|
|
2016
|
-
class: `mn-play-icon${filled ? "" : " mn-play-icon-loop"}`,
|
|
2017
|
-
viewBox: "0 0 16 16",
|
|
2018
|
-
width: 12,
|
|
2019
|
-
height: 12,
|
|
2020
|
-
"aria-hidden": "true"
|
|
2021
|
-
});
|
|
2022
|
-
root.appendChild(svg(doc, "path", { d: ICONS[name] }));
|
|
2023
|
-
return root;
|
|
2024
|
-
}
|
|
2025
2136
|
var time = (ms) => {
|
|
2026
2137
|
const s = Math.max(0, Math.round(ms / 1000));
|
|
2027
2138
|
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
2028
2139
|
};
|
|
2029
|
-
function playerBar(doc, api, alphaTab, assets) {
|
|
2030
|
-
const bar =
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
bar.setAttribute("aria-label", "Playback");
|
|
2034
|
-
const state = { loop: false, metronome: false, countIn: false, speed: 1, volume: 1 };
|
|
2140
|
+
function playerBar(doc, api, alphaTab, assets, volume) {
|
|
2141
|
+
const bar = playBar(doc, "mn-tab-bar", "Playback");
|
|
2142
|
+
const state = { loop: false, metronome: false, countIn: false, speed: 1 };
|
|
2143
|
+
const level = () => volumeOf(volume);
|
|
2035
2144
|
let started = null;
|
|
2036
2145
|
let cantStart = null;
|
|
2037
2146
|
const start = () => {
|
|
@@ -2051,78 +2160,49 @@ function playerBar(doc, api, alphaTab, assets) {
|
|
|
2051
2160
|
api.metronomeVolume = state.metronome ? 1 : 0;
|
|
2052
2161
|
api.countInVolume = state.countIn ? 1 : 0;
|
|
2053
2162
|
api.playbackSpeed = state.speed;
|
|
2054
|
-
api.masterVolume =
|
|
2163
|
+
api.masterVolume = level();
|
|
2055
2164
|
}
|
|
2056
2165
|
return ok;
|
|
2057
2166
|
});
|
|
2058
2167
|
return started;
|
|
2059
2168
|
};
|
|
2060
|
-
const button = (name, label, run) => {
|
|
2061
|
-
const b = html(doc, "button");
|
|
2062
|
-
b.type = "button";
|
|
2063
|
-
b.title = label;
|
|
2064
|
-
b.setAttribute("aria-label", label);
|
|
2065
|
-
b.appendChild(icon(doc, name));
|
|
2066
|
-
b.addEventListener("click", run);
|
|
2067
|
-
bar.appendChild(b);
|
|
2068
|
-
return b;
|
|
2069
|
-
};
|
|
2070
2169
|
const live = (apply) => {
|
|
2071
2170
|
if (api.player)
|
|
2072
2171
|
apply();
|
|
2073
2172
|
};
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2076
|
-
state[key] = !state[key];
|
|
2077
|
-
live(() => {
|
|
2078
|
-
api.isLooping = state.loop;
|
|
2079
|
-
api.metronomeVolume = state.metronome ? 1 : 0;
|
|
2080
|
-
api.countInVolume = state.countIn ? 1 : 0;
|
|
2081
|
-
});
|
|
2082
|
-
b.classList.toggle("mn-on", state[key]);
|
|
2083
|
-
b.setAttribute("aria-pressed", String(state[key]));
|
|
2084
|
-
});
|
|
2085
|
-
b.setAttribute("aria-pressed", "false");
|
|
2086
|
-
};
|
|
2087
|
-
const play = button("play", "Play", () => {
|
|
2173
|
+
const play = iconButton(doc, "mn-play-toggle", "Play", "play");
|
|
2174
|
+
play.addEventListener("click", () => {
|
|
2088
2175
|
start().then((ok) => {
|
|
2089
2176
|
if (ok)
|
|
2090
2177
|
api.playPause();
|
|
2091
2178
|
});
|
|
2092
2179
|
});
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
field.append(tag, input);
|
|
2114
|
-
bar.appendChild(field);
|
|
2115
|
-
};
|
|
2116
|
-
slider("Speed", "%", 25, 150, 100, (n) => {
|
|
2180
|
+
const stop = iconButton(doc, "mn-tab-stop", "Stop", "stop");
|
|
2181
|
+
stop.addEventListener("click", () => live(() => api.stop()));
|
|
2182
|
+
const toggles = () => live(() => {
|
|
2183
|
+
api.isLooping = state.loop;
|
|
2184
|
+
api.metronomeVolume = state.metronome ? 1 : 0;
|
|
2185
|
+
api.countInVolume = state.countIn ? 1 : 0;
|
|
2186
|
+
});
|
|
2187
|
+
const loop = pressedButton(doc, "mn-tab-loop", "Loop", "loop", false, (on) => {
|
|
2188
|
+
state.loop = on;
|
|
2189
|
+
toggles();
|
|
2190
|
+
});
|
|
2191
|
+
const metronome = pressedButton(doc, "mn-tab-click", "Metronome", "click", false, (on) => {
|
|
2192
|
+
state.metronome = on;
|
|
2193
|
+
toggles();
|
|
2194
|
+
});
|
|
2195
|
+
const countIn = pressedButton(doc, "mn-tab-count", "Count-in", "count", false, (on) => {
|
|
2196
|
+
state.countIn = on;
|
|
2197
|
+
toggles();
|
|
2198
|
+
});
|
|
2199
|
+
const speed = valueSlider(doc, "Speed", "%", 25, 150, 100, (n) => {
|
|
2117
2200
|
state.speed = n / 100;
|
|
2118
2201
|
live(() => api.playbackSpeed = state.speed);
|
|
2119
|
-
}, "%");
|
|
2120
|
-
slider("Volume", icon(doc, "volume"), 0, 100, 100, (n) => {
|
|
2121
|
-
state.volume = n / 100;
|
|
2122
|
-
live(() => api.masterVolume = state.volume);
|
|
2123
2202
|
});
|
|
2124
2203
|
const position = html(doc, "span", "mn-tab-time", "");
|
|
2125
|
-
bar.
|
|
2204
|
+
bar.append(play, stop, loop, metronome, countIn, speed.field, position);
|
|
2205
|
+
const unfollow = followVolume(level, () => [{ stop() {}, setVolume: (v) => live(() => api.masterVolume = v) }], level());
|
|
2126
2206
|
api.playerStateChanged.on((e) => {
|
|
2127
2207
|
const playing = Number(e.state) === Number(alphaTab.synth.PlayerState.Playing);
|
|
2128
2208
|
play.replaceChildren(icon(doc, playing ? "pause" : "play"));
|
|
@@ -2135,6 +2215,7 @@ function playerBar(doc, api, alphaTab, assets) {
|
|
|
2135
2215
|
return {
|
|
2136
2216
|
bar,
|
|
2137
2217
|
speed: () => state.speed,
|
|
2218
|
+
destroy: unfollow,
|
|
2138
2219
|
failed: (message) => {
|
|
2139
2220
|
cantStart?.();
|
|
2140
2221
|
play.disabled = true;
|
|
@@ -2198,6 +2279,7 @@ function renderTab(language, source, host, options) {
|
|
|
2198
2279
|
host.appendChild(el);
|
|
2199
2280
|
let api = null;
|
|
2200
2281
|
let speedOf = () => 1;
|
|
2282
|
+
let unbar = () => {};
|
|
2201
2283
|
let gone = false;
|
|
2202
2284
|
let settled = false;
|
|
2203
2285
|
let settle = () => {};
|
|
@@ -2272,7 +2354,8 @@ function renderTab(language, source, host, options) {
|
|
|
2272
2354
|
if (settled || gone)
|
|
2273
2355
|
return;
|
|
2274
2356
|
if (options.player !== false) {
|
|
2275
|
-
bar = playerBar(doc, current, at, assets);
|
|
2357
|
+
bar = playerBar(doc, current, at, assets, options.volume);
|
|
2358
|
+
unbar = bar.destroy;
|
|
2276
2359
|
speedOf = bar.speed;
|
|
2277
2360
|
el.appendChild(bar.bar);
|
|
2278
2361
|
if (options.views !== false && tablature)
|
|
@@ -2333,6 +2416,7 @@ function renderTab(language, source, host, options) {
|
|
|
2333
2416
|
speed: () => speedOf(),
|
|
2334
2417
|
destroy() {
|
|
2335
2418
|
gone = true;
|
|
2419
|
+
unbar();
|
|
2336
2420
|
try {
|
|
2337
2421
|
api?.destroy();
|
|
2338
2422
|
} catch {}
|
|
@@ -2517,5 +2601,5 @@ export {
|
|
|
2517
2601
|
textTabToAlphaTex
|
|
2518
2602
|
};
|
|
2519
2603
|
|
|
2520
|
-
//# debugId=
|
|
2604
|
+
//# debugId=F0BE008A00DBAFB664756E2164756E21
|
|
2521
2605
|
//# sourceMappingURL=index.js.map
|