fix practice mode no sound and score system during practice
This commit is contained in:
committed by
Clément Le Bihan
parent
9fd70d3110
commit
a24a960184
@@ -202,6 +202,8 @@ const PartitionMagic = ({
|
|||||||
easing: Easing.inOut(Easing.ease),
|
easing: Easing.inOut(Easing.ease),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
if (playType == 'practice')
|
||||||
|
return;
|
||||||
cursor.notes.forEach((note) => {
|
cursor.notes.forEach((note) => {
|
||||||
piano.current?.start({
|
piano.current?.start({
|
||||||
note: note.note,
|
note: note.note,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import Song from '../../models/Song';
|
|||||||
import { useTheme } from 'native-base';
|
import { useTheme } from 'native-base';
|
||||||
|
|
||||||
type PlayViewControlBarProps = {
|
type PlayViewControlBarProps = {
|
||||||
|
playType: 'practice' | 'normal' | null;
|
||||||
song: Song;
|
song: Song;
|
||||||
time: number;
|
time: number;
|
||||||
paused: boolean;
|
paused: boolean;
|
||||||
@@ -19,6 +20,7 @@ type PlayViewControlBarProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const PlayViewControlBar = ({
|
const PlayViewControlBar = ({
|
||||||
|
playType,
|
||||||
song,
|
song,
|
||||||
time,
|
time,
|
||||||
paused,
|
paused,
|
||||||
@@ -107,6 +109,7 @@ const PlayViewControlBar = ({
|
|||||||
gap: isPhone ? 10 : 25,
|
gap: isPhone ? 10 : 25,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{ playType != 'practice' &&
|
||||||
<IconButton
|
<IconButton
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
@@ -117,7 +120,7 @@ const PlayViewControlBar = ({
|
|||||||
name: paused ? 'play' : 'pause',
|
name: paused ? 'play' : 'pause',
|
||||||
}}
|
}}
|
||||||
onPress={paused ? onResume : onPause}
|
onPress={paused ? onResume : onPause}
|
||||||
/>
|
/>}
|
||||||
<IconButton
|
<IconButton
|
||||||
size="sm"
|
size="sm"
|
||||||
colorScheme="coolGray"
|
colorScheme="coolGray"
|
||||||
@@ -162,7 +165,8 @@ const PlayViewControlBar = ({
|
|||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MetronomeControls paused={paused} bpm={bpm.current} />
|
{ playType != 'practice' &&
|
||||||
|
<MetronomeControls paused={paused} bpm={bpm.current} />}
|
||||||
</View>
|
</View>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type PlayViewProps = {
|
|||||||
|
|
||||||
// this a hot fix this should be reverted soon
|
// this a hot fix this should be reverted soon
|
||||||
let scoroBaseApiUrl = process.env.EXPO_PUBLIC_SCORO_URL!;
|
let scoroBaseApiUrl = process.env.EXPO_PUBLIC_SCORO_URL!;
|
||||||
|
let interval: NodeJS.Timeout;
|
||||||
|
|
||||||
if (process.env.NODE_ENV != 'development' && Platform.OS === 'web') {
|
if (process.env.NODE_ENV != 'development' && Platform.OS === 'web') {
|
||||||
Linking.getInitialURL().then((initUrl) => {
|
Linking.getInitialURL().then((initUrl) => {
|
||||||
@@ -146,8 +147,16 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
bearer: accessToken,
|
bearer: accessToken,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
interval = setInterval(() => {
|
||||||
|
webSocket.current!.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: 'ping',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, 15000);
|
||||||
};
|
};
|
||||||
webSocket.current.onclose = () => {
|
webSocket.current.onclose = () => {
|
||||||
|
clearInterval(interval);
|
||||||
console.log('Websocket closed', endMsgReceived);
|
console.log('Websocket closed', endMsgReceived);
|
||||||
if (!endMsgReceived) {
|
if (!endMsgReceived) {
|
||||||
toast.show({ description: 'Connection lost with Scorometer' });
|
toast.show({ description: 'Connection lost with Scorometer' });
|
||||||
@@ -165,25 +174,28 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
toast.show({ description: 'Scoro: ' + data.error });
|
toast.show({ description: 'Scoro: ' + data.error });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (data.type == 'pong')
|
||||||
|
return;
|
||||||
if (data.type == 'end') {
|
if (data.type == 'end') {
|
||||||
|
const maxPoints = data.score.max_score || 1;
|
||||||
|
const points = data.overallScore;
|
||||||
|
|
||||||
endMsgReceived = true;
|
endMsgReceived = true;
|
||||||
webSocket.current?.close();
|
webSocket.current?.close();
|
||||||
|
setScore(Math.floor((Math.max(points, 0) * 100) / maxPoints));
|
||||||
setEndResult({ songId: song.data!.id, ...data });
|
setEndResult({ songId: song.data!.id, ...data });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.type == 'step') {
|
|
||||||
console.log(data.timestamp)
|
|
||||||
setTime(data.timestamp)
|
|
||||||
//set idx += 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
const points = data.info.score;
|
const points = data.info.score;
|
||||||
const maxPoints = data.info.max_score || 1;
|
const maxPoints = data.info.max_score || 1;
|
||||||
|
|
||||||
setScore(Math.floor((Math.max(points, 0) * 100) / maxPoints));
|
setScore(Math.floor((Math.max(points, 0) * 100) / maxPoints));
|
||||||
|
|
||||||
|
if (data.type == 'step') {
|
||||||
|
setTime(data.timestamp)
|
||||||
|
return
|
||||||
|
}
|
||||||
let formattedMessage = '';
|
let formattedMessage = '';
|
||||||
let messageColor: ColorSchemeType | undefined;
|
let messageColor: ColorSchemeType | undefined;
|
||||||
|
|
||||||
@@ -416,6 +428,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<PlayViewControlBar
|
<PlayViewControlBar
|
||||||
|
playType={playType}
|
||||||
score={score}
|
score={score}
|
||||||
time={time}
|
time={time}
|
||||||
paused={paused}
|
paused={paused}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ class StartMessage(ValidatedDC):
|
|||||||
mode: Literal["normal", "practice"]
|
mode: Literal["normal", "practice"]
|
||||||
type: Literal["start"] = "start"
|
type: Literal["start"] = "start"
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PingMessage(ValidatedDC):
|
||||||
|
type: Literal["ping"] = "ping"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EndMessage(ValidatedDC):
|
class EndMessage(ValidatedDC):
|
||||||
@@ -52,6 +57,7 @@ message_map = {
|
|||||||
"note_on": NoteOnMessage,
|
"note_on": NoteOnMessage,
|
||||||
"note_off": NoteOffMessage,
|
"note_off": NoteOffMessage,
|
||||||
"pause": PauseMessage,
|
"pause": PauseMessage,
|
||||||
|
"ping": PingMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +68,8 @@ def getMessage() -> (
|
|||||||
| NoteOnMessage
|
| NoteOnMessage
|
||||||
| NoteOffMessage
|
| NoteOffMessage
|
||||||
| PauseMessage
|
| PauseMessage
|
||||||
| InvalidMessage,
|
| InvalidMessage
|
||||||
|
| PingMessage,
|
||||||
str,
|
str,
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from chroma_case.Message import (
|
|||||||
NoteOffMessage,
|
NoteOffMessage,
|
||||||
NoteOnMessage,
|
NoteOnMessage,
|
||||||
PauseMessage,
|
PauseMessage,
|
||||||
|
PingMessage,
|
||||||
StartMessage,
|
StartMessage,
|
||||||
getMessage,
|
getMessage,
|
||||||
)
|
)
|
||||||
@@ -215,6 +216,9 @@ class Scorometer:
|
|||||||
|
|
||||||
def practiceCheck(self):
|
def practiceCheck(self):
|
||||||
if self.to_play == self.keys_down_practice:
|
if self.to_play == self.keys_down_practice:
|
||||||
|
|
||||||
|
self.info["perfect"] += len(self.to_play)
|
||||||
|
self.info["score"] += 100 * len(self.to_play)
|
||||||
if len(self.practice_partition) == 0:
|
if len(self.practice_partition) == 0:
|
||||||
self.endGamePractice()
|
self.endGamePractice()
|
||||||
self.send({"type": "step", "timestamp": self.practice_partition[0][0].start + 1})
|
self.send({"type": "step", "timestamp": self.practice_partition[0][0].start + 1})
|
||||||
@@ -250,13 +254,16 @@ class Scorometer:
|
|||||||
| NoteOnMessage
|
| NoteOnMessage
|
||||||
| NoteOffMessage
|
| NoteOffMessage
|
||||||
| PauseMessage
|
| PauseMessage
|
||||||
| InvalidMessage,
|
| InvalidMessage
|
||||||
|
| PingMessage,
|
||||||
line: str,
|
line: str,
|
||||||
):
|
):
|
||||||
match message:
|
match message:
|
||||||
case InvalidMessage(error):
|
case InvalidMessage(error):
|
||||||
logging.warning(f"Invalid message {line} with error: {error}")
|
logging.warning(f"Invalid message {line} with error: {error}")
|
||||||
self.send({"error": f"Invalid message {line} with error: {error}"})
|
self.send({"error": f"Invalid message {line} with error: {error}"})
|
||||||
|
case PingMessage():
|
||||||
|
self.send({"type": "pong"})
|
||||||
case NoteOnMessage():
|
case NoteOnMessage():
|
||||||
if self.mode == NORMAL:
|
if self.mode == NORMAL:
|
||||||
self.handleNoteOn(message)
|
self.handleNoteOn(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user