mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-10-03 00:55:14 -07:00
fix(captures+chord): Stop button stops, ChordPicker accepts shorter chords
Two unrelated correctness bugs caught in PR review: - The Play As "Stop" button was wired to handlePlayAs() unconditionally, so clicking it during playback kicked a fresh generation instead of halting. Now pauses the player when the click came from the main button while playbackState is 'playing'. Picking a different voice from the dropdown still kicks a new generation as before. - ChordPicker tracked the peak set of held keys but seeded the peak from initialKeys, so a user who opened the picker with a 3-key chord saved couldn't replace it with a 2-key chord — the candidate length never beat the seed. The peak now resets on the first press of a fresh sequence (when no keys were held immediately prior), then grows monotonically within that hold.
This commit is contained in:
@@ -154,6 +154,8 @@ export function CapturesTab() {
|
|||||||
const playerIsPlaying = usePlayerStore((s) => s.isPlaying);
|
const playerIsPlaying = usePlayerStore((s) => s.isPlaying);
|
||||||
const isPlayerVisible = !!audioUrl;
|
const isPlayerVisible = !!audioUrl;
|
||||||
|
|
||||||
|
const setIsPlaying = usePlayerStore((s) => s.setIsPlaying);
|
||||||
|
|
||||||
const addPendingGeneration = useGenerationStore((s) => s.addPendingGeneration);
|
const addPendingGeneration = useGenerationStore((s) => s.addPendingGeneration);
|
||||||
const pendingGenerationIds = useGenerationStore((s) => s.pendingGenerationIds);
|
const pendingGenerationIds = useGenerationStore((s) => s.pendingGenerationIds);
|
||||||
|
|
||||||
@@ -410,6 +412,12 @@ export function CapturesTab() {
|
|||||||
|
|
||||||
const handlePlayAs = (voice?: VoiceProfileResponse) => {
|
const handlePlayAs = (voice?: VoiceProfileResponse) => {
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
|
// Stop the current playback when the button is in its 'playing' state
|
||||||
|
// and the user clicked the main button without picking a new voice.
|
||||||
|
if (!voice && playbackState === 'playing') {
|
||||||
|
setIsPlaying(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const target = voice ?? playAsVoice;
|
const target = voice ?? playAsVoice;
|
||||||
if (!target) {
|
if (!target) {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -95,11 +95,12 @@ export function ChordPicker({
|
|||||||
if (prev.has(canonical)) return prev;
|
if (prev.has(canonical)) return prev;
|
||||||
const next = new Set(prev);
|
const next = new Set(prev);
|
||||||
next.add(canonical);
|
next.add(canonical);
|
||||||
// Update peak whenever the live set grows. Comparing against
|
|
||||||
// the captured chord (which may be the previous saved value)
|
|
||||||
// would lose the user's first new keypress.
|
|
||||||
setCaptured((prevCaptured) => {
|
setCaptured((prevCaptured) => {
|
||||||
const candidate = sortChordKeys(Array.from(next));
|
const candidate = sortChordKeys(Array.from(next));
|
||||||
|
// First key in a fresh sequence replaces the peak — otherwise a
|
||||||
|
// user trying to swap a longer saved chord for a shorter one is
|
||||||
|
// stuck because their candidate never beats the seed length.
|
||||||
|
if (prev.size === 0) return candidate;
|
||||||
return candidate.length >= prevCaptured.length ? candidate : prevCaptured;
|
return candidate.length >= prevCaptured.length ? candidate : prevCaptured;
|
||||||
});
|
});
|
||||||
return next;
|
return next;
|
||||||
|
|||||||
Reference in New Issue
Block a user