Restore sound-specific rings and refine studio UI
This commit is contained in:
1 parent
02eb8911e8
commit
e7b6c0bb3e
16 files changed
+318
-524
No files matched your search
@@ -8,7 +8,7 @@ import {
|
||||
import {
|
||||
getPointForStep,
|
||||
getLoopPositionPercent,
|
||||
getCategoryOrbitRadius,
|
||||
getSoundOrbitRadius,
|
||||
getStepFromPosition,
|
||||
ORBIT_RADIUS,
|
||||
SVG_CENTER,
|
||||
@@ -16,22 +16,20 @@ import {
|
||||
getStackedPosition,
|
||||
wrapStepPosition,
|
||||
} from '../domain/timeline';
|
||||
import { INSTRUMENT_BY_ID, INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||
import { INSTRUMENT_BY_ID } from '../domain/instruments';
|
||||
import type { InstrumentId } from '../domain/instruments';
|
||||
|
||||
interface CircularTimelineProps {
|
||||
beats: BeatPoint[];
|
||||
categoryIds: readonly InstrumentCategoryId[];
|
||||
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||
labelByCategoryId: CategoryLabelOverrides;
|
||||
soundIds: readonly InstrumentId[];
|
||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
||||
currentStep: number;
|
||||
totalSteps: number;
|
||||
focusedCategoryId: InstrumentCategoryId | null;
|
||||
focusedSoundId: InstrumentId | null;
|
||||
selectedBeatId: string | null;
|
||||
onMoveBeat: (beatId: string, step: number) => void;
|
||||
onSelectBeat: (beatId: string) => void;
|
||||
onSelectCategory: (categoryId: InstrumentCategoryId) => void;
|
||||
onSelectSound: (soundId: InstrumentId) => void;
|
||||
}
|
||||
|
||||
function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
|
||||
@@ -44,29 +42,25 @@ function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
|
||||
|
||||
export function CircularTimeline({
|
||||
beats,
|
||||
categoryIds,
|
||||
colorByCategoryId,
|
||||
labelByCategoryId,
|
||||
soundIds,
|
||||
colorBySoundId,
|
||||
currentStep,
|
||||
totalSteps,
|
||||
focusedCategoryId,
|
||||
focusedSoundId,
|
||||
selectedBeatId,
|
||||
onMoveBeat,
|
||||
onSelectBeat,
|
||||
onSelectCategory,
|
||||
onSelectSound,
|
||||
}: CircularTimelineProps) {
|
||||
const draggingBeatIdRef = useRef<string | null>(null);
|
||||
const selectedBeatSoundId = beats.find((beat) => beat.id === selectedBeatId)?.soundId;
|
||||
const selectedBeatCategoryId = selectedBeatSoundId
|
||||
? INSTRUMENT_BY_ID[selectedBeatSoundId].categoryId
|
||||
: null;
|
||||
const activeCategoryId = selectedBeatCategoryId ?? focusedCategoryId;
|
||||
const orderedCategoryIds = activeCategoryId
|
||||
const activeSoundId = selectedBeatSoundId ?? focusedSoundId;
|
||||
const orderedSoundIds = activeSoundId
|
||||
? [
|
||||
...categoryIds.filter((categoryId) => categoryId === activeCategoryId),
|
||||
...categoryIds.filter((categoryId) => categoryId !== activeCategoryId),
|
||||
...soundIds.filter((soundId) => soundId === activeSoundId),
|
||||
...soundIds.filter((soundId) => soundId !== activeSoundId),
|
||||
]
|
||||
: categoryIds;
|
||||
: soundIds;
|
||||
|
||||
function handlePointerDown(event: ReactPointerEvent<SVGGElement>, beatId: string): void {
|
||||
event.preventDefault();
|
||||
@@ -102,11 +96,11 @@ export function CircularTimeline({
|
||||
|
||||
function handleOrbitKeyDown(
|
||||
event: ReactKeyboardEvent<SVGCircleElement>,
|
||||
categoryId: InstrumentCategoryId,
|
||||
soundId: InstrumentId,
|
||||
): void {
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||
event.preventDefault();
|
||||
onSelectCategory(categoryId);
|
||||
onSelectSound(soundId);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -114,42 +108,26 @@ export function CircularTimeline({
|
||||
className="circular-timeline"
|
||||
viewBox={`0 0 ${SVG_SIZE} ${SVG_SIZE}`}
|
||||
role="group"
|
||||
aria-label={`${totalSteps}-step circular beat timeline with one orbit per instrument category. Drag beat points to move them.`}
|
||||
aria-label={`${totalSteps}-step circular beat timeline with one orbit per sound. Drag beat points to move them.`}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={() => { draggingBeatIdRef.current = null; }}
|
||||
onPointerCancel={() => { draggingBeatIdRef.current = null; }}
|
||||
>
|
||||
{orderedCategoryIds.map((categoryId, categoryIndex) => {
|
||||
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||
const color = colorByCategoryId[categoryId] ?? '#b8b4e0';
|
||||
const radius = getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length);
|
||||
const letterPosition = getPointForStep(totalSteps * 0.12, radius, SVG_CENTER, totalSteps);
|
||||
const focused = categoryId === activeCategoryId;
|
||||
{orderedSoundIds.map((soundId, soundIndex) => {
|
||||
const focused = soundId === activeSoundId;
|
||||
return (
|
||||
<g key={categoryId}>
|
||||
<circle
|
||||
cx={SVG_CENTER}
|
||||
cy={SVG_CENTER}
|
||||
r={radius}
|
||||
className={`timeline-orbit${focused ? ' is-focused' : ''}`}
|
||||
style={{
|
||||
stroke: color,
|
||||
opacity: focused ? 0.55 : 0.32,
|
||||
strokeWidth: focused ? 2.2 : 1.5,
|
||||
}}
|
||||
/>
|
||||
<g className="timeline-category-letter" style={{ color }} aria-hidden="true">
|
||||
<circle cx={letterPosition.x} cy={letterPosition.y} r="9" />
|
||||
<text
|
||||
x={letterPosition.x}
|
||||
y={letterPosition.y}
|
||||
textAnchor="middle"
|
||||
dominantBaseline="middle"
|
||||
>
|
||||
{category.letter}
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
<circle
|
||||
key={soundId}
|
||||
cx={SVG_CENTER}
|
||||
cy={SVG_CENTER}
|
||||
r={getSoundOrbitRadius(soundIndex, orderedSoundIds.length)}
|
||||
className={`timeline-orbit${focused ? ' is-focused' : ''}`}
|
||||
style={{
|
||||
stroke: colorBySoundId[soundId] ?? '#b8b4e0',
|
||||
opacity: focused ? 0.55 : 0.32,
|
||||
strokeWidth: focused ? 2.2 : 1.5,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -180,12 +158,12 @@ export function CircularTimeline({
|
||||
);
|
||||
})}
|
||||
|
||||
{orderedCategoryIds.map((categoryId, categoryIndex) => (
|
||||
{orderedSoundIds.map((soundId, soundIndex) => (
|
||||
<circle
|
||||
key={categoryId}
|
||||
key={soundId}
|
||||
cx={SVG_CENTER}
|
||||
cy={SVG_CENTER}
|
||||
r={getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length)}
|
||||
r={getSoundOrbitRadius(soundIndex, orderedSoundIds.length)}
|
||||
className="timeline-orbit-hit-area"
|
||||
fill="none"
|
||||
stroke="transparent"
|
||||
@@ -193,11 +171,11 @@ export function CircularTimeline({
|
||||
pointerEvents="stroke"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`Select ${INSTRUMENT_CATEGORY_BY_ID[categoryId].letter} ${labelByCategoryId[categoryId] ?? INSTRUMENT_CATEGORY_BY_ID[categoryId].label} ring`}
|
||||
aria-pressed={categoryId === activeCategoryId}
|
||||
onClick={() => onSelectCategory(categoryId)}
|
||||
onKeyDown={(event) => handleOrbitKeyDown(event, categoryId)}
|
||||
onFocus={() => onSelectCategory(categoryId)}
|
||||
aria-label={`Select ${INSTRUMENT_BY_ID[soundId].label} ring`}
|
||||
aria-pressed={soundId === activeSoundId}
|
||||
onClick={() => onSelectSound(soundId)}
|
||||
onKeyDown={(event) => handleOrbitKeyDown(event, soundId)}
|
||||
onFocus={() => onSelectSound(soundId)}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -213,23 +191,22 @@ export function CircularTimeline({
|
||||
|
||||
{beats.map((beat) => {
|
||||
const instrument = INSTRUMENT_BY_ID[beat.soundId];
|
||||
const category = INSTRUMENT_CATEGORY_BY_ID[instrument.categoryId];
|
||||
const categoryIndex = orderedCategoryIds.indexOf(instrument.categoryId);
|
||||
const soundIndex = orderedSoundIds.indexOf(beat.soundId);
|
||||
const point = getStackedPosition(
|
||||
beat,
|
||||
beats,
|
||||
totalSteps,
|
||||
getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length),
|
||||
getSoundOrbitRadius(soundIndex, orderedSoundIds.length),
|
||||
);
|
||||
const selected = selectedBeatId === beat.id;
|
||||
return (
|
||||
<g
|
||||
key={beat.id}
|
||||
className={`sound-point${selected ? ' is-selected' : ''}`}
|
||||
style={{ color: colorByCategoryId[instrument.categoryId] ?? '#f4f1ed' }}
|
||||
style={{ color: colorBySoundId[beat.soundId] ?? '#f4f1ed' }}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={`${category.letter} ${labelByCategoryId[category.id] ?? category.label}, beat ${beat.letter}, ${instrument.label}, ${getLoopPositionPercent(beat.step, totalSteps)}% around the loop. Drag to move freely, or use arrow keys for small steps.`}
|
||||
aria-label={`${instrument.label}, beat ${beat.letter}, ${getLoopPositionPercent(beat.step, totalSteps)}% around the loop. Drag to move freely, or use arrow keys for small steps.`}
|
||||
aria-pressed={selected}
|
||||
onPointerDown={(event) => handlePointerDown(event, beat.id)}
|
||||
onClick={() => onSelectBeat(beat.id)}
|
||||
|
||||
Reference in new issue
Block a user