diff --git a/brain.js b/brain.js index 7e48693..0c42e97 100644 --- a/brain.js +++ b/brain.js @@ -124,19 +124,17 @@ function tasteText() { (likes ? ` Words it warms to: ${likes}.` : "") + (dislikes ? ` Words it cools on: ${dislikes}.` : "") + ` Aim near the likely region and lean on the warm words unless the listener's own words say otherwise; keep some variety.`; } -const _djPromptBase = djPrompt; // assignment, not a declaration: a declaration would hoist over this -djPrompt = function () { - const base = _djPromptBase(); +/* the page's hooks (index.html › hooks): the taste text rides into the DJ's prompt, and a station opening retrains */ +hooks.djPrompt = (base) => { const tt = tasteText(); return tt ? base.replace("\nWrite the NEXT track.", `\n${tt}\n\nWrite the NEXT track.`) : base; }; -const _openStation = openStation; -openStation = async function (seed, s) { await _openStation(seed, s); rebuildBrains().catch(() => {}); }; +hooks.stationOpened = () => { rebuildBrains().catch(() => {}); }; /* ---------- plays: every start counts, and so does every pass of the loop ---------- */ async function countPlay(spec) { if (!spec || !spec.id) return; - const row = (await db.all()).find((t) => t.id === spec.id); if (!row) return; + const row = await db.get(spec.id); if (!row) return; row.plays = (row.plays || 0) + 1; row.spec.plays = row.plays; spec.plays = row.plays; await db.put(row); if (row.plays === 2 || row.plays === 4 || row.plays % 8 === 0) rebuildBrains().catch(() => {}); @@ -150,11 +148,7 @@ state.audio.addEventListener("timeupdate", () => { // a loop wra }); /* ---------- the NEXT line carries the net's guess for the track in the oven ---------- */ -const _makeJob = makeJob; -makeJob = function (spec) { - const net = brainNow(); if (net) spec.guess = net.predict(spec); - return _makeJob(spec); -}; +hooks.jobMade = (spec) => { const net = brainNow(); if (net) spec.guess = net.predict(spec); }; const guessText = (spec) => spec && spec.guess != null ? ` · ${Math.round(spec.guess * 100)}% YOU` : ""; (function () { const next = $("#next"); @@ -283,9 +277,7 @@ async function openTaste() { openTaste.redraw = show; } /* a reaction while TASTE is open: retrain, and let the neurons flare */ -const _react = react; -react = async function (emoji, text) { - await _react(emoji, text); +hooks.reacted = () => { rebuildBrains().then(() => { if ($("#taste").classList.contains("hidden") || !openTaste.redraw) return; let t0 = performance.now();