mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix(review): show duet singer chips in Waveforms view (v0.276.3) (#1171)
## Summary In duet mode, the Simple/Advanced lyrics views show a per-line singer chip (● 1 / ● 2 / Both) to see and toggle which singer each line belongs to. The Waveforms view was missing it, because `WaveformSegmentRow` never got the duet props. ## Changes - `WaveformSegmentRow`: new optional `singer` / `hasSingerOverrides` / `onSingerChange` props render the same `SingerChip` after the index/trash/play controls, plus `onFocus`/`onBlur`/`className` props. - `TranscriptionView`: in duet mode, passes the singer, the singer row tint and focus tracking to each waveform row, so the singer keyboard shortcuts work there too. Moved the tint logic into a shared `singerTintClass` helper. ## Testing - New `TranscriptionView.waveformsDuet.test.tsx`: chips render per line in duet mode, clicking cycles the singer, and no chips appear when duet mode is off. - `WaveformSegmentRow.test.tsx`: chip renders and cycles; focus and blur get reported. - Full frontend jest: 141 suites / 1735 tests pass. - Local CodeRabbit review: no findings. @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015cvzKpvvadUsJGZFMv9DXy Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d4c9c4e6e
commit
8a16e33a34
4 files changed
+142
-7
No files matched your search
@@ -26,6 +26,13 @@ import { useAudioReady } from '@/lib/lyrics-review/hooks/useAudioReady'
|
||||
import type { SingerId } from '@/lib/lyrics-review/types'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
// Duet row tint: a faint gradient in the singer's colour (1 = blue, 2 = pink, both = yellow).
|
||||
function singerTintClass(singer: SingerId): string {
|
||||
if (singer === 1) return 'bg-gradient-to-r from-blue-500/10 to-transparent'
|
||||
if (singer === 2) return 'bg-gradient-to-r from-pink-500/10 to-transparent'
|
||||
return 'bg-gradient-to-r from-yellow-500/10 to-transparent'
|
||||
}
|
||||
|
||||
export default function TranscriptionView({
|
||||
data,
|
||||
onElementClick,
|
||||
@@ -254,6 +261,16 @@ export default function TranscriptionView({
|
||||
? (wordId) => onWordClick({ word_id: wordId, type: 'other' })
|
||||
: undefined
|
||||
}
|
||||
{...(isDuet && {
|
||||
singer: resolveSegmentSinger(segment),
|
||||
hasSingerOverrides: hasWordOverrides(segment),
|
||||
onSingerChange: onSegmentSingerChange
|
||||
? (next: SingerId) => onSegmentSingerChange(segmentIndex, next)
|
||||
: undefined,
|
||||
onFocus: onSegmentFocus ? () => onSegmentFocus(segmentIndex) : undefined,
|
||||
onBlur: onSegmentFocus ? () => onSegmentFocus(null) : undefined,
|
||||
className: singerTintClass(resolveSegmentSinger(segment)),
|
||||
})}
|
||||
/>
|
||||
</Fragment>
|
||||
))}
|
||||
@@ -307,11 +324,7 @@ export default function TranscriptionView({
|
||||
)
|
||||
|
||||
const segmentSinger: SingerId = resolveSegmentSinger(segment)
|
||||
const rowTintClass = isDuet
|
||||
? segmentSinger === 1 ? 'bg-gradient-to-r from-blue-500/10 to-transparent' :
|
||||
segmentSinger === 2 ? 'bg-gradient-to-r from-pink-500/10 to-transparent' :
|
||||
'bg-gradient-to-r from-yellow-500/10 to-transparent'
|
||||
: ''
|
||||
const rowTintClass = isDuet ? singerTintClass(segmentSinger) : ''
|
||||
|
||||
return (
|
||||
<Fragment key={segment.id}>
|
||||
|
||||
@@ -9,6 +9,9 @@ import TimelineEditor from './TimelineEditor'
|
||||
import { recomputeSegmentFromWords } from '@/lib/lyrics-review/utils/segmentTiming'
|
||||
import { WordDecoration } from '@/lib/lyrics-review/utils/wordDecorations'
|
||||
import { useAudioReady } from '@/lib/lyrics-review/hooks/useAudioReady'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { SingerId } from '@/lib/lyrics-review/types'
|
||||
import SingerChip from './SingerChip'
|
||||
|
||||
interface WaveformSegmentRowProps {
|
||||
segment: LyricsSegment
|
||||
@@ -30,6 +33,15 @@ interface WaveformSegmentRowProps {
|
||||
onDeleteSegment: (segmentIndex: number) => void
|
||||
/** Set while Ctrl/Cmd is held (delete-word mode): pressing a word deletes it. */
|
||||
onDeleteWord?: (wordId: string) => void
|
||||
/** Duet mode: the line's singer chip (same control as the Simple/Advanced views). */
|
||||
singer?: SingerId
|
||||
hasSingerOverrides?: boolean
|
||||
onSingerChange?: (next: SingerId) => void
|
||||
/** Duet mode: focus tracking so the singer keyboard shortcuts target this line. */
|
||||
onFocus?: () => void
|
||||
onBlur?: () => void
|
||||
/** Extra row classes (e.g. the duet singer tint). */
|
||||
className?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +67,12 @@ export default function WaveformSegmentRow({
|
||||
onEditSegment,
|
||||
onDeleteSegment,
|
||||
onDeleteWord,
|
||||
singer,
|
||||
hasSingerOverrides = false,
|
||||
onSingerChange,
|
||||
onFocus,
|
||||
onBlur,
|
||||
className,
|
||||
}: WaveformSegmentRowProps) {
|
||||
const t = useTranslations('lyricsReview.transcription')
|
||||
const tHeader = useTranslations('lyricsReview.header')
|
||||
@@ -90,8 +108,12 @@ export default function WaveformSegmentRow({
|
||||
const hasTimedWords = words.some((w) => w.start_time !== null && w.end_time !== null)
|
||||
|
||||
return (
|
||||
<div className="flex items-start w-full gap-1">
|
||||
{/* Left controls: index (opens modal), play, edit */}
|
||||
<div
|
||||
tabIndex={onFocus ? 0 : undefined}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
className={cn('flex items-start w-full gap-1', className)}
|
||||
>
|
||||
{/* Left controls match the Advanced view: index, delete, play. */}
|
||||
<div className="flex items-center gap-0.5 pr-1 h-[20px]" style={{ minWidth: '2.5em' }}>
|
||||
<span
|
||||
@@ -124,6 +146,16 @@ export default function WaveformSegmentRow({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Singer chip (duet mode only) */}
|
||||
{singer !== undefined && onSingerChange && (
|
||||
<SingerChip
|
||||
singer={singer}
|
||||
hasOverrides={hasSingerOverrides}
|
||||
onChange={onSingerChange}
|
||||
className="mr-1 flex-shrink-0"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Inline timeline (waveform + resizable word bars), ruler hidden for compactness */}
|
||||
<div className="flex-1 min-w-0">
|
||||
{hasTimedWords ? (
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import TranscriptionView from '../TranscriptionView'
|
||||
import { VocalsAudioDataLoaderContext } from '../VocalsAudioDataLoader'
|
||||
import type { CorrectionData } from '@/lib/lyrics-review/types'
|
||||
|
||||
const data = {
|
||||
corrected_segments: [
|
||||
{ id: 's1', text: 'one', start_time: 0, end_time: 2, words: [{ id: 'w1', text: 'one', start_time: 0, end_time: 2 }] },
|
||||
{ id: 's2', text: 'two', start_time: 3, end_time: 5, singer: 2, words: [{ id: 'w2', text: 'two', start_time: 3, end_time: 5 }] },
|
||||
],
|
||||
original_segments: [],
|
||||
reference_lyrics: {},
|
||||
anchor_sequences: [],
|
||||
gap_sequences: [],
|
||||
corrections: [],
|
||||
} as unknown as CorrectionData
|
||||
|
||||
const renderView = (isDuet: boolean, onSegmentSingerChange = jest.fn()) =>
|
||||
render(
|
||||
<VocalsAudioDataLoaderContext.Provider value={{ audioData: null, status: 'ready' }}>
|
||||
<TranscriptionView
|
||||
data={data}
|
||||
onElementClick={jest.fn()}
|
||||
flashingType={null}
|
||||
highlightInfo={null}
|
||||
mode="edit"
|
||||
viewMode="waveforms"
|
||||
isDuet={isDuet}
|
||||
onSegmentSingerChange={onSegmentSingerChange}
|
||||
/>
|
||||
</VocalsAudioDataLoaderContext.Provider>
|
||||
)
|
||||
|
||||
describe('TranscriptionView Waveforms mode in duet', () => {
|
||||
it('shows a singer chip per line and changes the singer on click', async () => {
|
||||
const onSegmentSingerChange = jest.fn()
|
||||
renderView(true, onSegmentSingerChange)
|
||||
const chips = screen.getAllByText('●').map((dot) => dot.closest('button')!)
|
||||
expect(chips.map((c) => c.textContent)).toEqual(['●1', '●2'])
|
||||
const chip2 = chips[1]
|
||||
await userEvent.click(chip2)
|
||||
expect(onSegmentSingerChange).toHaveBeenCalledWith(1, 0)
|
||||
})
|
||||
|
||||
it('shows no singer chips when duet mode is off', () => {
|
||||
renderView(false)
|
||||
expect(screen.queryByText('●')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -89,3 +89,43 @@ describe('WaveformSegmentRow Ctrl-click delete', () => {
|
||||
expect(props.onEditSegment).toHaveBeenCalledWith(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('WaveformSegmentRow duet singer chip', () => {
|
||||
it('omits the singer chip when no singer is passed (non-duet)', () => {
|
||||
renderRow()
|
||||
expect(screen.queryByText('●')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the singer chip and cycles the singer on click', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onSingerChange = jest.fn()
|
||||
renderRow({ singer: 1, onSingerChange })
|
||||
const chip = screen.getByText('●').closest('button')!
|
||||
await user.click(chip)
|
||||
expect(onSingerChange).toHaveBeenCalledWith(2)
|
||||
})
|
||||
|
||||
it('reports focus/blur so singer shortcuts target this line', () => {
|
||||
const onFocus = jest.fn()
|
||||
const onBlur = jest.fn()
|
||||
const { container } = render(
|
||||
<WaveformSegmentRow
|
||||
segment={timedSegment}
|
||||
segmentIndex={0}
|
||||
contextWords={[]}
|
||||
wordDecorations={new Map()}
|
||||
onCommit={jest.fn()}
|
||||
onEditSegment={jest.fn()}
|
||||
onDeleteSegment={jest.fn()}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
/>
|
||||
)
|
||||
const row = container.firstChild as HTMLElement
|
||||
expect(row).toHaveAttribute('tabindex', '0')
|
||||
fireEvent.focus(row)
|
||||
fireEvent.blur(row)
|
||||
expect(onFocus).toHaveBeenCalled()
|
||||
expect(onBlur).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user