Skip to content

the ultimate vocal synthesizer - sing, speak, beatbox, and more

Rust

Tabs: Play's Whisper and Beatbox's ready pose stay in their tab (they leaked into the others)

Jameson Hodgeb133d5170582
diff --git a/src/ui/store.ts b/src/ui/store.ts
index a982a0a..29ac889 100644
--- a/src/ui/store.ts
+++ b/src/ui/store.ts
@@ -115,6 +115,14 @@ let pressSerial = 0;
const pressOf = new Map<number, number>();
let session = 0;
+/**
+ * Per-tab voice settings, kept out of the other tabs. Play's Whisper is the one switch for
+ * voicing, and no other tab shows it: left on, Speak and Sing went voiceless with no way to tell
+ * why. Beatbox closes the jaw and lips to its ready pose, and the pose stayed after leaving.
+ */
+let whisperInPlay = false;
+let poseBeforeBeat: { artic: HumanArtic; tipFree: boolean } | null = null;
+
const FIRST_BEAT = BEAT_PRESETS[0];
export const useStore = create<State>((set, get) => ({
@@ -139,6 +147,14 @@ export const useStore = create<State>((set, get) => ({
session++;
// notes held across the switch would keep breathing into the other voice
set({ mode: m, heldNotes: [] });
+ if (prev === "play" && !get().source.voiced) {
+ whisperInPlay = true;
+ get().setSource({ voiced: true });
+ }
+ if (m === "play" && whisperInPlay) {
+ whisperInPlay = false;
+ get().setSource({ voiced: false });
+ }
// speech belongs to Speak: under a creature the human clock stops and it would resume later
if (prev === "speak" || m === "bestiary") stopSpeaking();
if ((prev === "bestiary") !== (m === "bestiary")) {
@@ -150,6 +166,8 @@ export const useStore = create<State>((set, get) => ({
if (prev === "beatbox") {
get().setBeatPlaying(false);
engine.setMic(false);
+ if (poseBeforeBeat) get().setArtic(poseBeforeBeat.artic, poseBeforeBeat.tipFree);
+ poseBeforeBeat = null;
}
if (prev === "sing") stopSinging();
// speech and song breathe by themselves: a held breath would drone under them
@@ -158,6 +176,7 @@ export const useStore = create<State>((set, get) => ({
if (m === "beatbox") {
// a beatboxer waits with the jaw nearly closed; the sounds bring their own breath
set({ hold: false });
+ poseBeforeBeat = { artic: get().artic, tipFree: get().tipFree };
get().setArtic(beatReady(get().body));
engine.setMic(get().mic);
}
diff --git a/tests/singing-live.test.ts b/tests/singing-live.test.ts
index 9ada67d..d3fe557 100644
--- a/tests/singing-live.test.ts
+++ b/tests/singing-live.test.ts
@@ -2,7 +2,8 @@
* Sing mode's live path end to end, without a browser: the key handling in src/ui/singing.ts
* talks to a stand-in for the audio engine that does what the worklet does with each message
* (schedule at clock + lead, release by tag, cancel), on the real engine (the wasm build, in its
- * own instance as in the worklet).
+ * own instance as in the worklet). The store's tab switches are tested here too, against the
+ * same stand-in: a second file mocking the engine module would replace this one's mid-run.
*/
import { describe, expect, mock, test } from "bun:test";
import { initEngine, WasmVoice } from "./harness.ts";
@@ -268,3 +269,78 @@ describe("keys pressed before the audio has started", () => {
engineStub.scheduleGestures = sg;
});
});
+
+describe("settings that belong to one tab stay in it", () => {
+ const sent: { source: Record<string, unknown>[]; artic: Record<string, unknown>[] } = { source: [], artic: [] };
+ const recording = async () => {
+ const { useStore } = await import("../src/ui/store.ts");
+ const { beatReady } = await import("../src/wasm/engine.ts");
+ engineStub.setSource = (v: Record<string, unknown>) => void sent.source.push(v);
+ engineStub.setArtic = (v: Record<string, unknown>) => void sent.artic.push(v);
+ useStore.setState({ mode: "play", started: true, body: MALE });
+ useStore.getState().setSource({ voiced: true });
+ sent.source.length = sent.artic.length = 0;
+ return { st: useStore.getState, beatReady };
+ };
+ const done = () => {
+ delete engineStub.setSource;
+ delete engineStub.setArtic;
+ };
+
+ test("Play's Whisper doesn't make Speak or Sing voiceless, and Play whispers again on return", async () => {
+ const { st } = await recording();
+ st().setSource({ voiced: false });
+ st().setMode("speak");
+ expect(st().source.voiced).toBe(true);
+ expect(sent.source.at(-1)).toEqual({ voiced: true });
+ st().setMode("sing");
+ expect(st().source.voiced).toBe(true);
+ st().setMode("play");
+ expect(st().source.voiced).toBe(false);
+ expect(sent.source.at(-1)).toEqual({ voiced: false });
+ done();
+ });
+
+ test("Whisper is kept through Bestiary and Beatbox too, and left alone when off", async () => {
+ const { st } = await recording();
+ st().setSource({ voiced: false });
+ st().setMode("bestiary");
+ st().setMode("beatbox");
+ expect(st().source.voiced).toBe(true);
+ st().setMode("play");
+ expect(st().source.voiced).toBe(false);
+ st().setSource({ voiced: true });
+ sent.source.length = 0;
+ st().setMode("speak");
+ st().setMode("play");
+ expect(st().source.voiced).toBe(true);
+ expect(sent.source.filter((v) => "voiced" in v)).toEqual([]);
+ done();
+ });
+
+ test("leaving Beatbox puts back the pose from before it", async () => {
+ const { st, beatReady } = await recording();
+ st().setArtic({ jaw: 0.9, lipAp: 1.2, lipProt: 0.3 }, false);
+ const before = { ...st().artic };
+ st().setMode("beatbox");
+ const ready = beatReady(MALE);
+ expect(st().artic.jaw).toBeCloseTo(ready.jaw!, 6);
+ expect(st().artic.lipAp).toBeCloseTo(ready.lipAp!, 6);
+ st().setMode("play");
+ expect(st().artic).toEqual(before);
+ expect(st().tipFree).toBe(false);
+ expect(sent.artic.at(-1)).toEqual(before);
+ done();
+ });
+
+ test("a pose dragged inside Beatbox doesn't follow the player out either", async () => {
+ const { st } = await recording();
+ st().setArtic({ jaw: 0.7, lipAp: 0.8 }, true);
+ const before = { ...st().artic };
+ st().setMode("beatbox");
+ st().setArtic({ jaw: 0.2, tbY: 2 });
+ st().setMode("speak");
+ expect(st().artic).toEqual(before);
+ done();
+ });
+});