From c1d714e02a16d0c150d7b9c031d6639f4e342b14 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Tue, 16 Jan 2024 00:35:17 +0100 Subject: [PATCH] practice mode working, timestamp is delayed for some reason --- front/components/Play/PartitionMagic.tsx | 2 +- front/views/PlayView.tsx | 1 + scorometer/main.py | 75 +++--------------------- 3 files changed, 10 insertions(+), 68 deletions(-) diff --git a/front/components/Play/PartitionMagic.tsx b/front/components/Play/PartitionMagic.tsx index 4ac7465..f1add24 100644 --- a/front/components/Play/PartitionMagic.tsx +++ b/front/components/Play/PartitionMagic.tsx @@ -186,7 +186,7 @@ const PartitionMagic = ({ }, [data?.cursors, melodySound.current?._loaded]); React.useEffect(() => { - if (!shouldPlay) return; + if (!shouldPlay && playType != 'practice') return; if (!piano.current || !isPianoLoaded) return; if (!data || data?.cursors.length === 0) return; getCursorToPlay( diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index 6302b43..b713a24 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -172,6 +172,7 @@ const PlayView = ({ songId }: PlayViewProps) => { return; } if (data.type == 'step') { + console.log(data.timestamp) setTime(data.timestamp) //set idx += 1 return diff --git a/scorometer/main.py b/scorometer/main.py index 6cdf67e..8320138 100755 --- a/scorometer/main.py +++ b/scorometer/main.py @@ -200,81 +200,22 @@ class Scorometer: logging.warning("note_off: no key to play but it was not a wrong note_on") def handleNoteOnPractice(self, message: NoteOnMessage): - #is_down = any(x[0] == message.note for x in self.keys_down) 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.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 len(self.practice_partition) == 0: self.endGamePractice() 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 - 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): tempo_percent = abs((key.duration / to_play.duration) - 1) if tempo_percent < 0.3: