From 88cb7b2b653cd8366118a3c8d4b429a1791da9e6 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Thu, 18 Jan 2024 00:47:39 +0100 Subject: [PATCH] is working i swear --- front/components/Play/PartitionMagic.tsx | 16 ++++++++-------- front/views/PlayView.tsx | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/front/components/Play/PartitionMagic.tsx b/front/components/Play/PartitionMagic.tsx index 3661088..78d875d 100644 --- a/front/components/Play/PartitionMagic.tsx +++ b/front/components/Play/PartitionMagic.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { Platform, View } from 'react-native'; import API from '../../API'; import { useQuery } from '../../Queries'; -import Animated, { useSharedValue, withTiming, Easing } from 'react-native-reanimated'; +import Animated, { useSharedValue, withTiming, Easing, useAnimatedStyle } from 'react-native-reanimated'; import { CursorInfoItem } from '../../models/SongCursorInfos'; import { Audio } from 'expo-av'; import { SvgContainer } from './SvgContainer'; @@ -36,7 +36,7 @@ const getCursorToPlay = ( } for (let i = cursorInfos.length - 1; i > currentCurIdx; i--) { if (cursorInfos[i]!.timestamp <= timestamp) { - onCursorMove(cursorInfos[i]!, i); + return onCursorMove(cursorInfos[i]!, i); } } }; @@ -152,7 +152,7 @@ const PartitionMagic = ({ }, [shouldPlay]); React.useEffect(() => { - if (endPartitionReached) { + if (endPartitionReached && playType === 'normal') { // if the audio is unsync melodySound.current?.pauseAsync(); onEndReached(); @@ -193,8 +193,6 @@ const PartitionMagic = ({ currentCurIdx.current, timestamp + transitionDuration, (cursor, idx) => { - console.log(data.cursors) - console.log("b ", timestamp, cursor, currentCurIdx.current) currentCurIdx.current = idx; partitionOffset.value = withTiming( -(cursor.x - data!.cursors[0]!.x) / partitionDims[0], @@ -214,6 +212,9 @@ const PartitionMagic = ({ ); }, [timestamp, data?.cursors, isPianoLoaded]); + const animatedStyle = useAnimatedStyle(() => ({ + left: `${partitionOffset.value * 100}%`, + })) return ( { const [endResult, setEndResult] = useState(); const [shouldPlay, setShouldPlay] = useState(false); const songHistory = useQuery(API.getSongHistory(songId)); + const endCalled = useRef(false) const [score, setScore] = useState(0); // Between 0 and 100 - const getElapsedTime = () => stopwatch.getElapsedRunningTime(); + const getElapsedTime = () => stopwatch.getElapsedRunningTime() - 3000; const [readyToPlay, setReadyToPlay] = useState(false); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [midiKeyboardFound, setMidiKeyboardFound] = useState(); @@ -113,6 +114,9 @@ const PlayView = ({ songId }: PlayViewProps) => { }; const onEnd = () => { + if (endCalled.current == true) + return; + endCalled.current = true; stopwatch.stop(); if (webSocket.current?.readyState != WebSocket.OPEN) { console.warn('onEnd: Websocket not open');