def AutoMusic(self, parent, page_type, loadpic, waitpic, incontainer, outcontainer, records, music): """ This is a callback function for 'Generate' button. It takes the selected inputs from the listbox, make an AutoComposeSong object, and execute its functions to output a MIDI file. * See 'AutoComposeSong.py' for the detailed explanation on how these methods work. """ genre = self.genreList[int(self.gr_listbox.curselection()[0])] key = eval(self.keyList[int(self.key_listbox.curselection()[0])]) cp = self.cpList[int(self.cp_listbox.curselection()[0])] title = self.title.get() mode = Tonics numPhrase = 4 beat = 72 if self.entry_field.get() == '': userInput = [] else: userInput = Song() userInput.reset() userInputMelody = wrapNote(self.entry_field.get().split('-')) userInputTimes = constant_times(userInputMelody, 2, beat) userInput.wrapNotesAndTimes(userInputMelody, userInputTimes) autoSong = AutoComposeSong() autoSong.reset() autoSong.setTitle(title) autoSong.setup(genre, key, mode, cp, numPhrase, beat, userInput) autoSong.exportMidi(1, 'Output MIDIs/' + title + '.mid') self.page_factory(parent, page_type, loadpic, waitpic, incontainer, outcontainer, records, autoSong)
return wrapNote(notes) if __name__ == '__main__': autoSong = AutoComposeSong('Test') # Example Inputs genre = 'New Age' key = B mode = Tonics chordProgression = CP2 numPhrase = 80 beat = 48 # Excerpt from 'River Flows in You', by Yiruma inputNotes = wrapNote([69, 68, 69, 68, 69, 64, 69, 62]) inputTimes = [72, 144, 216, 288, 360, 432, 504, 578] userInput = Song() userInput.wrapNotesAndTimes(inputNotes, inputTimes) userInput = [] # Export the Automated Song autoSong.setup(genre, key, mode, chordProgression, numPhrase, beat, userInput) autoSong.exportMidi(1, 'TEST.mid') print autoSong