Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/403: [FE] [녹음] 녹음 시 트랙 재생 관련 인터랙션 막기 #407

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/components/atoms/TrackPlayBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function TrackPlayBox({
isDisabled
min={0}
max={maxMeasure}
cursor="initial"
>
<SliderTrack width="100%" minH="inherit" borderRadius="inherit" bgColor="rgba(177, 255, 0, 0.1)">
<SliderFilledTrack minH="inherit" bgColor={bgColor} borderLeftRadius="inherit" />
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/atoms/TrackRecordBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function TrackRecordBox({ onRecord }: { onRecord: () => void }) {
};

useEffect(() => {
if (isExpired) {
if (count === 0) {
startRecord();
}
}, [isExpired]);
}, [count]);

useEffect(() => {
const $recordBox = document.querySelector("#record-box");
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/atoms/TrackRecordBox/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
display: flex;
justify-content: center;
align-items: center;
background-color: #404040;
background-color: rgba(255, 255, 255, 0.1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

player 스틱이 마이크 아이콘을 가리지 않도록 투명도를 설정했어요

border-radius: 10px;
cursor: initial;
}
9 changes: 6 additions & 3 deletions client/src/components/blocks/TrackPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ function TrackPlayer({
onChange={handlePlayerChange}
min={0}
max={totalMeasure}
step={0.5}
focusThumbOnChange={false}
isReadOnly={isRecording}
cursor="pointer"
>
<SliderThumb top="-6px" w="fit-content" h="100%" cursor="pointer" _focus={{ outline: "none" }}>
<PlayStick />
</SliderThumb>
<SliderTrack w="100%" height="calc(100% - 3rem)" maxH="inherit" minH="inherit" paddingY="5%">
<VStack
w="100%"
Expand Down Expand Up @@ -73,9 +79,6 @@ function TrackPlayer({
)}
</VStack>
</SliderTrack>
<SliderThumb top="-6px" w="fit-content" h="100%" cursor="pointer" _focus={{ outline: "none" }}>
<PlayStick />
</SliderThumb>
</Slider>
);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/blocks/TrackSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function TrackSetting({ projectTitle, bpmState, trackTags, tracks }: ProjectInfo
/>
</div>
<div id="bottom-section">
<UnderPlayBarViewModel />
<UnderPlayBarViewModel isRecording={isRecording} />
</div>
</div>
);
Expand Down
21 changes: 13 additions & 8 deletions client/src/hooks/useCreateTrack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useEffect } from "react";
import { useRecoilValue } from "recoil";

import type { AudioType } from "types/audioType";

import { isTrackPlayingState } from "model/audioModel";
import useRecord from "./useRecord";
import useTimer from "./useTimer";

const useCreateTrack = ({
inputDeviceId,
Expand All @@ -16,6 +17,8 @@ const useCreateTrack = ({
onRecordCancel?: () => void;
onTrackRemove?: (audioId: AudioType["id"]) => void;
}) => {
const isTrackPlaying = useRecoilValue(isTrackPlayingState);

const {
isRecording,
isSuccess: isRecordSuccess,
Expand All @@ -26,29 +29,31 @@ const useCreateTrack = ({
initRecord,
} = useRecord(inputDeviceId);

const { start: startTimer, pause: pauseTimer, isExpired, time: timerTime } = useTimer(30);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 로직에서는 녹음 타이머, player 재생을 위한 타이머가 각각 30초씩 동작하고 있었는데, 상태로 관리하다보니 녹음 상태와 Player 재생 상태가 불일치하는 문제가 발생해서 녹음은 트랙 재생 상태에 의존하여 시작하도록 수정했어요.


const handleRecordButtonClick = () => {
startRecord();
startTimer();
};

const handleTrackRemove = (audioId: AudioType["id"]) => {
stopRecord();
pauseTimer();

if (window.confirm("녹음된 트랙이 있어요. 정말 삭제할까요?")) {
initRecord();
onTrackRemove?.(audioId);
}
};

// timer가 종료되면 트랙 녹음 중지
// 녹음 상태이고, track player가 재생상태인 경우에 녹음 시작
useEffect(() => {
if (isExpired) {
if (!isRecording) {
return;
}

if (isTrackPlaying) {
startRecord();
} else {
stopRecord();
}
}, [isExpired]);
}, [isTrackPlaying]);

useEffect(() => {
if (isRecordSuccess) {
Expand Down
10 changes: 6 additions & 4 deletions client/src/hooks/useTrackPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ const useTrackPlayer = ({ bpm, isRecording }: { bpm: number; isRecording?: boole
const { trackTime, setTrackTime, startTrackTimer, stopTrackTimer, resetTrackTimer } = useTrackTimer();

// bpm에 따른 전체 마디 계산
const totalMeasure = Math.floor(bpm / 2) + 1;
const totalMeasure = Math.floor(bpm / 2) + 2;
const measure = trackTime / (30 / totalMeasure);

// 현재 재생 중인 마디 값이 바뀌면 TrackPlayer, 오디오의 재생 시간도 변경
const setMeasure = useCallback(
(nextMeasure: number) => {
const currentTime = Number((nextMeasure * (30 / totalMeasure)).toFixed(3));
setTrackTime(currentTime);
changeAudioTime(currentTime);
const currentTime = nextMeasure * (30 / totalMeasure);
// TrackPlayer 재생 시간 정수 단위로 설정
setTrackTime(Math.floor(currentTime));
// 오디오 재생 시간 설정
changeAudioTime(Number(currentTime.toFixed(3)));
},
[changeAudioTime],
);
Expand Down
15 changes: 13 additions & 2 deletions client/src/viewmodel/UnderPlayBarViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ import useAudios from "hooks/useAudios";

import UnderPlayBar from "components/blocks/UnderPlayBar";

function UnderPlayBarViewModel() {
function UnderPlayBarViewModel({ isRecording }: { isRecording?: boolean }) {
const { isAudioPlaying, toggleAudio, chanegeAudioVolume } = useAudios();
const time = useRecoilValue(trackTimeState);
const refinedTime = `00:${Math.floor(time).toString().padStart(2, "0")}`;

// 녹음 중이면 오디오 재생상태 조작 불가능
const handlePlayButtonClick = () => {
if (!isRecording) {
toggleAudio();
}
};

return (
<UnderPlayBar
sound={INITIAL_AUDIO_VOLUME}
currentTime={refinedTime}
totalTime="00:30"
onSoundInput={chanegeAudioVolume}
isPlaying={isAudioPlaying}
onClickPlay={toggleAudio}
onClickPlay={handlePlayButtonClick}
/>
);
}

UnderPlayBarViewModel.defaultProps = {
isRecording: false,
};

export default UnderPlayBarViewModel;