-
Notifications
You must be signed in to change notification settings - Fork 1
feat(workspace): tap a session tempo when the song has none #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
16
commits into
develop
Choose a base branch
from
feat/workspace-tap-tempo
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ac1a020
feat(workspace): tap a session tempo when the song has none
seonghobae d487673
test(tap-tempo): reproduce cross-song session carryover
seonghobae bb862e6
fix(tap-tempo): scope session taps to song identity
seonghobae d6ad784
test(workspace): preserve tapped tempo across chord edits
seonghobae 10af39e
fix(workspace): keep tapped tempo across song edits
seonghobae 39c1b53
test(workspace): align stored tempo authority with contract
seonghobae c03c87d
fix(workspace): honor stored tempo contract consistently
seonghobae 7dc56fd
test(workspace): bind tap sessions to loaded song instances
seonghobae 571698b
fix(workspace): key tap tempo by loaded song instance
seonghobae f475cc9
fix(workspace): preserve taps only across owned edits
seonghobae 31d8541
fix(workspace): avoid tap tempo module case collision
seonghobae a213f6f
docs(workspace): align tap tempo authority
seonghobae abe1444
fix(workspace): remove unsupported tap tempo heuristics
seonghobae b8cbfe0
fix(workspace): ground tap tempo bounds in research
seonghobae 3e9dc17
test(workspace): cover tap tempo panel
seonghobae 759d571
docs(workspace): align tap tempo range
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createTranslator } from "../../i18n"; | ||
| import { TapTempo } from "./TapTempoPanel"; | ||
|
|
||
| const t = createTranslator("en"); | ||
|
|
||
| describe("TapTempo", () => { | ||
| it("names the tap next action and unlocks a 120 BPM count-in after four steady taps", () => { | ||
| let now = 10_000; | ||
| render(<TapTempo t={t} nowMs={() => now} />); | ||
|
|
||
| const region = screen.getByTestId("tap-tempo"); | ||
| expect(region).toHaveTextContent("Tonight's tap tempo"); | ||
| expect(region).toHaveTextContent( | ||
| "Tonight's first count-in still needs a tempo. Tap a steady groove at least four times, then count in at that tempo and check the first range." | ||
| ); | ||
|
|
||
| const tap = screen.getByRole("button", { name: /tap the groove to set tonight's tempo/i }); | ||
| fireEvent.click(tap); | ||
| now += 500; | ||
| fireEvent.click(tap); | ||
| expect(region).toHaveTextContent("Keep tapping a steady groove"); | ||
| now += 500; | ||
| fireEvent.click(tap); | ||
| now += 500; | ||
| fireEvent.click(tap); | ||
|
|
||
| expect(region).toHaveTextContent("120 BPM from 4 taps. Count in 4 at 120 BPM, then check tonight's first range."); | ||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-amber-300"); | ||
| expect(screen.getByTestId("tap-lamp-3").className).toContain("bg-amber-300"); | ||
| }); | ||
|
|
||
| it("resets the session taps without writing a song tempo", () => { | ||
| let now = 1_000; | ||
| render(<TapTempo t={t} nowMs={() => now} />); | ||
| const tap = screen.getByRole("button", { name: /tap the groove to set tonight's tempo/i }); | ||
| fireEvent.click(tap); | ||
| now += 500; | ||
| fireEvent.click(tap); | ||
| fireEvent.click(screen.getByRole("button", { name: /reset tonight's tap tempo/i })); | ||
| expect(screen.getByTestId("tap-tempo")).toHaveTextContent( | ||
| "Tonight's first count-in still needs a tempo. Tap a steady groove at least four times, then count in at that tempo and check the first range." | ||
| ); | ||
| expect(screen.getByRole("button", { name: /reset tonight's tap tempo/i })).toBeDisabled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { useMemo, useState } from "react"; | ||
| import { CircleDot } from "lucide-react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { createTranslator } from "../../i18n"; | ||
| import { | ||
| emptyTapTempo, | ||
| fillTapCopy, | ||
| MIN_TAP_COUNT, | ||
| recordTap, | ||
| tapTempoReading, | ||
| type TapTempoState | ||
| } from "./tapTempo"; | ||
|
|
||
| type Translator = ReturnType<typeof createTranslator>; | ||
|
|
||
| interface TapTempoProps { | ||
| t: Translator; | ||
| nowMs?: () => number; | ||
| } | ||
|
|
||
| /** | ||
| * Measure tonight's count-in tempo from the player's taps when the song | ||
| * has no trusted BPM. Session-only; this does not write `song.tempo`. | ||
| */ | ||
| export function TapTempo({ t, nowMs }: TapTempoProps) { | ||
| const [state, setState] = useState<TapTempoState>(emptyTapTempo); | ||
| const reading = useMemo(() => tapTempoReading(state), [state]); | ||
| const clock = nowMs ?? Date.now; | ||
|
|
||
| const guidance = reading | ||
| ? fillTapCopy(t("workspaceTapTempoReady"), { | ||
| tempo: String(reading.tempoBpm), | ||
| taps: String(reading.tapCount) | ||
| }) | ||
| : state.tapsMs.length > 0 | ||
| ? t("workspaceTapTempoKeep") | ||
| : t("workspaceTapTempoNeed"); | ||
|
|
||
| const filledLamps = Math.min(state.tapsMs.length, MIN_TAP_COUNT); | ||
|
|
||
| return ( | ||
| <section | ||
| className="rounded-2xl border border-amber-300/20 bg-amber-300/[0.07] p-4" | ||
| data-testid="tap-tempo" | ||
| aria-label={t("workspaceTapTempoTitle")} | ||
| > | ||
| <p className="text-xs font-black uppercase tracking-[0.24em] text-amber-200">{t("workspaceTapTempoTitle")}</p> | ||
| <p className="mt-2 text-sm leading-6 text-slate-100">{guidance}</p> | ||
| <div className="mt-3 flex gap-2" aria-hidden="true"> | ||
| {Array.from({ length: MIN_TAP_COUNT }, (_, index) => ( | ||
| <span | ||
| key={index} | ||
| data-testid={`tap-lamp-${index}`} | ||
| className={ | ||
| "size-3 rounded-full " + | ||
| (index < filledLamps ? "bg-amber-300" : "bg-white/15") | ||
| } | ||
| /> | ||
| ))} | ||
| </div> | ||
| <div className="mt-3 flex flex-wrap gap-2"> | ||
| <Button | ||
| type="button" | ||
| onClick={() => { | ||
| setState((current) => recordTap(current, clock())); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }} | ||
| aria-label={t("workspaceTapTempoActionLabel")} | ||
| className="min-h-11 border-amber-300/30 bg-amber-300/15 font-semibold text-amber-50 hover:bg-amber-300/25 hover:text-white" | ||
| > | ||
| <CircleDot className="mr-2 size-4 text-amber-200" aria-hidden="true" /> | ||
| {t("workspaceTapTempoAction")} | ||
| </Button> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={() => { | ||
| setState(emptyTapTempo()); | ||
| }} | ||
| disabled={state.tapsMs.length === 0} | ||
| aria-label={t("workspaceTapTempoResetLabel")} | ||
| className="min-h-11 border-white/10 bg-white/5 font-semibold text-slate-100" | ||
| > | ||
| {t("workspaceTapTempoReset")} | ||
| </Button> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
70 changes: 70 additions & 0 deletions
70
apps/desktop/src/features/workspace/Workspace.tap-tempo-session.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; | ||
| import { useState } from "react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { Workspace } from "./Workspace"; | ||
|
|
||
| function EditableWorkspace({ initialSong }: { initialSong: RehearsalSong }) { | ||
| const [song, setSong] = useState(initialSong); | ||
| return <Workspace song={song} onSongUpdate={setSong} />; | ||
| } | ||
|
|
||
| describe("Workspace tap-tempo session ownership", () => { | ||
| it("resets session taps when a different tempo-less song replaces a same-id analysis result", () => { | ||
| const firstSong = createDemoRehearsalSong(); | ||
| firstSong.tempo = undefined; | ||
| firstSong.title = "First room song"; | ||
|
|
||
| const nextSong = createDemoRehearsalSong(); | ||
| nextSong.tempo = undefined; | ||
| nextSong.title = "Second room song"; | ||
| expect(nextSong.id).toBe(firstSong.id); | ||
|
|
||
| const { rerender } = render(<Workspace song={firstSong} />); | ||
| fireEvent.click(screen.getByRole("button", { name: /tap the groove to set tonight's tempo/i })); | ||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-amber-300"); | ||
|
|
||
| rerender(<Workspace song={nextSong} />); | ||
|
|
||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-white/15"); | ||
| expect(screen.getByRole("button", { name: /reset tonight's tap tempo/i })).toBeDisabled(); | ||
| }); | ||
|
|
||
| it("resets session taps when a distinct loaded song collides on projected identity", () => { | ||
| const firstSong = createDemoRehearsalSong(); | ||
| firstSong.tempo = undefined; | ||
| const nextSong = structuredClone(firstSong); | ||
| nextSong.sections[0]!.roles[0]!.harmony.chord = `${nextSong.sections[0]!.roles[0]!.harmony.chord}sus4`; | ||
|
|
||
| expect(nextSong.id).toBe(firstSong.id); | ||
| expect(nextSong.title).toBe(firstSong.title); | ||
| expect(nextSong.sections.map(({ id, timeRange }) => ({ id, timeRange }))).toEqual( | ||
| firstSong.sections.map(({ id, timeRange }) => ({ id, timeRange })) | ||
| ); | ||
|
|
||
| const { rerender } = render(<Workspace song={firstSong} />); | ||
| fireEvent.click(screen.getByRole("button", { name: /tap the groove to set tonight's tempo/i })); | ||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-amber-300"); | ||
|
|
||
| rerender(<Workspace song={nextSong} />); | ||
|
|
||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-white/15"); | ||
| expect(screen.getByRole("button", { name: /reset tonight's tap tempo/i })).toBeDisabled(); | ||
| }); | ||
|
|
||
| it("preserves session taps when the supported chord editor updates the current song", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| song.tempo = undefined; | ||
| const prompt = vi.spyOn(window, "prompt").mockReturnValue("Dm7"); | ||
|
|
||
| render(<EditableWorkspace initialSong={song} />); | ||
| fireEvent.click(screen.getByRole("button", { name: /tap the groove to set tonight's tempo/i })); | ||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-amber-300"); | ||
|
|
||
| fireEvent.click(screen.getAllByRole("button", { name: /edit chord for/i })[0]!); | ||
|
|
||
| expect(prompt).toHaveBeenCalled(); | ||
| expect(screen.getByTestId("tap-lamp-0").className).toContain("bg-amber-300"); | ||
| prompt.mockRestore(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.