@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/dist/tab/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type * as AT from '@coderline/alphatab';
|
|
|
9
9
|
import { type Language } from '../i18n/language.js';
|
|
10
10
|
import type { NotePlayer } from '../playback/player.js';
|
|
11
11
|
import { type Engine } from '../playback/engine.js';
|
|
12
|
+
import type { PlayEffects } from '../playback/effects.js';
|
|
12
13
|
import { type Naming } from '../theory/naming.js';
|
|
13
14
|
import { type TempoUnit } from './tempo.js';
|
|
14
15
|
import { type InstrumentSource } from './instruments.js';
|
|
@@ -93,6 +94,12 @@ export interface TabOptions {
|
|
|
93
94
|
* #85); 0.8 by default. The bar has no volume of its own (#82).
|
|
94
95
|
*/
|
|
95
96
|
volume?: number | (() => number);
|
|
97
|
+
/**
|
|
98
|
+
* The room and the ceiling this tab's sound goes through (#103): the page's or the app's
|
|
99
|
+
* choice (`reverb`, `room`, `dry`), read each time the tab starts to play. The light room by
|
|
100
|
+
* default.
|
|
101
|
+
*/
|
|
102
|
+
effects?: PlayEffects | (() => PlayEffects | null | undefined);
|
|
96
103
|
/**
|
|
97
104
|
* The Full screen button at the end of the player bar (default true; #113): the block fills
|
|
98
105
|
* the screen, the score is drawn again at that width and scrolls in an area of its own, where
|
package/dist/tab/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) {
|
|
@@ -3219,6 +3224,450 @@ function followVolume(read, handles, start) {
|
|
|
3219
3224
|
};
|
|
3220
3225
|
}
|
|
3221
3226
|
|
|
3227
|
+
// src/playback/effects.ts
|
|
3228
|
+
var DEFAULT_REVERB = 0.125;
|
|
3229
|
+
var ROOM_SECONDS = 1.2;
|
|
3230
|
+
var ROOM_RANGE = [0.2, 3];
|
|
3231
|
+
function roomSeconds(value) {
|
|
3232
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(ROOM_RANGE[1], Math.max(ROOM_RANGE[0], value)) : ROOM_SECONDS;
|
|
3233
|
+
}
|
|
3234
|
+
function reverbLevel(value) {
|
|
3235
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : DEFAULT_REVERB;
|
|
3236
|
+
}
|
|
3237
|
+
function pageEffects(options) {
|
|
3238
|
+
if (!options || typeof options !== "object" || !("play" in options))
|
|
3239
|
+
return null;
|
|
3240
|
+
const play = options.play;
|
|
3241
|
+
if (!play || typeof play !== "object")
|
|
3242
|
+
return null;
|
|
3243
|
+
const read = (key) => {
|
|
3244
|
+
const value = play[key];
|
|
3245
|
+
if (typeof value !== "function")
|
|
3246
|
+
return value;
|
|
3247
|
+
try {
|
|
3248
|
+
return value();
|
|
3249
|
+
} catch {
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
};
|
|
3253
|
+
const reverb = read("reverb");
|
|
3254
|
+
const room = read("room");
|
|
3255
|
+
const amp = read("amp");
|
|
3256
|
+
const drive = amp && typeof amp === "object" ? amp["drive"] : null;
|
|
3257
|
+
const cabinet = amp && typeof amp === "object" && amp["cabinet"];
|
|
3258
|
+
const effects = {
|
|
3259
|
+
...typeof reverb === "number" && Number.isFinite(reverb) ? { reverb: Math.min(1, Math.max(0, reverb)) } : {},
|
|
3260
|
+
...typeof room === "number" && Number.isFinite(room) ? { room: roomSeconds(room) } : {},
|
|
3261
|
+
...read("dry") === true ? { dry: true } : {},
|
|
3262
|
+
...cabinet === true || typeof drive === "number" && Number.isFinite(drive) ? {
|
|
3263
|
+
amp: {
|
|
3264
|
+
...typeof drive === "number" && Number.isFinite(drive) ? { drive: Math.min(1, Math.max(0, drive)) } : {},
|
|
3265
|
+
...cabinet === true ? { cabinet: true } : {}
|
|
3266
|
+
}
|
|
3267
|
+
} : {}
|
|
3268
|
+
};
|
|
3269
|
+
return Object.keys(effects).length ? effects : null;
|
|
3270
|
+
}
|
|
3271
|
+
function seeded(seed) {
|
|
3272
|
+
let a = seed >>> 0;
|
|
3273
|
+
return () => {
|
|
3274
|
+
a = a + 1831565813 >>> 0;
|
|
3275
|
+
let t = a;
|
|
3276
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
3277
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
3278
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3281
|
+
var ROOM_SHAPE = { bright: 4000, dark: 800, rise: 0.02, width: 0.5 };
|
|
3282
|
+
var ROOM_BAND = [300, 3000];
|
|
3283
|
+
var ROOM_WIDE_FROM = 400;
|
|
3284
|
+
var ROOM_SLOPE = 3;
|
|
3285
|
+
function roomImpulse(sampleRate, seconds = ROOM_SECONDS, shape = {}) {
|
|
3286
|
+
const { bright, dark, rise: riseSeconds, width } = { ...ROOM_SHAPE, ...shape };
|
|
3287
|
+
const length = Math.max(1, Math.round(sampleRate * seconds));
|
|
3288
|
+
const start = Math.min(length, Math.round(sampleRate * 0.012));
|
|
3289
|
+
const fade = Math.max(1, Math.round(length * 0.1));
|
|
3290
|
+
const fall = Math.pow(10, -3 / (sampleRate * seconds));
|
|
3291
|
+
const darker = Math.pow(dark / bright, 1 / (sampleRate * seconds));
|
|
3292
|
+
const rise = Math.max(1, Math.round(sampleRate * Math.max(0, riseSeconds)));
|
|
3293
|
+
const keepAt = (cutoff) => Math.exp(-2 * Math.PI * Math.min(cutoff, sampleRate * 0.45) / sampleRate);
|
|
3294
|
+
const shapeAt = (i) => (i - start < rise ? (i - start) / rise : 1) * (i > length - fade ? (length - i) / fade : 1);
|
|
3295
|
+
const make = (seed) => {
|
|
3296
|
+
const random = seeded(seed);
|
|
3297
|
+
const data = new Float32Array(length);
|
|
3298
|
+
let level = Math.pow(fall, start);
|
|
3299
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
3300
|
+
let keep = 0;
|
|
3301
|
+
const lows = new Float64Array(ROOM_SLOPE);
|
|
3302
|
+
for (let i = start;i < length; i++) {
|
|
3303
|
+
if ((i - start) % 64 === 0)
|
|
3304
|
+
keep = keepAt(cutoff);
|
|
3305
|
+
let value = random() * 2 - 1;
|
|
3306
|
+
for (let pole = 0;pole < ROOM_SLOPE; pole++) {
|
|
3307
|
+
value = keep * lows[pole] + (1 - keep) * value;
|
|
3308
|
+
lows[pole] = value;
|
|
3309
|
+
}
|
|
3310
|
+
data[i] = value * level * shapeAt(i);
|
|
3311
|
+
level *= fall;
|
|
3312
|
+
cutoff *= darker;
|
|
3313
|
+
}
|
|
3314
|
+
return data;
|
|
3315
|
+
};
|
|
3316
|
+
let power = 0;
|
|
3317
|
+
const pitches = 8;
|
|
3318
|
+
for (let p = 0;p < pitches; p++) {
|
|
3319
|
+
const hz = ROOM_BAND[0] * Math.pow(ROOM_BAND[1] / ROOM_BAND[0], (p + 0.5) / pitches);
|
|
3320
|
+
const cos = Math.cos(2 * Math.PI * hz / sampleRate);
|
|
3321
|
+
let level = Math.pow(fall, start);
|
|
3322
|
+
let cutoff = bright * Math.pow(darker, start);
|
|
3323
|
+
const step = Math.pow(fall, 64);
|
|
3324
|
+
const darkerStep = Math.pow(darker, 64);
|
|
3325
|
+
for (let i = start;i < length; i += 64) {
|
|
3326
|
+
const keep = keepAt(cutoff);
|
|
3327
|
+
const pole = (1 - keep) * (1 - keep) / (1 - 2 * keep * cos + keep * keep);
|
|
3328
|
+
const size = Math.min(64, length - i);
|
|
3329
|
+
const here = level * shapeAt(i + (size >> 1));
|
|
3330
|
+
power += size * here * here * Math.pow(pole, ROOM_SLOPE) / 3;
|
|
3331
|
+
level *= step;
|
|
3332
|
+
cutoff *= darkerStep;
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
const scale = power > 0 ? 1 / Math.sqrt(power / pitches) : 0;
|
|
3336
|
+
const middle = make(625341585);
|
|
3337
|
+
const apart = make(1374496523);
|
|
3338
|
+
const pass = Math.exp(-2 * Math.PI * ROOM_WIDE_FROM / sampleRate);
|
|
3339
|
+
for (let turn = 0;turn < 2; turn++) {
|
|
3340
|
+
let low = 0;
|
|
3341
|
+
for (let i = 0;i < length; i++) {
|
|
3342
|
+
low = pass * low + (1 - pass) * apart[i];
|
|
3343
|
+
apart[i] = apart[i] - low;
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
const angle = Math.min(1, Math.max(0, width)) * Math.PI / 4;
|
|
3347
|
+
const left = new Float32Array(length);
|
|
3348
|
+
const right = new Float32Array(length);
|
|
3349
|
+
for (let i = 0;i < length; i++) {
|
|
3350
|
+
const m = middle[i] * Math.cos(angle) * scale;
|
|
3351
|
+
const a = apart[i] * Math.sin(angle) * scale;
|
|
3352
|
+
left[i] = m + a;
|
|
3353
|
+
right[i] = m - a;
|
|
3354
|
+
}
|
|
3355
|
+
return [left, right];
|
|
3356
|
+
}
|
|
3357
|
+
var CEILING = { knee: 0.9, range: 2 };
|
|
3358
|
+
function ceilingCurve(points = 4097) {
|
|
3359
|
+
const { knee, range } = CEILING;
|
|
3360
|
+
const curve = new Float32Array(points);
|
|
3361
|
+
for (let i = 0;i < points; i++) {
|
|
3362
|
+
const level = (i / (points - 1) * 2 - 1) * range;
|
|
3363
|
+
const size = Math.abs(level);
|
|
3364
|
+
curve[i] = Math.sign(level) * (size <= knee ? size : knee + (1 - knee) * Math.tanh((size - knee) / (1 - knee)));
|
|
3365
|
+
}
|
|
3366
|
+
return curve;
|
|
3367
|
+
}
|
|
3368
|
+
var ROOM_LOW_CUT = 180;
|
|
3369
|
+
var chains = new WeakMap;
|
|
3370
|
+
var canBuild = (ctx) => typeof ctx.createConvolver === "function" && typeof ctx.createBuffer === "function";
|
|
3371
|
+
var rooms = new Map;
|
|
3372
|
+
function roomBuffer(ctx, seconds) {
|
|
3373
|
+
const key = `${ctx.sampleRate}:${seconds}`;
|
|
3374
|
+
let sides = rooms.get(key);
|
|
3375
|
+
if (!sides) {
|
|
3376
|
+
sides = roomImpulse(ctx.sampleRate, seconds);
|
|
3377
|
+
if (rooms.size >= 3)
|
|
3378
|
+
rooms.delete(rooms.keys().next().value);
|
|
3379
|
+
rooms.set(key, sides);
|
|
3380
|
+
}
|
|
3381
|
+
const [left, right] = sides;
|
|
3382
|
+
const impulse = ctx.createBuffer(2, left.length, ctx.sampleRate);
|
|
3383
|
+
impulse.getChannelData(0).set(left);
|
|
3384
|
+
impulse.getChannelData(1).set(right);
|
|
3385
|
+
return impulse;
|
|
3386
|
+
}
|
|
3387
|
+
function build(ctx, speakers, seconds) {
|
|
3388
|
+
const input = ctx.createGain();
|
|
3389
|
+
const wet = ctx.createGain();
|
|
3390
|
+
wet.gain.value = 0;
|
|
3391
|
+
const room = ctx.createConvolver();
|
|
3392
|
+
room.normalize = false;
|
|
3393
|
+
room.buffer = roomBuffer(ctx, seconds);
|
|
3394
|
+
const sum = ctx.createGain();
|
|
3395
|
+
input.connect(sum);
|
|
3396
|
+
input.connect(room);
|
|
3397
|
+
if (typeof ctx.createBiquadFilter === "function") {
|
|
3398
|
+
const lowCut = ctx.createBiquadFilter();
|
|
3399
|
+
lowCut.type = "highpass";
|
|
3400
|
+
lowCut.frequency.value = ROOM_LOW_CUT;
|
|
3401
|
+
lowCut.Q.value = 0.7;
|
|
3402
|
+
room.connect(lowCut);
|
|
3403
|
+
lowCut.connect(wet);
|
|
3404
|
+
} else
|
|
3405
|
+
room.connect(wet);
|
|
3406
|
+
wet.connect(sum);
|
|
3407
|
+
if (typeof ctx.createWaveShaper === "function") {
|
|
3408
|
+
const ceiling = ctx.createWaveShaper();
|
|
3409
|
+
ceiling.curve = ceilingCurve();
|
|
3410
|
+
sum.gain.value = 1 / CEILING.range;
|
|
3411
|
+
sum.connect(ceiling);
|
|
3412
|
+
ceiling.connect(speakers);
|
|
3413
|
+
} else
|
|
3414
|
+
sum.connect(speakers);
|
|
3415
|
+
return { input, wet, room, seconds };
|
|
3416
|
+
}
|
|
3417
|
+
function outputFor(ctx, effects, speakers = ctx.destination) {
|
|
3418
|
+
if (effects?.dry || !canBuild(ctx))
|
|
3419
|
+
return speakers;
|
|
3420
|
+
const seconds = roomSeconds(effects?.room);
|
|
3421
|
+
let chain = chains.get(ctx);
|
|
3422
|
+
if (!chain) {
|
|
3423
|
+
try {
|
|
3424
|
+
chain = build(ctx, speakers, seconds);
|
|
3425
|
+
} catch {
|
|
3426
|
+
return speakers;
|
|
3427
|
+
}
|
|
3428
|
+
chains.set(ctx, chain);
|
|
3429
|
+
} else if (chain.seconds !== seconds) {
|
|
3430
|
+
try {
|
|
3431
|
+
chain.room.buffer = roomBuffer(ctx, seconds);
|
|
3432
|
+
chain.seconds = seconds;
|
|
3433
|
+
} catch {}
|
|
3434
|
+
}
|
|
3435
|
+
const level = reverbLevel(effects?.reverb);
|
|
3436
|
+
if (typeof chain.wet.gain.setTargetAtTime === "function")
|
|
3437
|
+
chain.wet.gain.setTargetAtTime(level, ctx.currentTime, 0.02);
|
|
3438
|
+
else
|
|
3439
|
+
chain.wet.gain.value = level;
|
|
3440
|
+
return chain.input;
|
|
3441
|
+
}
|
|
3442
|
+
var driveAmount = (drive) => 1 + 14 * Math.min(1, Math.max(0, drive));
|
|
3443
|
+
function driveCurve(drive, points = 2048) {
|
|
3444
|
+
const amount = driveAmount(drive);
|
|
3445
|
+
const curve = new Float32Array(points);
|
|
3446
|
+
const ceiling = Math.tanh(amount);
|
|
3447
|
+
for (let i = 0;i < points; i++) {
|
|
3448
|
+
const x = i / (points - 1) * 2 - 1;
|
|
3449
|
+
curve[i] = Math.tanh(amount * x) / ceiling;
|
|
3450
|
+
}
|
|
3451
|
+
return curve;
|
|
3452
|
+
}
|
|
3453
|
+
var DRIVE_REFERENCE = 0.2;
|
|
3454
|
+
function driveLevel(drive, reference = DRIVE_REFERENCE) {
|
|
3455
|
+
const amount = driveAmount(drive);
|
|
3456
|
+
const ceiling = Math.tanh(amount);
|
|
3457
|
+
let before = 0;
|
|
3458
|
+
let after = 0;
|
|
3459
|
+
for (let i = 0;i < 256; i++) {
|
|
3460
|
+
const x = reference * Math.sin(2 * Math.PI * i / 256);
|
|
3461
|
+
const y = Math.tanh(amount * x) / ceiling;
|
|
3462
|
+
before += x * x;
|
|
3463
|
+
after += y * y;
|
|
3464
|
+
}
|
|
3465
|
+
return after > 0 ? Math.sqrt(before / after) : 1;
|
|
3466
|
+
}
|
|
3467
|
+
var CABINET_TRIM_DB = -2;
|
|
3468
|
+
function ampFor(ctx, amp) {
|
|
3469
|
+
const drive = typeof amp?.drive === "number" ? Math.min(1, Math.max(0, amp.drive)) : 0;
|
|
3470
|
+
const cabinet = amp?.cabinet === true;
|
|
3471
|
+
if (!drive && !cabinet)
|
|
3472
|
+
return null;
|
|
3473
|
+
if (typeof ctx.createWaveShaper !== "function" || typeof ctx.createBiquadFilter !== "function")
|
|
3474
|
+
return null;
|
|
3475
|
+
const input = ctx.createGain();
|
|
3476
|
+
let last = input;
|
|
3477
|
+
const filter = (type, frequency, q, gain = 0) => {
|
|
3478
|
+
const node = ctx.createBiquadFilter();
|
|
3479
|
+
node.type = type;
|
|
3480
|
+
node.frequency.value = frequency;
|
|
3481
|
+
node.Q.value = q;
|
|
3482
|
+
node.gain.value = gain;
|
|
3483
|
+
last.connect(node);
|
|
3484
|
+
last = node;
|
|
3485
|
+
};
|
|
3486
|
+
if (drive) {
|
|
3487
|
+
filter("highpass", 120, 0.7);
|
|
3488
|
+
const shaper = ctx.createWaveShaper();
|
|
3489
|
+
shaper.curve = driveCurve(drive);
|
|
3490
|
+
shaper.oversample = "4x";
|
|
3491
|
+
const level = ctx.createGain();
|
|
3492
|
+
level.gain.value = driveLevel(drive);
|
|
3493
|
+
last.connect(shaper);
|
|
3494
|
+
shaper.connect(level);
|
|
3495
|
+
last = level;
|
|
3496
|
+
}
|
|
3497
|
+
if (cabinet) {
|
|
3498
|
+
filter("highpass", 90, 0.7);
|
|
3499
|
+
filter("peaking", 2200, 1, 4);
|
|
3500
|
+
filter("lowpass", 4800, 0.7);
|
|
3501
|
+
filter("lowpass", 6500, 0.7);
|
|
3502
|
+
const level = ctx.createGain();
|
|
3503
|
+
level.gain.value = Math.pow(10, CABINET_TRIM_DB / 20);
|
|
3504
|
+
last.connect(level);
|
|
3505
|
+
last = level;
|
|
3506
|
+
}
|
|
3507
|
+
return { input, output: last };
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
// src/tab/room.ts
|
|
3511
|
+
var isOutputNode = (value) => typeof value === "object" && value !== null && typeof value.connect === "function" && typeof value.disconnect === "function" && !("start" in value);
|
|
3512
|
+
var LOOKS = [0, 20, 60, 150, 400, 1000];
|
|
3513
|
+
function outputNodeOf(player) {
|
|
3514
|
+
const output = player?.output;
|
|
3515
|
+
const ctx = output?.context;
|
|
3516
|
+
if (!output || !ctx)
|
|
3517
|
+
return null;
|
|
3518
|
+
for (const field of Object.keys(output)) {
|
|
3519
|
+
const value = output[field];
|
|
3520
|
+
if (value !== output.source && value !== ctx && isOutputNode(value))
|
|
3521
|
+
return { ctx, node: value };
|
|
3522
|
+
}
|
|
3523
|
+
return null;
|
|
3524
|
+
}
|
|
3525
|
+
function contextOf(player) {
|
|
3526
|
+
return player?.output?.context ?? null;
|
|
3527
|
+
}
|
|
3528
|
+
var taken = new WeakMap;
|
|
3529
|
+
function throughRoom(api, playing, room, win) {
|
|
3530
|
+
const routed = new WeakSet;
|
|
3531
|
+
const self = {};
|
|
3532
|
+
let timers = [];
|
|
3533
|
+
let alive = true;
|
|
3534
|
+
let mine = null;
|
|
3535
|
+
let amp = null;
|
|
3536
|
+
let leaving = [];
|
|
3537
|
+
const cut = (node) => {
|
|
3538
|
+
try {
|
|
3539
|
+
node.disconnect();
|
|
3540
|
+
} catch {}
|
|
3541
|
+
};
|
|
3542
|
+
const entryFor = (ctx, speakers) => {
|
|
3543
|
+
let effects;
|
|
3544
|
+
let guitar = null;
|
|
3545
|
+
try {
|
|
3546
|
+
effects = room.effects() ?? undefined;
|
|
3547
|
+
guitar = room.guitar?.() ?? null;
|
|
3548
|
+
} catch {
|
|
3549
|
+
effects = undefined;
|
|
3550
|
+
}
|
|
3551
|
+
const out = effects?.dry ? speakers : outputFor(ctx, effects, speakers);
|
|
3552
|
+
const wish = out !== speakers && (guitar === "clean" || guitar === "overdrive") ? effects?.amp : undefined;
|
|
3553
|
+
const key = wish ? `${wish.drive ?? 0}:${wish.cabinet === true}` : "";
|
|
3554
|
+
if (amp && (amp.key !== key || amp.ctx !== ctx || amp.out !== out)) {
|
|
3555
|
+
const going = { id: 0, node: amp.output };
|
|
3556
|
+
amp = null;
|
|
3557
|
+
going.id = win.setTimeout(() => {
|
|
3558
|
+
cut(going.node);
|
|
3559
|
+
leaving = leaving.filter((one) => one !== going);
|
|
3560
|
+
}, 1000);
|
|
3561
|
+
leaving.push(going);
|
|
3562
|
+
}
|
|
3563
|
+
if (!key)
|
|
3564
|
+
return out;
|
|
3565
|
+
if (!amp) {
|
|
3566
|
+
const made = ampFor(ctx, wish);
|
|
3567
|
+
if (!made)
|
|
3568
|
+
return out;
|
|
3569
|
+
made.output.connect(out);
|
|
3570
|
+
amp = { key, ctx, out, ...made };
|
|
3571
|
+
}
|
|
3572
|
+
return amp.input;
|
|
3573
|
+
};
|
|
3574
|
+
const take = () => {
|
|
3575
|
+
const ctx = contextOf(api.player);
|
|
3576
|
+
if (!ctx)
|
|
3577
|
+
return false;
|
|
3578
|
+
const entry = (speakers) => entryFor(ctx, speakers);
|
|
3579
|
+
const had = taken.get(ctx);
|
|
3580
|
+
if (had) {
|
|
3581
|
+
had.owner = self;
|
|
3582
|
+
had.entry = entry;
|
|
3583
|
+
mine = had;
|
|
3584
|
+
return true;
|
|
3585
|
+
}
|
|
3586
|
+
try {
|
|
3587
|
+
const holder = { speakers: ctx.destination, owner: self, entry, asked: 0 };
|
|
3588
|
+
Object.defineProperty(ctx, "destination", {
|
|
3589
|
+
configurable: true,
|
|
3590
|
+
get: () => {
|
|
3591
|
+
holder.asked++;
|
|
3592
|
+
try {
|
|
3593
|
+
return holder.entry ? holder.entry(holder.speakers) : holder.speakers;
|
|
3594
|
+
} catch {
|
|
3595
|
+
return holder.speakers;
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
});
|
|
3599
|
+
taken.set(ctx, holder);
|
|
3600
|
+
mine = holder;
|
|
3601
|
+
return true;
|
|
3602
|
+
} catch {
|
|
3603
|
+
return false;
|
|
3604
|
+
}
|
|
3605
|
+
};
|
|
3606
|
+
const route = (since) => {
|
|
3607
|
+
if (!alive)
|
|
3608
|
+
return;
|
|
3609
|
+
const found = outputNodeOf(api.player);
|
|
3610
|
+
if (!found || routed.has(found.node))
|
|
3611
|
+
return;
|
|
3612
|
+
const holder = taken.get(found.ctx);
|
|
3613
|
+
if (holder && (since === null || holder.asked > since))
|
|
3614
|
+
return;
|
|
3615
|
+
try {
|
|
3616
|
+
const speakers = holder ? holder.speakers : found.ctx.destination;
|
|
3617
|
+
const entry = entryFor(found.ctx, speakers);
|
|
3618
|
+
if (entry === speakers)
|
|
3619
|
+
return;
|
|
3620
|
+
found.node.disconnect();
|
|
3621
|
+
found.node.connect(entry);
|
|
3622
|
+
routed.add(found.node);
|
|
3623
|
+
} catch {}
|
|
3624
|
+
};
|
|
3625
|
+
const look = () => {
|
|
3626
|
+
if (!alive)
|
|
3627
|
+
return;
|
|
3628
|
+
for (const id of timers)
|
|
3629
|
+
win.clearTimeout(id);
|
|
3630
|
+
timers = [];
|
|
3631
|
+
const before = contextOf(api.player);
|
|
3632
|
+
if (before && taken.has(before) && take())
|
|
3633
|
+
return;
|
|
3634
|
+
const since = take() ? mine?.asked ?? 0 : null;
|
|
3635
|
+
timers = LOOKS.map((ms) => win.setTimeout(() => route(since), ms));
|
|
3636
|
+
};
|
|
3637
|
+
take();
|
|
3638
|
+
const ready = api.playerReady;
|
|
3639
|
+
if (typeof ready?.on === "function")
|
|
3640
|
+
ready.on(() => {
|
|
3641
|
+
if (alive)
|
|
3642
|
+
take();
|
|
3643
|
+
});
|
|
3644
|
+
api.playerStateChanged.on((e) => {
|
|
3645
|
+
if (alive && playing(e.state))
|
|
3646
|
+
look();
|
|
3647
|
+
});
|
|
3648
|
+
return {
|
|
3649
|
+
look,
|
|
3650
|
+
stop() {
|
|
3651
|
+
alive = false;
|
|
3652
|
+
for (const id of timers)
|
|
3653
|
+
win.clearTimeout(id);
|
|
3654
|
+
timers = [];
|
|
3655
|
+
for (const { id, node } of leaving) {
|
|
3656
|
+
win.clearTimeout(id);
|
|
3657
|
+
cut(node);
|
|
3658
|
+
}
|
|
3659
|
+
leaving = [];
|
|
3660
|
+
if (amp)
|
|
3661
|
+
cut(amp.output);
|
|
3662
|
+
amp = null;
|
|
3663
|
+
if (mine && mine.owner === self) {
|
|
3664
|
+
mine.owner = null;
|
|
3665
|
+
mine.entry = null;
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
};
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3222
3671
|
// src/playback/full-screen.ts
|
|
3223
3672
|
var SCROLL_KEYS = new Set(["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown"]);
|
|
3224
3673
|
function backgroundBehind(el) {
|
|
@@ -4429,7 +4878,6 @@ function renderTab(language, source, host, options) {
|
|
|
4429
4878
|
enableLazyLoading: false
|
|
4430
4879
|
},
|
|
4431
4880
|
display: {
|
|
4432
|
-
staveProfile: "Default",
|
|
4433
4881
|
resources: colorsOf(el),
|
|
4434
4882
|
...line ? { layoutMode: at.LayoutMode?.Horizontal ?? 1 } : {}
|
|
4435
4883
|
},
|
|
@@ -4442,6 +4890,11 @@ function renderTab(language, source, host, options) {
|
|
|
4442
4890
|
};
|
|
4443
4891
|
const current = new at.AlphaTabApi(surface, settings);
|
|
4444
4892
|
api = current;
|
|
4893
|
+
const roomWindow = host.ownerDocument.defaultView;
|
|
4894
|
+
if (roomWindow)
|
|
4895
|
+
throughRoom(current, (state) => Number(state) === Number(at.synth.PlayerState.Playing), {
|
|
4896
|
+
effects: () => typeof options.effects === "function" ? options.effects() : options.effects
|
|
4897
|
+
}, roomWindow);
|
|
4445
4898
|
current.settings.player.scrollElement = surface;
|
|
4446
4899
|
if (gone) {
|
|
4447
4900
|
current.destroy();
|
|
@@ -4745,6 +5198,9 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
4745
5198
|
}
|
|
4746
5199
|
});
|
|
4747
5200
|
const current = api;
|
|
5201
|
+
const view = doc.defaultView;
|
|
5202
|
+
if (view)
|
|
5203
|
+
room = throughRoom(current, (state) => Number(state) === Number(alphaTab.synth.PlayerState.Playing), { effects: () => asked.effects, guitar: () => asked.guitar }, view);
|
|
4748
5204
|
ready = new Promise((resolve) => {
|
|
4749
5205
|
let soundFont = false;
|
|
4750
5206
|
let player = !current.playerReady;
|
|
@@ -4812,6 +5268,11 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
4812
5268
|
return more;
|
|
4813
5269
|
};
|
|
4814
5270
|
const inner = soundfontPlayer(alphaTab, () => api);
|
|
5271
|
+
let room = null;
|
|
5272
|
+
const asked = {
|
|
5273
|
+
effects: undefined,
|
|
5274
|
+
guitar: null
|
|
5275
|
+
};
|
|
4815
5276
|
return {
|
|
4816
5277
|
reportsStart: true,
|
|
4817
5278
|
play(events, options) {
|
|
@@ -4823,7 +5284,10 @@ function createSoundfontPlayer(alphaTab, assets, doc, fallback) {
|
|
|
4823
5284
|
return;
|
|
4824
5285
|
try {
|
|
4825
5286
|
if (ok) {
|
|
5287
|
+
asked.effects = options.effects;
|
|
5288
|
+
asked.guitar = options.sound === "guitar" ? options.guitar ?? "steel" : null;
|
|
4826
5289
|
handle = inner.play(events, { ...options, volume });
|
|
5290
|
+
room?.look();
|
|
4827
5291
|
return;
|
|
4828
5292
|
}
|
|
4829
5293
|
} catch {}
|
|
@@ -4890,5 +5354,5 @@ export {
|
|
|
4890
5354
|
textTabToAlphaTex
|
|
4891
5355
|
};
|
|
4892
5356
|
|
|
4893
|
-
//# debugId=
|
|
5357
|
+
//# debugId=DF52191A0D0F48AC64756E2164756E21
|
|
4894
5358
|
//# sourceMappingURL=index.js.map
|