def __init__(self, directories, *args, **kwargs): print(args, kwargs) tk.Tk.__init__(self, *args, **kwargs) # Stream for audio playback self.pa = pyaudio.PyAudio() self.stream = self.pa.open(format = pyaudio.paFloat32, channels=1, rate=44100, output=True) self.protocol("WM_DELETE_WINDOW", self.close_window) sc = SongCollection() print(directories) for dir_ in directories: sc.load_directory(dir_) self.songs = sc.get_marked() self.song = None self.varSongSelector = tk.Variable(self) self.songSelector = tk.OptionMenu(self, self.varSongSelector, '', *tuple([s.title for s in self.songs]), command = self.select_song) self.songSelector.grid(row=0,columnspan=3) tk.Label(self, text="Beats: ").grid(row=1) self.b_beats_play = tk.Button(self, text="[ > ]", command=self.play_beats) self.b_beats_play.grid(row=1,column=1) self.b_beats_fix = tk.Button(self, text="[+1]", command=self.shift_beats) self.b_beats_fix.grid(row=1,column=2) tk.Label(self, text="Downbeats: ").grid(row=2) self.b_downbeats_play = tk.Button(self, text="[ > ]", command=self.play_downbeats) self.b_downbeats_play.grid(row=2,column=1) self.b_downbeats_fix = tk.Button(self, text="[+1]", command=self.shift_downbeats) self.b_downbeats_fix.grid(row=2,column=2) tk.Label(self, text="Segments: ").grid(row=3) self.b_segments_shift_min8 = tk.Button(self, text="[-8]", command=lambda : self.shift_segments(-8)) self.b_segments_shift_min8.grid(row=3,column=1) self.b_segments_shift_min1 = tk.Button(self, text="[-1]", command=lambda : self.shift_segments(-1)) self.b_segments_shift_min1.grid(row=3,column=2) self.b_segments_shift_plus1 = tk.Button(self, text="[+1]", command=lambda : self.shift_segments(1)) self.b_segments_shift_plus1.grid(row=3,column=3) self.b_segments_shift_plus8 = tk.Button(self, text="[+8]", command=lambda : self.shift_segments(8)) self.b_segments_shift_plus8.grid(row=3,column=4) self.segment_buttons = [] # TODO How to insert segments? self.b_save = tk.Button(self, text="[ SAVE CHANGES ]", command=self.save) self.b_save.grid(row=0,column=4)
pool = Pool() for idx in range(start_sample, stop_sample - length_samples, hop_size): print 'Analysed until {:.2f}'.format((idx/44100.0)/60) start_idx = idx end_idx = idx + length_samples fragment = audio[start_idx : end_idx] theme_descr = calculateThemeDescriptor(fragment) print theme_descr pool.add('theme_descriptors', theme_descr.tolist()[0]) # --------------------- Load all audio files --------------------------- from songcollection import SongCollection sc = SongCollection() sc.load_directory('../music') sc.load_directory('../moremusic') sc.load_directory('../evenmoremusic') sc.load_directory('../music/test') songs = [] for song in sc.get_annotated(): song.open() pool.add('song.themes', song.song_theme_descriptor.tolist()[0]) songs.append(song.title) song.close() # --------------------- Make nice plots --------------------------- Y = pool['song.themes'] # All songs in "/music" and "/moremusic" libraries X = pool['theme_descriptors'] # Evolution of mix theme descriptors
from songcollection import SongCollection import pyaudio, csv import numpy as np from essentia.standard import AudioOnsetsMarker if __name__ == '__main__': # Open the long library sc = SongCollection() sc.load_directory('../moremusic/') analysedSongs = [] with open('evaluateMoresongs.csv', 'a+') as csvfile: for row in csv.reader(csvfile): analysedSongs.append(row[0]) print analysedSongs with open('evaluateMoresongs.csv', 'a') as csvfile: writer = csv.writer(csvfile) p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=44100, output=True) if len(analysedSongs) == 0: initrow = [ 'Song title', 'Segment index (downbeats)', 'Is aligned', 'Is low-to-high' ]
from essentia.standard import * from sklearn.decomposition import PCA from sklearn import preprocessing import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np if __name__ == '__main__': scaler = preprocessing.StandardScaler() pca = PCA(n_components=3) sc = SongCollection() for dir_ in sys.argv[1:]: sc.load_directory(dir_) pool = Pool() songs = [] for song in sc.get_annotated(): song.open() pool.add('themefeatures', song.spectral_contrast) songs.append(song.title) song.close() #~ # Test 1: spectral centroid on itself #~ X = pool['spectral_centroid'] #~ plt.figure() #~ plt.scatter(X[:,0],X[:,1]) #~ for label, x, y in zip(songs, X[:, 0], X[:, 1]):
while (True): try: cmd_split = str.split(raw_input('> : '), ' ') except KeyboardInterrupt: logger.info('Goodbye!') break cmd = cmd_split[0] if cmd == 'loaddir': if len(cmd_split) == 1: logger.warning('Please provide a directory name to load!') continue elif not os.path.isdir(cmd_split[1]): logger.warning(cmd_split[1] + ' is not a valid directory!') continue sc.load_directory(cmd_split[1]) logger.info( str(len(sc.songs)) + ' songs loaded [annotated: ' + str(len(sc.get_annotated())) + ']') elif cmd == 'play': if len(sc.get_annotated()) == 0: logger.warning( 'Use the loaddir command to load some songs before playing!' ) continue if len(cmd_split) > 1 and cmd_split[1] == 'save': logger.info('Saving this new mix to disk!') save_mix = True else: save_mix = False
def index_dj(request): template = get_template("Index.html") LOG_LEVEL = logging.DEBUG LOGFORMAT = "%(log_color)s%(message)s%(reset)s" logging.root.setLevel(LOG_LEVEL) formatter = ColoredFormatter(LOGFORMAT) stream = logging.StreamHandler() stream.setLevel(LOG_LEVEL) stream.setFormatter(formatter) logger = logging.getLogger('colorlogger') logger.setLevel(LOG_LEVEL) logger.addHandler(stream) sc = SongCollection() tl = TrackLister(sc) dj = DjController(tl) essentia.log.infoActive = False essentia.log.warningActive = False if request.method == "POST": cmd = request.POST.get("cmd", None) cmd = str(cmd) # cmd_split = str(cmd).split # cmd = cmd_split[0] while (True): # try: # cmd_split = str.split(input('> : '), ' ') # except KeyboardInterrupt: # logger.info('Goodbye!') # break # cmd = cmd_split[0] # if cmd == 'loaddir': # if len(cmd_split) == 1: # return HttpResponse('Please provide a directory name to load!') # continue # elif not os.path.isdir(cmd_split[1]): # return HttpResponse(cmd_split[1] + ' is not a valid directory!') # continue message = "abc" sc.load_directory("/home/ddman/音樂/upload") message = str(len(sc.songs)) + ' songs loaded [annotated: ' + str( len(sc.get_annotated())) + ']' if cmd == 'play': if len(sc.get_annotated()) == 0: message = 'Use the loaddir command to load some songs before playing!' continue # if len(cmd_split) > 1 and cmd_split[1] == 'save': # message = 'Saving this new mix to disk!' # save_mix = True # else: # save_mix = False message = 'Starting playback!' try: dj.play(save_mix=False) except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'pause': message = 'Pausing playback!' try: dj.pause() except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'skip' or cmd == 's': message = 'Skipping to next segment...' try: dj.skipToNextSegment() except Exception as e: logger.error(e) return render(request, "Index.html", locals()) elif cmd == 'stop': message = 'Stopping playback!' dj.stop() return render(request, "Index.html", locals()) elif cmd == 'save': message = 'Saving the next new mix!' return render(request, "Index.html", locals()) elif cmd == 'showannotated': message = 'Number of annotated songs ' + str( len(sc.get_annotated())) message = 'Number of unannotated songs ' + str( len(sc.get_unannotated())) return render(request, "Index.html", locals()) elif cmd == 'annotate': message = 'Started annotating!' sc.annotate() message = 'Done annotating!' return render(request, "Index.html", locals()) elif cmd == 'debug': LOG_LEVEL = logging.DEBUG logging.root.setLevel(LOG_LEVEL) stream.setLevel(LOG_LEVEL) logger.setLevel(LOG_LEVEL) message = 'Enabled debug info. Use this command before playing, or it will have no effect.' return render(request, "Index.html", locals()) elif cmd == 'mark': dj.markCurrentMaster() return render(request, "Index.html", locals()) elif cmd == "quit": break return render(request, "Index.html", locals()) else: message = 'The command ' + str(cmd) + ' does not exist!' return render(request, "Index.html", locals()) return render(request, "Index.html", locals())