Skip to content

Commit

Permalink
time scale is better now
Browse files Browse the repository at this point in the history
  • Loading branch information
ekm507 committed Jul 5, 2020
1 parent 1de1ce9 commit ecf1443
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions read_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

def read_midi(filename:str) -> list:
midiFile = mido.MidiFile(filename)
tempoRate = 1
tickTime = 1
time_scale = midiFile.ticks_per_beat * tempoRate
tempo = 500000 # default tempo
time_scale = mido.tick2second(1, midiFile.ticks_per_beat , tempo)

notes_temp = dict()
notes = []
time = 0
kk = set()

for track in midiFile.tracks:
time = 0
for note in track:
if note.type in ['note_on', 'note_off']:
#TODO: get true time scale from midi file data
time += note.time / 10000.0 * 3
time += note.time * time_scale
if note.type == 'note_on':
notes_temp[note.note] = (time, note.velocity)
elif note.type == 'note_off':
Expand All @@ -22,5 +27,10 @@ def read_midi(filename:str) -> list:
notes.append( (noteNumber, startTime, noteDuration, velocity) )
except KeyError:
pass

return notes
elif note.type == 'set_tempo':
tempo = note.tempo
time_scale = mido.tick2second(tickTime, midiFile.ticks_per_beat , tempo)
# else:
# print(note) # for debugging and deveeloping

return notes

0 comments on commit ecf1443

Please sign in to comment.