is working i swear
This commit is contained in:
committed by
Clément Le Bihan
parent
69329118f7
commit
88cb7b2b65
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
import { Platform, View } from 'react-native';
|
import { Platform, View } from 'react-native';
|
||||||
import API from '../../API';
|
import API from '../../API';
|
||||||
import { useQuery } from '../../Queries';
|
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 { CursorInfoItem } from '../../models/SongCursorInfos';
|
||||||
import { Audio } from 'expo-av';
|
import { Audio } from 'expo-av';
|
||||||
import { SvgContainer } from './SvgContainer';
|
import { SvgContainer } from './SvgContainer';
|
||||||
@@ -36,7 +36,7 @@ const getCursorToPlay = (
|
|||||||
}
|
}
|
||||||
for (let i = cursorInfos.length - 1; i > currentCurIdx; i--) {
|
for (let i = cursorInfos.length - 1; i > currentCurIdx; i--) {
|
||||||
if (cursorInfos[i]!.timestamp <= timestamp) {
|
if (cursorInfos[i]!.timestamp <= timestamp) {
|
||||||
onCursorMove(cursorInfos[i]!, i);
|
return onCursorMove(cursorInfos[i]!, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -152,7 +152,7 @@ const PartitionMagic = ({
|
|||||||
}, [shouldPlay]);
|
}, [shouldPlay]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (endPartitionReached) {
|
if (endPartitionReached && playType === 'normal') {
|
||||||
// if the audio is unsync
|
// if the audio is unsync
|
||||||
melodySound.current?.pauseAsync();
|
melodySound.current?.pauseAsync();
|
||||||
onEndReached();
|
onEndReached();
|
||||||
@@ -193,8 +193,6 @@ const PartitionMagic = ({
|
|||||||
currentCurIdx.current,
|
currentCurIdx.current,
|
||||||
timestamp + transitionDuration,
|
timestamp + transitionDuration,
|
||||||
(cursor, idx) => {
|
(cursor, idx) => {
|
||||||
console.log(data.cursors)
|
|
||||||
console.log("b ", timestamp, cursor, currentCurIdx.current)
|
|
||||||
currentCurIdx.current = idx;
|
currentCurIdx.current = idx;
|
||||||
partitionOffset.value = withTiming(
|
partitionOffset.value = withTiming(
|
||||||
-(cursor.x - data!.cursors[0]!.x) / partitionDims[0],
|
-(cursor.x - data!.cursors[0]!.x) / partitionDims[0],
|
||||||
@@ -214,6 +212,9 @@ const PartitionMagic = ({
|
|||||||
);
|
);
|
||||||
}, [timestamp, data?.cursors, isPianoLoaded]);
|
}, [timestamp, data?.cursors, isPianoLoaded]);
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => ({
|
||||||
|
left: `${partitionOffset.value * 100}%`,
|
||||||
|
}))
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@@ -247,15 +248,14 @@ const PartitionMagic = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={{
|
style={[animatedStyle, {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
aspectRatio: partitionDims[0] / partitionDims[1],
|
aspectRatio: partitionDims[0] / partitionDims[1],
|
||||||
left: `${partitionOffset.value * 100}%`,
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'stretch',
|
alignItems: 'stretch',
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
}}
|
}]}
|
||||||
>
|
>
|
||||||
<SvgContainer
|
<SvgContainer
|
||||||
url={getSVGURL(songID)}
|
url={getSVGURL(songID)}
|
||||||
|
|||||||
@@ -72,8 +72,9 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
const [endResult, setEndResult] = useState<unknown>();
|
const [endResult, setEndResult] = useState<unknown>();
|
||||||
const [shouldPlay, setShouldPlay] = useState(false);
|
const [shouldPlay, setShouldPlay] = useState(false);
|
||||||
const songHistory = useQuery(API.getSongHistory(songId));
|
const songHistory = useQuery(API.getSongHistory(songId));
|
||||||
|
const endCalled = useRef(false)
|
||||||
const [score, setScore] = useState(0); // Between 0 and 100
|
const [score, setScore] = useState(0); // Between 0 and 100
|
||||||
const getElapsedTime = () => stopwatch.getElapsedRunningTime();
|
const getElapsedTime = () => stopwatch.getElapsedRunningTime() - 3000;
|
||||||
const [readyToPlay, setReadyToPlay] = useState(false);
|
const [readyToPlay, setReadyToPlay] = useState(false);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const [midiKeyboardFound, setMidiKeyboardFound] = useState<boolean>();
|
const [midiKeyboardFound, setMidiKeyboardFound] = useState<boolean>();
|
||||||
@@ -113,6 +114,9 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onEnd = () => {
|
const onEnd = () => {
|
||||||
|
if (endCalled.current == true)
|
||||||
|
return;
|
||||||
|
endCalled.current = true;
|
||||||
stopwatch.stop();
|
stopwatch.stop();
|
||||||
if (webSocket.current?.readyState != WebSocket.OPEN) {
|
if (webSocket.current?.readyState != WebSocket.OPEN) {
|
||||||
console.warn('onEnd: Websocket not open');
|
console.warn('onEnd: Websocket not open');
|
||||||
|
|||||||
Reference in New Issue
Block a user