Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ This project is for personal and educational use. It is **not a medical, therape

- The background **is** the interface, not decoration on top of one: a full-viewport sky whose gradient, sun/moon arc position, star density, and rain streaks are computed directly from the real hour and weather (`sky/skyMath.ts`, pure and unit-tested). These are the same inputs driving the synthesis engine, rendered instead of just logged
- Atmospheric depth beyond the flat gradient: a distant rolling-hills silhouette (tinted with the same day→night blend as the sky), a warm horizon glow that blooms in specifically around real sunrise/sunset and fades once the sun clears the horizon, and a field of slow-drifting ambient particles so the scene stays alive even on a still, clear, cloudless day
- **The sky answers the music** (`sky/useSkyReactions.ts`): the engine emits chord, arp-note and kick events in sync with the audio, and the sun/moon glow pulses with each kick, a star (or a drifting mote by day) flares on arp notes, and the light washes warm on major chords and cool on minor ones. Driven by the Web Animations API, so it never re-renders React; off under `prefers-reduced-motion`
- Precipitation renders as rain or snow depending on the actual weather type, and a thunderstorm brings a randomized screen-flash lightning strike (`useLightning.ts`) paired with a low rumbling boom from the audio engine (`AudioEngine.triggerThunder()`); both are skipped under `prefers-reduced-motion` for the visual side
- A single minimal glass "now playing" tray floats at the bottom: time, a short weather/scale/tempo readout, a live waveform, play/stop, volume, and record. Everything else stays out of the way
- Every other control (Simulate mode, per-layer mixer, presets, the full input/parameter readout) lives in a collapsible "Studio" drawer styled as an instrument HUD: corner-bracketed panels, a segmented Live/Simulate toggle, and the same glowing brass slider skin used everywhere else, instead of raw browser form controls. Closeable three ways (an explicit close button, clicking outside, or Escape) after early feedback that the original tiny toggle icon was too easy to lose track of
- Start/Stop gated behind a user gesture (per browser autoplay policy), with a Space-bar shortcut once the page has focus (ignored while typing in a text field, so it doesn't hijack the preset-name input)
- A single minimal glass "now playing" tray floats at the bottom: where the weather is from (a picked city, "Your location", "Simulated weather"...), the chord playing now, the time, a weather/key/mode/tempo readout (the key briefly lights up when it changes), a glowing auto-gained waveform that gently "breathes" while stopped, and labeled play, volume, Rec and Studio controls. If the weather can't be fetched it says WEATHER OFFLINE and retries (30s, 60s, 120s...) instead of loading forever
- Every other control lives in the "Studio" drawer, split into three tabs (arrow keys move between them): **Sound** (focus mode, sleep timer, mixer), **Source** (Live/Simulate, location picker, the full input/parameter readout) and **Presets**. It's styled as an instrument HUD with corner-bracketed panels and the same glowing brass slider skin used everywhere else. Closeable three ways (the close button, clicking outside, or Escape)
- Start/Stop gated behind a user gesture (per browser autoplay policy), with a Space-bar shortcut once the page has focus (ignored while typing in a text field, so it doesn't hijack the preset-name input). A small "or press Space" hint shows under the tray on devices with a keyboard
- **OS media controls** (`useMediaSession.ts`): publishes "Scale · Tempo" as now-playing metadata with real play/pause controls to the lock screen, notification shade, Control Center, or Chrome's media widget, so a session can be controlled after the screen locks or the tab is backgrounded, not just from inside the page
- **Volume and mixer levels persist** across reloads (`lib/localSettings.ts`); a "leave it running" tool shouldn't make you re-balance the mix every time you open the tab
- Deliberately single dark visual world (no light-mode toggle). A night sky doesn't make sense re-skinned light, so the app commits to one presentation instead of following the OS theme preference
- **First-run onboarding hint**: a one-time callout explaining what the app is reacting to and where the Studio lives, dismissed on "Got it" or automatically on first Start; the dismissal persists across reloads (`lib/localSettings.ts`)

### Resilience & Accessibility

- **Crackle-free playback**: the audio runs on a "playback" latency context (a larger buffer than Tone's low-latency default) with a 0.25 s lookahead, so a busy page can't starve the audio thread, plus a -1 dB limiter on the output to catch thunder and chord peaks
- **React error boundary** (`components/ErrorBoundary.tsx`): a top-level class component wraps the whole app, so a thrown error during render doesn't blank the page. Shows a plain-language fallback with a Refresh button instead of a white screen
- **Studio drawer is a real focus trap, not just a visual overlay**: the main view and the drawer toggle native `inert` on each other based on which is open, so a closed drawer's controls are fully unreachable by Tab (not just visually hidden), and an open drawer keeps focus from leaking back to the page behind it. Opening the drawer moves focus to its close button; closing it returns focus to the toggle
- **Disambiguated per-item labels**: repeated "Load"/"Delete" buttons in the presets list carry item-specific `aria-label`s (e.g. "Load preset Rainy Night") instead of generic, indistinguishable ones
Expand Down
29 changes: 25 additions & 4 deletions client/public/sw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Minimal app-shell service worker: stale-while-revalidate for same-origin
// GET requests, and it deliberately never touches /api/* — weather and
// presets must always hit the network, never a stale cache.
const CACHE_NAME = 'ambient-weather-engine-v1';
// Minimal app-shell service worker. It deliberately never touches /api/*:
// weather and presets must always hit the network, never a stale cache.
//
// Page loads (navigations) are network-first: the HTML names the current
// build's hashed JS/CSS, so serving a cached copy first would keep showing
// the previous release until a second reload after every deploy. The cache
// is only the offline fallback for pages. Hashed assets never change once
// built, so for everything else a cached copy is safe to serve first.
const CACHE_NAME = 'petrichor-v2';
const APP_SHELL = ['/', '/index.html', '/manifest.webmanifest', '/icon.svg'];

self.addEventListener('install', (event) => {
Expand Down Expand Up @@ -30,6 +35,22 @@ self.addEventListener('fetch', (event) => {
const url = new URL(request.url);
if (url.origin !== self.location.origin || url.pathname.startsWith('/api/')) return;

const isPage = request.mode === 'navigate' || url.pathname === '/' || url.pathname.endsWith('.html');
if (isPage) {
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok) {
const copy = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
}
return response;
})
.catch(() => caches.match(request).then((cached) => cached || caches.match('/index.html'))),
);
return;
}

event.respondWith(
caches.match(request).then((cached) => {
const network = fetch(request)
Expand Down
220 changes: 195 additions & 25 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@
left: 26px;
z-index: 5;
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.14em;
font-size: 13px;
font-weight: 500;
letter-spacing: 0.24em;
text-transform: uppercase;
color: rgba(236, 238, 242, 0.5);
color: rgba(236, 238, 242, 0.82);
text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
}

/* ============ Now-playing tray ============ */
Expand Down Expand Up @@ -308,7 +310,7 @@

.visualizer {
width: 100%;
height: 32px;
height: 44px;
display: block;
margin-top: 14px;
}
Expand Down Expand Up @@ -384,34 +386,51 @@
flex: 1;
}

.tray-dot, .tray-download, .tray-drawer-toggle {
width: 30px;
height: 30px;
border-radius: 50%;
.tray-pill {
display: inline-flex;
align-items: center;
gap: 6px;
height: 32px;
padding: 0 12px 0 10px;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.18);
background: rgba(255, 255, 255, 0.06);
display: flex;
align-items: center;
justify-content: center;
color: var(--ink-dim);
font-family: var(--font-mono);
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
text-decoration: none;
cursor: pointer;
flex-shrink: 0;
font-size: 12px;
text-decoration: none;
color: var(--ink-dim);
transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tray-dot {
color: #ff9b9b;
.tray-pill:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.14);
color: var(--ink);
}

.tray-dot:disabled {
.tray-pill--icon {
width: 32px;
padding: 0;
justify-content: center;
color: var(--ink);
}

.tray-rec svg {
color: #ff8f8f;
}

.tray-rec:disabled {
opacity: 0.35;
cursor: not-allowed;
}

.tray-dot--live {
background: rgba(255, 75, 75, 0.25);
.tray-rec--live {
background: rgba(255, 75, 75, 0.22);
border-color: rgba(255, 75, 75, 0.6);
color: #ffd0d0;
animation: tray-pulse 1.4s ease-in-out infinite;
}

Expand All @@ -420,24 +439,25 @@
50% { box-shadow: 0 0 0 6px rgba(255, 75, 75, 0); }
}

.tray-download {
color: var(--ink);
font-size: 13px;
}

.tray-drawer-toggle--open {
color: var(--brass);
border-color: var(--brass-soft);
}

/* Narrow phones: icons only, the labels live on in aria-label/title. */
@media (max-width: 360px) {
.tray-pill-label { display: none; }
.tray-pill { width: 32px; padding: 0; justify-content: center; }
}

.tray-error {
margin-top: 10px;
font-size: 12px;
color: #ff9b9b;
}

@media (prefers-reduced-motion: reduce) {
.tray-dot--live { animation: none; }
.tray-rec--live { animation: none; }
}

/* ============ Studio drawer ============ */
Expand Down Expand Up @@ -1079,3 +1099,153 @@ input[type="text"] {
background: var(--brass);
color: #1a1206;
}

/* ============ Sky reacting to the music (see sky/useSkyReactions.ts) ============ */

.sky-body-pulse {
position: absolute;
inset: -70%;
border-radius: 50%;
background: radial-gradient(circle, rgba(255, 228, 170, 0.55) 0%, rgba(255, 210, 140, 0.18) 40%, transparent 68%);
opacity: 0;
pointer-events: none;
}

.sky-chord-wash {
position: absolute;
inset: 0;
opacity: 0;
pointer-events: none;
}

.sky-chord-wash[data-tone='warm'] {
background: radial-gradient(ellipse at 50% 100%, rgba(255, 190, 110, 0.9), transparent 70%);
}

.sky-chord-wash[data-tone='cool'] {
background: radial-gradient(ellipse at 50% 100%, rgba(120, 150, 255, 0.9), transparent 70%);
}

/* ============ Now playing: place, chord, key change ============ */

.tray-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 22px;
margin-bottom: 6px;
}

.tray-place {
font-family: var(--font-mono);
font-size: 10.5px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--ink-dim);
opacity: 0.75;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.tray-chord {
flex-shrink: 0;
min-width: 34px;
padding: 2px 9px;
border-radius: 999px;
border: 1px solid rgba(242, 197, 104, 0.35);
background: rgba(242, 197, 104, 0.1);
color: #f2d39a;
font-family: var(--font-display);
font-size: 14px;
text-align: center;
animation: chord-in 0.9s ease;
}

@keyframes chord-in {
from { opacity: 0; transform: translateY(3px); }
to { opacity: 1; transform: translateY(0); }
}

.tray-meta-key--changed {
animation: key-flash 3s ease;
}

@keyframes key-flash {
0% { color: var(--brass); text-shadow: 0 0 10px rgba(242, 197, 104, 0.7); }
100% { color: inherit; text-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
.tray-chord, .tray-meta-key--changed { animation: none; }
}

/* ============ Studio tabs ============ */

.studio-tabs {
display: flex;
gap: 4px;
padding: 4px;
margin-top: -8px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.08);
}

.studio-tab {
flex: 1;
border: none;
border-radius: 999px;
background: transparent;
color: var(--ink-dim);
font-family: var(--font-mono);
font-size: 11.5px;
letter-spacing: 0.08em;
text-transform: uppercase;
padding: 8px 10px;
}

.studio-tab:hover:not(.studio-tab--active) {
background: rgba(255, 255, 255, 0.08);
color: var(--ink);
}

.studio-tab--active,
.studio-tab--active:hover:not(:disabled) {
background: var(--brass);
color: #1a1206;
font-weight: 600;
}

.studio-panel {
display: flex;
flex-direction: column;
gap: 26px;
}

/* Space-bar hint under the tray, only where there's a keyboard to press it. */
.tray-hint {
margin-top: 10px;
font-family: var(--font-mono);
font-size: 10.5px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ink-dim);
opacity: 0.6;
}

.tray-hint kbd {
display: inline-block;
padding: 1px 6px;
margin: 0 2px;
border-radius: 4px;
border: 1px solid rgba(255, 255, 255, 0.22);
background: rgba(255, 255, 255, 0.06);
font-family: inherit;
font-size: 10px;
}

@media (hover: none) {
.tray-hint { display: none; }
}
Loading
Loading