I'm playing with the music generation project "Magenta" made by TensorFlow.
Reference: [Let Sakanaction learn from TensorFlow's art and music generation project "Magenta". ] (http://qiita.com/tackey/items/1295a0347a8b4cc30d46)
As a pre-process, I found out that I wanted to play with MIDI files in Python, and it seemed that Magenta was using pretty_midi. In this post, I'll run the sample pretty_midi 0.2.6 documentation to see how pretty_midi works.
Write the sample code and comments.
import pretty_midi # Create a PrettyMIDI object #Create a Pretty MIDI object. cello_c_chord = pretty_midi.PrettyMIDI() # Create an Instrument instance for a cello instrument #Create an Instrument Instance. Here Cello #Enter the instrument name and it will return the corresponding General MIDI program number cello_program = pretty_midi.instrument_name_to_program('Cello') #Create Instrument instance as Cello cello = pretty_midi.Instrument(program=cello_program) # Iterate over note names, which will be converted to note number later #The melody is described by NoteName, but it will be converted to NoteNumber later. for note_name in ['C5', 'E5', 'G5']: # Retrieve the MIDI note number for this note name #Searching for Note Number from Note Name. note_number = pretty_midi.note_name_to_number(note_name) # Create a Note instance, starting at 0s and ending at .5s #Create a NoteInstance. sound(pitch)Start time and end time, #Define velocity. note = pretty_midi.Note( velocity=100, pitch=note_number, start=0, end=.5) # Add it to our cello instrument #Add the NoteInstance created above to the Cello Instrument. cello.notes.append(note) # Add the cello instrument to the PrettyMIDI object #Add the Chello Instrument to the PrettyMIDI object. cello_c_chord.instruments.append(cello) # Write out the MIDI data #Export a PrettyMIDI object as a MIDI file. cello_c_chord.write('cello-C-chord.mid')
A MIDI file with a domiso sound of 0.5 seconds (1 beat at 120 BPM) has been created. (Displayed in logic X)
Next, I would like to read an existing MIDI file and divide the file for each instrument.
Thank you very much.