Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get metric time of notes in midi track. #164

Closed
NeroBlackstone opened this issue May 18, 2023 · 5 comments
Closed

Get metric time of notes in midi track. #164

NeroBlackstone opened this issue May 18, 2023 · 5 comments

Comments

@NeroBlackstone
Copy link
Member

For now, there is no function to get the metric time of notes in the midi track.

Proposal:
If we have a note from midi.track, then we can get metric time use:

# get the onset time of a note in milliseconds
onset_metric_time(midi_file, note)
# get the duration of a note in milliseconds
duration_metric_time(midi_file, note)

Describe the solution you'd like
I'm not very familiar with MIDI file, but here are my thoughts about onset_metric_time:

# get all tempo change qpm
tc_tuples = tempochanges(midi)
# all tempo change before note
tc_before = all_tuples_before_note_position(tc_tuples, note)
# tempo of note
latest_tempo_change = max_position_tempo(tc_before)
# passed by metric time before the latest tempo change
time_before = reduce(+, calculate_time(tc_before, latest_tempo_change))
# passed by time after the latest tempo change
change_pos, qpm = latest_tempo_change
time_now = (note.position - change_pos)  * ms_per_tick(midi.tpq,qpm)

onset_metric_time = time_before + time_now

I don't know if this is correct, I want to implement this feature. Do you willing to give me some advice?

@MarkNahabedian
Copy link

I'm trying to do something even simpler. I have a simple track which has no tempo changes. I just want to determine the absolue tick for the start and end of each note.

My problem is that the documentation doesn't describe what "dT::Int : Delta time in ticks." is a delta between. The minuend is clearly the tick of the current event. Is the subtrahend the dT of the immediately previous event in the track, the immediately previous note event, or something else?

@Datseris
Copy link
Member

dT is delta time (in ticks) from previous event.

@Datseris
Copy link
Member

I just want to determine the absolue tick for the start and end of each note.

Isn't this just the note position and the note position + note duration...?

@NeroBlackstone
Copy link
Member Author

☺️ Close this issue since codes are merged.

@MarkNahabedian
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants