Esempio n. 1
0
    def init(self, music_dirs):
        def calculate_weight_conservative(conductor, score, user_score):
            ease = lambda x, length, height: (math.tanh(x * (math.pi / length))
                                              + 1) * (height / 2)
            num_chains = len(conductor.chains)
            return ease(user_score, 10 * num_chains, 10) * math.pow(2, score)

        def calculate_weight_eager(conductor, score, user_score):
            return math.pow(1 + (1.0 / len(conductor.chains)),
                            user_score) * (math.sqrt(score) + 1)

        self.conductor = MarkovConductor(
            "/tmp/conductor-demo.db",
            {"weight_function": calculate_weight_eager})
        self.conductor.load()
        self.conductor.init_chain("trackid", "trackid")
        self.conductor.init_chain("albumid", "albumid")
        self.conductor.init_chain("albumid", "trackid")
        self.conductor.init_chain("albumid", "artistid")
        self.conductor.init_chain("artistid", "artistid")
        self.conductor.init_chain("artistid", "trackid")
        self.conductor.init_chain("genreid", "genreid")

        self.library = Library(self.conductor)
        for dir in music_dirs:
            self.library.load_files(dir)
Esempio n. 2
0
def main(args):
    c = MarkovConductor("/tmp/conductor-test.db")
    c.load()

    tracks = [{
        "title": "Blue",
        "album": "Cold",
        "artist": "Colors",
        "genre": "Electronic"
    }, {
        "title": "Cyan",
        "album": "Cold",
        "artist": "Colors",
        "genre": "Electronic"
    }, {
        "title": "Green",
        "album": "Cold",
        "artist": "Colors",
        "genre": "Electronic"
    }, {
        "title": "Purple",
        "album": "Cold",
        "artist": "Colors",
        "genre": "Electronic"
    }, {
        "title": "One",
        "album": "Low",
        "artist": "Numbers",
        "genre": "Math Rock"
    }]

    for prev, cur in izip([None] + tracks, tracks):
        c.record_transition(prev, cur)

    c.unload()
Esempio n. 3
0
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()
Esempio n. 4
0
def main(args):
    c = MarkovConductor("/tmp/conductor-test.db")
    c.load()
    
    tracks = [{"title": "Blue",   "album": "Cold", "artist": "Colors",  "genre": "Electronic"},
              {"title": "Cyan",   "album": "Cold", "artist": "Colors",  "genre": "Electronic"},
              {"title": "Green",  "album": "Cold", "artist": "Colors",  "genre": "Electronic"},
              {"title": "Purple", "album": "Cold", "artist": "Colors",  "genre": "Electronic"},
              {"title": "One",    "album": "Low",  "artist": "Numbers", "genre": "Math Rock"}]
    
    prev = None
    for i in range(0, 200):
        cur = random.choice(tracks)
        print cur, prev
        c.record_transition(prev, cur)
        prev = cur
        
    c.unload()