Ejemplo n.º 1
0
 def analyze_songs(self):
     self.log_message("Analyzing songs")
     usersong.batch_analyze_user_songs(self.loaded_songs, cache_path=self.cache_path)
     self.log_message("Writing analysis files to: %s" % self.cache_path)
     for s in self.loaded_songs:
         s.write_analysis_to_folder(self.cache_path)
     self.message.set("Songs analyzed!")
songs_path = os.path.join(os.path.abspath(".."), "testmp3s")
filepaths = [
    os.path.join(songs_path, '140bpm_8bars.mp3'),
    os.path.join(songs_path, '130bpm_8bars.mp3'),
    os.path.join(songs_path, '125bpm_8bars.mp3'),
    os.path.join(songs_path, '120bpm_8bars.mp3'),
    os.path.join(songs_path, '110bpm_8bars.mp3')
]

song_a = usersong.UserSong(filepaths[0])
song_b = usersong.UserSong(filepaths[1])
song_c = usersong.UserSong(filepaths[2])
song_d = usersong.UserSong(filepaths[3])
song_e = usersong.UserSong(filepaths[4])

usersong.batch_analyze_user_songs([song_a, song_b, song_c, song_d, song_e])

# get beat 16 beats from the end of Song a for transition 2
beat_a_0 = len(song_a.get_analysis_feature(analysis.Feature.BEATS)) - 13
beat_b_1 = len(song_b.get_analysis_feature(analysis.Feature.BEATS)) - 13
beat_c_1 = len(song_c.get_analysis_feature(analysis.Feature.BEATS)) - 13
beat_d_1 = len(song_d.get_analysis_feature(analysis.Feature.BEATS)) - 13
beat_e_1 = len(song_e.get_analysis_feature(analysis.Feature.BEATS)) - 13

# length in beats
length = 12
# pass transition type
t_1 = Transition_Types.CROSSFADE
t_2 = Transition_Types.TEMPO_MATCH
mix = [{
    "song_a": song_a,
    
    file_paths = []
    for root, _, files in os.walk(directory):
        for f in files:
            file_path = os.path.join(os.path.abspath(root), f)
            for ext in usersong.UserSong.EXTENSIONS:
                if fnmatch.fnmatch(file_path, "*%s" % ext):
                    file_paths.append(file_path)
                    break
    return file_paths

song_folder_path = os.path.normpath(os.path.join(project_path, "djskinnyg_songs"))
song_paths = get_file_paths(song_folder_path)
cache_path = os.path.normpath(os.path.join(song_folder_path, "cache"))
song_objects = usersong.batch_create_user_songs(song_paths)
usersong.batch_analyze_user_songs(song_objects, cache_path)

for song in song_objects:
    song.write_analysis_to_folder(cache_path)
    print("{} : {} : {} : {} : {} : {}".format(song.get_analysis_feature(analysis.Feature.NAME), song.get_analysis_feature(analysis.Feature.TEMPO), song.get_analysis_feature(analysis.Feature.KEY), song.get_analysis_feature(analysis.Feature.DANCEABILITY), song.get_analysis_feature(analysis.Feature.ENERGY), song.get_analysis_feature(analysis.Feature.VALENCE)))

# create a list with one goal (start)
first_goal = mix_goal.MixGoal(0.0, 0.0, 0.0, 0.0, 1)
goals = list([first_goal])
# initialize optimizer
dj = optimizer.Optimizer(song_objects, goals, style.Style_Lib.tempo_based.value)
mix_script = dj.generate_mixtape()
print("***MIX SCRIPT RESULT***")

for mix in mix_script:
    print(mix)