def draw(canvas, audio_file, branches): """ Draws all necessary items (beats and branches) for the specified LocalAudioFile. """ bounds = sc.normalizeColor(audio_file) beats = audio_file.analysis.beats width = (1440 - (xpad * 2)) / float(len(beats)) draw_branches(canvas, audio_file, branches, bounds, width) draw_beats(canvas, beats, bounds, width)
def drawBeats(C, beats, bounds, width): for i in range(len(beats)): mycolor = sc.getSegmentColor(bounds, beats[i].segments[0]) C.create_polygon(xpad + (i * width), ypad, xpad + (i * width) + width, ypad, xpad + (i * width) + width, ypad + height, xpad + (i * width), ypad + height, fill=mycolor)
def drawBranches(C, beats, branches, threshold, bounds, width): keys = branches.keys() lastBranch = max(keys) for key in keys: for branch in branches[key]: if branch[1] <= threshold or key == lastBranch: mycolor = sc.getSegmentColor(bounds, beats[key].segments[0]) x0 = xpad + key * width + width / 2 x1 = xpad + branch[0] * width + width / 2 xmid = (x0 + x1) / 2 coord = x0, ypad, xmid, ypad - 200, x1, ypad C.create_line(coord, width=width / 2, smooth=True, fill=mycolor)
def draw_beats(canvas, beats, bounds, width): """ Draws all beats for a given song. """ for i in range(len(beats)): my_color = sc.getSegmentColor(bounds, beats[i].segments[0]) canvas.create_polygon(xpad + (i * width), ypad, xpad + (i * width) + width, ypad, xpad + (i * width) + width, ypad + height, xpad + (i * width), ypad + height, fill=my_color)
def draw_branches(canvas, audio_file, branches, bounds, width): """ Draws all branches both within and out of a song. """ beats = audio_file.analysis.beats md5 = audio_file.analysis.pyechonest_track.md5 keys = branches[md5].keys() num_branches_in = 0 num_branches_out = 0 for key in keys: for branch in branches[md5][key]: if branch[0] <= THRESHOLD_OUT and branch[1] != md5: canvas.create_polygon(xpad + (key * width), ypad + height, xpad + (key * width) + width, ypad + height, xpad + (key * width) + width, ypad + height + 50, xpad + (key * width), ypad + height + 50, fill="green") num_branches_out += 1 elif (branch[0] <= THRESHOLD and branch[1] == md5) or (branch[2] == max(keys) and branch[1] == md5): num_branches_in += 1 mycolor = sc.getSegmentColor(bounds, beats[key].segments[0]) x0 = xpad + key * width + width / 2 x1 = xpad + branch[2] * width + width / 2 xmid = (x0 + x1) / 2 coord = x0, ypad, xmid, ypad - 200, x1, ypad canvas.create_line(coord, width=width / 2, smooth=True, fill=mycolor) print md5, "in:", num_branches_in, "out:", num_branches_out
__author__ = 'lukestack' import echonest.remix.audio as audio import matplotlib.pyplot as plt import SegColor import aqplayer import music_info as mi SONG_DIR = "MP3Songs/" SONG = "Song.mp3" OUTPUT_NAME = "pic.png" audio_file = audio.LocalAudioFile(SONG_DIR + SONG) bounds = SegColor.normalizeColor(audio_file) segments = audio_file.analysis.segments tatums = audio_file.analysis.tatums beats = audio_file.analysis.beats bars = audio_file.analysis.bars sections = audio_file.analysis.sections fig = plt.figure() ax = fig.add_subplot(111) for i in range(0, len(segments)): start = segments[i].start loudest_point = start + segments[i].time_loudness_max end = start + segments[i].duration color = SegColor.getSegmentColor(bounds, segments[i]) if i + 1 < len(segments): next_seg_loudness = segments[i + 1].loudness_begin
def draw(C, audio_file, branches, threshold): bounds = sc.normalizeColor(audio_file) beats = audio_file.analysis.beats width = (1440 - (xpad * 2)) / float(len(beats)) drawBranches(C, beats, branches, threshold, bounds, width) drawBeats(C, beats, bounds, width)