@dsebastien/music-notation 0.23.0 → 0.24.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/README.md +4 -2
- package/dist/i18n/en/index.d.ts +1 -0
- package/dist/i18n/en/play.d.ts +1 -0
- package/dist/i18n/fr/diagrams.d.ts +2 -2
- package/dist/i18n/fr/parse.d.ts +4 -4
- package/dist/i18n/fr/play.d.ts +1 -0
- package/dist/i18n/fr/timed.d.ts +4 -4
- package/dist/i18n/language.d.ts +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +158 -36
- package/dist/index.js.map +15 -14
- package/dist/music-notation.publish.min.js +32 -32
- package/dist/music-notation.tab.min.js +7 -7
- package/dist/playback/controls.d.ts +14 -0
- package/dist/playback/guitar-tone.d.ts +27 -0
- package/dist/playback/player.d.ts +12 -0
- package/dist/publish/index.js +135 -28
- package/dist/publish/index.js.map +14 -13
- package/dist/tab/index.js +87 -27
- package/dist/tab/index.js.map +10 -9
- package/dist/voicings/index.js +13 -11
- package/dist/voicings/index.js.map +7 -7
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import { type Language } from '../i18n/language.js';
|
|
|
2
2
|
import type { Hand } from '../render/layout.js';
|
|
3
3
|
import { type NotePlayer, type PlayKind, type Sound } from './player.js';
|
|
4
4
|
import { type Engine } from './engine.js';
|
|
5
|
+
import { type GuitarTone } from './guitar-tone.js';
|
|
5
6
|
export interface PlayOptions {
|
|
6
7
|
/**
|
|
7
8
|
* The language of the bars' texts and of the diagrams they redraw (#136): `'en'` or `'fr'`.
|
|
@@ -26,6 +27,12 @@ export interface PlayOptions {
|
|
|
26
27
|
engine?: Engine;
|
|
27
28
|
/** Guitar or piano; by default the diagram's (piano for keyboards and piano chords). */
|
|
28
29
|
sound?: Sound;
|
|
30
|
+
/**
|
|
31
|
+
* Which guitar plays the guitar sound (#103): `steel` (a steel-string acoustic, the default),
|
|
32
|
+
* `nylon`, `clean` (an electric) or `overdrive`. A function is read at each play, so a setting
|
|
33
|
+
* changed in the app is heard at the next Play. A block's `guitar:` line comes first.
|
|
34
|
+
*/
|
|
35
|
+
guitar?: GuitarTone | (() => GuitarTone | null | undefined);
|
|
29
36
|
/**
|
|
30
37
|
* 0 to 1, 0.8 by default. The bars have no volume (#58): it is the app's setting. A function
|
|
31
38
|
* is read at each play (and each pass of a loop), so a setting changed in the app applies at
|
|
@@ -100,6 +107,13 @@ export declare function lightFor(win: Window): NotePlayer;
|
|
|
100
107
|
* fallback order; the light synthesizer when it has none.
|
|
101
108
|
*/
|
|
102
109
|
export declare function playerFor(win: Window, options: PlayOptions, el?: Element | null): NotePlayer;
|
|
110
|
+
/**
|
|
111
|
+
* `player` playing the guitar an element asks for (#103); `player` itself when nothing names a
|
|
112
|
+
* guitar, so an app that names none gets exactly the player it gave.
|
|
113
|
+
*/
|
|
114
|
+
export declare function toned(player: NotePlayer, options: PlayOptions, el?: Element | null): NotePlayer;
|
|
115
|
+
/** The guitar that plays for an element: its block's `guitar:` line, else the app's or page's. */
|
|
116
|
+
export declare function guitarFor(options: PlayOptions, el?: Element | null): GuitarTone | null;
|
|
103
117
|
/** The diagram's own playback data, set by its renderer. */
|
|
104
118
|
export interface DiagramData {
|
|
105
119
|
kind: PlayKind;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which guitar plays the diagrams (#103): a steel-string acoustic (the default), a nylon-string
|
|
3
|
+
* classical guitar, a clean electric or an overdriven electric. The reader's side chooses (a
|
|
4
|
+
* page's or an app's `guitar`); a block may say `guitar:`. It changes the guitar sound only: a
|
|
5
|
+
* piano stays a piano, and tabs and scores keep the instruments their tracks name.
|
|
6
|
+
*/
|
|
7
|
+
/** The guitars, the default first. */
|
|
8
|
+
export declare const GUITAR_TONES: readonly ["steel", "nylon", "clean", "overdrive"];
|
|
9
|
+
export type GuitarTone = (typeof GUITAR_TONES)[number];
|
|
10
|
+
export declare const DEFAULT_GUITAR_TONE: GuitarTone;
|
|
11
|
+
/** The General MIDI program of each guitar, for the players that play a soundfont. */
|
|
12
|
+
export declare const GUITAR_PROGRAMS: Readonly<Record<GuitarTone, number>>;
|
|
13
|
+
/** A guitar's name from a page option, a setting or a block line; null when it isn't one. */
|
|
14
|
+
export declare function guitarToneOf(value: unknown): GuitarTone | null;
|
|
15
|
+
/**
|
|
16
|
+
* A block's `guitar:` line (the last one wins; `{guitar: …}` in a ChordPro chart), taken out of
|
|
17
|
+
* its source so that no block parser has to know it. Throws a message for the user when the value
|
|
18
|
+
* isn't a guitar.
|
|
19
|
+
*/
|
|
20
|
+
export declare function blockGuitar(source: string, chart?: boolean): {
|
|
21
|
+
guitar: GuitarTone | null;
|
|
22
|
+
source: string;
|
|
23
|
+
};
|
|
24
|
+
/** The guitar of the block an element is in (`data-mn-guitar`, set from its `guitar:` line). */
|
|
25
|
+
export declare function guitarWish(el: Element | null | undefined): GuitarTone | null;
|
|
26
|
+
/** A page's guitar (`play: { guitar }` in `window.musicNotationOptions`), when it names one. */
|
|
27
|
+
export declare function pageGuitar(options: unknown): GuitarTone | undefined;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* light synthesizer to play them (a plucked string for guitar, a simple piano), with no download.
|
|
4
4
|
* Apps can pass another NotePlayer (a soundfont one) for realistic sound.
|
|
5
5
|
*/
|
|
6
|
+
import { type GuitarTone } from './guitar-tone.js';
|
|
6
7
|
export type Sound = 'guitar' | 'piano';
|
|
7
8
|
export interface NoteEvent {
|
|
8
9
|
midi: number;
|
|
@@ -35,6 +36,11 @@ export interface NotePlayer {
|
|
|
35
36
|
volume: number;
|
|
36
37
|
onEnd?: () => void;
|
|
37
38
|
onStart?: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Which guitar plays when `sound` is guitar (#103): steel-string by default. A player
|
|
41
|
+
* that doesn't know it plays its own guitar.
|
|
42
|
+
*/
|
|
43
|
+
guitar?: GuitarTone;
|
|
38
44
|
}): PlayHandle;
|
|
39
45
|
/**
|
|
40
46
|
* True when `play` calls `onStart`: the bar then waits for it before it lights notes.
|
|
@@ -96,6 +102,12 @@ export interface PluckOptions {
|
|
|
96
102
|
pick?: number;
|
|
97
103
|
/** How fast the string loses its energy, times the usual (1 by default). */
|
|
98
104
|
damping?: number;
|
|
105
|
+
/**
|
|
106
|
+
* How hard an amplifier is driven (0, the default: not at all). The string's wave is pressed
|
|
107
|
+
* against a soft ceiling, which adds harmonics and holds the level while the string fades, as
|
|
108
|
+
* an overdriven amplifier does.
|
|
109
|
+
*/
|
|
110
|
+
drive?: number;
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* A plucked string (Karplus-Strong): a burst of noise through a delay line one period long,
|
package/dist/publish/index.js
CHANGED
|
@@ -597,6 +597,7 @@ var enPlay = {
|
|
|
597
597
|
"playback.redraw.guitar": "{name}, drawn for guitar",
|
|
598
598
|
"playback.redraw.piano": "{name}, drawn for piano",
|
|
599
599
|
"playback.engine.invalid": 'engine: use generaluser, sonivox or light, got "{value}"',
|
|
600
|
+
"playback.guitar.invalid": 'guitar: use steel, nylon, clean or overdrive, got "{value}"',
|
|
600
601
|
"tab.source.staves": 'staves: use tab, score or both, got "{value}"',
|
|
601
602
|
"tab.source.layout": 'layout: use page or line, got "{value}"',
|
|
602
603
|
"tab.source.names": 'names: use on or off, got "{value}"',
|
|
@@ -752,7 +753,7 @@ var frDiagrams = {
|
|
|
752
753
|
"render.voicings.inversion": "inversion : utilisez 0 (fondamentale), 1, 2, 3 ou any, reçu « {inversion} »",
|
|
753
754
|
"render.voicings.manyStringsAny": "Sur {count} cordes, inversion: any demande six cordes ou moins : ajoutez par exemple strings: 1-6",
|
|
754
755
|
"render.voicings.wideArea": "une zone large",
|
|
755
|
-
"render.voicings.oneWidening": "Sur {count} cordes, utilisez
|
|
756
|
+
"render.voicings.oneWidening": "Sur {count} cordes, utilisez une seule option à la fois parmi {list}",
|
|
756
757
|
"render.noVoicing.gaps": "Les cordes {strings} ne sont pas côte à côte : ajoutez gaps: yes",
|
|
757
758
|
"render.noVoicing.rootString": "root-string {string} ne fait pas partie des cordes {strings}",
|
|
758
759
|
"render.noVoicing.inversion": "{symbol} a {notes} notes : inversion va jusqu'à {max}",
|
|
@@ -810,7 +811,7 @@ var frDiagrams = {
|
|
|
810
811
|
"fretboard.exercise.capo": "capo : utilisez une case de 1 à 12 (0 pour aucun), reçu {text}",
|
|
811
812
|
"fretboard.positions.numbering": "numbering : utilisez minor (positions depuis le relatif mineur), reçu « {text} »",
|
|
812
813
|
"fretboard.positions.numberingPentatonic": "numbering: minor sert aux positions de la pentatonique majeure (par exemple A major pentatonic), pas à {title}",
|
|
813
|
-
"fretboard.positions.numberingCaged": "numbering: minor numérote les positions
|
|
814
|
+
"fretboard.positions.numberingCaged": "numbering: minor numérote les positions (« box ») et 3nps, pas les formes CAGED",
|
|
814
815
|
"fretboard.positions.position": "position doit être un nombre entier à partir de 1, reçu « {text} »",
|
|
815
816
|
"fretboard.positions.shape": "Forme inconnue « {text} » : utilisez C, A, G, E, D ou 3nps",
|
|
816
817
|
"keyboard.fingering.finger": "fingering : les doigts vont de 1 (pouce) à 5 (auriculaire), reçu « {text} »",
|
|
@@ -971,7 +972,7 @@ var frParse = {
|
|
|
971
972
|
"blocks.fretboard.fromMinor": " (depuis {minor}m)",
|
|
972
973
|
"blocks.fretboard.shapeTitle": "{name}, forme {shape}",
|
|
973
974
|
"blocks.fretboard.threeNpsTitle": "{name}, 3nps {n}{from}",
|
|
974
|
-
"blocks.fretboard.boxTitle": "{name},
|
|
975
|
+
"blocks.fretboard.boxTitle": "{name}, position {n}{from}",
|
|
975
976
|
"blocks.scalesFor.both": "Utilisez scales-for (accords) ou scales-for-notes, pas les deux",
|
|
976
977
|
"blocks.scalesFor.findsItself": '{key} trouve la gamme seul : retirez "{what}"',
|
|
977
978
|
"blocks.scalesFor.addChords": "Ajoutez les accords : par ex. scales-for: G D Em C",
|
|
@@ -1020,8 +1021,8 @@ var frParse = {
|
|
|
1020
1021
|
"chord.words.fingerOn": "{finger} sur {strings}, {fret} case.",
|
|
1021
1022
|
"chord.words.fingerBars": "{finger} fait le barré à la {fret} case, cordes {from} à {to}.",
|
|
1022
1023
|
"chord.words.fingerAlsoOn": "{finger} aussi sur {string}, {fret} case.",
|
|
1023
|
-
"chord.words.muteOne": "Étouffez {list} :
|
|
1024
|
-
"chord.words.mutePlural": "Étouffez {list} :
|
|
1024
|
+
"chord.words.muteOne": "Étouffez {list} : laissez un doigt de l'accord l'effleurer.",
|
|
1025
|
+
"chord.words.mutePlural": "Étouffez {list} : laissez un doigt de l'accord les effleurer.",
|
|
1025
1026
|
"chord.words.groupRingOpenOne": "La corde {list} sonne à vide.",
|
|
1026
1027
|
"chord.words.groupRingOpenPlural": "Les cordes {list} sonnent à vide.",
|
|
1027
1028
|
"chord.words.groupRingCapoOne": "La corde {list} sonne au capodastre.",
|
|
@@ -1061,7 +1062,7 @@ var frParse = {
|
|
|
1061
1062
|
"theory.formula.formula": "Formule {formula}.",
|
|
1062
1063
|
"theory.formula.alsoWritten": "S'écrit aussi {list}.",
|
|
1063
1064
|
"theory.formula.scale": "{title} : {notes}.",
|
|
1064
|
-
"theory.formula.steps": "
|
|
1065
|
+
"theory.formula.steps": "Intervalles {steps}.",
|
|
1065
1066
|
"chords.chart.chorus": "Refrain",
|
|
1066
1067
|
"chords.chart.bridge": "Pont",
|
|
1067
1068
|
"chords.chart.tab": "Tablature",
|
|
@@ -1151,6 +1152,7 @@ var frPlay = {
|
|
|
1151
1152
|
"playback.redraw.guitar": "{name}, dessiné pour la guitare",
|
|
1152
1153
|
"playback.redraw.piano": "{name}, dessiné pour le piano",
|
|
1153
1154
|
"playback.engine.invalid": "engine: utilisez generaluser, sonivox ou light, reçu « {value} »",
|
|
1155
|
+
"playback.guitar.invalid": "guitar: utilisez steel, nylon, clean ou overdrive, reçu « {value} »",
|
|
1154
1156
|
"tab.source.staves": "staves: utilisez tab, score ou both, reçu « {value} »",
|
|
1155
1157
|
"tab.source.layout": "layout: utilisez page ou line, reçu « {value} »",
|
|
1156
1158
|
"tab.source.names": "names: utilisez on ou off, reçu « {value} »",
|
|
@@ -1215,7 +1217,7 @@ var frTimed = {
|
|
|
1215
1217
|
"strum.line.parenUnclosed": "« ) » manquant dans « {line} » : écrivez un coup fantôme ainsi : (U)",
|
|
1216
1218
|
"strum.line.chordEndsPattern": "L’accord [{chord}] termine le rythme : placez-le avant un coup ou un -",
|
|
1217
1219
|
"strum.pattern.chordLineAlone": "Une ligne d’accords demande une ligne de rythme dessous, par exemple D - D U - U D U",
|
|
1218
|
-
"strum.pattern.missing": "Écrivez
|
|
1220
|
+
"strum.pattern.missing": "Écrivez une rythmique, par exemple D - D U - U D U (ou D DU UDU)",
|
|
1219
1221
|
"strum.key.unknown": "Clé « {key} » inconnue : utilisez time, subdivision, swing, chord, tempo, tuning, title ou pattern",
|
|
1220
1222
|
"strum.swing.withTriplets": "Les triolets et le swing sont deux façons d’écrire un shuffle : gardez subdivision: triplets (D - U sur chaque temps), ou écrivez 8ths avec swing: yes",
|
|
1221
1223
|
"strum.swing.compound": "{time} a déjà trois {unit} par temps : retirez swing: (il swingue les 8ths ou les 16ths en 4/4, 3/4, 2/4…)",
|
|
@@ -1240,8 +1242,8 @@ var frTimed = {
|
|
|
1240
1242
|
"strum.feel.swingPercent": "Swing {percent} %",
|
|
1241
1243
|
"strum.feel.swing16": "Swing en doubles croches",
|
|
1242
1244
|
"strum.feel.swing16Percent": "Swing en doubles croches {percent} %",
|
|
1243
|
-
"strum.name": "
|
|
1244
|
-
"strum.name.titled": "{title} :
|
|
1245
|
+
"strum.name": "Rythmique {written}, {time}, {subdivision}{feel}",
|
|
1246
|
+
"strum.name.titled": "{title} : rythmique {written}, {time}, {subdivision}{feel}",
|
|
1245
1247
|
"strum.name.feel": ", {feel}",
|
|
1246
1248
|
"strum.tuning.unknown": "Accordage « {tuning} » inconnu : utilisez par exemple tuning: standard, drop d, ukulele ou E2 A2 D3 G3 B3 E4",
|
|
1247
1249
|
"strum.tuning.tooManyStrings": "12 cordes au plus",
|
|
@@ -1261,7 +1263,7 @@ var frTimed = {
|
|
|
1261
1263
|
"picking.name": "Motif de picking {written}, {time}, {subdivision}{over}",
|
|
1262
1264
|
"picking.name.titled": "{title} : motif de picking {written}, {time}, {subdivision}{over}",
|
|
1263
1265
|
"picking.name.over": ", sur {chords}",
|
|
1264
|
-
"picking.voicing.none": "
|
|
1266
|
+
"picking.voicing.none": "Aucune position jouable de {chord} pour cet accordage",
|
|
1265
1267
|
"export.image.title": "Notation musicale"
|
|
1266
1268
|
};
|
|
1267
1269
|
|
|
@@ -5481,6 +5483,55 @@ function strumVoicing(chord, tuning = STANDARD_TUNING, voicings) {
|
|
|
5481
5483
|
return [...pitches];
|
|
5482
5484
|
}
|
|
5483
5485
|
|
|
5486
|
+
// src/playback/guitar-tone.ts
|
|
5487
|
+
var GUITAR_TONES = ["steel", "nylon", "clean", "overdrive"];
|
|
5488
|
+
var DEFAULT_GUITAR_TONE = "steel";
|
|
5489
|
+
var GUITAR_PROGRAMS = {
|
|
5490
|
+
steel: 25,
|
|
5491
|
+
nylon: 24,
|
|
5492
|
+
clean: 27,
|
|
5493
|
+
overdrive: 29
|
|
5494
|
+
};
|
|
5495
|
+
var ALIASES3 = {
|
|
5496
|
+
acoustic: "steel",
|
|
5497
|
+
"steel-string": "steel",
|
|
5498
|
+
classical: "nylon",
|
|
5499
|
+
"nylon-string": "nylon",
|
|
5500
|
+
electric: "clean",
|
|
5501
|
+
overdriven: "overdrive"
|
|
5502
|
+
};
|
|
5503
|
+
function guitarToneOf(value) {
|
|
5504
|
+
if (typeof value !== "string")
|
|
5505
|
+
return null;
|
|
5506
|
+
const name = value.trim().toLowerCase().replace(/\s+/g, "-");
|
|
5507
|
+
return GUITAR_TONES.find((tone) => tone === name) ?? ALIASES3[name] ?? null;
|
|
5508
|
+
}
|
|
5509
|
+
var LINE = /^[ \t]*guitar[ \t]*:[ \t]*(.*?)[ \t]*(?:\r?\n|$)/gim;
|
|
5510
|
+
var DIRECTIVE = /^[ \t]*\{[ \t]*guitar[ \t]*:[ \t]*(.*?)[ \t]*\}[ \t]*(?:\r?\n|$)/gim;
|
|
5511
|
+
function blockGuitar(source, chart = false) {
|
|
5512
|
+
let guitar = null;
|
|
5513
|
+
const rest = source.replace(chart ? DIRECTIVE : LINE, (_line, value) => {
|
|
5514
|
+
const read = guitarToneOf(value);
|
|
5515
|
+
if (!read) {
|
|
5516
|
+
throw new Error(t("playback.guitar.invalid", { value }));
|
|
5517
|
+
}
|
|
5518
|
+
guitar = read;
|
|
5519
|
+
return "";
|
|
5520
|
+
});
|
|
5521
|
+
return { guitar, source: rest };
|
|
5522
|
+
}
|
|
5523
|
+
function guitarWish(el) {
|
|
5524
|
+
return guitarToneOf(el?.closest("[data-mn-guitar]")?.getAttribute("data-mn-guitar"));
|
|
5525
|
+
}
|
|
5526
|
+
function pageGuitar(options) {
|
|
5527
|
+
if (!options || typeof options !== "object" || !("play" in options))
|
|
5528
|
+
return;
|
|
5529
|
+
const play = options.play;
|
|
5530
|
+
if (!play || typeof play !== "object" || !("guitar" in play))
|
|
5531
|
+
return;
|
|
5532
|
+
return guitarToneOf(play.guitar) ?? undefined;
|
|
5533
|
+
}
|
|
5534
|
+
|
|
5484
5535
|
// src/playback/player.ts
|
|
5485
5536
|
var DEFAULT_SEQUENCE = { bpm: 90, strum: 12 };
|
|
5486
5537
|
var DEFAULT_STRUM = { guitar: 12, piano: 0 };
|
|
@@ -5574,8 +5625,21 @@ function pluckedString(midi, sampleRate, seconds, random = Math.random, options
|
|
|
5574
5625
|
out[i] = value * 0.5;
|
|
5575
5626
|
at = next;
|
|
5576
5627
|
}
|
|
5628
|
+
const drive = options.drive !== undefined && Number.isFinite(options.drive) ? Math.max(0, options.drive) : 0;
|
|
5629
|
+
if (drive > 0) {
|
|
5630
|
+
const push = 1 + drive;
|
|
5631
|
+
for (let i = 0;i < out.length; i++)
|
|
5632
|
+
out[i] = Math.tanh(out[i] * 2 * push) * OVERDRIVE_LEVEL;
|
|
5633
|
+
}
|
|
5577
5634
|
return out;
|
|
5578
5635
|
}
|
|
5636
|
+
var OVERDRIVE_LEVEL = 0.18;
|
|
5637
|
+
var TONE_PLUCKS = {
|
|
5638
|
+
steel: { brightness: [0.55, 0.95], pick: [0.08, 0.2], damping: [0.85, 1.15], drive: 0 },
|
|
5639
|
+
nylon: { brightness: [0.05, 0.25], pick: [0.2, 0.34], damping: [2.2, 2.8], drive: 0 },
|
|
5640
|
+
clean: { brightness: [0.7, 1], pick: [0.1, 0.18], damping: [0.55, 0.75], drive: 0 },
|
|
5641
|
+
overdrive: { brightness: [0.7, 1], pick: [0.1, 0.18], damping: [0.45, 0.6], drive: 5 }
|
|
5642
|
+
};
|
|
5579
5643
|
function pianoTone(midi, sampleRate, seconds) {
|
|
5580
5644
|
const out = new Float32Array(Math.round(sampleRate * seconds));
|
|
5581
5645
|
const f = frequency(midi);
|
|
@@ -5661,14 +5725,16 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5661
5725
|
const strings = new Map;
|
|
5662
5726
|
const waves = new WeakMap;
|
|
5663
5727
|
const between = (lo, hi) => lo + (hi - lo) * random();
|
|
5664
|
-
const stringBuffer = (ctx, midi, pluck) => {
|
|
5665
|
-
const key = midi * PLUCKS + pluck
|
|
5728
|
+
const stringBuffer = (ctx, midi, pluck, tone) => {
|
|
5729
|
+
const key = `${tone}:${midi * PLUCKS + pluck}`;
|
|
5666
5730
|
let buffer = strings.get(key);
|
|
5667
5731
|
if (!buffer) {
|
|
5732
|
+
const ranges = TONE_PLUCKS[tone];
|
|
5668
5733
|
const data = pluckedString(midi, ctx.sampleRate, STRING_SECONDS, random, {
|
|
5669
|
-
brightness: between(0
|
|
5670
|
-
pick: between(0
|
|
5671
|
-
damping: between(0
|
|
5734
|
+
brightness: between(ranges.brightness[0], ranges.brightness[1]),
|
|
5735
|
+
pick: between(ranges.pick[0], ranges.pick[1]),
|
|
5736
|
+
damping: between(ranges.damping[0], ranges.damping[1]),
|
|
5737
|
+
...ranges.drive ? { drive: ranges.drive } : {}
|
|
5672
5738
|
});
|
|
5673
5739
|
buffer = ctx.createBuffer(1, data.length, ctx.sampleRate);
|
|
5674
5740
|
buffer.getChannelData(0).set(data);
|
|
@@ -5687,10 +5753,11 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5687
5753
|
};
|
|
5688
5754
|
return {
|
|
5689
5755
|
reportsStart: true,
|
|
5690
|
-
play(events, { sound, volume, onEnd, onStart }) {
|
|
5756
|
+
play(events, { sound, volume, onEnd, onStart, guitar }) {
|
|
5691
5757
|
const ctx = contextFor(win);
|
|
5692
5758
|
if (!ctx || !events.length)
|
|
5693
5759
|
return { stop() {} };
|
|
5760
|
+
const tone = guitar ?? DEFAULT_GUITAR_TONE;
|
|
5694
5761
|
const resumed = ctx.resume();
|
|
5695
5762
|
const touches = events.map(() => ({
|
|
5696
5763
|
pluck: Math.min(PLUCKS - 1, Math.floor(random() * PLUCKS)),
|
|
@@ -5701,9 +5768,9 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5701
5768
|
if (sound === "guitar")
|
|
5702
5769
|
events.forEach((e, i) => {
|
|
5703
5770
|
if (e.kind === "muted")
|
|
5704
|
-
stringBuffer(ctx, e.midi, 0);
|
|
5771
|
+
stringBuffer(ctx, e.midi, 0, tone);
|
|
5705
5772
|
else if (!e.kind)
|
|
5706
|
-
stringBuffer(ctx, e.midi, touches[i].pluck);
|
|
5773
|
+
stringBuffer(ctx, e.midi, touches[i].pluck, tone);
|
|
5707
5774
|
});
|
|
5708
5775
|
const gain = ctx.createGain();
|
|
5709
5776
|
gain.gain.value = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
|
|
@@ -5711,7 +5778,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5711
5778
|
const start = ctx.currentTime + 0.05;
|
|
5712
5779
|
const sources = events.map((e, i) => {
|
|
5713
5780
|
if (e.kind)
|
|
5714
|
-
return percussive(ctx, gain, e, start, sound, (c, m) => stringBuffer(c, m, 0));
|
|
5781
|
+
return percussive(ctx, gain, e, start, sound, (c, m) => stringBuffer(c, m, 0, tone));
|
|
5715
5782
|
const touch = touches[i];
|
|
5716
5783
|
const at = start + e.time;
|
|
5717
5784
|
const end = at + e.duration;
|
|
@@ -5722,7 +5789,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5722
5789
|
let source;
|
|
5723
5790
|
if (sound === "guitar") {
|
|
5724
5791
|
const buffer = ctx.createBufferSource();
|
|
5725
|
-
buffer.buffer = stringBuffer(ctx, e.midi, touch.pluck);
|
|
5792
|
+
buffer.buffer = stringBuffer(ctx, e.midi, touch.pluck, tone);
|
|
5726
5793
|
buffer.playbackRate.value = Math.pow(2, touch.cents / 1200);
|
|
5727
5794
|
source = buffer;
|
|
5728
5795
|
env.gain.setValueAtTime(level, at);
|
|
@@ -6730,11 +6797,11 @@ function chooseEngine(wish, has) {
|
|
|
6730
6797
|
}
|
|
6731
6798
|
return null;
|
|
6732
6799
|
}
|
|
6733
|
-
var
|
|
6734
|
-
var
|
|
6800
|
+
var LINE2 = /^[ \t]*engine[ \t]*:[ \t]*(.*?)[ \t]*(?:\r?\n|$)/gim;
|
|
6801
|
+
var DIRECTIVE2 = /^[ \t]*\{[ \t]*engine[ \t]*:[ \t]*(.*?)[ \t]*\}[ \t]*(?:\r?\n|$)/gim;
|
|
6735
6802
|
function blockEngine(source, chart = false) {
|
|
6736
6803
|
let engine = null;
|
|
6737
|
-
const rest = source.replace(chart ?
|
|
6804
|
+
const rest = source.replace(chart ? DIRECTIVE2 : LINE2, (_line, value) => {
|
|
6738
6805
|
const read = engineOf(value);
|
|
6739
6806
|
if (!read) {
|
|
6740
6807
|
throw new Error(t("playback.engine.invalid", { value }));
|
|
@@ -7882,7 +7949,7 @@ function barPlayer(wrap, win, options) {
|
|
|
7882
7949
|
try {
|
|
7883
7950
|
return chosen.play(events, given);
|
|
7884
7951
|
} catch {
|
|
7885
|
-
return lightFor(here).play(events, opts);
|
|
7952
|
+
return toned(lightFor(here), options, wrap).play(events, opts);
|
|
7886
7953
|
}
|
|
7887
7954
|
}
|
|
7888
7955
|
};
|
|
@@ -8162,7 +8229,7 @@ var PICKING_PATTERNS = {
|
|
|
8162
8229
|
"alternate bass": { name: "Alternate bass", slots: "p i m i p' i m i" },
|
|
8163
8230
|
"1-2-3-4": { name: "1-2-3-4", slots: "p i m a p i m a" }
|
|
8164
8231
|
};
|
|
8165
|
-
var
|
|
8232
|
+
var ALIASES4 = {
|
|
8166
8233
|
"travis picking": "travis",
|
|
8167
8234
|
"alternating bass": "alternate bass",
|
|
8168
8235
|
"alternate-bass": "alternate bass",
|
|
@@ -8172,7 +8239,7 @@ var ALIASES3 = {
|
|
|
8172
8239
|
};
|
|
8173
8240
|
function namedPicking(text) {
|
|
8174
8241
|
const t = text.trim().toLowerCase().replace(/\s+/g, " ");
|
|
8175
|
-
const key =
|
|
8242
|
+
const key = ALIASES4[t] ?? t;
|
|
8176
8243
|
return PICKING_PATTERNS[key] ? key : null;
|
|
8177
8244
|
}
|
|
8178
8245
|
var KEYS2 = [
|
|
@@ -8817,7 +8884,7 @@ function diagramGroup(doc, win, diagrams, options, how) {
|
|
|
8817
8884
|
try {
|
|
8818
8885
|
return run(playerFor(here, options, item.wrap));
|
|
8819
8886
|
} catch {
|
|
8820
|
-
return run(lightFor(here));
|
|
8887
|
+
return run(toned(lightFor(here), options, item.wrap));
|
|
8821
8888
|
}
|
|
8822
8889
|
};
|
|
8823
8890
|
const select = (item) => {
|
|
@@ -9097,6 +9164,42 @@ function lightFor(win) {
|
|
|
9097
9164
|
return player;
|
|
9098
9165
|
}
|
|
9099
9166
|
function playerFor(win, options, el) {
|
|
9167
|
+
return toned(enginePlayerFor(win, options, el), options, el);
|
|
9168
|
+
}
|
|
9169
|
+
function toned(player, options, el) {
|
|
9170
|
+
const tone = guitarFor(options, el);
|
|
9171
|
+
return tone ? withGuitar(player, tone) : player;
|
|
9172
|
+
}
|
|
9173
|
+
function guitarFor(options, el) {
|
|
9174
|
+
const wish = guitarWish(el);
|
|
9175
|
+
if (wish)
|
|
9176
|
+
return wish;
|
|
9177
|
+
try {
|
|
9178
|
+
return guitarToneOf(typeof options.guitar === "function" ? options.guitar() : options.guitar);
|
|
9179
|
+
} catch {
|
|
9180
|
+
return null;
|
|
9181
|
+
}
|
|
9182
|
+
}
|
|
9183
|
+
var guitarPlayers = new WeakMap;
|
|
9184
|
+
function withGuitar(player, guitar) {
|
|
9185
|
+
let twins = guitarPlayers.get(player);
|
|
9186
|
+
if (!twins) {
|
|
9187
|
+
twins = new Map;
|
|
9188
|
+
guitarPlayers.set(player, twins);
|
|
9189
|
+
}
|
|
9190
|
+
let twin = twins.get(guitar);
|
|
9191
|
+
if (!twin) {
|
|
9192
|
+
twin = {
|
|
9193
|
+
get reportsStart() {
|
|
9194
|
+
return player.reportsStart;
|
|
9195
|
+
},
|
|
9196
|
+
play: (events, options) => player.play(events, options.guitar ? options : { ...options, guitar })
|
|
9197
|
+
};
|
|
9198
|
+
twins.set(guitar, twin);
|
|
9199
|
+
}
|
|
9200
|
+
return twin;
|
|
9201
|
+
}
|
|
9202
|
+
function enginePlayerFor(win, options, el) {
|
|
9100
9203
|
const engines = options.engines;
|
|
9101
9204
|
if (engines) {
|
|
9102
9205
|
const chosen = chooseEngine(engineWish(el) ?? engineOf(options.engine), (engine) => {
|
|
@@ -14198,6 +14301,10 @@ function drawBlock(language, source, host, given) {
|
|
|
14198
14301
|
text = wish.source;
|
|
14199
14302
|
if (wish.engine)
|
|
14200
14303
|
el.setAttribute("data-mn-engine", wish.engine);
|
|
14304
|
+
const tone = blockGuitar(text, language === "chords");
|
|
14305
|
+
text = tone.source;
|
|
14306
|
+
if (tone.guitar)
|
|
14307
|
+
el.setAttribute("data-mn-guitar", tone.guitar);
|
|
14201
14308
|
} catch (e) {
|
|
14202
14309
|
return failed(el, host, language, messageOf(e));
|
|
14203
14310
|
}
|
|
@@ -15137,5 +15244,5 @@ export {
|
|
|
15137
15244
|
renderAll
|
|
15138
15245
|
};
|
|
15139
15246
|
|
|
15140
|
-
//# debugId=
|
|
15247
|
+
//# debugId=A605C3830CDF43CA64756E2164756E21
|
|
15141
15248
|
//# sourceMappingURL=index.js.map
|