Let each sound cue pick from 19 sounds in Preferences

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 12:53:53 -08:00
1 parent 459b840db9
commit 02380fa6fe
33 files changed
+402 -41

No files matched your search

+41 -9
View File
@@ -3684,15 +3684,47 @@
<legend>Sounds</legend>
<label><input type="checkbox" id="looks-sound" checked /> <span>Play sounds</span></label>
<div class="looks-row looks-sound-events" id="looks-sound-events">
<label><input type="checkbox" data-sound="snore" checked /> <span>Planny snoring</span></label>
<label><input type="checkbox" data-sound="bootup" checked /> <span>Planny waking up</span></label>
<label><input type="checkbox" data-sound="startSkill" checked /> <span>Starting a skill</span></label>
<label><input type="checkbox" data-sound="sessionStart" checked /> <span>Session opens</span></label>
<label><input type="checkbox" data-sound="skillReady" checked /> <span>Skill is ready</span></label>
<label><input type="checkbox" data-sound="sessionEnd" checked /> <span>Session ends</span></label>
<label><input type="checkbox" data-sound="question" checked /> <span>New questions for you</span></label>
<label><input type="checkbox" data-sound="chatReply" checked /> <span>Reply on the Ask tab</span></label>
<label><input type="checkbox" data-sound="newTab" checked /> <span>New tab added</span></label>
<div class="sound-plain">
<label><input type="checkbox" data-sound="snore" checked /> <span>Planny snoring</span></label>
<label><input type="checkbox" data-sound="bootup" checked /> <span>Planny waking up</span></label>
</div>
<div class="sound-rows">
<div class="sound-row">
<label><input type="checkbox" data-sound="startSkill" checked /> <span>Starting a skill</span></label>
<select data-sound-file="startSkill" aria-label="Starting a skill sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="startSkill" aria-label="Play Starting a skill sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="sessionStart" checked /> <span>Session opens</span></label>
<select data-sound-file="sessionStart" aria-label="Session opens sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="sessionStart" aria-label="Play Session opens sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="skillReady" checked /> <span>Skill is ready</span></label>
<select data-sound-file="skillReady" aria-label="Skill is ready sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="skillReady" aria-label="Play Skill is ready sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="sessionEnd" checked /> <span>Session ends</span></label>
<select data-sound-file="sessionEnd" aria-label="Session ends sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="sessionEnd" aria-label="Play Session ends sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="question" checked /> <span>New questions for you</span></label>
<select data-sound-file="question" aria-label="New questions for you sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="question" aria-label="Play New questions for you sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="chatReply" checked /> <span>Reply on the Ask tab</span></label>
<select data-sound-file="chatReply" aria-label="Reply on the Ask tab sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="chatReply" aria-label="Play Reply on the Ask tab sound">Play</button>
</div>
<div class="sound-row">
<label><input type="checkbox" data-sound="newTab" checked /> <span>New tab added</span></label>
<select data-sound-file="newTab" aria-label="New tab added sound"><option value="sound-01">sound-01</option><option value="sound-02">sound-02</option><option value="sound-03">sound-03</option><option value="sound-04">sound-04</option><option value="sound-05">sound-05</option><option value="sound-06">sound-06</option><option value="sound-07">sound-07</option><option value="sound-08">sound-08</option><option value="sound-09">sound-09</option><option value="sound-10">sound-10</option><option value="sound-11">sound-11</option><option value="sound-12">sound-12</option><option value="sound-13">sound-13</option><option value="sound-14">sound-14</option><option value="sound-15">sound-15</option><option value="sound-16">sound-16</option><option value="sound-17">sound-17</option><option value="sound-18">sound-18</option><option value="sound-19">sound-19</option></select>
<button type="button" class="btn ghost" data-sound-play="newTab" aria-label="Play New tab added sound">Play</button>
</div>
</div>
</div>
<p class="help">Ticking one plays it. Play sounds switches them all off at once and keeps your picks for when you switch back on.</p>
</fieldset>
+10 -1
View File
@@ -4,7 +4,7 @@
// `looks` is a live binding: every file reads the current object, and only
// this file replaces it.
import { DEFAULT_ACCENT, soundPrefs, DEFAULT_CARD_WIDTH, ACCENTS, accentId, cardWidth, soundKey } from "./palette.js";
import { DEFAULT_ACCENT, soundPrefs, soundFilePrefs, DEFAULT_CARD_WIDTH, ACCENTS, accentId, cardWidth, soundKey, soundFileKey } from "./palette.js";
import { normalizeRole, ROLE_NOT_SET } from "./starters.js";
import { bootData, hooks } from "./state.js";
import { el } from "./render.js";
@@ -29,6 +29,8 @@ export const DEFAULT_LOOKS = {
accent: DEFAULT_ACCENT,
sound: true,
...soundPrefs(null),
// Which sound file each pickable cue plays (soundFileQuestion: "sound-03").
...soundFilePrefs(null),
width: DEFAULT_CARD_WIDTH,
hideUnavailable: true,
// Always SKIP Intro: never play the dashboard's first-open wake-up (Planny asleep), off by default.
@@ -61,6 +63,7 @@ export function adoptLooks(saved) {
if (!["system", "light", "dark"].includes(looks.theme)) looks.theme = DEFAULT_LOOKS.theme;
if (typeof looks.sound !== "boolean") looks.sound = DEFAULT_LOOKS.sound;
Object.assign(looks, soundPrefs(looks));
Object.assign(looks, soundFilePrefs(looks));
if (typeof looks.hideUnavailable !== "boolean") looks.hideUnavailable = DEFAULT_LOOKS.hideUnavailable;
looks.width = cardWidth(looks.width);
if (typeof looks.skipIntro !== "boolean") looks.skipIntro = DEFAULT_LOOKS.skipIntro;
@@ -265,6 +268,12 @@ export function renderSwatches() {
box.checked = looks[soundKey(box.dataset.sound)];
box.disabled = !looks.sound;
}
// The pick per pickable cue; a select and a play button lock with the master switch.
for (const select of document.querySelectorAll("select[data-sound-file]")) {
select.value = looks[soundFileKey(select.dataset.soundFile)];
select.disabled = !looks.sound;
}
for (const button of document.querySelectorAll("button[data-sound-play]")) button.disabled = !looks.sound;
$("looks-role").value = looks.role ?? ROLE_NOT_SET;
$("looks-skip-intro").checked = looks.skipIntro;
$("looks-activities").checked = !looks.hideActivities;
+43 -8
View File
@@ -249,20 +249,40 @@ export function cardWidth(value) {
return typeof value === "string" && Object.hasOwn(CARD_WIDTHS, value) ? value : DEFAULT_CARD_WIDTH;
}
// The sound files a person can give a cue, sound-01 to sound-19, served from
// /sounds/<name>.mp3 (static.mjs).
export const SOUND_FILES = Array.from({ length: 19 }, (_, i) => `sound-${String(i + 1).padStart(2, "0")}`);
// The cues that take a picked file, in the order the picker lists them.
// Planny snoring and waking (snore, bootup) keep their own files.
export const PICKABLE_SOUNDS = ["startSkill", "sessionStart", "skillReady", "sessionEnd", "question", "chatReply", "newTab"];
// The file each pickable cue plays until a person picks another.
export const DEFAULT_SOUND_FILE = {
startSkill: "sound-01",
sessionStart: "sound-02",
sessionEnd: "sound-02",
question: "sound-03",
skillReady: "sound-03",
chatReply: "sound-03",
newTab: "sound-04",
};
// Every moment the page makes a noise, each switchable on its own in User
// Preferences (the `data-sound` boxes in index.html). Several share a file;
// the event, not the file, is what a person turns off. `rank` settles which
// wins when two ask at once (see the sounds section in app.js). Stored flat as
// `soundQuestion` and so on, because looks.json only holds flat values.
// `soundQuestion` and so on, because looks.json only holds flat values. For a
// pickable cue `file` is its default; the pick is `soundFile<Event>` in looks.
export const SOUND_EVENTS = {
startSkill: { file: "start-skill", rank: 5 },
startSkill: { file: `sounds/${DEFAULT_SOUND_FILE.startSkill}`, rank: 5 },
bootup: { file: "bootup", rank: 4 },
sessionStart: { file: "start-stop", rank: 3 },
sessionEnd: { file: "start-stop", rank: 3 },
question: { file: "next", rank: 2 },
skillReady: { file: "next", rank: 2 },
chatReply: { file: "next", rank: 2 },
newTab: { file: "insert", rank: 1 },
sessionStart: { file: `sounds/${DEFAULT_SOUND_FILE.sessionStart}`, rank: 3 },
sessionEnd: { file: `sounds/${DEFAULT_SOUND_FILE.sessionEnd}`, rank: 3 },
question: { file: `sounds/${DEFAULT_SOUND_FILE.question}`, rank: 2 },
skillReady: { file: `sounds/${DEFAULT_SOUND_FILE.skillReady}`, rank: 2 },
chatReply: { file: `sounds/${DEFAULT_SOUND_FILE.chatReply}`, rank: 2 },
newTab: { file: `sounds/${DEFAULT_SOUND_FILE.newTab}`, rank: 1 },
snore: { file: "sleeping", rank: 0 },
};
@@ -280,3 +300,18 @@ export function soundPrefs(saved) {
})
);
}
export const soundFileKey = (event) => "soundFile" + event[0].toUpperCase() + event.slice(1);
// The picked file per pickable cue out of a saved looks object: each one as
// saved when it names one of SOUND_FILES, the cue's default otherwise (a
// looks.json from before the picker, a removed file, a non-string).
export function soundFilePrefs(saved) {
const source = saved && typeof saved === "object" ? saved : {};
return Object.fromEntries(
PICKABLE_SOUNDS.map((event) => {
const value = source[soundFileKey(event)];
return [soundFileKey(event), typeof value === "string" && SOUND_FILES.includes(value) ? value : DEFAULT_SOUND_FILE[event]];
})
);
}
+2 -2
View File
@@ -4,7 +4,7 @@
// each. No DOM access at module scope, and its one import is the data-only
// palette.js: the page and `node --test` both import this file.
import { SOUND_EVENTS, soundKey } from "./palette.js";
import { SOUND_EVENTS, soundKey, PICKABLE_SOUNDS, soundFileKey } from "./palette.js";
const tab = (id, label, hint, sections) => Object.freeze({ id, label, hint, sections: Object.freeze(sections) });
@@ -26,6 +26,6 @@ export function prefsOpenTab(asked) {
// nothing to reset (and is hidden).
export function prefsResetScope(tab) {
if (tab === "appearance") return ["theme", "width", "accent", "role", "skipIntro"];
if (tab === "sounds") return ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), "hideActivities", "activitySounds", "gameMusic"];
if (tab === "sounds") return ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), ...PICKABLE_SOUNDS.map(soundFileKey), "hideActivities", "activitySounds", "gameMusic"];
return null;
}
+17 -2
View File
@@ -2,10 +2,10 @@
// Agents & models tab is agents-view.js's.
import { adoptLooks, applyLooks, loadLooks, looks, renderSwatches, saveLooks, syncLooks } from "../looks.js";
import { dropHeldSound, releaseHeldSound, sound, soundOn } from "../sound.js";
import { dropHeldSound, previewSound, releaseHeldSound, sound, soundOn } from "../sound.js";
import { hushTones, tone, unlockTones } from "../tones.js";
import { hushMusic } from "../music.js";
import { SOUND_EVENTS, soundKey } from "../palette.js";
import { SOUND_EVENTS, soundFileKey, soundKey } from "../palette.js";
import { ROLES, ROLE_NOT_SET, ROLE_NOT_SET_LABEL, needsRoleNudge, normalizeRole } from "../starters.js";
import { isDashboard } from "../selectors.js";
import { el } from "../render.js";
@@ -118,6 +118,21 @@ export function wireLooks() {
});
}
// The sound picked for a cue: a change saves it and plays it once, and the
// play button replays the current pick. Neither depends on the cue's own tick.
for (const select of document.querySelectorAll("select[data-sound-file]")) {
select.addEventListener("change", () => {
looks[soundFileKey(select.dataset.soundFile)] = select.value;
hooks.markSaved(fieldsetOf(select), saveLooks());
previewSound(select.value);
});
}
for (const button of document.querySelectorAll("button[data-sound-play]")) {
button.addEventListener("click", () => {
previewSound(looks[soundFileKey(button.dataset.soundPlay)]);
});
}
// Desktop app: the taskbar switch, kept by the app in its own app.json. The
// app says what it holds once the page is up; checked until it does.
if (framed()) {
+31 -4
View File
@@ -1,7 +1,7 @@
// Plan2Code Web Console - the sound cues: which plays, one at a time, held until the first click; defines only.
import { looks } from "./looks.js";
import { soundKey, SOUND_EVENTS } from "./palette.js";
import { soundKey, SOUND_EVENTS, PICKABLE_SOUNDS, soundFileKey } from "./palette.js";
/* ------------------------------------------------------------- sounds
@@ -34,7 +34,17 @@ let soundPlaying = null;
export const soundOn = (event) => looks.sound && looks[soundKey(event)];
const soundAudio = (event) => SOUNDS[SOUND_EVENTS[event].file];
// The file (path under the page's root, no extension) a cue plays: the pick
// for a pickable cue, the event's own file otherwise.
const soundPath = (event) =>
PICKABLE_SOUNDS.includes(event) && looks[soundFileKey(event)] ? `sounds/${looks[soundFileKey(event)]}` : SOUND_EVENTS[event].file;
const audioFor = (path) => (SOUNDS[path] ||= new Audio(`/${path}.mp3`));
// The Audio a cue last played, so a pick changed mid-sound still stops the right one.
const soundAudio = (event) => SOUNDS[playingPath[event] || soundPath(event)];
const playingPath = {};
const louderSound = (a, b) => (!b || SOUND_EVENTS[a].rank > SOUND_EVENTS[b].rank ? a : b);
@@ -51,8 +61,11 @@ function flushSound() {
const busy = soundPlaying && !soundAudio(soundPlaying).paused;
if (busy && SOUND_EVENTS[event].rank <= SOUND_EVENTS[soundPlaying].rank) return;
if (busy) soundAudio(soundPlaying).pause();
const { file } = SOUND_EVENTS[event];
const a = (SOUNDS[file] ||= new Audio(`/${file}.mp3`));
const path = soundPath(event);
playingPath[event] = path;
const a = audioFor(path);
// Stops a preview, or any cue the rank check let through, before this one starts.
for (const other of Object.values(SOUNDS)) if (other !== a) other.pause();
a.currentTime = 0;
soundPlaying = event;
a.play().catch(() => {
@@ -61,6 +74,20 @@ function flushSound() {
});
}
// Plays one picked file (sound-07) from the start for the picker's preview,
// cutting off whatever is playing. Dropped while a higher-ranked cue is
// playing, on the same busy check as flushSound. A preview is always a click
// or change, so the browser lets it play.
export function previewSound(file) {
const busy = soundPlaying && !soundAudio(soundPlaying).paused;
if (busy && SOUND_EVENTS[soundPlaying].rank > 0) return;
const a = audioFor(`sounds/${file}`);
for (const other of Object.values(SOUNDS)) if (other !== a) other.pause();
a.currentTime = 0;
soundPlaying = null;
a.play().catch(() => {});
}
// Fades a cue out over `ms` and stops it, so a long one never outlasts the
// moment it belongs to. Timers, not frames: a background tab still finishes.
export function fadeSound(event, ms) {
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+40 -2
View File
@@ -799,10 +799,48 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
.looks-desktop[hidden] { display: none; }
/* The per-cue boxes sit under the master switch, grayed and locked while it
is off rather than hidden, so the picks stay visible. */
.looks-sound-events { display: grid; gap: 8px; }
.looks-sound-events { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.looks-sound-events.is-off { opacity: 0.45; }
.looks-sound-events.is-off label { cursor: default; }
.looks-sound-events.is-off label:hover { border-color: var(--rule-2); }
.looks-sound-events.is-off label:hover,
.looks-sound-events.is-off .sound-row:hover { border-color: var(--rule-2); }
.looks-sound-events.is-off select,
.looks-sound-events.is-off .sound-row .btn { cursor: default; }
/* Planny's snoring and waking keep plain boxes in a row of their own; the
seven pickable cues are a list, each a label with its sound and a play
button on the right, stacked on a narrow window. */
.sound-plain { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sound-rows { display: grid; gap: 8px; }
.sound-row {
display: flex;
align-items: center;
gap: 10px;
border: 1px solid var(--rule-2);
border-radius: 8px;
padding: 6px 8px 6px 0;
background: var(--panel);
}
.sound-row:hover { border-color: var(--accent-line); }
.modal-ranges .sound-row label { flex: 1 1 auto; border: 0; border-radius: 0; background: none; padding: 4px 13px; }
.sound-row select {
flex: none;
font: inherit;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--rule-2);
border-radius: 8px;
padding: 6px 8px;
}
.sound-row select:focus-visible,
.sound-row .btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sound-row select:disabled,
.sound-row .btn:disabled { opacity: 1; cursor: default; }
@media (max-width: 720px) {
.sound-plain { grid-template-columns: 1fr; }
.sound-row { flex-wrap: wrap; padding: 6px 8px; }
.modal-ranges .sound-row label { flex: 1 1 100%; padding: 4px 5px; }
.sound-row select { flex: 1 1 auto; min-width: 0; }
}
@media (max-width: 720px) {
.looks-row, .looks-row.four { grid-template-columns: 1fr; }
}