practice mode working, timestamp is delayed for some reason
This commit is contained in:
committed by
Clément Le Bihan
parent
c08a1a2c74
commit
c1d714e02a
@@ -186,7 +186,7 @@ const PartitionMagic = ({
|
|||||||
}, [data?.cursors, melodySound.current?._loaded]);
|
}, [data?.cursors, melodySound.current?._loaded]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!shouldPlay) return;
|
if (!shouldPlay && playType != 'practice') return;
|
||||||
if (!piano.current || !isPianoLoaded) return;
|
if (!piano.current || !isPianoLoaded) return;
|
||||||
if (!data || data?.cursors.length === 0) return;
|
if (!data || data?.cursors.length === 0) return;
|
||||||
getCursorToPlay(
|
getCursorToPlay(
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.type == 'step') {
|
if (data.type == 'step') {
|
||||||
|
console.log(data.timestamp)
|
||||||
setTime(data.timestamp)
|
setTime(data.timestamp)
|
||||||
//set idx += 1
|
//set idx += 1
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -200,81 +200,22 @@ class Scorometer:
|
|||||||
logging.warning("note_off: no key to play but it was not a wrong note_on")
|
logging.warning("note_off: no key to play but it was not a wrong note_on")
|
||||||
|
|
||||||
def handleNoteOnPractice(self, message: NoteOnMessage):
|
def handleNoteOnPractice(self, message: NoteOnMessage):
|
||||||
#is_down = any(x[0] == message.note for x in self.keys_down)
|
|
||||||
logging.debug({"note_on": message.note})
|
logging.debug({"note_on": message.note})
|
||||||
#if is_down:
|
|
||||||
# return
|
|
||||||
#self.keys_down.append((message.note, message.time))
|
|
||||||
self.keys_down_practice.add(message.note)
|
self.keys_down_practice.add(message.note)
|
||||||
|
self.practiceCheck()
|
||||||
|
|
||||||
|
def handleNoteOffPractice(self, message: NoteOffMessage):
|
||||||
|
logging.debug({"note_off": message.note})
|
||||||
|
self.keys_down_practice.remove(message.note)
|
||||||
|
self.practiceCheck()
|
||||||
|
|
||||||
|
def practiceCheck(self):
|
||||||
if self.to_play == self.keys_down_practice:
|
if self.to_play == self.keys_down_practice:
|
||||||
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})
|
||||||
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)])
|
||||||
|
|
||||||
'''
|
|
||||||
self.to_play
|
|
||||||
key = Key(key=message.note, start=message.time, duration=0)
|
|
||||||
keys_to_play = next(
|
|
||||||
(i for i in self.practice_partition if any(x.done is not True for x in i)),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
if keys_to_play is None:
|
|
||||||
self.send({"type": "error", "error": "no keys should be played"})
|
|
||||||
return
|
|
||||||
to_play = next(
|
|
||||||
(i for i in keys_to_play if i.key == key.key and i.done is not True), None
|
|
||||||
)
|
|
||||||
if to_play:
|
|
||||||
perf = "practice"
|
|
||||||
logging.debug({"note_on": f"{perf} on {message.note}"})
|
|
||||||
self.incrementStreak()
|
|
||||||
self.send({"type": "timing", "id": message.id, "timing": perf})
|
|
||||||
else:
|
|
||||||
self.wrong_ids += [message.id]
|
|
||||||
logging.debug({"note_on": f"wrong key {message.note}"})
|
|
||||||
self.info["current_streak"] = 0
|
|
||||||
self.send({"type": "timing", "id": message.id, "timing": "wrong"})
|
|
||||||
'''
|
|
||||||
|
|
||||||
def handleNoteOffPractice(self, message: NoteOffMessage):
|
|
||||||
logging.debug({"note_off": message.note})
|
|
||||||
self.keys_down_practice.remove(message.note)
|
|
||||||
'''
|
|
||||||
down_since = next(
|
|
||||||
since for (h_key, since) in self.keys_down if h_key == message.note
|
|
||||||
)
|
|
||||||
self.keys_down.remove((message.note, down_since))
|
|
||||||
if message.id in self.wrong_ids:
|
|
||||||
logging.debug({"note_off": f"wrong key {message.note}"})
|
|
||||||
self.send({"type": "duration", "id": message.id, "duration": "wrong"})
|
|
||||||
self.info["wrong"] += 1;
|
|
||||||
return
|
|
||||||
key = Key(
|
|
||||||
key=message.note, start=down_since, duration=(message.time - down_since)
|
|
||||||
)
|
|
||||||
keys_to_play = next(
|
|
||||||
(i for i in self.practice_partition if any(x.done is not True for x in i)),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
if keys_to_play is None:
|
|
||||||
logging.info("Invalid key.")
|
|
||||||
self.info["score"] -= 50
|
|
||||||
# TODO: I dont think this if is right
|
|
||||||
# self.sendScore(message.id, "wrong key", "wrong key")
|
|
||||||
return
|
|
||||||
to_play = next(
|
|
||||||
(i for i in keys_to_play if i.key == key.key and i.done is not True), None
|
|
||||||
)
|
|
||||||
if to_play:
|
|
||||||
perf = "practice"
|
|
||||||
to_play.done = True
|
|
||||||
logging.debug({"note_off": f"{perf} on {message.note}"})
|
|
||||||
self.send({"type": "duration", "id": message.id, "duration": perf})
|
|
||||||
else:
|
|
||||||
self.send({"type": "duration", "id": message.id, "duration": "wrong"})
|
|
||||||
'''
|
|
||||||
|
|
||||||
def getDurationScore(self, key: Key, to_play: Key):
|
def getDurationScore(self, key: Key, to_play: Key):
|
||||||
tempo_percent = abs((key.duration / to_play.duration) - 1)
|
tempo_percent = abs((key.duration / to_play.duration) - 1)
|
||||||
if tempo_percent < 0.3:
|
if tempo_percent < 0.3:
|
||||||
|
|||||||
Reference in New Issue
Block a user