diff --git a/frontend/components/lyrics-review/TranscriptionView.tsx b/frontend/components/lyrics-review/TranscriptionView.tsx index 175e0b3d..69dcb3e0 100644 --- a/frontend/components/lyrics-review/TranscriptionView.tsx +++ b/frontend/components/lyrics-review/TranscriptionView.tsx @@ -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)), + })} /> ))} @@ -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 ( diff --git a/frontend/components/lyrics-review/WaveformSegmentRow.tsx b/frontend/components/lyrics-review/WaveformSegmentRow.tsx index 49166c17..067abc34 100644 --- a/frontend/components/lyrics-review/WaveformSegmentRow.tsx +++ b/frontend/components/lyrics-review/WaveformSegmentRow.tsx @@ -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 ( -
- {/* Left controls: index (opens modal), play, edit */} +
{/* Left controls match the Advanced view: index, delete, play. */}
+ {/* Singer chip (duet mode only) */} + {singer !== undefined && onSingerChange && ( + + )} + {/* Inline timeline (waveform + resizable word bars), ruler hidden for compactness */}
{hasTimedWords ? ( diff --git a/frontend/components/lyrics-review/__tests__/TranscriptionView.waveformsDuet.test.tsx b/frontend/components/lyrics-review/__tests__/TranscriptionView.waveformsDuet.test.tsx new file mode 100644 index 00000000..3d1b5257 --- /dev/null +++ b/frontend/components/lyrics-review/__tests__/TranscriptionView.waveformsDuet.test.tsx @@ -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( + + + + ) + +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() + }) +}) diff --git a/frontend/components/lyrics-review/__tests__/WaveformSegmentRow.test.tsx b/frontend/components/lyrics-review/__tests__/WaveformSegmentRow.test.tsx index 26974613..653558eb 100644 --- a/frontend/components/lyrics-review/__tests__/WaveformSegmentRow.test.tsx +++ b/frontend/components/lyrics-review/__tests__/WaveformSegmentRow.test.tsx @@ -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( + + ) + const row = container.firstChild as HTMLElement + expect(row).toHaveAttribute('tabindex', '0') + fireEvent.focus(row) + fireEvent.blur(row) + expect(onFocus).toHaveBeenCalled() + expect(onBlur).toHaveBeenCalled() + }) +})