Skip to content

Commit

Permalink
Add midpoint for waveform editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat committed Sep 1, 2024
1 parent 175e6fa commit 5b24bb3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/WaveformEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,24 @@ const SampleColumn: React.FC<{
key={i}
value={i}
isActive={i === value}
isMidPoint={i === 8}
onChange={handleChange}
/>
))}
</Flex>
);
};

const SamplePointWrapper = styled.div<{ isActive: boolean }>(
({ isActive: isActive }) => ({
width: POINT_SIZE,
height: POINT_SIZE,
const SamplePointWrapper = styled.div<{
isActive: boolean;
isMidpoint: boolean;
}>(({ isActive, isMidpoint }) => ({
width: POINT_SIZE,
height: POINT_SIZE,

backgroundColor: isActive ? "white" : undefined,
})
);
backgroundColor: isActive ? "white" : undefined,
boxShadow: isMidpoint ? "inset 0 -1px 0 0 var(--highlight-bg)" : undefined,
}));

type OnSampleChange = (index: number, value: number) => void;

Expand All @@ -106,10 +109,10 @@ const SamplePoint: React.FC<{
readonly onChange: Callback<number>;
readonly value: number;
readonly isActive: boolean;
}> = memo(({ value, isActive, onChange }) => {
readonly isMidPoint: boolean;
}> = memo(({ value, isActive, isMidPoint, onChange }) => {
const setPoint: MouseEventHandler = (e) => {
if (e.buttons & LEFT_BUTTON) {
// console.log(`${index} = ${value}`);
onChange(value);
}
e.preventDefault();
Expand All @@ -118,6 +121,7 @@ const SamplePoint: React.FC<{

return (
<SamplePointWrapper
isMidpoint={isMidPoint}
isActive={isActive}
onMouseMove={setPoint}
onMouseDown={setPoint}
Expand Down

0 comments on commit 5b24bb3

Please sign in to comment.