Fade a sound's start and end apart, each along its own curve (#345)
A cut sound had one edge fade for both ends, always a straight ramp. Now its start and its end each have a fade of their own, and each fade has a curve of its own. - Fade in (ms) and Fade out (ms) replace Edge fade (ms), 5 ms each by default. Like before they apply only to an edge inside the file. - Fade in curve and Fade out curve each offer Linear (the default), Equal power, S-curve, Exponential and Logarithmic. A fade out runs its curve backwards. - The Sound tab's header has a field and a curve dropdown per edge. Each dropdown shows its curve as a small picture, rising or falling, and names it in its tooltip. With two named dropdowns the header was too wide at 1280 px and cut off the readout on the right. - The inspector shows the same four rows, the curves by name. - The wave draws each ramp in its curve rather than as a line. - A cut plays by <file>#<start>~<end>~<fadeIn>~<fadeOut>~<curveIn>~<curveOut>. - No migration, as asked in the issue: the old fade key is no longer read, so saved sounds start with 5 ms each and Linear on both. Tests: - Unit sounds, sound-library: 96 tests - Counter-check (fade out along the fade in's curve): 1 red - e2e 34 (melektaus-atx): ALL PASSED - 69 checks - Gate (melektaus-atx): CHECK EXIT 0, 256 files, 3978 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b49a0bea7
commit
29b604dc07
10 files changed
+421
-96
No files matched your search
+51
-6
@@ -1513,26 +1513,71 @@ export async function sound(t) {
|
||||
'a drag beside the handles spans a new stretch, played by a name of its own, cut to the sample',
|
||||
Math.abs(spanned?.start - 0.1) < 0.01 &&
|
||||
Math.abs(spanned?.end - 0.3) < 0.01 &&
|
||||
cutPlayed === `${drone.file}#${spanned?.start}~${spanned?.end}~0.01` &&
|
||||
cutPlayed === `${drone.file}#${spanned?.start}~${spanned?.end}~0.005~0.005~linear~linear` &&
|
||||
cutSamples?.length === keptSamples,
|
||||
JSON.stringify({ spanned, cutPlayed, cutSamples, keptSamples }),
|
||||
);
|
||||
check(
|
||||
'the cut rises from silence and falls back to it, the default 10 ms at each edge inside the file',
|
||||
'the cut rises from silence and falls back to it, the default 5 ms at each edge inside the file',
|
||||
cutSamples?.head[0] === 0 && Math.abs(cutSamples?.tail.at(-1)) < 0.01,
|
||||
JSON.stringify(cutSamples),
|
||||
);
|
||||
const tabFade = await json('__gm.soundTab.fadeField()');
|
||||
await click(tabFade.x, tabFade.y);
|
||||
// 34h-ii. Each edge has a fade of its own, each shaped by its own curve (#345).
|
||||
const tabFadeOut = await json('__gm.soundTab.fadeOutField()');
|
||||
await click(tabFadeOut.x, tabFadeOut.y);
|
||||
await t.typeText('40');
|
||||
await press('Enter');
|
||||
await sleep(150);
|
||||
const curveOutButton = await json('__gm.soundTab.curveOutButton()');
|
||||
await click(curveOutButton.x, curveOutButton.y);
|
||||
await clickText('Exponential');
|
||||
await sleep(150);
|
||||
const curved = await json(`__gm.soundTab.played(${JSON.stringify(droneId)})`);
|
||||
const curvedSamples = await evaluate(`__gm.soundTab.samples(${JSON.stringify(curved)})`);
|
||||
check(
|
||||
'the header sets the fade out and its curve on their own, the fade in staying Linear',
|
||||
(await droneProps())?.fadeOut === 40 &&
|
||||
(await droneProps())?.fadeOutCurve === 'exponential' &&
|
||||
((await droneProps())?.fadeInCurve ?? 'linear') === 'linear' &&
|
||||
(await json('__gm.soundTab.curveOutButton()')).tooltip === 'Fade out curve: Exponential' &&
|
||||
(await json('__gm.soundTab.curveInButton()')).tooltip === 'Fade in curve: Linear' &&
|
||||
curved.endsWith('~0.005~0.04~linear~exponential'),
|
||||
JSON.stringify({ props: await droneProps(), curved }),
|
||||
);
|
||||
await press('z', { ctrl: true });
|
||||
await press('z', { ctrl: true });
|
||||
const tabFadeIn = await json('__gm.soundTab.fadeInField()');
|
||||
await click(tabFadeIn.x, tabFadeIn.y);
|
||||
await t.typeText('0');
|
||||
await press('Enter');
|
||||
const fadeOutField = await json('__gm.soundTab.fadeOutField()');
|
||||
await click(fadeOutField.x, fadeOutField.y);
|
||||
await t.typeText('0');
|
||||
await press('Enter');
|
||||
await sleep(150);
|
||||
const unfaded = await json(`__gm.soundTab.played(${JSON.stringify(droneId)})`);
|
||||
check(
|
||||
'the header sets the fade at the edges, in milliseconds on the asset',
|
||||
(await droneProps())?.fade === 0 && unfaded.endsWith('~0'),
|
||||
'after two undos the curve is Linear again, and both fades go to 0 in the header',
|
||||
(await droneProps())?.fadeIn === 0 &&
|
||||
(await droneProps())?.fadeOut === 0 &&
|
||||
((await droneProps())?.fadeOutCurve ?? 'linear') === 'linear' &&
|
||||
unfaded.endsWith('~0~0~linear~linear'),
|
||||
JSON.stringify({ props: await droneProps(), unfaded }),
|
||||
);
|
||||
// The same stretch unfaded is the drone itself: against it, the i-th sample before the end of the
|
||||
// exponential fall is (i / ramp)² of it, where a straight line would leave i / ramp.
|
||||
const rawSamples = await evaluate(`__gm.soundTab.samples(${JSON.stringify(unfaded)})`);
|
||||
const outRamp = Math.round(0.04 * (rawSamples?.rate ?? 0));
|
||||
const fall = [1, 2, 3]
|
||||
.map((i) => ({ i, raw: rawSamples?.tail.at(-1 - i), curved: curvedSamples?.tail.at(-1 - i) }))
|
||||
.filter((s) => Math.abs(s.raw) > 1e-3);
|
||||
check(
|
||||
'the end falls along the curve: (i / ramp)² of the drone on an exponential one',
|
||||
curvedSamples?.tail.at(-1) === 0 &&
|
||||
fall.length > 0 &&
|
||||
fall.every((s) => Math.abs(s.curved / s.raw / (s.i / outRamp) ** 2 - 1) < 1e-3),
|
||||
JSON.stringify({ fall, outRamp }),
|
||||
);
|
||||
await evaluate('__gm.sound.stopAll()');
|
||||
const tabPlay = await json('__gm.soundTab.playButton()');
|
||||
await click(tabPlay.x, tabPlay.y);
|
||||
|
||||
Reference in new issue
Block a user