@dsebastien/music-notation 0.25.0 → 0.26.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 +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +361 -18
- package/dist/index.js.map +9 -8
- package/dist/music-notation.publish.min.js +36 -36
- package/dist/music-notation.tab.min.js +7 -7
- package/dist/playback/controls.d.ts +28 -0
- package/dist/playback/effects.d.ts +142 -0
- package/dist/playback/player.d.ts +14 -0
- package/dist/publish/index.js +354 -14
- package/dist/publish/index.js.map +8 -7
- package/dist/tab/index.d.ts +7 -0
- package/dist/tab/index.js +468 -4
- package/dist/tab/index.js.map +8 -6
- package/dist/tab/room.d.ts +45 -0
- package/dist/theory/suffix.d.ts +6 -0
- package/dist/voicings/index.js +8 -3
- package/dist/voicings/index.js.map +4 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -158,7 +158,7 @@ if (!result.ok) console.warn(result.error)
|
|
|
158
158
|
|
|
159
159
|
- `renderBlock(language, source, host, options)` appends the rendering to `host` and never throws. It returns `{ ok, el, error, destroy() }`.
|
|
160
160
|
- `@dsebastien/music-notation/voicings` adds about 1,800 guitar voicings, found by chord symbol (`chord` blocks with only a symbol). It's a separate entry point because the data weighs about 230 KB.
|
|
161
|
-
- **Hear the diagrams**: with the `play` option, a click on a diagram plays it and a click on a dot or a key plays that note; one bar under each block plays the selected diagram or all of them in turn, with loop, speed and the sound (the volume is the app's setting). Guitar chords strum, piano chords strike as a block, scales run from their tonic up and back. Four guitars can play them: a steel-string acoustic (the default), a classical, a clean electric or an overdriven electric guitar (the reader's pick in the bar's Sound menu, `guitar: nylon` in a block, or the app's choice, in that order). While it plays, each note lights up on the drawing when you hear it.
|
|
161
|
+
- **Hear the diagrams**: with the `play` option, a click on a diagram plays it and a click on a dot or a key plays that note; one bar under each block plays the selected diagram or all of them in turn, with loop, speed and the sound (the volume is the app's setting). Guitar chords strum, piano chords strike as a block, scales run from their tonic up and back. Four guitars can play them: a steel-string acoustic (the default), a classical, a clean electric or an overdriven electric guitar (the reader's pick in the bar's Sound menu, `guitar: nylon` in a block, or the app's choice, in that order). Everything plays in a small room, light by default, and the app can set its level and length, or turn on an amplifier for the electric guitars. While it plays, each note lights up on the drawing when you hear it.
|
|
162
162
|
- **Strumming patterns**: `strum` blocks draw a pattern (`D DU UDU`, `D - D U - U D U`) on a beat grid with counts, accents, muted and ghost strums and chord changes; with playback on, they play over their chords, with loop, tempo and a count-in. `playStrum(pattern, { bpm, chord, tuning })` plays one from code.
|
|
163
163
|
- **Practice in time**: `progression` blocks and ChordPro charts get a bar that plays their chords in time, one chord a bar (or as a chart's bar lines say), with a metronome click, a count-in and a loop. Each chord is strummed on the beats, once a bar, as an arpeggio or to a strumming pattern, and the chord playing lights up. `playProgression(chords, { bpm, strum, pattern, click, countIn, loop })` does it from code, with your own player.
|
|
164
164
|
- **Harmonize a scale**: a `progression` block with `harmonize: triads`, `sevenths`, `sus` or `power` and any 7-note scale as its `key:` (`A harmonic minor`, `D dorian`) draws the chord on each degree with its numeral and a diagram, ready to play in time. `harmonize(scale, { kind })` gives the same chords from code.
|
|
@@ -192,7 +192,7 @@ Add this to your site's `publish.js`. It loads the bundle only on pages that hav
|
|
|
192
192
|
|
|
193
193
|
```js
|
|
194
194
|
;(() => {
|
|
195
|
-
const VERSION = '0.
|
|
195
|
+
const VERSION = '0.26.0'
|
|
196
196
|
const CDN = `https://cdn.jsdelivr.net/npm/@dsebastien/music-notation@${VERSION}/dist`
|
|
197
197
|
const selector = (languages) => languages.map((l) => `pre > code.language-${l}`).join(', ')
|
|
198
198
|
const BLOCKS = selector([
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { pageInstruments, type InstrumentSource } from './tab/instruments.js';
|
|
|
11
11
|
export { attachPlayback, type PlayOptions, type TimedBar } from './playback/controls.js';
|
|
12
12
|
export { ENGINES, chooseEngine, engineOf, engineOrder, pageEngine, type Engine } from './playback/engine.js';
|
|
13
13
|
export { DEFAULT_GUITAR_TONE, GUITAR_PROGRAMS, GUITAR_TONES, guitarToneOf, pageGuitar, type GuitarTone } from './playback/guitar-tone.js';
|
|
14
|
+
export { DEFAULT_REVERB, pageEffects, outputFor, type PlayEffects, type AmpOptions } from './playback/effects.js';
|
|
14
15
|
export { volumeChanged } from './playback/live-volume.js';
|
|
15
16
|
export { attachCopy } from './playback/copy-image.js';
|
|
16
17
|
export { toSvgString, toPng, type ExportTheme, type SvgExportOptions, type PngExportOptions } from './export/image.js';
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,11 @@ function withoutParentheses(suffix) {
|
|
|
95
95
|
return null;
|
|
96
96
|
return suffix.replace(/[(),\s]/g, "");
|
|
97
97
|
}
|
|
98
|
+
var leadSheetSuffix = (suffix) => suffix.replace(/^(?:mi|MI|min|MIN)(?![A-Za-z])/, "m").replace(/^(?:ma|MA)(?![A-Za-z])/, "maj");
|
|
98
99
|
function canonicalSuffix(suffix) {
|
|
100
|
+
const lead = leadSheetSuffix(suffix);
|
|
101
|
+
if (lead !== suffix)
|
|
102
|
+
return canonicalSuffix(lead);
|
|
99
103
|
const direct = CANONICAL.get(suffix);
|
|
100
104
|
if (direct !== undefined)
|
|
101
105
|
return direct;
|
|
@@ -1523,9 +1527,10 @@ function parseChord(symbol) {
|
|
|
1523
1527
|
return null;
|
|
1524
1528
|
const trimmed = symbol.trim();
|
|
1525
1529
|
const { root, bass } = parts;
|
|
1526
|
-
const
|
|
1530
|
+
const lead = leadSheetSuffix(parts.suffix);
|
|
1531
|
+
const suffix = withoutParentheses(lead);
|
|
1527
1532
|
let quality = null;
|
|
1528
|
-
for (const written of suffix === null || suffix ===
|
|
1533
|
+
for (const written of suffix === null || suffix === lead ? [lead] : [lead, suffix]) {
|
|
1529
1534
|
for (const [re, label] of QUALITY_SUFFIXES) {
|
|
1530
1535
|
const hit = re.exec(written);
|
|
1531
1536
|
if (hit) {
|
|
@@ -5579,6 +5584,289 @@ function pageGuitar(options) {
|
|
|
5579
5584
|
return guitarToneOf(play.guitar) ?? undefined;
|
|
5580
5585
|
}
|
|
5581
5586
|
|
|
5587
|
+
// src/playback/effects.ts
|
|
5588
|
+
var DEFAULT_REVERB = 0.125;
|
|
5589
|
+
var ROOM_SECONDS = 1.2;
|
|
5590
|
+
var ROOM_RANGE = [0.2, 3];
|
|
5591
|
+
function roomSeconds(value) {
|
|
5592
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(ROOM_RANGE[1], Math.max(ROOM_RANGE[0], value)) : ROOM_SECONDS;
|
|
5593
|
+
}
|
|
5594
|
+
function reverbLevel(value) {
|
|
5595
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_REVERB;
|
|
5596
|
+
}
|
|
5597
|
+
function pageEffects(options) {
|
|
5598
|
+
if (!options || typeof options !== "object" || !("play" in options))
|
|
5599
|
+
return null;
|
|
5600
|
+
const play = options.play;
|
|
5601
|
+
if (!play || typeof play !== "object")
|
|
5602
|
+
return null;
|
|
5603
|
+
const read = (key) => {
|
|
5604
|
+
const value = play[key];
|
|
5605
|
+
if (typeof value !== "function")
|
|
5606
|
+
return value;
|
|
5607
|
+
try {
|
|
5608
|
+
return value();
|
|
5609
|
+
} catch {
|
|
5610
|
+
return;
|
|
5611
|
+
}
|
|
5612
|
+
};
|
|
5613
|
+
const reverb = read("reverb");
|
|
5614
|
+
const room = read("room");
|
|
5615
|
+
const amp = read("amp");
|
|
5616
|
+
const drive = amp && typeof amp === "object" ? amp["drive"] : null;
|
|
5617
|
+
const cabinet = amp && typeof amp === "object" && amp["cabinet"];
|
|
5618
|
+
const effects = {
|
|
5619
|
+
...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.min(1, Math.max(0, reverb)) } : {},
|
|
5620
|
+
...typeof room === "number" && Number.isFinite(room) ? { room: roomSeconds(room) } : {},
|
|
5621
|
+
...read("dry") === true ? { dry: true } : {},
|
|
5622
|
+
...cabinet === true || typeof drive === "number" && Number.isFinite(drive) ? {
|
|
5623
|
+
amp: {
|
|
5624
|
+
...typeof drive === "number" && Number.isFinite(drive) ? { drive: Math.min(1, Math.max(0, drive)) } : {},
|
|
5625
|
+
...cabinet === true ? { cabinet: true } : {}
|
|
5626
|
+
}
|
|
5627
|
+
} : {}
|
|
5628
|
+
};
|
|
5629
|
+
return Object.keys(effects).length ? effects : null;
|
|
5630
|
+
}
|
|
5631
|
+
function seeded(seed) {
|
|
5632
|
+
let a = seed >>> 0;
|
|
5633
|
+
return () => {
|
|
5634
|
+
a = a + 1831565813 >>> 0;
|
|
5635
|
+
let t = a;
|
|
5636
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
5637
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
5638
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
5639
|
+
};
|
|
5640
|
+
}
|
|
5641
|
+
var ROOM_SHAPE = { bright: 4000, dark: 800, rise: 0.02, width: 0.5 };
|
|
5642
|
+
var ROOM_BAND = [300, 3000];
|
|
5643
|
+
var ROOM_WIDE_FROM = 400;
|
|
5644
|
+
var ROOM_SLOPE = 3;
|
|
5645
|
+
function roomImpulse(sampleRate, seconds = ROOM_SECONDS, shape = {}) {
|
|
5646
|
+
const { bright, dark, rise: riseSeconds, width } = { ...ROOM_SHAPE, ...shape };
|
|
5647
|
+
const length = Math.max(1, Math.round(sampleRate * seconds));
|
|
5648
|
+
const start = Math.min(length, Math.round(sampleRate * 0.012));
|
|
5649
|
+
const fade = Math.max(1, Math.round(length * 0.1));
|
|
5650
|
+
const fall = Math.pow(10, -3 / (sampleRate * seconds));
|
|
5651
|
+
const darker = Math.pow(dark / bright, 1 / (sampleRate * seconds));
|
|
5652
|
+
const rise = Math.max(1, Math.round(sampleRate * Math.max(0, riseSeconds)));
|
|
5653
|
+
const keepAt = (cutoff) => Math.exp(-2 * Math.PI * Math.min(cutoff, sampleRate * 0.45) / sampleRate);
|
|
5654
|
+
const shapeAt = (i) => (i - start < rise ? (i - start) / rise : 1) * (i > length - fade ? (length - i) / fade : 1);
|
|
5655
|
+
const make = (seed) => {
|
|
5656
|
+
const random = seeded(seed);
|
|
5657
|
+
const data = new Float32Array(length);
|
|
5658
|
+
let level = Math.pow(fall, start);
|
|
5659
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
5660
|
+
let keep = 0;
|
|
5661
|
+
const lows = new Float64Array(ROOM_SLOPE);
|
|
5662
|
+
for (let i = start;i < length; i++) {
|
|
5663
|
+
if ((i - start) % 64 === 0)
|
|
5664
|
+
keep = keepAt(cutoff);
|
|
5665
|
+
let value = random() * 2 - 1;
|
|
5666
|
+
for (let pole = 0;pole < ROOM_SLOPE; pole++) {
|
|
5667
|
+
value = keep * lows[pole] + (1 - keep) * value;
|
|
5668
|
+
lows[pole] = value;
|
|
5669
|
+
}
|
|
5670
|
+
data[i] = value * level * shapeAt(i);
|
|
5671
|
+
level *= fall;
|
|
5672
|
+
cutoff *= darker;
|
|
5673
|
+
}
|
|
5674
|
+
return data;
|
|
5675
|
+
};
|
|
5676
|
+
let power = 0;
|
|
5677
|
+
const pitches = 8;
|
|
5678
|
+
for (let p = 0;p < pitches; p++) {
|
|
5679
|
+
const hz = ROOM_BAND[0] * Math.pow(ROOM_BAND[1] / ROOM_BAND[0], (p + 0.5) / pitches);
|
|
5680
|
+
const cos = Math.cos(2 * Math.PI * hz / sampleRate);
|
|
5681
|
+
let level = Math.pow(fall, start);
|
|
5682
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
5683
|
+
const step = Math.pow(fall, 64);
|
|
5684
|
+
const darkerStep = Math.pow(darker, 64);
|
|
5685
|
+
for (let i = start;i < length; i += 64) {
|
|
5686
|
+
const keep = keepAt(cutoff);
|
|
5687
|
+
const pole = (1 - keep) * (1 - keep) / (1 - 2 * keep * cos + keep * keep);
|
|
5688
|
+
const size = Math.min(64, length - i);
|
|
5689
|
+
const here = level * shapeAt(i + (size >> 1));
|
|
5690
|
+
power += size * here * here * Math.pow(pole, ROOM_SLOPE) / 3;
|
|
5691
|
+
level *= step;
|
|
5692
|
+
cutoff *= darkerStep;
|
|
5693
|
+
}
|
|
5694
|
+
}
|
|
5695
|
+
const scale = power > 0 ? 1 / Math.sqrt(power / pitches) : 0;
|
|
5696
|
+
const middle = make(625341585);
|
|
5697
|
+
const apart = make(1374496523);
|
|
5698
|
+
const pass = Math.exp(-2 * Math.PI * ROOM_WIDE_FROM / sampleRate);
|
|
5699
|
+
for (let turn = 0;turn < 2; turn++) {
|
|
5700
|
+
let low = 0;
|
|
5701
|
+
for (let i = 0;i < length; i++) {
|
|
5702
|
+
low = pass * low + (1 - pass) * apart[i];
|
|
5703
|
+
apart[i] = apart[i] - low;
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
const angle = Math.min(1, Math.max(0, width)) * Math.PI / 4;
|
|
5707
|
+
const left = new Float32Array(length);
|
|
5708
|
+
const right = new Float32Array(length);
|
|
5709
|
+
for (let i = 0;i < length; i++) {
|
|
5710
|
+
const m = middle[i] * Math.cos(angle) * scale;
|
|
5711
|
+
const a = apart[i] * Math.sin(angle) * scale;
|
|
5712
|
+
left[i] = m + a;
|
|
5713
|
+
right[i] = m - a;
|
|
5714
|
+
}
|
|
5715
|
+
return [left, right];
|
|
5716
|
+
}
|
|
5717
|
+
var CEILING = { knee: 0.9, range: 2 };
|
|
5718
|
+
function ceilingCurve(points = 4097) {
|
|
5719
|
+
const { knee, range } = CEILING;
|
|
5720
|
+
const curve = new Float32Array(points);
|
|
5721
|
+
for (let i = 0;i < points; i++) {
|
|
5722
|
+
const level = (i / (points - 1) * 2 - 1) * range;
|
|
5723
|
+
const size = Math.abs(level);
|
|
5724
|
+
curve[i] = Math.sign(level) * (size <= knee ? size : knee + (1 - knee) * Math.tanh((size - knee) / (1 - knee)));
|
|
5725
|
+
}
|
|
5726
|
+
return curve;
|
|
5727
|
+
}
|
|
5728
|
+
var ROOM_LOW_CUT = 180;
|
|
5729
|
+
var chains = new WeakMap;
|
|
5730
|
+
var canBuild = (ctx) => typeof ctx.createConvolver === "function" && typeof ctx.createBuffer === "function";
|
|
5731
|
+
var rooms = new Map;
|
|
5732
|
+
function roomBuffer(ctx, seconds) {
|
|
5733
|
+
const key = `${ctx.sampleRate}:${seconds}`;
|
|
5734
|
+
let sides = rooms.get(key);
|
|
5735
|
+
if (!sides) {
|
|
5736
|
+
sides = roomImpulse(ctx.sampleRate, seconds);
|
|
5737
|
+
if (rooms.size >= 3)
|
|
5738
|
+
rooms.delete(rooms.keys().next().value);
|
|
5739
|
+
rooms.set(key, sides);
|
|
5740
|
+
}
|
|
5741
|
+
const [left, right] = sides;
|
|
5742
|
+
const impulse = ctx.createBuffer(2, left.length, ctx.sampleRate);
|
|
5743
|
+
impulse.getChannelData(0).set(left);
|
|
5744
|
+
impulse.getChannelData(1).set(right);
|
|
5745
|
+
return impulse;
|
|
5746
|
+
}
|
|
5747
|
+
function build(ctx, speakers, seconds) {
|
|
5748
|
+
const input = ctx.createGain();
|
|
5749
|
+
const wet = ctx.createGain();
|
|
5750
|
+
wet.gain.value = 0;
|
|
5751
|
+
const room = ctx.createConvolver();
|
|
5752
|
+
room.normalize = false;
|
|
5753
|
+
room.buffer = roomBuffer(ctx, seconds);
|
|
5754
|
+
const sum = ctx.createGain();
|
|
5755
|
+
input.connect(sum);
|
|
5756
|
+
input.connect(room);
|
|
5757
|
+
if (typeof ctx.createBiquadFilter === "function") {
|
|
5758
|
+
const lowCut = ctx.createBiquadFilter();
|
|
5759
|
+
lowCut.type = "highpass";
|
|
5760
|
+
lowCut.frequency.value = ROOM_LOW_CUT;
|
|
5761
|
+
lowCut.Q.value = 0.7;
|
|
5762
|
+
room.connect(lowCut);
|
|
5763
|
+
lowCut.connect(wet);
|
|
5764
|
+
} else
|
|
5765
|
+
room.connect(wet);
|
|
5766
|
+
wet.connect(sum);
|
|
5767
|
+
if (typeof ctx.createWaveShaper === "function") {
|
|
5768
|
+
const ceiling = ctx.createWaveShaper();
|
|
5769
|
+
ceiling.curve = ceilingCurve();
|
|
5770
|
+
sum.gain.value = 1 / CEILING.range;
|
|
5771
|
+
sum.connect(ceiling);
|
|
5772
|
+
ceiling.connect(speakers);
|
|
5773
|
+
} else
|
|
5774
|
+
sum.connect(speakers);
|
|
5775
|
+
return { input, wet, room, seconds };
|
|
5776
|
+
}
|
|
5777
|
+
function outputFor(ctx, effects, speakers = ctx.destination) {
|
|
5778
|
+
if (effects?.dry || !canBuild(ctx))
|
|
5779
|
+
return speakers;
|
|
5780
|
+
const seconds = roomSeconds(effects?.room);
|
|
5781
|
+
let chain = chains.get(ctx);
|
|
5782
|
+
if (!chain) {
|
|
5783
|
+
try {
|
|
5784
|
+
chain = build(ctx, speakers, seconds);
|
|
5785
|
+
} catch {
|
|
5786
|
+
return speakers;
|
|
5787
|
+
}
|
|
5788
|
+
chains.set(ctx, chain);
|
|
5789
|
+
} else if (chain.seconds !== seconds) {
|
|
5790
|
+
try {
|
|
5791
|
+
chain.room.buffer = roomBuffer(ctx, seconds);
|
|
5792
|
+
chain.seconds = seconds;
|
|
5793
|
+
} catch {}
|
|
5794
|
+
}
|
|
5795
|
+
const level = reverbLevel(effects?.reverb);
|
|
5796
|
+
if (typeof chain.wet.gain.setTargetAtTime === "function")
|
|
5797
|
+
chain.wet.gain.setTargetAtTime(level, ctx.currentTime, 0.02);
|
|
5798
|
+
else
|
|
5799
|
+
chain.wet.gain.value = level;
|
|
5800
|
+
return chain.input;
|
|
5801
|
+
}
|
|
5802
|
+
var driveAmount = (drive) => 1 + 14 * Math.min(1, Math.max(0, drive));
|
|
5803
|
+
function driveCurve(drive, points = 2048) {
|
|
5804
|
+
const amount = driveAmount(drive);
|
|
5805
|
+
const curve = new Float32Array(points);
|
|
5806
|
+
const ceiling = Math.tanh(amount);
|
|
5807
|
+
for (let i = 0;i < points; i++) {
|
|
5808
|
+
const x = i / (points - 1) * 2 - 1;
|
|
5809
|
+
curve[i] = Math.tanh(amount * x) / ceiling;
|
|
5810
|
+
}
|
|
5811
|
+
return curve;
|
|
5812
|
+
}
|
|
5813
|
+
var DRIVE_REFERENCE = 0.2;
|
|
5814
|
+
function driveLevel(drive, reference = DRIVE_REFERENCE) {
|
|
5815
|
+
const amount = driveAmount(drive);
|
|
5816
|
+
const ceiling = Math.tanh(amount);
|
|
5817
|
+
let before = 0;
|
|
5818
|
+
let after = 0;
|
|
5819
|
+
for (let i = 0;i < 256; i++) {
|
|
5820
|
+
const x = reference * Math.sin(2 * Math.PI * i / 256);
|
|
5821
|
+
const y = Math.tanh(amount * x) / ceiling;
|
|
5822
|
+
before += x * x;
|
|
5823
|
+
after += y * y;
|
|
5824
|
+
}
|
|
5825
|
+
return after > 0 ? Math.sqrt(before / after) : 1;
|
|
5826
|
+
}
|
|
5827
|
+
var CABINET_TRIM_DB = -2;
|
|
5828
|
+
function ampFor(ctx, amp) {
|
|
5829
|
+
const drive = typeof amp?.drive === "number" ? Math.min(1, Math.max(0, amp.drive)) : 0;
|
|
5830
|
+
const cabinet = amp?.cabinet === true;
|
|
5831
|
+
if (!drive && !cabinet)
|
|
5832
|
+
return null;
|
|
5833
|
+
if (typeof ctx.createWaveShaper !== "function" || typeof ctx.createBiquadFilter !== "function")
|
|
5834
|
+
return null;
|
|
5835
|
+
const input = ctx.createGain();
|
|
5836
|
+
let last = input;
|
|
5837
|
+
const filter = (type, frequency, q, gain = 0) => {
|
|
5838
|
+
const node = ctx.createBiquadFilter();
|
|
5839
|
+
node.type = type;
|
|
5840
|
+
node.frequency.value = frequency;
|
|
5841
|
+
node.Q.value = q;
|
|
5842
|
+
node.gain.value = gain;
|
|
5843
|
+
last.connect(node);
|
|
5844
|
+
last = node;
|
|
5845
|
+
};
|
|
5846
|
+
if (drive) {
|
|
5847
|
+
filter("highpass", 120, 0.7);
|
|
5848
|
+
const shaper = ctx.createWaveShaper();
|
|
5849
|
+
shaper.curve = driveCurve(drive);
|
|
5850
|
+
shaper.oversample = "4x";
|
|
5851
|
+
const level = ctx.createGain();
|
|
5852
|
+
level.gain.value = driveLevel(drive);
|
|
5853
|
+
last.connect(shaper);
|
|
5854
|
+
shaper.connect(level);
|
|
5855
|
+
last = level;
|
|
5856
|
+
}
|
|
5857
|
+
if (cabinet) {
|
|
5858
|
+
filter("highpass", 90, 0.7);
|
|
5859
|
+
filter("peaking", 2200, 1, 4);
|
|
5860
|
+
filter("lowpass", 4800, 0.7);
|
|
5861
|
+
filter("lowpass", 6500, 0.7);
|
|
5862
|
+
const level = ctx.createGain();
|
|
5863
|
+
level.gain.value = Math.pow(10, CABINET_TRIM_DB / 20);
|
|
5864
|
+
last.connect(level);
|
|
5865
|
+
last = level;
|
|
5866
|
+
}
|
|
5867
|
+
return { input, output: last };
|
|
5868
|
+
}
|
|
5869
|
+
|
|
5582
5870
|
// src/playback/player.ts
|
|
5583
5871
|
var DEFAULT_SEQUENCE = { bpm: 90, strum: 12 };
|
|
5584
5872
|
var DEFAULT_STRUM = { guitar: 12, piano: 0 };
|
|
@@ -5768,6 +6056,25 @@ var PLUCKS = 4;
|
|
|
5768
6056
|
var RELEASE = { guitar: 0.15, piano: 0.3 };
|
|
5769
6057
|
var releaseOf = (sound, duration) => Math.min(RELEASE[sound], Math.max(0.03, duration / 2));
|
|
5770
6058
|
var pianoDecay = (midi) => Math.min(2.5, Math.max(0.35, Math.pow(2, (60 - midi) / 24)));
|
|
6059
|
+
function sendOut(ctx, from, guitar, effects) {
|
|
6060
|
+
const out = outputFor(ctx, effects);
|
|
6061
|
+
const amp = !effects?.dry && (guitar === "clean" || guitar === "overdrive") ? ampFor(ctx, effects?.amp) : null;
|
|
6062
|
+
const cut = (node) => {
|
|
6063
|
+
try {
|
|
6064
|
+
node.disconnect();
|
|
6065
|
+
} catch {}
|
|
6066
|
+
};
|
|
6067
|
+
if (!amp) {
|
|
6068
|
+
from.connect(out);
|
|
6069
|
+
return () => cut(from);
|
|
6070
|
+
}
|
|
6071
|
+
from.connect(amp.input);
|
|
6072
|
+
amp.output.connect(out);
|
|
6073
|
+
return () => {
|
|
6074
|
+
cut(from);
|
|
6075
|
+
cut(amp.output);
|
|
6076
|
+
};
|
|
6077
|
+
}
|
|
5771
6078
|
function lightPlayer(win, random = Math.random) {
|
|
5772
6079
|
const strings = new Map;
|
|
5773
6080
|
const waves = new WeakMap;
|
|
@@ -5800,7 +6107,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5800
6107
|
};
|
|
5801
6108
|
return {
|
|
5802
6109
|
reportsStart: true,
|
|
5803
|
-
play(events, { sound, volume, onEnd, onStart, guitar }) {
|
|
6110
|
+
play(events, { sound, volume, onEnd, onStart, guitar, effects }) {
|
|
5804
6111
|
const ctx = contextFor(win);
|
|
5805
6112
|
if (!ctx || !events.length)
|
|
5806
6113
|
return { stop() {} };
|
|
@@ -5821,7 +6128,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5821
6128
|
});
|
|
5822
6129
|
const gain = ctx.createGain();
|
|
5823
6130
|
gain.gain.value = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
|
|
5824
|
-
|
|
6131
|
+
const letGo = sendOut(ctx, gain, sound === "guitar" ? tone : null, effects);
|
|
5825
6132
|
const start = ctx.currentTime + 0.05;
|
|
5826
6133
|
const sources = events.map((e, i) => {
|
|
5827
6134
|
if (e.kind)
|
|
@@ -5857,7 +6164,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5857
6164
|
source.stop(Math.max(at + 0.006, end) + release);
|
|
5858
6165
|
return source;
|
|
5859
6166
|
});
|
|
5860
|
-
const finish = () =>
|
|
6167
|
+
const finish = () => letGo();
|
|
5861
6168
|
let stopped = false;
|
|
5862
6169
|
let heard;
|
|
5863
6170
|
const announce = () => {
|
|
@@ -9296,7 +9603,32 @@ function playerFor(win, options, el) {
|
|
|
9296
9603
|
}
|
|
9297
9604
|
function toned(player, options, el) {
|
|
9298
9605
|
const tone = guitarFor(options, el);
|
|
9299
|
-
|
|
9606
|
+
const effects = effectsOf(options);
|
|
9607
|
+
return tone || effects ? withPlay(player, tone, effects) : player;
|
|
9608
|
+
}
|
|
9609
|
+
function effectsOf(options) {
|
|
9610
|
+
const read = (value) => {
|
|
9611
|
+
try {
|
|
9612
|
+
return (typeof value === "function" ? value() : value) ?? null;
|
|
9613
|
+
} catch {
|
|
9614
|
+
return null;
|
|
9615
|
+
}
|
|
9616
|
+
};
|
|
9617
|
+
const reverb = read(options.reverb);
|
|
9618
|
+
const room = read(options.room);
|
|
9619
|
+
const amp = read(options.amp);
|
|
9620
|
+
const effects = {
|
|
9621
|
+
...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.round(Math.min(1, Math.max(0, reverb)) * 1000) / 1000 } : {},
|
|
9622
|
+
...typeof room === "number" && Number.isFinite(room) ? { room: Math.round(roomSeconds(room) * 100) / 100 } : {},
|
|
9623
|
+
...read(options.dry) === true ? { dry: true } : {},
|
|
9624
|
+
...amp && typeof amp === "object" && (amp.cabinet === true || typeof amp.drive === "number") ? {
|
|
9625
|
+
amp: {
|
|
9626
|
+
...amp.cabinet === true ? { cabinet: true } : {},
|
|
9627
|
+
...typeof amp.drive === "number" && Number.isFinite(amp.drive) ? { drive: Math.round(Math.min(1, Math.max(0, amp.drive)) * 100) / 100 } : {}
|
|
9628
|
+
}
|
|
9629
|
+
} : {}
|
|
9630
|
+
};
|
|
9631
|
+
return Object.keys(effects).length ? effects : null;
|
|
9300
9632
|
}
|
|
9301
9633
|
function guitarFor(options, el) {
|
|
9302
9634
|
const wish = guitarChoice(el) ?? guitarWish(el);
|
|
@@ -9308,22 +9640,30 @@ function guitarFor(options, el) {
|
|
|
9308
9640
|
return null;
|
|
9309
9641
|
}
|
|
9310
9642
|
}
|
|
9311
|
-
var
|
|
9312
|
-
|
|
9313
|
-
|
|
9643
|
+
var twinPlayers = new WeakMap;
|
|
9644
|
+
var TWINS_KEPT = 32;
|
|
9645
|
+
function withPlay(player, guitar, effects) {
|
|
9646
|
+
let twins = twinPlayers.get(player);
|
|
9314
9647
|
if (!twins) {
|
|
9315
9648
|
twins = new Map;
|
|
9316
|
-
|
|
9649
|
+
twinPlayers.set(player, twins);
|
|
9317
9650
|
}
|
|
9318
|
-
|
|
9651
|
+
const key = `${guitar ?? ""}|${effects ? JSON.stringify(effects) : ""}`;
|
|
9652
|
+
let twin = twins.get(key);
|
|
9319
9653
|
if (!twin) {
|
|
9320
9654
|
twin = {
|
|
9321
9655
|
get reportsStart() {
|
|
9322
9656
|
return player.reportsStart;
|
|
9323
9657
|
},
|
|
9324
|
-
play: (events, options) => player.play(events,
|
|
9658
|
+
play: (events, options) => player.play(events, {
|
|
9659
|
+
...options,
|
|
9660
|
+
...guitar && !options.guitar ? { guitar } : {},
|
|
9661
|
+
...effects && !options.effects ? { effects } : {}
|
|
9662
|
+
})
|
|
9325
9663
|
};
|
|
9326
|
-
twins.
|
|
9664
|
+
if (twins.size >= TWINS_KEPT)
|
|
9665
|
+
twins.delete(twins.keys().next().value);
|
|
9666
|
+
twins.set(key, twin);
|
|
9327
9667
|
}
|
|
9328
9668
|
return twin;
|
|
9329
9669
|
}
|
|
@@ -17341,10 +17681,10 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17341
17681
|
};
|
|
17342
17682
|
return {
|
|
17343
17683
|
reportsStart: true,
|
|
17344
|
-
play(events, { sound: instrument, volume, onEnd, onStart, guitar }) {
|
|
17684
|
+
play(events, { sound: instrument, volume, onEnd, onStart, guitar, effects }) {
|
|
17345
17685
|
const ctx = contextOf();
|
|
17346
17686
|
const tone = guitar ?? DEFAULT_GUITAR_TONE;
|
|
17347
|
-
const same = guitar ? { guitar } : {};
|
|
17687
|
+
const same = { ...guitar ? { guitar } : {}, ...effects ? { effects } : {} };
|
|
17348
17688
|
if (!ctx)
|
|
17349
17689
|
return fallback.play(events, {
|
|
17350
17690
|
sound: instrument,
|
|
@@ -17376,7 +17716,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17376
17716
|
const byKind = new Map(kinds.map((kind, i) => [kind, loaded[i]]));
|
|
17377
17717
|
const master = ctx.createGain();
|
|
17378
17718
|
master.gain.value = level;
|
|
17379
|
-
|
|
17719
|
+
const letGo = sendOut(ctx, master, instrument === "guitar" ? tone : null, effects);
|
|
17380
17720
|
const start = ctx.currentTime + 0.05;
|
|
17381
17721
|
const sources = [];
|
|
17382
17722
|
let tail = 0;
|
|
@@ -17394,7 +17734,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17394
17734
|
tail = Math.max(tail, made.over - start);
|
|
17395
17735
|
}
|
|
17396
17736
|
}
|
|
17397
|
-
const finish = () =>
|
|
17737
|
+
const finish = () => letGo();
|
|
17398
17738
|
let heard;
|
|
17399
17739
|
const announce = () => {
|
|
17400
17740
|
if (stopped || !onStart)
|
|
@@ -18336,6 +18676,7 @@ export {
|
|
|
18336
18676
|
DEFAULT_EXERCISE_TEMPO,
|
|
18337
18677
|
DEFAULT_GUITAR_TONE,
|
|
18338
18678
|
DEFAULT_PROPERTY_NAMES,
|
|
18679
|
+
DEFAULT_REVERB,
|
|
18339
18680
|
DEFAULT_SEQUENCE,
|
|
18340
18681
|
DEFAULT_STRUM,
|
|
18341
18682
|
DEFAULT_STRUM_CHORD,
|
|
@@ -18455,6 +18796,8 @@ export {
|
|
|
18455
18796
|
noteOf,
|
|
18456
18797
|
noteTargets,
|
|
18457
18798
|
numeralOf,
|
|
18799
|
+
outputFor,
|
|
18800
|
+
pageEffects,
|
|
18458
18801
|
pageEngine,
|
|
18459
18802
|
pageGuitar,
|
|
18460
18803
|
pageInstruments,
|
|
@@ -18560,5 +18903,5 @@ export {
|
|
|
18560
18903
|
withTonicizations
|
|
18561
18904
|
};
|
|
18562
18905
|
|
|
18563
|
-
//# debugId=
|
|
18906
|
+
//# debugId=A93BDCD6EB2011A264756E2164756E21
|
|
18564
18907
|
//# sourceMappingURL=index.js.map
|