Merge branch 'copy-pass-soundscapes'
All checks were successful
Build and Deploy / deploy (push) Successful in 12s

This commit is contained in:
djg 2026-09-23 04:37:16 +00:00
commit 242c855004
3 changed files with 132 additions and 5 deletions

View file

@ -16,6 +16,7 @@
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:image" content="https://myadhd.dev/static/og.png"> <meta property="og:image" content="https://myadhd.dev/static/og.png">
<meta property="og:url" content="https://myadhd.dev/"> <meta property="og:url" content="https://myadhd.dev/">
<script src="/static/audio.js" defer></script>
</head> </head>
<body> <body>
<header class="top"> <header class="top">
@ -116,6 +117,21 @@
</div> </div>
<p class="tiny" id="timer-note">Tip: 25 minutes is a suggestion, not a law. The best length is the one you'll actually start.</p> <p class="tiny" id="timer-note">Tip: 25 minutes is a suggestion, not a law. The best length is the one you'll actually start.</p>
</div> </div>
<div class="card center" style="margin-top: 16px;">
<h3>Focus soundscapes</h3>
<p class="tiny" style="margin-bottom: 16px; margin-top: 4px;">Locally generated procedural audio to help you focus. No internet required!</p>
<div class="presets" style="margin-bottom: 16px;">
<button class="chip preset bg-sound" data-sound="brown" aria-label="Brown Noise">Brown Noise</button>
<button class="chip preset bg-sound" data-sound="pink" aria-label="Pink Noise">Pink Noise</button>
<button class="chip preset bg-sound off active" data-sound="off" aria-label="Off">Off</button>
</div>
<div class="row center gap" style="max-width: 300px; margin: 0 auto;">
<label for="bg-volume" style="font-size: 0.85rem; color: var(--dim);">Volume</label>
<input type="range" id="bg-volume" min="0" max="1" step="0.05" value="0.2" style="flex: 1;">
</div>
</div>
<!-- Timer completion overlay --> <!-- Timer completion overlay -->
<div id="timer-complete" class="completion-overlay" hidden> <div id="timer-complete" class="completion-overlay" hidden>
<div class="completion-card"> <div class="completion-card">
@ -164,14 +180,14 @@
<div class="card"> <div class="card">
<form id="inbox-form" class="row"> <form id="inbox-form" class="row">
<label for="inbox-input" class="sr-only">New task</label> <label for="inbox-input" class="sr-only">New task</label>
<input id="inbox-input" type="text" placeholder="Type a task and hit Enter..." autocomplete="off"> <input id="inbox-input" type="text" placeholder="Type a task and hit enter..." autocomplete="off">
<button class="btn" type="submit">dump it</button> <button class="btn" type="submit">dump</button>
</form> </form>
<div id="inbox-out" hidden> <div id="inbox-out" hidden>
<p class="tiny" id="inbox-count"></p> <p class="tiny" id="inbox-count"></p>
<ul id="inbox-list" class="steps" role="list"></ul> <ul id="inbox-list" class="steps" role="list"></ul>
<div id="inbox-actions" class="row gap mt-2"> <div id="inbox-actions" class="row gap mt-2">
<button class="btn ghost" id="inbox-clear" type="button">clear all</button> <button class="btn ghost" id="inbox-clear" type="button">clear all dumped tasks</button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -719,7 +719,7 @@
var breakBtn = document.createElement('button'); var breakBtn = document.createElement('button');
breakBtn.className = 'btn ghost small'; breakBtn.className = 'btn ghost small';
breakBtn.textContent = 'break down'; breakBtn.textContent = 'break this down';
breakBtn.addEventListener('click', function() { breakBtn.addEventListener('click', function() {
inboxItems.splice(i, 1); inboxItems.splice(i, 1);
saveInbox(); saveInbox();
@ -756,7 +756,7 @@
}); });
$inboxClear.addEventListener('click', function () { $inboxClear.addEventListener('click', function () {
if (confirm('Clear entire inbox?')) { if (confirm('Clear entire inbox of dumps?')) {
inboxItems = []; inboxItems = [];
saveInbox(); saveInbox();
} }

111
site/static/audio.js Normal file
View file

@ -0,0 +1,111 @@
/* =========================================================================
BACKGROUND AUDIO (PROCEDURAL NOISE)
========================================================================= */
let audioCtx;
let noiseNode;
let gainNode;
let currentNoiseType = 'off';
/**
* Procedural noise generation (Brownian, Pink)
*/
function createNoiseBuffer(type) {
const bufferSize = audioCtx.sampleRate * 2; // 2 seconds of noise
const buffer = audioCtx.createBuffer(1, bufferSize, audioCtx.sampleRate);
const output = buffer.getChannelData(0);
if (type === 'brown') {
let lastOut = 0;
for (let i = 0; i < bufferSize; i++) {
let white = Math.random() * 2 - 1;
output[i] = (lastOut + (0.02 * white)) / 1.02;
lastOut = output[i];
output[i] *= 3.5; // Compensate for gain
}
} else if (type === 'pink') {
let b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0;
for (let i = 0; i < bufferSize; i++) {
let white = Math.random() * 2 - 1;
b0 = 0.99886 * b0 + white * 0.0555179;
b1 = 0.99332 * b1 + white * 0.0750759;
b2 = 0.96900 * b2 + white * 0.1538520;
b3 = 0.86650 * b3 + white * 0.3104856;
b4 = 0.55000 * b4 + white * 0.5329522;
b5 = -0.7616 * b5 - white * 0.0168980;
output[i] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
output[i] *= 0.11; // Compensate for gain
b6 = white * 0.115926;
}
}
return buffer;
}
function initAudio() {
if (!audioCtx) {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
gainNode = audioCtx.createGain();
const volInput = document.getElementById('bg-volume');
gainNode.gain.value = volInput ? Number(volInput.value) : 0.2;
gainNode.connect(audioCtx.destination);
}
if (audioCtx.state === 'suspended') {
audioCtx.resume();
}
}
function stopNoise() {
if (noiseNode) {
noiseNode.stop();
noiseNode.disconnect();
noiseNode = null;
}
}
function playNoise(type) {
stopNoise();
initAudio();
if (type === 'off') return;
noiseNode = audioCtx.createBufferSource();
noiseNode.buffer = createNoiseBuffer(type);
noiseNode.loop = true;
noiseNode.connect(gainNode);
noiseNode.start();
}
function setupAudioUI() {
const soundBtns = document.querySelectorAll('.bg-sound');
const volControl = document.getElementById('bg-volume');
soundBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Update UI
soundBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// Update audio
const soundType = btn.dataset.sound;
currentNoiseType = soundType;
playNoise(soundType);
});
});
if (volControl) {
volControl.addEventListener('input', (e) => {
if (gainNode) {
// Logarithmic volume scaling for smoother feel
const val = Number(e.target.value);
gainNode.gain.setTargetAtTime(val * val, audioCtx.currentTime, 0.05);
}
});
}
}
// Wire it up on app load
document.addEventListener('DOMContentLoaded', () => {
setupAudioUI();
});