def main(args): sample_path = args[0] c = MarkovConductor("/tmp/conductor-markov-demo.db") c.load() c.init_chain("trackid", "trackid") load_files(c, sample_path) prev = c.choose_next_track() c.record_transition(None, prev) cur = c.choose_next_track(prev) cmd = None playcount = 0 while True: c.record_transition(prev, cur, False) if playcount == 0: os.system(PLAYCMD % os.path.join(sample_path, prev["title"])) os.system(PLAYCMD % os.path.join(sample_path, cur["title"])) print previd = c.get_track(prev).id curid = c.get_track(cur).id print "%s -> %s" % (previd, curid) print "---" scores = c.get_transitions_from_id(previd) print_histogram(c, scores) if playcount > 0: playcount -= 1 else: cmd = read_chr().lower() if cmd == "g": c.record_user_feedback(True) elif cmd == "b": c.record_user_feedback(False) elif cmd == "p": playcount = 10 elif cmd == "q": sys.exit() # If the last choice wasn't bad, continue to the next track if not cmd == "b": prev = cur cur = c.choose_next_track(prev) c.unload()
def run(self, args): self.init(args) self.previous_track = None self.current_track = None playcount = 0 # Command line loop while True: if playcount > 0: playcount -= 1 elif self.current_track is not None: print "Please enter a key (G = Good, B = Bad): " cmd = read_chr().lower() if self.current_track is not None: if cmd == "g": # Rate "Good!" print "User: that choice was GOOD!" print self.conductor.record_user_feedback(True) elif cmd == "b": # Rate "Bad!" print "User: that choice was BAD!" print self.conductor.record_user_feedback(False) # Return to the previous track to try again. self.current_track = self.previous_track elif cmd == "p": # Play the next 10 tracks without pausing playcount = 10 print "Playing %s tracks..." % playcount elif cmd == "c": # Manually choose next track. self.play_track(self.prompt_track(), userchoice=True) continue elif cmd == "s": # Manually choose next tracks. for track in self.prompt_tracks(): self.play_track(track, userchoice=True) continue elif cmd == "x": # Forget about the previous track to simulate a session beginning. self.previous_track = None print "New session started." continue elif cmd == "q": # "Quit" print "Bye!" sys.exit() curid = self.conductor.get_track(self.current_track).id if self.current_track else None scores = self.conductor.get_transitions_from_id(curid) print "---" print "%s -> ..." % (self.current_track["title"] if self.current_track else "[Start]") print_histogram(self.conductor, scores) print "---" self.play_track(self.conductor.choose_next_track(self.current_track), userchoice=False) self.conductor.unload()
def run(self, args): self.init(args) self.previous_track = None self.current_track = None playcount = 0 # Command line loop while True: if playcount > 0: playcount -= 1 elif self.current_track is not None: print "Please enter a key (G = Good, B = Bad): " cmd = read_chr().lower() if self.current_track is not None: if cmd == "g": # Rate "Good!" print "User: that choice was GOOD!" print self.conductor.record_user_feedback(True) elif cmd == "b": # Rate "Bad!" print "User: that choice was BAD!" print self.conductor.record_user_feedback(False) # Return to the previous track to try again. self.current_track = self.previous_track elif cmd == "p": # Play the next 10 tracks without pausing playcount = 10 print "Playing %s tracks..." % playcount elif cmd == "c": # Manually choose next track. self.play_track(self.prompt_track(), userchoice=True) continue elif cmd == "s": # Manually choose next tracks. for track in self.prompt_tracks(): self.play_track(track, userchoice=True) continue elif cmd == "x": # Forget about the previous track to simulate a session beginning. self.previous_track = None print "New session started." continue elif cmd == "q": # "Quit" print "Bye!" sys.exit() curid = self.conductor.get_track( self.current_track).id if self.current_track else None scores = self.conductor.get_transitions_from_id(curid) print "---" print "%s -> ..." % (self.current_track["title"] if self.current_track else "[Start]") print_histogram(self.conductor, scores) print "---" self.play_track(self.conductor.choose_next_track( self.current_track), userchoice=False) self.conductor.unload()