@dsebastien/music-notation 0.16.0 → 0.17.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +80 -7
- package/dist/index.js.map +10 -9
- package/dist/music-notation.css +7 -0
- package/dist/music-notation.publish.min.js +36 -29
- package/dist/music-notation.tab.min.js +14 -7
- package/dist/playback/live-volume.d.ts +14 -0
- package/dist/playback/player.d.ts +2 -0
- package/dist/publish/index.js +72 -7
- package/dist/publish/index.js.map +10 -9
- package/dist/tab/index.js +22 -6
- package/dist/tab/index.js.map +4 -4
- package/dist/voicings/index.js +5 -3
- package/dist/voicings/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { soundingChord, soundsLike, fretsFromCapo, capoTuning, parseCapo, parseF
|
|
|
7
7
|
export { generateVoicings, fingerVoicing, voicingShape, MAX_GENERATED_STRINGS, type GeneratedVoicing, type VoicingOptions, type VoicingShape } from './chord/generate.js';
|
|
8
8
|
export { sequenceOf, scaleRun, lengthOf, lightPlayer, pluckedString, pianoTone, DEFAULT_SEQUENCE, DEFAULT_STRUM, type NoteEvent, type NotePlayer, type PluckOptions, type PlayHandle, type PlayKind, type Sound, type SequenceOptions } from './playback/player.js';
|
|
9
9
|
export { attachPlayback, type PlayOptions, type TimedBar } from './playback/controls.js';
|
|
10
|
+
export { volumeChanged } from './playback/live-volume.js';
|
|
10
11
|
export { followNotes, noteTargets, PLAYING_CLASS, START_WAIT, type Follower } from './playback/follow.js';
|
|
11
12
|
export { transition, smoothProgression, type TransitionStep, type TransitionOptions, type ProgressionStep, type ProgressionOptions } from './chord/transitions.js';
|
|
12
13
|
export { fingeringInWords, type GuitarFingering, type PianoFingering } from './chord/fingering-words.js';
|
package/dist/index.js
CHANGED
|
@@ -422,6 +422,8 @@ var SIGN = "(##|bb|#|b|♯|♭)?";
|
|
|
422
422
|
var syllableLetter = (syllable) => SYLLABLE_LETTER[plain2(syllable)];
|
|
423
423
|
var AFTER_ROOT = /^(?:$|[0-9/(+°øΔ^-]|m|M|a(?:dd|ug|lt)|sus|dim)/;
|
|
424
424
|
var QUALITY_WORD = /^(?:[0-9(+°øΔ^]|m|M|a(?:dd|ug|lt)|sus|dim)/;
|
|
425
|
+
var WORD_QUALITY = /^(?:major|minor)$/i;
|
|
426
|
+
var joinsAsQuality = (word) => QUALITY_WORD.test(word) && !WORD_QUALITY.test(word);
|
|
425
427
|
var reads = (letters) => midiOf(letters) !== null || /^[A-G]/.test(letters) && parseChord(letters) !== null;
|
|
426
428
|
function rootToken(token, naming, h, solfegeLine = false) {
|
|
427
429
|
const b = naming === "german" ? /^B(?![#♯b♭x])(.*)$/.exec(token) : null;
|
|
@@ -492,7 +494,7 @@ function read(text, naming, options, changes) {
|
|
|
492
494
|
let out = text.normalize("NFC").replace(new RegExp(`(^|[\\s,/|])${SYLLABLE}\\s+(dièse|diese|bémol|bemol)(?=$|[\\s,|])`, "g"), (_, before, syllable, sign) => `${before}${syllable}${/^d/.test(sign) ? "#" : "b"}`);
|
|
493
495
|
if (options.chord) {
|
|
494
496
|
const joined = new RegExp(`^\\s*${SYLLABLE}${SIGN}\\s+(\\S+)\\s*$`).exec(out);
|
|
495
|
-
if (joined &&
|
|
497
|
+
if (joined && joinsAsQuality(joined[3])) {
|
|
496
498
|
const word = `${joined[1]}${joined[2] ?? ""}${joined[3]}`;
|
|
497
499
|
const letters = rootToken(word, naming, h) ?? letterPiece(word, naming, h);
|
|
498
500
|
if (letters !== word) {
|
|
@@ -505,7 +507,7 @@ function read(text, naming, options, changes) {
|
|
|
505
507
|
for (let i = 0;i + 2 < words.length; i += 2) {
|
|
506
508
|
const head = words[i];
|
|
507
509
|
const next = words[i + 2];
|
|
508
|
-
if (!syllableOnly(head) || !
|
|
510
|
+
if (!syllableOnly(head) || !joinsAsQuality(next))
|
|
509
511
|
continue;
|
|
510
512
|
if (naming !== "solfege" && reads(head))
|
|
511
513
|
continue;
|
|
@@ -4217,6 +4219,11 @@ function lightPlayer(win, random = Math.random) {
|
|
|
4217
4219
|
} catch {}
|
|
4218
4220
|
}
|
|
4219
4221
|
cleanup = win.setTimeout(finish, 80);
|
|
4222
|
+
},
|
|
4223
|
+
setVolume(next) {
|
|
4224
|
+
if (stopped || !Number.isFinite(next))
|
|
4225
|
+
return;
|
|
4226
|
+
gain.gain.setTargetAtTime(Math.min(1, Math.max(0, next)), ctx.currentTime, 0.015);
|
|
4220
4227
|
}
|
|
4221
4228
|
};
|
|
4222
4229
|
}
|
|
@@ -4366,6 +4373,32 @@ function followNotes(win, drawing, targets, events, wait = START_WAIT) {
|
|
|
4366
4373
|
};
|
|
4367
4374
|
}
|
|
4368
4375
|
|
|
4376
|
+
// src/playback/live-volume.ts
|
|
4377
|
+
var listeners = new Set;
|
|
4378
|
+
var level = (value) => typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : null;
|
|
4379
|
+
function volumeChanged() {
|
|
4380
|
+
for (const listener of [...listeners]) {
|
|
4381
|
+
try {
|
|
4382
|
+
listener();
|
|
4383
|
+
} catch {}
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
function followVolume(read, handles, start) {
|
|
4387
|
+
let last = level(start);
|
|
4388
|
+
const listener = () => {
|
|
4389
|
+
const now = level(read());
|
|
4390
|
+
if (now === null || now === last)
|
|
4391
|
+
return;
|
|
4392
|
+
last = now;
|
|
4393
|
+
for (const h of handles())
|
|
4394
|
+
h.setVolume?.(now);
|
|
4395
|
+
};
|
|
4396
|
+
listeners.add(listener);
|
|
4397
|
+
return () => {
|
|
4398
|
+
listeners.delete(listener);
|
|
4399
|
+
};
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4369
4402
|
// src/strum/play.ts
|
|
4370
4403
|
function scoreOf(pattern, voicing) {
|
|
4371
4404
|
const changes = pattern.slots.filter((s) => s.chord);
|
|
@@ -4474,14 +4507,16 @@ function runPasses(make, player, settings, timers, onEnd, follow) {
|
|
|
4474
4507
|
let stopped = false;
|
|
4475
4508
|
let timer;
|
|
4476
4509
|
let pass = 0;
|
|
4510
|
+
const handles = [];
|
|
4511
|
+
const unfollow = followVolume(() => settings().volume, () => handles, settings().volume);
|
|
4477
4512
|
let anchor = null;
|
|
4478
4513
|
let elapsed = 0;
|
|
4479
|
-
const handles = [];
|
|
4480
4514
|
const followers = [];
|
|
4481
4515
|
const finish = () => {
|
|
4482
4516
|
if (stopped)
|
|
4483
4517
|
return;
|
|
4484
4518
|
stopped = true;
|
|
4519
|
+
unfollow();
|
|
4485
4520
|
onEnd?.();
|
|
4486
4521
|
};
|
|
4487
4522
|
const schedule = (looping) => {
|
|
@@ -4550,6 +4585,7 @@ function runPasses(make, player, settings, timers, onEnd, follow) {
|
|
|
4550
4585
|
return {
|
|
4551
4586
|
stop() {
|
|
4552
4587
|
stopped = true;
|
|
4588
|
+
unfollow();
|
|
4553
4589
|
timers.clearTimeout(timer);
|
|
4554
4590
|
for (const h of handles)
|
|
4555
4591
|
h.stop();
|
|
@@ -6197,17 +6233,32 @@ function diagramGroup(doc, win, diagrams, options, how) {
|
|
|
6197
6233
|
sawStart(player);
|
|
6198
6234
|
follower.heard();
|
|
6199
6235
|
};
|
|
6236
|
+
const volume = volumeOf(options.volume);
|
|
6237
|
+
let handle = null;
|
|
6238
|
+
const unfollow = followVolume(() => volumeOf(options.volume), () => handle ? [handle] : [], volume);
|
|
6200
6239
|
try {
|
|
6201
|
-
|
|
6240
|
+
handle = player.play(events, {
|
|
6202
6241
|
sound: soundOf(item),
|
|
6203
|
-
volume
|
|
6204
|
-
onEnd
|
|
6242
|
+
volume,
|
|
6243
|
+
onEnd: () => {
|
|
6244
|
+
unfollow();
|
|
6245
|
+
onEnd();
|
|
6246
|
+
},
|
|
6205
6247
|
onStart
|
|
6206
6248
|
});
|
|
6207
6249
|
} catch (error) {
|
|
6250
|
+
unfollow();
|
|
6208
6251
|
follower.stop();
|
|
6209
6252
|
throw error;
|
|
6210
6253
|
}
|
|
6254
|
+
const played = handle;
|
|
6255
|
+
return {
|
|
6256
|
+
stop() {
|
|
6257
|
+
unfollow();
|
|
6258
|
+
played.stop();
|
|
6259
|
+
},
|
|
6260
|
+
setVolume: (next) => played.setVolume?.(next)
|
|
6261
|
+
};
|
|
6211
6262
|
};
|
|
6212
6263
|
try {
|
|
6213
6264
|
return run(playerFor(here, options));
|
|
@@ -6699,6 +6750,7 @@ var DIRECTIONS = {
|
|
|
6699
6750
|
ArrowUp: [0, -1],
|
|
6700
6751
|
ArrowDown: [0, 1]
|
|
6701
6752
|
};
|
|
6753
|
+
var TOUCH = ["touchstart", "touchend"];
|
|
6702
6754
|
var RESULT_CLASS = { right: "mn-pick-right", wrong: "mn-pick-wrong" };
|
|
6703
6755
|
var num = (el, name) => Number(el.getAttribute(name));
|
|
6704
6756
|
var optional = (el, name) => el.hasAttribute(name) ? num(el, name) : null;
|
|
@@ -6863,6 +6915,8 @@ function attachPick(diagram, options = {}) {
|
|
|
6863
6915
|
}
|
|
6864
6916
|
for (const type of ["pointerdown", "mousedown"])
|
|
6865
6917
|
diagram.addEventListener(type, onPress);
|
|
6918
|
+
for (const type of TOUCH)
|
|
6919
|
+
diagram.addEventListener(type, onPress, { passive: true });
|
|
6866
6920
|
diagram.addEventListener("click", onClick);
|
|
6867
6921
|
diagram.addEventListener("keydown", onKey);
|
|
6868
6922
|
const groups = new Set(targets.map((t) => t.parentElement));
|
|
@@ -6976,6 +7030,8 @@ function attachPick(diagram, options = {}) {
|
|
|
6976
7030
|
marks = null;
|
|
6977
7031
|
for (const type of ["pointerdown", "mousedown"])
|
|
6978
7032
|
diagram.removeEventListener(type, onPress);
|
|
7033
|
+
for (const type of TOUCH)
|
|
7034
|
+
diagram.removeEventListener(type, onPress);
|
|
6979
7035
|
diagram.removeEventListener("click", onClick);
|
|
6980
7036
|
diagram.removeEventListener("keydown", onKey);
|
|
6981
7037
|
for (const el of targets) {
|
|
@@ -10808,6 +10864,8 @@ var renderChord = (doc, block, options) => {
|
|
|
10808
10864
|
}
|
|
10809
10865
|
const sounding = symbol && capo ? soundingChord(symbol, capo) : symbol;
|
|
10810
10866
|
const sounds = soundsField(field2(block, "sounds"), symbol, capo);
|
|
10867
|
+
if (capo && sounding && soundsInTitle(field2(block, "sounds")) && !field2(block, "title"))
|
|
10868
|
+
title = `${sounding} (${title ?? symbol} shape)`;
|
|
10811
10869
|
const root = sounding ? chordNoteSet(sounding)?.root ?? rootOf2(sounding) : null;
|
|
10812
10870
|
const strings = tuning ?? (voicing.frets.length === 6 ? STANDARD_TUNING : undefined);
|
|
10813
10871
|
const labels = dotLabels(field2(block, "labels"), sounding, shape, strings && capo ? capoTuning(strings, capo) : tuning);
|
|
@@ -10857,10 +10915,17 @@ function captioned(doc, diagram, sentences) {
|
|
|
10857
10915
|
figure.append(diagram, html(doc, "figcaption", "mn-fingering", sentences.join(" ")));
|
|
10858
10916
|
return figure;
|
|
10859
10917
|
}
|
|
10918
|
+
var soundsInTitle = (text) => /^title$/i.test(text?.trim() ?? "");
|
|
10860
10919
|
function soundsField(text, shape, capo) {
|
|
10861
10920
|
const value = text?.trim();
|
|
10862
10921
|
if (!value || /^(no|false|off)$/i.test(value))
|
|
10863
10922
|
return;
|
|
10923
|
+
if (soundsInTitle(value)) {
|
|
10924
|
+
if (capo && (!shape || !chordNoteSet(shape))) {
|
|
10925
|
+
throw new Error("sounds: title needs a chord the library knows: add its symbol (e.g. symbol: A)");
|
|
10926
|
+
}
|
|
10927
|
+
return;
|
|
10928
|
+
}
|
|
10864
10929
|
const auto = /^(yes|true|on|auto)$/i.test(value);
|
|
10865
10930
|
if (!capo) {
|
|
10866
10931
|
if (auto)
|
|
@@ -12312,6 +12377,13 @@ var styles_default = `/* Music notation. Colors follow Obsidian's theme variable
|
|
|
12312
12377
|
.mn-svg.mn-fretboard {
|
|
12313
12378
|
zoom: 1.34;
|
|
12314
12379
|
}
|
|
12380
|
+
|
|
12381
|
+
/* A keyboard with a pick layer (Music Practice drills, click input): a black key (14 units)
|
|
12382
|
+
becomes 24 px wide. Keyboards that only play keep their size. On a narrow screen max-width
|
|
12383
|
+
still fits a wide range to the page: fewer keys, larger targets. */
|
|
12384
|
+
.mn-svg.mn-keyboard[data-mn-pick] {
|
|
12385
|
+
zoom: 1.72;
|
|
12386
|
+
}
|
|
12315
12387
|
}
|
|
12316
12388
|
|
|
12317
12389
|
.mn-svg text {
|
|
@@ -14551,9 +14623,10 @@ export {
|
|
|
14551
14623
|
voiceLeadVoicings,
|
|
14552
14624
|
voiceMotion,
|
|
14553
14625
|
voicingShape,
|
|
14626
|
+
volumeChanged,
|
|
14554
14627
|
withNaming,
|
|
14555
14628
|
withTonicizations
|
|
14556
14629
|
};
|
|
14557
14630
|
|
|
14558
|
-
//# debugId=
|
|
14631
|
+
//# debugId=B41A5636C218CAD964756E2164756E21
|
|
14559
14632
|
//# sourceMappingURL=index.js.map
|