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

adjust timing of note events according to tempo changes #427

Merged
merged 3 commits into from
Feb 17, 2025

Conversation

huispaty
Copy link
Collaborator

@huispaty huispaty commented Feb 4, 2025

No description provided.

@huispaty huispaty self-assigned this Feb 5, 2025
Copy link
Member

@CarlosCancino-Chacon CarlosCancino-Chacon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice and swift bug fix! There are three points that could be addressed:

  1. Also adjusting the time of time and key signature messages, as well as meta messages
  2. For clarity, use the helper method midi_ticks_to_seconds (to make clear what the line is computed
  3. Adding typing annotations to adjust_time


perf = performance.Performance(
id=doc_name,
performedparts=pps,
)
return perf

def adjust_time(tick, tempo_changes, ppq):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add typing annotations to this function? (we should try to include this in more things going forward)

partitura/io/importmidi.py Show resolved Hide resolved
for change_tick, mpq in tempo_changes:
if tick < change_tick:
break
time += (change_tick - last_tick) * (last_mpq / (ppq * 10**6))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Maybe we can use the midi_ticks_to_seconds (from partitura.utils.music) method here, and also below, so that it is clear what this line is computing?. It would be something like

time += midi_ticks_to_seconds(midi_ticks=(change_tick - last tick), mpq=last_mpq, ppq=ppq)

(This would be mostly to make clear what this method is computing, but if you think that it makes things less clear, feel free to leave it as it is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I added all the changes accordingly and extended the test case to also check for changing time and key signatures.

…moved to pt util function for converting ticks to seconds
@CarlosCancino-Chacon CarlosCancino-Chacon merged commit a27e4f3 into develop Feb 17, 2025
3 checks passed
@CarlosCancino-Chacon CarlosCancino-Chacon deleted the performance_tempo_change branch February 17, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants