![]() ![]() In this code, we have added a durations list which specifies the length of each note in beats. With open("simple_tune.mid", "wb") as output_file: Midi.addNote(0, 0, note, i+duration, duration, 0) Midi.addNote(0, 0, note, i, duration, 100) # use a for loop to add each note to the trackįor i, (note, duration) in enumerate(zip(notes, durations)): # create a list of notes and durations to add to the trackĭurations = Midi.addTrackName(0, 0, "My Simple Tune") # create the MIDIFile object with 1 track Here is an updated version of the code that allows for different note lengths: from midiutil.MidiFile import MIDIFile Sure, we can use the duration parameter in the addNote method to specify the length of each note. Note that at some points I had to edit previous sections of the conversation, so what you’re seeing is just the end result. (I couldn’t get it to play Happy Birthday.)Įventually I settled for python and got my first song!īelow is the full annotated conversation. So I tried combinations of “Write a program in R/python/bash that crates a simple tune.” I could get valid MIDI notation, but it was just gibberish.īut then I remembered a trick I’d seen posted on twitter: GPT can be bad at giving answers, but it can be good at creating code that returns the answer. Then, I remembered that MIDI files can be encoded as text, so I asked it to create a MIDI text for the tune. ![]() ![]() I don’t know enough of ABC notation, though, so that could be also my fault. There are several ways to represent music with text.Īt first I tried with ABC Notation, but asking it to create the ABC notation of the Happy Birthday tune resulted in invalid notation and I wasn’t able to nudge it to correct it. Having failed with images, I turned my attention to music. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |