![]() Track.append(mido.Message('note_on', channel=0, note=60, velocity=100, time=0)) Track.append(mido.MetaMessage('end_of_track', time=0)) It seems to be a problem with the blank midi creation and appending as I created this code that manually copied messages from a short midi files and they were still sounded wrong (slower) when played. # create a blank midi file and add a track to it # get the list of midi files from regulate_tracks This is the reconstructing code: import mido Msgwithtempos = remove_extra_tempo(msg, msgwithtempos, current_time)ĭef main(): # for each midi file do the followingĪll_messages, msgwithtempos = do_shit(mid, all_messages)įinal_messages = all_messages + msgwithtemposįinal_messages = sorted(final_messages, key=lambda x: x) If msgwithtempo = current_time: # this checks duplicatesĭef do_shit(mid, all_messages): # for each track (then message) do the following If not msgwithtempos: # if the list is empty # removes tempo duplicates and only keeps the last tempo stated for a particular cumulative timeĭef remove_extra_tempo(msg, msgwithtempos, current_time): Return True if msg.type in accept else False ![]() # check is midi file is type 2 (and removes if so) - this is unlikely but can happen on old sitesĪccept = This is the deconstructing and list building code: In the case of some files (for example the Bohemian Rhapsody file) the instrumental parts also seem to be detached and muddled. The reconstructed tracks either seem to be playing too fast or too slow. The major problem I seem to be encountering is the timing/tempo. The second part of the code adjusts the delta time of each item in this list and then appends all the messages from the list in order (with the corrected delta times) onto a track created from scratch. The first does all the filtering and constructs a big list of lists, where the first item in each sub-list is the message itself and second item in each sub-list is the cumulative time (and this is sorted by cumulative time as stated above). I realise this may seem pointless (as I am trying to construct the same song just cleaner), however the purpose is to have nicer data to then do other stuff with. The delta time is then adjusted accordingly (keeping in mind that each new midi track starts from cumulative time 0). This is then used to create a new mido file (from scratch) where I append all of these messages into one track (so essentially the tracks are merged)and sort them by cumulative time. It also calculated the cumulative time (as the time in each midi message is in delta time). I have written a program that takes in a MIDI file, then using Mido, it cleans the data by removing particular types of meta data, repeat messages, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |