def __init__(self, note_imgs, player, key_input, score=None): super().__init__(note_imgs, player, score) #Leave previous notes as is self.mark_black = False #Don't play notes on advance self.play_notes = False #Various parameters #tolerance of 0.2 notes self.early_tolerance = 0.2 self.colors['green'] = (14, 230, 71) self.colors['red'] = (224, 9, 9) #Take in key inputs self.key_input = key_input self.playable_pitches = key_input.get_playable_pitches() #Set of currently played pitches self.played_pitches = set() #Various parameters self.early_notes = 0 self.wrong_notes = 0 self.frames_used = 0 #FSM State self.WAITING = 0 self.PLAYING = 1 self.fsm_state = self.WAITING self.quit = False #Construct buttons self.exit_btn = Btn("Exit", (40, 200), on_click = \ self.on_exit_btn_click) self.stage.add_btn(self.exit_btn)
def __init__(self, note_imgs, player, key_input, score=None): super().__init__(note_imgs, player, score) self.colors['green'] = (14, 230, 71) self.colors['red'] = (224, 9, 9) #Take in key inputs self.key_input = key_input self.playable_pitches = key_input.get_playable_pitches() self.quit = False self.paused = False self.playback_rate_idx = 4 self.playback_rates = [0.25, 0.33, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0] #Set of currently played pitches self.played_pitches = set() #Construct buttons self.play_btn = ImageBtn('./img/pause.png', (80, 200), on_click = \ self.on_play_btn_click, dimen = (20, 20)) self.exit_btn = Btn("Exit", (40, 200), on_click = \ self.on_exit_btn_click) self.slow_btn = ImageBtn('./img/slow.png', (120, 200), \ on_click = self.on_slow_btn_click, dimen = (20, 20)) self.ffwd_btn = ImageBtn('./img/fast_forward.png', (160, 200), \ on_click = self.on_ffwd_btn_click, dimen = (20, 20)) self.pace_txt = Text("1.0x Pace", (240, 200), font_size=20) self.stage.add_btn(self.play_btn) self.stage.add_btn(self.exit_btn) self.stage.add_btn(self.slow_btn) self.stage.add_btn(self.ffwd_btn) self.stage.add_elt(self.pace_txt)
def __init__(self, wrong_notes, early_notes, timing, score, fps): #Various settings self.stage = Stage() self.colors = {} self.colors["blue"] = (39, 117, 242) self.colors["black"] = (0, 0, 0) self.colors['green'] = (14, 230, 71) self.colors['red'] = (224, 9, 9) self.quit = False self.stage = Stage() self.exit_btn = Btn("Exit", (40, 200), on_click = \ self.on_exit_btn_click) expected_dur = 0.0 num_notes = 0 total_bars = score.get_total_bars() for i in range(total_bars): curr_bar = score.get_bar(i) expected_dur += curr_bar.get_length() * 60.0 * fps \ / curr_bar.get_bpm() num_notes += len(curr_bar.get_treble()) num_notes += len(curr_bar.get_bass()) used_dur = float(timing) pct_time = used_dur / expected_dur * 100 pct_early = float(early_notes) / num_notes * 100 pct_wrong = float(wrong_notes) / num_notes * 100 wrong_notes_txt = Text("Wrong Notes: {}".format(wrong_notes), \ (20, 20), centering = "topleft") early_notes_txt = Text("Early Notes: {0:} ({1:.2f}%)"\ .format(early_notes, pct_early), (20, 50), centering = "topleft") timing_txt = Text("Time Used: {0:.2f}s ({1:.2f}%)" \ .format(used_dur / fps, pct_time), \ (20, 80), centering = "topleft") expected_time = Text("Expected: {0:.2f}s".format(expected_dur / fps), \ (20, 110), centering = "topleft") #cutoff (pct_wrong, pct_early, pct_time) grade_cutoff = [('S', 1.0, 1.0, 110.0), \ ('A', 5.0, 5.0, 125.0), \ ('B', 15.0, 15.0, 140.0), \ ('C', 30.0, 30.0, 180.0), \ ('D', 50.0, 50.0, 200.0)] grade = 'F' for (cutoff_grade, wrong_cutoff, early_cutoff, time_cutoff) \ in grade_cutoff: if pct_wrong <= wrong_cutoff and pct_early <= early_cutoff and \ pct_time <= time_cutoff: grade = cutoff_grade break #Assign grade grade_txt = Text("{}".format(grade), \ (160, 140), centering = "center", font_size = 48) self.stage.add_btn(self.exit_btn) self.stage.add_elt(wrong_notes_txt) self.stage.add_elt(early_notes_txt) self.stage.add_elt(timing_txt) self.stage.add_elt(grade_txt)
def refresh_scores(self): for _, btn in self.score_btns.items(): self.stage.remove_btn(btn) #Maps index to button objects self.score_btns = {} #Maps score name to index self.score_to_idx = {} for i in range(self.curr_idx, min(self.curr_idx + \ self.scores_per_page, len(self.scores))): score_name = self.scores[i].get_metadata()["name"] score_btn = Btn(score_name, (130, 40 + \ (i - self.curr_idx) * 30), \ on_click = self.on_score_btn_click, \ font_size = 24) self.stage.add_btn(score_btn) #Make blue if selected if i == self.sel_idx: score_btn.color = self.colors["blue"] self.score_to_idx[score_name] = i self.score_btns[i] = score_btn
def __init__(self, note_img_cache, player, key_input, scores \ , fps, train_mode = True): #Various settings self.stage = Stage() self.scores_per_page = 4 #Set various attributes self.scores = scores self.img_cache = note_img_cache self.player = player self.key_input = key_input self.train_mode = train_mode self.fps = fps self.colors = {} self.colors["blue"] = (39, 117, 242) self.colors["black"] = (0, 0, 0) self.quit = False self.score_btns = {} self.score_to_idx = {} self.curr_idx = 0 self.sel_idx = -1 self.return_from_mode = False self.stage = Stage() self.exit_btn = Btn("Exit", (40, 200), on_click = \ self.on_exit_btn_click) self.select_btn = Btn("Select", (260, 180), on_click = \ self.on_select_btn_click) self.up_btn = ImageBtn("./img/up.png", (260, 40), on_click = \ self.on_up_btn_click, dimen = (20, 20)) self.down_btn = ImageBtn("./img/down.png", (260, 120), on_click = \ self.on_down_btn_click, dimen = (20, 20)) self.stage.add_btn(self.exit_btn) self.stage.add_btn(self.up_btn) self.stage.add_btn(self.down_btn) self.stage.add_btn(self.select_btn) self.refresh_scores()
def __init__(self, player, key_input): self.stage = Stage() self.player = player self.key_input = key_input self.playable_pitches = key_input.get_playable_pitches() #Set of currently played pitches self.played_pitches = set() #Various parameters self.quit = False #Construct buttons self.exit_btn = Btn("Exit", (40, 200), on_click = \ self.on_exit_btn_click) self.piano_mode_txt = Text("Piano Mode", (160, 20)) self.notes_played_txt = Text("", (20, 100), centering="topleft") self.stage.add_btn(self.exit_btn) self.stage.add_elt(self.piano_mode_txt) self.stage.add_elt(self.notes_played_txt)