|
|
@ -32,6 +32,7 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
npm run lint:check
|
npm run lint:check
|
||||||
|
npm run format:check
|
||||||
npm run typecheck
|
npm run typecheck
|
||||||
npm run typecheck:e2e
|
npm run typecheck:e2e
|
||||||
npm test
|
npm test
|
||||||
|
|
@ -40,6 +41,10 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
npm run test:e2e
|
npm run test:e2e
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
npm run build
|
||||||
|
|
||||||
- name: Upload Playwright report
|
- name: Upload Playwright report
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
|
||||||
2
.nvmrc
|
|
@ -1 +1 @@
|
||||||
22
|
22.13.0
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@
|
||||||
"endOfLine": "lf",
|
"endOfLine": "lf",
|
||||||
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
|
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
|
||||||
"importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "", "^[./]"],
|
"importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "", "^[./]"],
|
||||||
"importOrderTypeScriptVersion": "5.6.0"
|
"importOrderTypeScriptVersion": "6.0.3"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
<path
|
<path
|
||||||
d="M12 3v11m0 0 4-4m-4 4-4-4M5 17v3h14v-3"
|
d="M12 3v11m0 0 4-4m-4 4-4-4M5 17v3h14v-3"
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="white"
|
stroke="currentColor"
|
||||||
stroke-linecap="round"
|
stroke-linecap="round"
|
||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
stroke-width="2"
|
stroke-width="1.5"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 239 B After Width: | Height: | Size: 248 B |
|
|
@ -1,4 +1,4 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
<circle cx="12" cy="12" r="9" />
|
<circle cx="12" cy="12" r="9" />
|
||||||
<line x1="12" y1="8" x2="12.01" y2="8" />
|
<line x1="12" y1="8" x2="12.01" y2="8" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 342 B After Width: | Height: | Size: 349 B |
|
|
@ -1,4 +1,4 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
<path d="M4 8v-2a2 2 0 0 1 2 -2h2" />
|
<path d="M4 8v-2a2 2 0 0 1 2 -2h2" />
|
||||||
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 382 B |
|
|
@ -1,4 +1,4 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
<path d="M15 19v-2a2 2 0 0 1 2 -2h2" />
|
<path d="M15 19v-2a2 2 0 0 1 2 -2h2" />
|
||||||
<path d="M15 5v2a2 2 0 0 0 2 2h2" />
|
<path d="M15 5v2a2 2 0 0 0 2 2h2" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 382 B |
|
|
@ -1,4 +1,4 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
<path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
|
<path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
|
||||||
<path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" />
|
<path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 324 B After Width: | Height: | Size: 331 B |
|
|
@ -1,4 +1,4 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="white" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
<path d="M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
<path d="M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
||||||
<path d="M4 6l8 0" />
|
<path d="M4 6l8 0" />
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 534 B After Width: | Height: | Size: 541 B |
|
|
@ -1,3 +1,3 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||||
<path d="M3 9.25v5.5h4.1L13 20V4L7.1 9.25H3Zm13.3-2.8-1.4 1.4A5.1 5.1 0 0 1 16.5 12a5.1 5.1 0 0 1-1.6 4.15l1.4 1.4A7.1 7.1 0 0 0 18.5 12a7.1 7.1 0 0 0-2.2-5.55Zm2.85-2.85-1.42 1.42A9.55 9.55 0 0 1 20.5 12a9.55 9.55 0 0 1-2.77 6.98l1.42 1.42A11.55 11.55 0 0 0 22.5 12a11.55 11.55 0 0 0-3.35-8.4Z" />
|
<path d="M3 9.25v5.5h4.1L13 20V4L7.1 9.25H3Zm13.3-2.8-1.4 1.4A5.1 5.1 0 0 1 16.5 12a5.1 5.1 0 0 1-1.6 4.15l1.4 1.4A7.1 7.1 0 0 0 18.5 12a7.1 7.1 0 0 0-2.2-5.55Zm2.85-2.85-1.42 1.42A9.55 9.55 0 0 1 20.5 12a9.55 9.55 0 0 1-2.77 6.98l1.42 1.42A11.55 11.55 0 0 0 22.5 12a11.55 11.55 0 0 0-3.35-8.4Z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 384 B After Width: | Height: | Size: 391 B |
8
definitions.d.ts
vendored
|
|
@ -1,8 +0,0 @@
|
||||||
declare module '*.wgsl?raw' {
|
|
||||||
const content: string;
|
|
||||||
export default content;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface HTMLCanvasElement {
|
|
||||||
getContext(contextId: 'webgpu'): GPUCanvasContext | null;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
import { expect, test, type Page } from '@playwright/test';
|
import { test as base, expect, type Page } from '@playwright/test';
|
||||||
|
|
||||||
const canvasName = 'Interactive generative garden canvas';
|
const canvasName = 'Interactive generative garden canvas';
|
||||||
|
|
||||||
|
interface BrowserDiagnostics {
|
||||||
|
browserFailures: Array<string>;
|
||||||
|
consoleErrors: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
const isLocalUrl = (url: string) => {
|
const isLocalUrl = (url: string) => {
|
||||||
const { hostname } = new URL(url);
|
const { hostname } = new URL(url);
|
||||||
return hostname === '127.0.0.1' || hostname === 'localhost';
|
return hostname === '127.0.0.1' || hostname === 'localhost';
|
||||||
|
|
@ -29,6 +34,27 @@ const collectLocalBrowserFailures = (page: Page) => {
|
||||||
return failures;
|
return failures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const test = base.extend<{ browserDiagnostics: BrowserDiagnostics }>({
|
||||||
|
browserDiagnostics: [
|
||||||
|
async ({ page }, use) => {
|
||||||
|
const browserFailures = collectLocalBrowserFailures(page);
|
||||||
|
const consoleErrors: Array<string> = [];
|
||||||
|
|
||||||
|
page.on('console', (message) => {
|
||||||
|
if (message.type() === 'error') {
|
||||||
|
consoleErrors.push(message.text());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await use({ browserFailures, consoleErrors });
|
||||||
|
|
||||||
|
expect(consoleErrors).toEqual([]);
|
||||||
|
expect(browserFailures).toEqual([]);
|
||||||
|
},
|
||||||
|
{ auto: true },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
const disableWebGpu = async (page: Page) => {
|
const disableWebGpu = async (page: Page) => {
|
||||||
await page.addInitScript(() => {
|
await page.addInitScript(() => {
|
||||||
Object.defineProperty(navigator, 'gpu', {
|
Object.defineProperty(navigator, 'gpu', {
|
||||||
|
|
@ -39,14 +65,6 @@ const disableWebGpu = async (page: Page) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
test('starts the WebGPU garden and accepts drawing input', async ({ page }) => {
|
test('starts the WebGPU garden and accepts drawing input', async ({ page }) => {
|
||||||
const browserFailures = collectLocalBrowserFailures(page);
|
|
||||||
const consoleErrors: Array<string> = [];
|
|
||||||
page.on('console', (message) => {
|
|
||||||
if (message.type() === 'error') {
|
|
||||||
consoleErrors.push(message.text());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await page.addInitScript((expectedCanvasName) => {
|
await page.addInitScript((expectedCanvasName) => {
|
||||||
const captureState = { count: 0 };
|
const captureState = { count: 0 };
|
||||||
Object.defineProperty(window, '__fleetingGardenPointerCaptures', {
|
Object.defineProperty(window, '__fleetingGardenPointerCaptures', {
|
||||||
|
|
@ -68,7 +86,7 @@ test('starts the WebGPU garden and accepts drawing input', async ({ page }) => {
|
||||||
}, canvasName);
|
}, canvasName);
|
||||||
|
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
const startButton = page.getByRole('button', { name: 'Start' });
|
const startButton = page.getByRole('button', { exact: true, name: 'Start' });
|
||||||
await expect(startButton).toBeVisible();
|
await expect(startButton).toBeVisible();
|
||||||
await expect(startButton).toBeEnabled({ timeout: 30_000 });
|
await expect(startButton).toBeEnabled({ timeout: 30_000 });
|
||||||
await page.keyboard.press('Enter');
|
await page.keyboard.press('Enter');
|
||||||
|
|
@ -117,13 +135,21 @@ test('starts the WebGPU garden and accepts drawing input', async ({ page }) => {
|
||||||
)
|
)
|
||||||
.toBeGreaterThan(0);
|
.toBeGreaterThan(0);
|
||||||
|
|
||||||
expect(consoleErrors).toEqual([]);
|
await expect
|
||||||
expect(browserFailures).toEqual([]);
|
.poll(() =>
|
||||||
|
page.evaluate(
|
||||||
|
() =>
|
||||||
|
(
|
||||||
|
window as unknown as {
|
||||||
|
__fleetingGardenBrushPasses?: number;
|
||||||
|
}
|
||||||
|
).__fleetingGardenBrushPasses ?? 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows a clear fallback when WebGPU is unavailable', async ({ page }) => {
|
test('shows a clear fallback when WebGPU is unavailable', async ({ page }) => {
|
||||||
const browserFailures = collectLocalBrowserFailures(page);
|
|
||||||
|
|
||||||
await disableWebGpu(page);
|
await disableWebGpu(page);
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
|
||||||
|
|
@ -135,23 +161,19 @@ test('shows a clear fallback when WebGPU is unavailable', async ({ page }) => {
|
||||||
const fallback = page.getByRole('alert');
|
const fallback = page.getByRole('alert');
|
||||||
await expect(fallback).toContainText('Fleeting Garden needs WebGPU');
|
await expect(fallback).toContainText('Fleeting Garden needs WebGPU');
|
||||||
await expect(fallback).toContainText('webgpu-unsupported');
|
await expect(fallback).toContainText('webgpu-unsupported');
|
||||||
expect(browserFailures).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('syncs the selected vibe with the URI', async ({ page }) => {
|
test('syncs the selected vibe with the URI', async ({ page }) => {
|
||||||
const browserFailures = collectLocalBrowserFailures(page);
|
|
||||||
|
|
||||||
await disableWebGpu(page);
|
await disableWebGpu(page);
|
||||||
await page.goto('/?vibe=Bone%20Archive');
|
await page.goto('/?vibe=Aurora%20Mycelium');
|
||||||
|
|
||||||
await expect(page).toHaveURL(/vibe=bone-archive/);
|
await expect(page).toHaveURL(/vibe=aurora-mycelium/);
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Next vibe' }).click();
|
await page.getByRole('button', { name: 'Next vibe' }).click();
|
||||||
await expect(page).toHaveURL(/vibe=pelagic-caustics/);
|
await expect(page).toHaveURL(/vibe=velvet-observatory/);
|
||||||
|
|
||||||
await page.goBack();
|
await page.goBack();
|
||||||
await expect(page).toHaveURL(/vibe=bone-archive/);
|
await expect(page).toHaveURL(/vibe=aurora-mycelium/);
|
||||||
expect(browserFailures).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('keeps audio focus outlines scoped to the active control', async ({ page }) => {
|
test('keeps audio focus outlines scoped to the active control', async ({ page }) => {
|
||||||
|
|
@ -194,7 +216,7 @@ test('keeps the config overlay scrollable and dismissible on mobile', async ({
|
||||||
await page.setViewportSize({ width: 390, height: 640 });
|
await page.setViewportSize({ width: 390, height: 640 });
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
|
||||||
const startButton = page.getByRole('button', { name: 'Start' });
|
const startButton = page.getByRole('button', { exact: true, name: 'Start' });
|
||||||
await expect(startButton).toBeEnabled({ timeout: 30_000 });
|
await expect(startButton).toBeEnabled({ timeout: 30_000 });
|
||||||
await startButton.click();
|
await startButton.click();
|
||||||
await expect(page.locator('body')).not.toHaveClass(/is-loading/, {
|
await expect(page.locator('body')).not.toHaveClass(/is-loading/, {
|
||||||
|
|
|
||||||
12
package-lock.json
generated
|
|
@ -10,13 +10,13 @@
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@plausible-analytics/tracker": "^0.4.5",
|
"@plausible-analytics/tracker": "^0.4.5",
|
||||||
"tweakpane": "^4.0.5"
|
"tweakpane": "~4.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@ianvs/prettier-plugin-sort-imports": "^4.7.1",
|
"@ianvs/prettier-plugin-sort-imports": "^4.7.1",
|
||||||
"@playwright/test": "^1.60.0",
|
"@playwright/test": "^1.60.0",
|
||||||
"@tweakpane/core": "^2.0.5",
|
"@tweakpane/core": "~2.0.5",
|
||||||
"@types/node": "^25.6.0",
|
"@types/node": "^25.6.0",
|
||||||
"@vite-pwa/assets-generator": "^1.0.2",
|
"@vite-pwa/assets-generator": "^1.0.2",
|
||||||
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
"vitest": "^4.1.5"
|
"vitest": "^4.1.5"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20"
|
"node": ">=22.13.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
|
|
@ -2774,9 +2774,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "5.0.5",
|
"version": "5.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz",
|
||||||
"integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==",
|
"integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
"generate-icons": "pwa-assets-generator"
|
"generate-icons": "pwa-assets-generator"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=22"
|
"node": ">=22.13.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export default defineConfig({
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
forbidOnly: isCi,
|
forbidOnly: isCi,
|
||||||
retries: isCi ? 2 : 0,
|
retries: isCi ? 2 : 0,
|
||||||
workers: isCi ? 1 : undefined,
|
workers: 1,
|
||||||
reporter: isCi ? [['list'], ['html', { open: 'never' }]] : 'list',
|
reporter: isCi ? [['list'], ['html', { open: 'never' }]] : 'list',
|
||||||
use: {
|
use: {
|
||||||
baseURL,
|
baseURL,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {
|
||||||
type PlausibleEventOptions,
|
type PlausibleEventOptions,
|
||||||
} from '@plausible-analytics/tracker';
|
} from '@plausible-analytics/tracker';
|
||||||
|
|
||||||
|
import { appConfig } from './config';
|
||||||
import type { VibeId } from './vibes';
|
import type { VibeId } from './vibes';
|
||||||
|
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
|
|
@ -23,10 +24,10 @@ export const initAnalytics = () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
plausibleInit({
|
plausibleInit({
|
||||||
domain: 'schmelczer.dev/floating',
|
domain: appConfig.analytics.domain,
|
||||||
endpoint: 'https://stats.schmelczer.dev/status',
|
endpoint: appConfig.analytics.endpoint,
|
||||||
autoCapturePageviews: true,
|
autoCapturePageviews: appConfig.analytics.autoCapturePageviews,
|
||||||
logging: true,
|
logging: appConfig.analytics.logging,
|
||||||
});
|
});
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { PianoNoteRole } from './garden-audio-types';
|
import type { PianoNoteRole } from './garden-audio-types';
|
||||||
|
|
||||||
const DEFAULT_AUDIO_VOLUME = 0.5;
|
export const DEFAULT_AUDIO_VOLUME = 0.5;
|
||||||
|
export const SILENT_AUDIO_GAIN = 0.0001;
|
||||||
|
|
||||||
type GardenAudioChordQuality = 'major' | 'minor' | 'sus2' | 'sus4';
|
type GardenAudioChordQuality = 'major' | 'minor' | 'sus2' | 'sus4';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { clamp } from '../utils/math';
|
import { clamp } from '../utils/math';
|
||||||
import type { GardenAudioConfig } from './garden-audio-config';
|
import { SILENT_AUDIO_GAIN, type GardenAudioConfig } from './garden-audio-config';
|
||||||
import type { PianoNoteRole } from './garden-audio-types';
|
import type { PianoNoteRole } from './garden-audio-types';
|
||||||
|
|
||||||
|
type AudioSessionType = NonNullable<NavigatorWithAudioSession['audioSession']>['type'];
|
||||||
|
|
||||||
type NavigatorWithAudioSession = Navigator & {
|
type NavigatorWithAudioSession = Navigator & {
|
||||||
audioSession?: {
|
audioSession?: {
|
||||||
type:
|
type:
|
||||||
|
|
@ -17,7 +19,7 @@ type NavigatorWithAudioSession = Navigator & {
|
||||||
const outputHighPassFrequencyHz = 45;
|
const outputHighPassFrequencyHz = 45;
|
||||||
const noiseBufferDurationSeconds = 1;
|
const noiseBufferDurationSeconds = 1;
|
||||||
const graphTuning = {
|
const graphTuning = {
|
||||||
closeGain: 0.0001,
|
closeGain: SILENT_AUDIO_GAIN,
|
||||||
closeRampSeconds: 0.015,
|
closeRampSeconds: 0.015,
|
||||||
delayMaxSeconds: 2,
|
delayMaxSeconds: 2,
|
||||||
eventBusGain: 1,
|
eventBusGain: 1,
|
||||||
|
|
@ -54,6 +56,7 @@ export class GardenAudioGraph {
|
||||||
private pianoBusGainScale = 1;
|
private pianoBusGainScale = 1;
|
||||||
private pianoBusGainScaleAutomationUntil = 0;
|
private pianoBusGainScaleAutomationUntil = 0;
|
||||||
private pianoBusGainScaleTimeConstantSeconds = 0;
|
private pianoBusGainScaleTimeConstantSeconds = 0;
|
||||||
|
private previousAudioSessionType: AudioSessionType | null = null;
|
||||||
private readonly pianoBuses = new Map<PianoNoteRole, GainNode>();
|
private readonly pianoBuses = new Map<PianoNoteRole, GainNode>();
|
||||||
|
|
||||||
public constructor(private readonly config: GardenAudioConfig) {}
|
public constructor(private readonly config: GardenAudioConfig) {}
|
||||||
|
|
@ -77,6 +80,7 @@ export class GardenAudioGraph {
|
||||||
// Audio Session API.
|
// Audio Session API.
|
||||||
const audioSession = (navigator as NavigatorWithAudioSession).audioSession;
|
const audioSession = (navigator as NavigatorWithAudioSession).audioSession;
|
||||||
if (audioSession) {
|
if (audioSession) {
|
||||||
|
this.previousAudioSessionType ??= audioSession.type;
|
||||||
audioSession.type = 'playback';
|
audioSession.type = 'playback';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,6 +207,21 @@ export class GardenAudioGraph {
|
||||||
if (context.state !== 'closed') {
|
if (context.state !== 'closed') {
|
||||||
await context.close().catch(() => undefined);
|
await context.close().catch(() => undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.restoreAudioSessionType();
|
||||||
|
}
|
||||||
|
|
||||||
|
private restoreAudioSessionType(): void {
|
||||||
|
const previousType = this.previousAudioSessionType;
|
||||||
|
this.previousAudioSessionType = null;
|
||||||
|
if (previousType === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const audioSession = (navigator as NavigatorWithAudioSession).audioSession;
|
||||||
|
if (audioSession) {
|
||||||
|
audioSession.type = previousType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private createDelay(context: AudioContext, masterGain: GainNode): void {
|
private createDelay(context: AudioContext, masterGain: GainNode): void {
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ const DEFAULT_PROGRESSION: ReadonlyArray<GardenAudioChord> = [
|
||||||
const DEFAULT_ROOT_MIDI = 57;
|
const DEFAULT_ROOT_MIDI = 57;
|
||||||
const DEFAULT_SCALE: ReadonlyArray<number> = [0, 2, 4, 7, 9];
|
const DEFAULT_SCALE: ReadonlyArray<number> = [0, 2, 4, 7, 9];
|
||||||
|
|
||||||
const profileCache = new WeakMap<VibePreset, GardenAudioVibeProfile>();
|
|
||||||
|
|
||||||
const getProfileScale = (vibe: VibePreset): Array<number> => {
|
const getProfileScale = (vibe: VibePreset): Array<number> => {
|
||||||
const scale = vibe.audio.scale?.length ? vibe.audio.scale : DEFAULT_SCALE;
|
const scale = vibe.audio.scale?.length ? vibe.audio.scale : DEFAULT_SCALE;
|
||||||
return [...scale];
|
return [...scale];
|
||||||
|
|
@ -26,21 +24,10 @@ const getProfileProgression = (vibe: VibePreset): Array<GardenAudioChord> =>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getVibeProfile = (vibe: VibePreset): GardenAudioVibeProfile => {
|
export const getVibeProfile = (vibe: VibePreset): GardenAudioVibeProfile => {
|
||||||
let profile = profileCache.get(vibe);
|
return {
|
||||||
if (!profile) {
|
...vibe.audio,
|
||||||
profile = {
|
rootMidi: DEFAULT_ROOT_MIDI + vibe.audio.notePitchOffset,
|
||||||
...vibe.audio,
|
scale: getProfileScale(vibe),
|
||||||
rootMidi: DEFAULT_ROOT_MIDI + vibe.audio.notePitchOffset,
|
progression: getProfileProgression(vibe),
|
||||||
scale: getProfileScale(vibe),
|
};
|
||||||
progression: getProfileProgression(vibe),
|
|
||||||
};
|
|
||||||
profileCache.set(vibe, profile);
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.assign(profile, vibe.audio);
|
|
||||||
profile.rootMidi = DEFAULT_ROOT_MIDI + vibe.audio.notePitchOffset;
|
|
||||||
profile.scale = getProfileScale(vibe);
|
|
||||||
profile.progression = getProfileProgression(vibe);
|
|
||||||
return profile;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { VibePreset } from '../vibes';
|
import type { VibePreset } from '../vibes';
|
||||||
|
|
||||||
export interface GardenAudioSnapshot {
|
export interface GardenAudioSnapshot {
|
||||||
vibe: VibePreset;
|
vibe: VibePreset;
|
||||||
|
|
|
||||||