Skip to content

Commit

Permalink
Merge pull request #21 from mbsantiago/fix/double-clicking
Browse files Browse the repository at this point in the history
Fixed issue when using double click on the spectrogram for seeking
  • Loading branch information
mbsantiago authored Jun 8, 2024
2 parents 97de568 + 4deb193 commit 893780c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,4 @@ whombat.db
back/src/whombat/statics/*
back/src/whombat/user_guide/*
back/.build_venv
front/tests-examples
12 changes: 11 additions & 1 deletion front/src/components/recordings/RecordingSpectrogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useCanvas from "@/hooks/draw/useCanvas";
import useSpectrogram from "@/hooks/spectrogram/useSpectrogram";
import useSpectrogramTrackAudio from "@/hooks/spectrogram/useSpectrogramTrackAudio";

import type { Recording, SpectrogramParameters } from "@/types";
import type { Recording, SpectrogramParameters, Position } from "@/types";

export default function RecordingSpectrogram({
recording,
Expand Down Expand Up @@ -62,12 +62,22 @@ export default function RecordingSpectrogram({
startTime: bounds.time.min,
});

const { seek, play } = audio;
const handleDoubleClick = useCallback(
({ position }: { position: Position }) => {
seek(position.time);
play();
},
[seek, play],
);

const spectrogram = useSpectrogram({
dimensions,
recording,
bounds,
initial,
parameters,
onDoubleClick: handleDoubleClick,
enabled: !audio.isPlaying,
});

Expand Down
4 changes: 2 additions & 2 deletions front/src/hooks/audio/useAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export default function useAudio({
}, []);

const handleSeek = useCallback((time: number) => {
audio.current.currentTime = time / speed;
}, [speed]);
audio.current.currentTime = (time - startTime) / speed;
}, [speed, startTime]);

const handleTogglePlay = useCallback(() => {
if (isPlaying) {
Expand Down

0 comments on commit 893780c

Please sign in to comment.