Spaces:
Running
Running
import os | |
from mido import MidiFile | |
#number of notes to be used for prediction | |
window = 3 | |
#num of notes to generate | |
#TODO: change this to accept values according to user | |
num_notes = 100 | |
#midi ticks per quarter note, indicates tempo of track | |
quarter_note_ticks = 480 | |
#accepted note durations: ranges from 16th note to whole dotted notes | |
accepeted_lengths = [0.25,0.375,0.5,0.75,1,1.5,2.0,3.0,4.0] | |
#Finds all absolute paths in directory | |
#https://stackoverflow.com/questions/9816816/get-absolute-paths-of-all-files-in-a-directory | |
def abs_paths(dir): | |
for dir_path,_,filenames in os.walk(dir): | |
for f in filenames: | |
yield os.path.abspath(os.path.join(dir_path, f)) | |
def pitch_to_int(): | |
#TODO: look at this later | |
pass | |
if not os.path.exists('tracks'): | |
# os.mkdir('tracks') | |
i = 0 | |
#Parse midi files into tracks folder | |
for path in abs_paths('data'): | |
print(path) | |
mid = MidiFile(path) | |
for i, track in enumerate(mid.tracks): | |
print('Track {}: {}'.format(i, track.name)) | |
for message in track: | |
print(message) | |
break |