front practice listener and scorometer sending timestamp
This commit is contained in:
committed by
Clément Le Bihan
parent
b80167001f
commit
23a1ff8d19
@@ -10,6 +10,7 @@ import LoadingComponent from '../Loading';
|
|||||||
import { SplendidGrandPiano } from 'smplr';
|
import { SplendidGrandPiano } from 'smplr';
|
||||||
|
|
||||||
export type ParitionMagicProps = {
|
export type ParitionMagicProps = {
|
||||||
|
playType: 'practice' | 'normal' | null
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
songID: number;
|
songID: number;
|
||||||
shouldPlay: boolean;
|
shouldPlay: boolean;
|
||||||
@@ -44,6 +45,7 @@ const getCursorToPlay = (
|
|||||||
const transitionDuration = 50;
|
const transitionDuration = 50;
|
||||||
|
|
||||||
const PartitionMagic = ({
|
const PartitionMagic = ({
|
||||||
|
playType,
|
||||||
timestamp,
|
timestamp,
|
||||||
songID,
|
songID,
|
||||||
shouldPlay,
|
shouldPlay,
|
||||||
@@ -79,6 +81,11 @@ const PartitionMagic = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
// In practice mode, no sound is played so just act as the piano is loaded
|
||||||
|
if (playType == 'practice') {
|
||||||
|
setIsPianoLoaded(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Platform.OS === 'web' && !piano.current) {
|
if (Platform.OS === 'web' && !piano.current) {
|
||||||
const audio = new AudioContext();
|
const audio = new AudioContext();
|
||||||
piano.current = new SplendidGrandPiano(audio);
|
piano.current = new SplendidGrandPiano(audio);
|
||||||
|
|||||||
@@ -171,6 +171,11 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
setEndResult({ songId: song.data!.id, ...data });
|
setEndResult({ songId: song.data!.id, ...data });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (data.type == 'step') {
|
||||||
|
setTime(data.timestamp)
|
||||||
|
//set idx += 1
|
||||||
|
return
|
||||||
|
}
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
const points = data.info.score;
|
const points = data.info.score;
|
||||||
@@ -239,7 +244,9 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE).catch(() => {});
|
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE).catch(() => {});
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
setTime(() => getElapsedTime()); // Countdown
|
if (playType != 'practice') {
|
||||||
|
setTime(() => getElapsedTime());
|
||||||
|
} // Countdown
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@@ -247,7 +254,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
stopwatch.stop();
|
stopwatch.stop();
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [playType]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Song.data is updated on navigation.navigate (do not know why)
|
// Song.data is updated on navigation.navigate (do not know why)
|
||||||
@@ -386,6 +393,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PartitionMagic
|
<PartitionMagic
|
||||||
|
playType={playType}
|
||||||
shouldPlay={shouldPlay}
|
shouldPlay={shouldPlay}
|
||||||
timestamp={time}
|
timestamp={time}
|
||||||
songID={song.data.id}
|
songID={song.data.id}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class Scorometer:
|
|||||||
#self.keys_down.append((message.note, message.time))
|
#self.keys_down.append((message.note, message.time))
|
||||||
self.keys_down_practice.add(message.note)
|
self.keys_down_practice.add(message.note)
|
||||||
if self.to_play == self.keys_down_practice:
|
if self.to_play == self.keys_down_practice:
|
||||||
self.send({"type": "step", "message": "Good"})
|
self.send({"type": "step", "timestamp": self.practice_partition[0][0].start + 1})
|
||||||
if len(self.practice_partition) == 0:
|
if len(self.practice_partition) == 0:
|
||||||
self.endGamePractice()
|
self.endGamePractice()
|
||||||
self.to_play = set([x.key for x in self.practice_partition.pop(0)])
|
self.to_play = set([x.key for x in self.practice_partition.pop(0)])
|
||||||
|
|||||||
Reference in New Issue
Block a user