def song_attributes(filename, verbose=True, db=None): if db is None: db = DB_Helper() if db.is_in_db(filename): return msys.updControl('mrs_string/filename', filename) if not get_control(msys, 'bool', 'hasData'): raise RuntimeError( 'It looks like Marsyas was unable to load your file! ' 'Make sure you have the right codec support enabled.') # The StereoPanningSpectrumFeatures will only work # correctly with two channels. if get_control(msys, 'natural', 'channels') == 2: chan_control = 'enableChild' else: chan_control = 'disableChild' msys.updControl('Fanout/timbrepanning/mrs_string/' + chan_control, 'StereoPanningSpectrumFeatures/SPSFeatures') observations = get_control(msys, 'natural', 'onObservations') sum_vals = [0] * observations sum_of_squares = [0] * observations count = 0 while get_control(msys, 'bool', 'hasData'): msys.tick() vals = get_control(msys, 'realvec', 'processedData') sum_vals = [old + new for old, new in izip(sum_vals, vals)] sum_of_squares = [ old + new**2 for old, new in izip(sum_of_squares, vals) ] count += 1 reset_msys(msys) out = {field.name: None for field in attribute_schema} for i, attr in enumerate(obs_names(msys)): avg = sum_vals[i] / count squares_avg = sum_of_squares[i] / count out['mean_' + attr] = avg out['stdev_' + attr] = math.sqrt(squares_avg - avg**2) out[commonPath] = filename out[commonArtist] = None out[commonTitle] = None db.add_song(out)
def song_attributes(songpath, verbose=True, db=None): if db is None: db = DB_Helper() if not db.is_in_db(songpath): fp = open(songpath, 'rb') if verbose: print "Harvesting: " + songpath get_attr(fp, songpath, db)
def song_attributes(songpath, verbose = True, db = None): if db is None: db = DB_Helper() if not db.is_in_db(songpath): fp = open(songpath, 'rb') if verbose: print "Harvesting: " + songpath get_attr(fp, songpath, db)
def song_attributes(filename, verbose=True, db=None): if db is None: db = DB_Helper() if db.is_in_db(filename): return msys.updControl('mrs_string/filename', filename) if not get_control(msys, 'bool', 'hasData'): raise RuntimeError('It looks like Marsyas was unable to load your file! ' 'Make sure you have the right codec support enabled.') # The StereoPanningSpectrumFeatures will only work # correctly with two channels. if get_control(msys, 'natural', 'channels') == 2: chan_control = 'enableChild' else: chan_control = 'disableChild' msys.updControl('Fanout/timbrepanning/mrs_string/' + chan_control, 'StereoPanningSpectrumFeatures/SPSFeatures') observations = get_control(msys, 'natural', 'onObservations') sum_vals = [0] * observations sum_of_squares = [0] * observations count = 0 while get_control(msys, 'bool', 'hasData'): msys.tick() vals = get_control(msys, 'realvec', 'processedData') sum_vals = [old + new for old, new in izip(sum_vals, vals)] sum_of_squares = [old + new**2 for old, new in izip(sum_of_squares, vals)] count += 1 reset_msys(msys) out = {field.name: None for field in attribute_schema} for i, attr in enumerate(obs_names(msys)): avg = sum_vals[i] / count squares_avg = sum_of_squares[i] / count out['mean_' + attr] = avg out['stdev_' + attr] = math.sqrt(squares_avg - avg**2) out[commonPath] = filename out[commonArtist] = None out[commonTitle] = None db.add_song(out)
def run_sandbox(): print "****************\nWelcome to the sandboxed MoodMusic\n****************" print "\nYou are using our DB of thousands of songs so that you can test our machine learning algorithms\n" #Makes the DB_Helper use Tom's Sandbox DB db = DB_Helper() print "Choose a mood from the options below:" moods = DB_Helper().all_moods() for mood in moods: print mood chosenMood = raw_input('Enter choice: ') while chosenMood not in moods: chosenMood = raw_input('Please enter one of the options above: ') print "Max length of your playlist: " x = True while x: maxlen = raw_input("> ") try: maxlen = int(maxlen) x = False except: print "Cannot be converted to integer, try again." # make playlist p = Playlist(db, moods) p.add_mood(chosenMood) p.generate_list_mood() plist = p.get_list(maxlen) for s in plist: print str(s) print "Save as .m3u? y/n" save = raw_input("> ") if save == "y": m3u = open("playlist.m3u", "wb") for song in plist: print >> m3u, song
def choice_d(db): while (True): moods = DB_Helper().all_moods() print "Enter the song file path you want to add to a mood (or q to quit):" filepath = raw_input("> ") if filepath == 'q': sys.exit(0) while not db.is_in_db(filepath) and filepath != "n": print "Song not in database. Try again. (or n to quit)" filepath = raw_input("> ") if filepath != "n": print "Choose mood to add (or enter a new mood)." for mood in moods: print mood chosenMood = raw_input('> ') db.add_mood(filepath, chosenMood)
def run(runBackgroundImporter=True): print "****************\nWelcome to MoodMusic!\n****************\n" atexit.register(FetchData.removePID) if not os.path.isfile('config.pkl'): __make_config_file() __check_db() daemon = None if runBackgroundImporter: #Starts background daemon daemon = FetchData() daemon.start() #Start CLI application = CLI(daemon) #Init Database Chatter db = DB_Helper() print "\nPlease choose an option:\n" print "a -> Enter song to play" moods = db.all_moods() if len(moods) > 0: print "b -> Enter mood to play" print "c -> Generate a playlist from mood (without playing)" print "d -> Add song to mood (without playing)" choice = raw_input('\nEnter your choice: ') while (choice not in ['a', 'b', 'c', 'd']): choice = raw_input('Please enter an option above: ') if choice == 'a': print "\nHow would you like to select a song?\n" print "l -> Search your Library" print "f -> Enter a filepath" selection = raw_input('> ') while (selection not in ['l', 'f']): selection = raw_input('Please enter an option above: ') if selection == 'l': songFile = song_search( Config().get_attr('MUSIC_LIBRARY_FILE_PATH')) elif selection == 'f': #User enters a filepath songFile = raw_input('Enter song file: ') if songFile != None: chosenSong = Song.song_from_filepath(songFile) application.play_song(chosenSong) elif choice == 'b': #User enters a mood print "Choose a mood from the options below:" for mood in moods: print mood chosenMood = raw_input('Enter choice: ') while chosenMood not in moods: chosenMood = raw_input('Please enter one of the options above: ') # make playlist p = Playlist(db, moods) p.add_mood(chosenMood) p.generate_list_mood() application.set_list(p) application.play_song() elif choice == 'c': choice_c(moods, db) elif choice == 'd': choice_d(moods, db)
def run(runBackgroundImporter = True): print "****************\nWelcome to MoodMusic!\n****************\n" atexit.register(FetchData.removePID) if not os.path.isfile('config.pkl'): __make_config_file() __check_db() daemon = None if runBackgroundImporter: #Starts background daemon daemon = FetchData() daemon.start() #Start CLI application = CLI(daemon) #Init Database Chatter db = DB_Helper() print "\nPlease choose an option:\n" print "a -> Enter song to play" moods = db.all_moods() if len(moods) > 0: print "b -> Enter mood to play" print "c -> Generate a playlist from mood (without playing)" print "d -> Add song to mood (without playing)" choice = raw_input('\nEnter your choice: ') while(choice not in ['a', 'b', 'c', 'd']): choice = raw_input('Please enter an option above: ') if choice == 'a': # User enters a filepath for a song to play print "\nHow would you like to select a song?\n" print "l -> Search your Library" print "f -> Enter a filepath" selection = raw_input('> ') while (selection not in ['l', 'f']): selection = raw_input('Please enter an option above: ') # searh the user library for a song and return the filepath if selection == 'l': songFile = song_search(Config().get_attr('MUSIC_LIBRARY_FILE_PATH')) elif selection == 'f': #User enters a filepath songFile = raw_input('Enter song file: ') # if a song was found, play it if songFile != None: chosenSong = Song.song_from_filepath(songFile) application.play_song(chosenSong) elif choice == 'b': #User enters a mood to generate a playlist and play print "Choose a mood from the options below:" for mood in moods: print mood chosenMood = raw_input('Enter choice: ') while chosenMood not in moods: chosenMood = raw_input('Please enter one of the options above: ') # make playlist p = Playlist(db, moods) p.add_mood(chosenMood) p.generate_list_mood() application.set_list(p) application.play_song() elif choice == 'c': choice_c(moods, db) elif choice == 'd': choice_d(db)