@dsebastien/music-notation 0.25.0 → 0.26.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 +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +354 -16
- package/dist/index.js.map +7 -6
- 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 +347 -12
- package/dist/publish/index.js.map +6 -5
- package/dist/tab/index.d.ts +7 -0
- package/dist/tab/index.js +461 -1
- package/dist/tab/index.js.map +6 -4
- package/dist/tab/room.d.ts +45 -0
- package/package.json +1 -1
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.25.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
|
@@ -5579,6 +5579,289 @@ function pageGuitar(options) {
|
|
|
5579
5579
|
return guitarToneOf(play.guitar) ?? undefined;
|
|
5580
5580
|
}
|
|
5581
5581
|
|
|
5582
|
+
// src/playback/effects.ts
|
|
5583
|
+
var DEFAULT_REVERB = 0.125;
|
|
5584
|
+
var ROOM_SECONDS = 1.2;
|
|
5585
|
+
var ROOM_RANGE = [0.2, 3];
|
|
5586
|
+
function roomSeconds(value) {
|
|
5587
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(ROOM_RANGE[1], Math.max(ROOM_RANGE[0], value)) : ROOM_SECONDS;
|
|
5588
|
+
}
|
|
5589
|
+
function reverbLevel(value) {
|
|
5590
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_REVERB;
|
|
5591
|
+
}
|
|
5592
|
+
function pageEffects(options) {
|
|
5593
|
+
if (!options || typeof options !== "object" || !("play" in options))
|
|
5594
|
+
return null;
|
|
5595
|
+
const play = options.play;
|
|
5596
|
+
if (!play || typeof play !== "object")
|
|
5597
|
+
return null;
|
|
5598
|
+
const read = (key) => {
|
|
5599
|
+
const value = play[key];
|
|
5600
|
+
if (typeof value !== "function")
|
|
5601
|
+
return value;
|
|
5602
|
+
try {
|
|
5603
|
+
return value();
|
|
5604
|
+
} catch {
|
|
5605
|
+
return;
|
|
5606
|
+
}
|
|
5607
|
+
};
|
|
5608
|
+
const reverb = read("reverb");
|
|
5609
|
+
const room = read("room");
|
|
5610
|
+
const amp = read("amp");
|
|
5611
|
+
const drive = amp && typeof amp === "object" ? amp["drive"] : null;
|
|
5612
|
+
const cabinet = amp && typeof amp === "object" && amp["cabinet"];
|
|
5613
|
+
const effects = {
|
|
5614
|
+
...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.min(1, Math.max(0, reverb)) } : {},
|
|
5615
|
+
...typeof room === "number" && Number.isFinite(room) ? { room: roomSeconds(room) } : {},
|
|
5616
|
+
...read("dry") === true ? { dry: true } : {},
|
|
5617
|
+
...cabinet === true || typeof drive === "number" && Number.isFinite(drive) ? {
|
|
5618
|
+
amp: {
|
|
5619
|
+
...typeof drive === "number" && Number.isFinite(drive) ? { drive: Math.min(1, Math.max(0, drive)) } : {},
|
|
5620
|
+
...cabinet === true ? { cabinet: true } : {}
|
|
5621
|
+
}
|
|
5622
|
+
} : {}
|
|
5623
|
+
};
|
|
5624
|
+
return Object.keys(effects).length ? effects : null;
|
|
5625
|
+
}
|
|
5626
|
+
function seeded(seed) {
|
|
5627
|
+
let a = seed >>> 0;
|
|
5628
|
+
return () => {
|
|
5629
|
+
a = a + 1831565813 >>> 0;
|
|
5630
|
+
let t = a;
|
|
5631
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
5632
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
5633
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5636
|
+
var ROOM_SHAPE = { bright: 4000, dark: 800, rise: 0.02, width: 0.5 };
|
|
5637
|
+
var ROOM_BAND = [300, 3000];
|
|
5638
|
+
var ROOM_WIDE_FROM = 400;
|
|
5639
|
+
var ROOM_SLOPE = 3;
|
|
5640
|
+
function roomImpulse(sampleRate, seconds = ROOM_SECONDS, shape = {}) {
|
|
5641
|
+
const { bright, dark, rise: riseSeconds, width } = { ...ROOM_SHAPE, ...shape };
|
|
5642
|
+
const length = Math.max(1, Math.round(sampleRate * seconds));
|
|
5643
|
+
const start = Math.min(length, Math.round(sampleRate * 0.012));
|
|
5644
|
+
const fade = Math.max(1, Math.round(length * 0.1));
|
|
5645
|
+
const fall = Math.pow(10, -3 / (sampleRate * seconds));
|
|
5646
|
+
const darker = Math.pow(dark / bright, 1 / (sampleRate * seconds));
|
|
5647
|
+
const rise = Math.max(1, Math.round(sampleRate * Math.max(0, riseSeconds)));
|
|
5648
|
+
const keepAt = (cutoff) => Math.exp(-2 * Math.PI * Math.min(cutoff, sampleRate * 0.45) / sampleRate);
|
|
5649
|
+
const shapeAt = (i) => (i - start < rise ? (i - start) / rise : 1) * (i > length - fade ? (length - i) / fade : 1);
|
|
5650
|
+
const make = (seed) => {
|
|
5651
|
+
const random = seeded(seed);
|
|
5652
|
+
const data = new Float32Array(length);
|
|
5653
|
+
let level = Math.pow(fall, start);
|
|
5654
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
5655
|
+
let keep = 0;
|
|
5656
|
+
const lows = new Float64Array(ROOM_SLOPE);
|
|
5657
|
+
for (let i = start;i < length; i++) {
|
|
5658
|
+
if ((i - start) % 64 === 0)
|
|
5659
|
+
keep = keepAt(cutoff);
|
|
5660
|
+
let value = random() * 2 - 1;
|
|
5661
|
+
for (let pole = 0;pole < ROOM_SLOPE; pole++) {
|
|
5662
|
+
value = keep * lows[pole] + (1 - keep) * value;
|
|
5663
|
+
lows[pole] = value;
|
|
5664
|
+
}
|
|
5665
|
+
data[i] = value * level * shapeAt(i);
|
|
5666
|
+
level *= fall;
|
|
5667
|
+
cutoff *= darker;
|
|
5668
|
+
}
|
|
5669
|
+
return data;
|
|
5670
|
+
};
|
|
5671
|
+
let power = 0;
|
|
5672
|
+
const pitches = 8;
|
|
5673
|
+
for (let p = 0;p < pitches; p++) {
|
|
5674
|
+
const hz = ROOM_BAND[0] * Math.pow(ROOM_BAND[1] / ROOM_BAND[0], (p + 0.5) / pitches);
|
|
5675
|
+
const cos = Math.cos(2 * Math.PI * hz / sampleRate);
|
|
5676
|
+
let level = Math.pow(fall, start);
|
|
5677
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
5678
|
+
const step = Math.pow(fall, 64);
|
|
5679
|
+
const darkerStep = Math.pow(darker, 64);
|
|
5680
|
+
for (let i = start;i < length; i += 64) {
|
|
5681
|
+
const keep = keepAt(cutoff);
|
|
5682
|
+
const pole = (1 - keep) * (1 - keep) / (1 - 2 * keep * cos + keep * keep);
|
|
5683
|
+
const size = Math.min(64, length - i);
|
|
5684
|
+
const here = level * shapeAt(i + (size >> 1));
|
|
5685
|
+
power += size * here * here * Math.pow(pole, ROOM_SLOPE) / 3;
|
|
5686
|
+
level *= step;
|
|
5687
|
+
cutoff *= darkerStep;
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
const scale = power > 0 ? 1 / Math.sqrt(power / pitches) : 0;
|
|
5691
|
+
const middle = make(625341585);
|
|
5692
|
+
const apart = make(1374496523);
|
|
5693
|
+
const pass = Math.exp(-2 * Math.PI * ROOM_WIDE_FROM / sampleRate);
|
|
5694
|
+
for (let turn = 0;turn < 2; turn++) {
|
|
5695
|
+
let low = 0;
|
|
5696
|
+
for (let i = 0;i < length; i++) {
|
|
5697
|
+
low = pass * low + (1 - pass) * apart[i];
|
|
5698
|
+
apart[i] = apart[i] - low;
|
|
5699
|
+
}
|
|
5700
|
+
}
|
|
5701
|
+
const angle = Math.min(1, Math.max(0, width)) * Math.PI / 4;
|
|
5702
|
+
const left = new Float32Array(length);
|
|
5703
|
+
const right = new Float32Array(length);
|
|
5704
|
+
for (let i = 0;i < length; i++) {
|
|
5705
|
+
const m = middle[i] * Math.cos(angle) * scale;
|
|
5706
|
+
const a = apart[i] * Math.sin(angle) * scale;
|
|
5707
|
+
left[i] = m + a;
|
|
5708
|
+
right[i] = m - a;
|
|
5709
|
+
}
|
|
5710
|
+
return [left, right];
|
|
5711
|
+
}
|
|
5712
|
+
var CEILING = { knee: 0.9, range: 2 };
|
|
5713
|
+
function ceilingCurve(points = 4097) {
|
|
5714
|
+
const { knee, range } = CEILING;
|
|
5715
|
+
const curve = new Float32Array(points);
|
|
5716
|
+
for (let i = 0;i < points; i++) {
|
|
5717
|
+
const level = (i / (points - 1) * 2 - 1) * range;
|
|
5718
|
+
const size = Math.abs(level);
|
|
5719
|
+
curve[i] = Math.sign(level) * (size <= knee ? size : knee + (1 - knee) * Math.tanh((size - knee) / (1 - knee)));
|
|
5720
|
+
}
|
|
5721
|
+
return curve;
|
|
5722
|
+
}
|
|
5723
|
+
var ROOM_LOW_CUT = 180;
|
|
5724
|
+
var chains = new WeakMap;
|
|
5725
|
+
var canBuild = (ctx) => typeof ctx.createConvolver === "function" && typeof ctx.createBuffer === "function";
|
|
5726
|
+
var rooms = new Map;
|
|
5727
|
+
function roomBuffer(ctx, seconds) {
|
|
5728
|
+
const key = `${ctx.sampleRate}:${seconds}`;
|
|
5729
|
+
let sides = rooms.get(key);
|
|
5730
|
+
if (!sides) {
|
|
5731
|
+
sides = roomImpulse(ctx.sampleRate, seconds);
|
|
5732
|
+
if (rooms.size >= 3)
|
|
5733
|
+
rooms.delete(rooms.keys().next().value);
|
|
5734
|
+
rooms.set(key, sides);
|
|
5735
|
+
}
|
|
5736
|
+
const [left, right] = sides;
|
|
5737
|
+
const impulse = ctx.createBuffer(2, left.length, ctx.sampleRate);
|
|
5738
|
+
impulse.getChannelData(0).set(left);
|
|
5739
|
+
impulse.getChannelData(1).set(right);
|
|
5740
|
+
return impulse;
|
|
5741
|
+
}
|
|
5742
|
+
function build(ctx, speakers, seconds) {
|
|
5743
|
+
const input = ctx.createGain();
|
|
5744
|
+
const wet = ctx.createGain();
|
|
5745
|
+
wet.gain.value = 0;
|
|
5746
|
+
const room = ctx.createConvolver();
|
|
5747
|
+
room.normalize = false;
|
|
5748
|
+
room.buffer = roomBuffer(ctx, seconds);
|
|
5749
|
+
const sum = ctx.createGain();
|
|
5750
|
+
input.connect(sum);
|
|
5751
|
+
input.connect(room);
|
|
5752
|
+
if (typeof ctx.createBiquadFilter === "function") {
|
|
5753
|
+
const lowCut = ctx.createBiquadFilter();
|
|
5754
|
+
lowCut.type = "highpass";
|
|
5755
|
+
lowCut.frequency.value = ROOM_LOW_CUT;
|
|
5756
|
+
lowCut.Q.value = 0.7;
|
|
5757
|
+
room.connect(lowCut);
|
|
5758
|
+
lowCut.connect(wet);
|
|
5759
|
+
} else
|
|
5760
|
+
room.connect(wet);
|
|
5761
|
+
wet.connect(sum);
|
|
5762
|
+
if (typeof ctx.createWaveShaper === "function") {
|
|
5763
|
+
const ceiling = ctx.createWaveShaper();
|
|
5764
|
+
ceiling.curve = ceilingCurve();
|
|
5765
|
+
sum.gain.value = 1 / CEILING.range;
|
|
5766
|
+
sum.connect(ceiling);
|
|
5767
|
+
ceiling.connect(speakers);
|
|
5768
|
+
} else
|
|
5769
|
+
sum.connect(speakers);
|
|
5770
|
+
return { input, wet, room, seconds };
|
|
5771
|
+
}
|
|
5772
|
+
function outputFor(ctx, effects, speakers = ctx.destination) {
|
|
5773
|
+
if (effects?.dry || !canBuild(ctx))
|
|
5774
|
+
return speakers;
|
|
5775
|
+
const seconds = roomSeconds(effects?.room);
|
|
5776
|
+
let chain = chains.get(ctx);
|
|
5777
|
+
if (!chain) {
|
|
5778
|
+
try {
|
|
5779
|
+
chain = build(ctx, speakers, seconds);
|
|
5780
|
+
} catch {
|
|
5781
|
+
return speakers;
|
|
5782
|
+
}
|
|
5783
|
+
chains.set(ctx, chain);
|
|
5784
|
+
} else if (chain.seconds !== seconds) {
|
|
5785
|
+
try {
|
|
5786
|
+
chain.room.buffer = roomBuffer(ctx, seconds);
|
|
5787
|
+
chain.seconds = seconds;
|
|
5788
|
+
} catch {}
|
|
5789
|
+
}
|
|
5790
|
+
const level = reverbLevel(effects?.reverb);
|
|
5791
|
+
if (typeof chain.wet.gain.setTargetAtTime === "function")
|
|
5792
|
+
chain.wet.gain.setTargetAtTime(level, ctx.currentTime, 0.02);
|
|
5793
|
+
else
|
|
5794
|
+
chain.wet.gain.value = level;
|
|
5795
|
+
return chain.input;
|
|
5796
|
+
}
|
|
5797
|
+
var driveAmount = (drive) => 1 + 14 * Math.min(1, Math.max(0, drive));
|
|
5798
|
+
function driveCurve(drive, points = 2048) {
|
|
5799
|
+
const amount = driveAmount(drive);
|
|
5800
|
+
const curve = new Float32Array(points);
|
|
5801
|
+
const ceiling = Math.tanh(amount);
|
|
5802
|
+
for (let i = 0;i < points; i++) {
|
|
5803
|
+
const x = i / (points - 1) * 2 - 1;
|
|
5804
|
+
curve[i] = Math.tanh(amount * x) / ceiling;
|
|
5805
|
+
}
|
|
5806
|
+
return curve;
|
|
5807
|
+
}
|
|
5808
|
+
var DRIVE_REFERENCE = 0.2;
|
|
5809
|
+
function driveLevel(drive, reference = DRIVE_REFERENCE) {
|
|
5810
|
+
const amount = driveAmount(drive);
|
|
5811
|
+
const ceiling = Math.tanh(amount);
|
|
5812
|
+
let before = 0;
|
|
5813
|
+
let after = 0;
|
|
5814
|
+
for (let i = 0;i < 256; i++) {
|
|
5815
|
+
const x = reference * Math.sin(2 * Math.PI * i / 256);
|
|
5816
|
+
const y = Math.tanh(amount * x) / ceiling;
|
|
5817
|
+
before += x * x;
|
|
5818
|
+
after += y * y;
|
|
5819
|
+
}
|
|
5820
|
+
return after > 0 ? Math.sqrt(before / after) : 1;
|
|
5821
|
+
}
|
|
5822
|
+
var CABINET_TRIM_DB = -2;
|
|
5823
|
+
function ampFor(ctx, amp) {
|
|
5824
|
+
const drive = typeof amp?.drive === "number" ? Math.min(1, Math.max(0, amp.drive)) : 0;
|
|
5825
|
+
const cabinet = amp?.cabinet === true;
|
|
5826
|
+
if (!drive && !cabinet)
|
|
5827
|
+
return null;
|
|
5828
|
+
if (typeof ctx.createWaveShaper !== "function" || typeof ctx.createBiquadFilter !== "function")
|
|
5829
|
+
return null;
|
|
5830
|
+
const input = ctx.createGain();
|
|
5831
|
+
let last = input;
|
|
5832
|
+
const filter = (type, frequency, q, gain = 0) => {
|
|
5833
|
+
const node = ctx.createBiquadFilter();
|
|
5834
|
+
node.type = type;
|
|
5835
|
+
node.frequency.value = frequency;
|
|
5836
|
+
node.Q.value = q;
|
|
5837
|
+
node.gain.value = gain;
|
|
5838
|
+
last.connect(node);
|
|
5839
|
+
last = node;
|
|
5840
|
+
};
|
|
5841
|
+
if (drive) {
|
|
5842
|
+
filter("highpass", 120, 0.7);
|
|
5843
|
+
const shaper = ctx.createWaveShaper();
|
|
5844
|
+
shaper.curve = driveCurve(drive);
|
|
5845
|
+
shaper.oversample = "4x";
|
|
5846
|
+
const level = ctx.createGain();
|
|
5847
|
+
level.gain.value = driveLevel(drive);
|
|
5848
|
+
last.connect(shaper);
|
|
5849
|
+
shaper.connect(level);
|
|
5850
|
+
last = level;
|
|
5851
|
+
}
|
|
5852
|
+
if (cabinet) {
|
|
5853
|
+
filter("highpass", 90, 0.7);
|
|
5854
|
+
filter("peaking", 2200, 1, 4);
|
|
5855
|
+
filter("lowpass", 4800, 0.7);
|
|
5856
|
+
filter("lowpass", 6500, 0.7);
|
|
5857
|
+
const level = ctx.createGain();
|
|
5858
|
+
level.gain.value = Math.pow(10, CABINET_TRIM_DB / 20);
|
|
5859
|
+
last.connect(level);
|
|
5860
|
+
last = level;
|
|
5861
|
+
}
|
|
5862
|
+
return { input, output: last };
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5582
5865
|
// src/playback/player.ts
|
|
5583
5866
|
var DEFAULT_SEQUENCE = { bpm: 90, strum: 12 };
|
|
5584
5867
|
var DEFAULT_STRUM = { guitar: 12, piano: 0 };
|
|
@@ -5768,6 +6051,25 @@ var PLUCKS = 4;
|
|
|
5768
6051
|
var RELEASE = { guitar: 0.15, piano: 0.3 };
|
|
5769
6052
|
var releaseOf = (sound, duration) => Math.min(RELEASE[sound], Math.max(0.03, duration / 2));
|
|
5770
6053
|
var pianoDecay = (midi) => Math.min(2.5, Math.max(0.35, Math.pow(2, (60 - midi) / 24)));
|
|
6054
|
+
function sendOut(ctx, from, guitar, effects) {
|
|
6055
|
+
const out = outputFor(ctx, effects);
|
|
6056
|
+
const amp = !effects?.dry && (guitar === "clean" || guitar === "overdrive") ? ampFor(ctx, effects?.amp) : null;
|
|
6057
|
+
const cut = (node) => {
|
|
6058
|
+
try {
|
|
6059
|
+
node.disconnect();
|
|
6060
|
+
} catch {}
|
|
6061
|
+
};
|
|
6062
|
+
if (!amp) {
|
|
6063
|
+
from.connect(out);
|
|
6064
|
+
return () => cut(from);
|
|
6065
|
+
}
|
|
6066
|
+
from.connect(amp.input);
|
|
6067
|
+
amp.output.connect(out);
|
|
6068
|
+
return () => {
|
|
6069
|
+
cut(from);
|
|
6070
|
+
cut(amp.output);
|
|
6071
|
+
};
|
|
6072
|
+
}
|
|
5771
6073
|
function lightPlayer(win, random = Math.random) {
|
|
5772
6074
|
const strings = new Map;
|
|
5773
6075
|
const waves = new WeakMap;
|
|
@@ -5800,7 +6102,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5800
6102
|
};
|
|
5801
6103
|
return {
|
|
5802
6104
|
reportsStart: true,
|
|
5803
|
-
play(events, { sound, volume, onEnd, onStart, guitar }) {
|
|
6105
|
+
play(events, { sound, volume, onEnd, onStart, guitar, effects }) {
|
|
5804
6106
|
const ctx = contextFor(win);
|
|
5805
6107
|
if (!ctx || !events.length)
|
|
5806
6108
|
return { stop() {} };
|
|
@@ -5821,7 +6123,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5821
6123
|
});
|
|
5822
6124
|
const gain = ctx.createGain();
|
|
5823
6125
|
gain.gain.value = Number.isFinite(volume) ? Math.min(1, Math.max(0, volume)) : 0.8;
|
|
5824
|
-
|
|
6126
|
+
const letGo = sendOut(ctx, gain, sound === "guitar" ? tone : null, effects);
|
|
5825
6127
|
const start = ctx.currentTime + 0.05;
|
|
5826
6128
|
const sources = events.map((e, i) => {
|
|
5827
6129
|
if (e.kind)
|
|
@@ -5857,7 +6159,7 @@ function lightPlayer(win, random = Math.random) {
|
|
|
5857
6159
|
source.stop(Math.max(at + 0.006, end) + release);
|
|
5858
6160
|
return source;
|
|
5859
6161
|
});
|
|
5860
|
-
const finish = () =>
|
|
6162
|
+
const finish = () => letGo();
|
|
5861
6163
|
let stopped = false;
|
|
5862
6164
|
let heard;
|
|
5863
6165
|
const announce = () => {
|
|
@@ -9296,7 +9598,32 @@ function playerFor(win, options, el) {
|
|
|
9296
9598
|
}
|
|
9297
9599
|
function toned(player, options, el) {
|
|
9298
9600
|
const tone = guitarFor(options, el);
|
|
9299
|
-
|
|
9601
|
+
const effects = effectsOf(options);
|
|
9602
|
+
return tone || effects ? withPlay(player, tone, effects) : player;
|
|
9603
|
+
}
|
|
9604
|
+
function effectsOf(options) {
|
|
9605
|
+
const read = (value) => {
|
|
9606
|
+
try {
|
|
9607
|
+
return (typeof value === "function" ? value() : value) ?? null;
|
|
9608
|
+
} catch {
|
|
9609
|
+
return null;
|
|
9610
|
+
}
|
|
9611
|
+
};
|
|
9612
|
+
const reverb = read(options.reverb);
|
|
9613
|
+
const room = read(options.room);
|
|
9614
|
+
const amp = read(options.amp);
|
|
9615
|
+
const effects = {
|
|
9616
|
+
...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.round(Math.min(1, Math.max(0, reverb)) * 1000) / 1000 } : {},
|
|
9617
|
+
...typeof room === "number" && Number.isFinite(room) ? { room: Math.round(roomSeconds(room) * 100) / 100 } : {},
|
|
9618
|
+
...read(options.dry) === true ? { dry: true } : {},
|
|
9619
|
+
...amp && typeof amp === "object" && (amp.cabinet === true || typeof amp.drive === "number") ? {
|
|
9620
|
+
amp: {
|
|
9621
|
+
...amp.cabinet === true ? { cabinet: true } : {},
|
|
9622
|
+
...typeof amp.drive === "number" && Number.isFinite(amp.drive) ? { drive: Math.round(Math.min(1, Math.max(0, amp.drive)) * 100) / 100 } : {}
|
|
9623
|
+
}
|
|
9624
|
+
} : {}
|
|
9625
|
+
};
|
|
9626
|
+
return Object.keys(effects).length ? effects : null;
|
|
9300
9627
|
}
|
|
9301
9628
|
function guitarFor(options, el) {
|
|
9302
9629
|
const wish = guitarChoice(el) ?? guitarWish(el);
|
|
@@ -9308,22 +9635,30 @@ function guitarFor(options, el) {
|
|
|
9308
9635
|
return null;
|
|
9309
9636
|
}
|
|
9310
9637
|
}
|
|
9311
|
-
var
|
|
9312
|
-
|
|
9313
|
-
|
|
9638
|
+
var twinPlayers = new WeakMap;
|
|
9639
|
+
var TWINS_KEPT = 32;
|
|
9640
|
+
function withPlay(player, guitar, effects) {
|
|
9641
|
+
let twins = twinPlayers.get(player);
|
|
9314
9642
|
if (!twins) {
|
|
9315
9643
|
twins = new Map;
|
|
9316
|
-
|
|
9644
|
+
twinPlayers.set(player, twins);
|
|
9317
9645
|
}
|
|
9318
|
-
|
|
9646
|
+
const key = `${guitar ?? ""}|${effects ? JSON.stringify(effects) : ""}`;
|
|
9647
|
+
let twin = twins.get(key);
|
|
9319
9648
|
if (!twin) {
|
|
9320
9649
|
twin = {
|
|
9321
9650
|
get reportsStart() {
|
|
9322
9651
|
return player.reportsStart;
|
|
9323
9652
|
},
|
|
9324
|
-
play: (events, options) => player.play(events,
|
|
9653
|
+
play: (events, options) => player.play(events, {
|
|
9654
|
+
...options,
|
|
9655
|
+
...guitar && !options.guitar ? { guitar } : {},
|
|
9656
|
+
...effects && !options.effects ? { effects } : {}
|
|
9657
|
+
})
|
|
9325
9658
|
};
|
|
9326
|
-
twins.
|
|
9659
|
+
if (twins.size >= TWINS_KEPT)
|
|
9660
|
+
twins.delete(twins.keys().next().value);
|
|
9661
|
+
twins.set(key, twin);
|
|
9327
9662
|
}
|
|
9328
9663
|
return twin;
|
|
9329
9664
|
}
|
|
@@ -17341,10 +17676,10 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17341
17676
|
};
|
|
17342
17677
|
return {
|
|
17343
17678
|
reportsStart: true,
|
|
17344
|
-
play(events, { sound: instrument, volume, onEnd, onStart, guitar }) {
|
|
17679
|
+
play(events, { sound: instrument, volume, onEnd, onStart, guitar, effects }) {
|
|
17345
17680
|
const ctx = contextOf();
|
|
17346
17681
|
const tone = guitar ?? DEFAULT_GUITAR_TONE;
|
|
17347
|
-
const same = guitar ? { guitar } : {};
|
|
17682
|
+
const same = { ...guitar ? { guitar } : {}, ...effects ? { effects } : {} };
|
|
17348
17683
|
if (!ctx)
|
|
17349
17684
|
return fallback.play(events, {
|
|
17350
17685
|
sound: instrument,
|
|
@@ -17376,7 +17711,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17376
17711
|
const byKind = new Map(kinds.map((kind, i) => [kind, loaded[i]]));
|
|
17377
17712
|
const master = ctx.createGain();
|
|
17378
17713
|
master.gain.value = level;
|
|
17379
|
-
|
|
17714
|
+
const letGo = sendOut(ctx, master, instrument === "guitar" ? tone : null, effects);
|
|
17380
17715
|
const start = ctx.currentTime + 0.05;
|
|
17381
17716
|
const sources = [];
|
|
17382
17717
|
let tail = 0;
|
|
@@ -17394,7 +17729,7 @@ function sampledPlayer(win, source, fallback, options = {}) {
|
|
|
17394
17729
|
tail = Math.max(tail, made.over - start);
|
|
17395
17730
|
}
|
|
17396
17731
|
}
|
|
17397
|
-
const finish = () =>
|
|
17732
|
+
const finish = () => letGo();
|
|
17398
17733
|
let heard;
|
|
17399
17734
|
const announce = () => {
|
|
17400
17735
|
if (stopped || !onStart)
|
|
@@ -18336,6 +18671,7 @@ export {
|
|
|
18336
18671
|
DEFAULT_EXERCISE_TEMPO,
|
|
18337
18672
|
DEFAULT_GUITAR_TONE,
|
|
18338
18673
|
DEFAULT_PROPERTY_NAMES,
|
|
18674
|
+
DEFAULT_REVERB,
|
|
18339
18675
|
DEFAULT_SEQUENCE,
|
|
18340
18676
|
DEFAULT_STRUM,
|
|
18341
18677
|
DEFAULT_STRUM_CHORD,
|
|
@@ -18455,6 +18791,8 @@ export {
|
|
|
18455
18791
|
noteOf,
|
|
18456
18792
|
noteTargets,
|
|
18457
18793
|
numeralOf,
|
|
18794
|
+
outputFor,
|
|
18795
|
+
pageEffects,
|
|
18458
18796
|
pageEngine,
|
|
18459
18797
|
pageGuitar,
|
|
18460
18798
|
pageInstruments,
|
|
@@ -18560,5 +18898,5 @@ export {
|
|
|
18560
18898
|
withTonicizations
|
|
18561
18899
|
};
|
|
18562
18900
|
|
|
18563
|
-
//# debugId=
|
|
18901
|
+
//# debugId=47E914BB1589446C64756E2164756E21
|
|
18564
18902
|
//# sourceMappingURL=index.js.map
|