-
Notifications
You must be signed in to change notification settings - Fork 206
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
Quantisation of events and notes #327
Conversation
5f42a17
to
7ebc0ff
Compare
f3be7c1
to
f510251
Compare
5525cfc
to
7f39a86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the code is fine, but I suggest some changes to documentation and the function signature.
madmom/utils/__init__.py
Outdated
def quantize_notes(notes, fps, length=None, num_notes=None, shift=None, | ||
offset=None, velocity=None): | ||
""" | ||
Quantize the notes with the given resolution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description needs to be elaborated. I would expect that "quantizing the notes" would "snap" their start and end points to a grid. This function, however, does something else. I'm not sure how to describe this concisely...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a more descriptive docstring.
madmom/utils/__init__.py
Outdated
length : int, optional | ||
Length of the returned array. If 'None', the length will be set | ||
according to the latest sounding note. | ||
num_notes : int, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this parameter is easily confused with the "number of notes in the notes array". Maybe changing the description to something like "Number of possible pitches"? Not sure...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to num_pitches
.
madmom/utils/__init__.py
Outdated
will be based on the highest note number in the `notes` array. All note | ||
numbers equal or greater this value will not be included in the | ||
returned quantized array. | ||
shift : float, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think shift
or offset
should be part of this function.
- It is very easy to implement both outside of the function
- It makes the function signature unnecessarily complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, at least for offset
. On the other hand, since shift
can be a float and rounding is used inside the function, moving this outside the function may introduces more errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO the following is not more error-prone:
notes[:, 0] += 2.3
qnotes = quantize_notes(notes)
than this:
qnotes = quantize_notes(notes, shift=2.3)
If there is a common use case for the shift, then the second option is fine, but if it is a special case, I vote for the first one, because I think a function should do only one thing, if possible. That said, I don't have a strong opinion on this specific case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I somehow only considered applying the shift after calling the function... I will remove it (and deprecate shift in quantize_events
).
02e69ee
to
19a2530
Compare
madmom/utils/__init__.py
Outdated
If no `length` and `num_pitches` are given the values are inferred from the | ||
notes. Then each note is put into the column corresponding to its pitch | ||
and all frames between the note's onset and offset (i.e. onset + duration) | ||
are set to the velocity of the note. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already much better! I would try to describe what the function does, and not how it does it, maybe like this:
"Create a sparse 2D array whose rows correspond to points in time (according to fps
and length
), and columns to note pitches (according to num_pitches
). The values of the array correspond to the velocity of a pitch at a given point in time (based on the note pitch, onset, duration, and velocity). If no values for length
and num_pitches
are given, they are inferred from notes
."
madmom/utils/__init__.py
Outdated
Number of pitches of the returned array. If 'None', the number of | ||
pitches will be based on the highest pitch in the `notes` array. | ||
shift : float, optional | ||
Shift the events by `shift` seconds before quantization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep the shift
parameter, I think it should say "Shift the notes...
I think there was a comment of yours about renaming of the function to |
98cf7ec
to
a116526
Compare
Changes proposed in this pull request
This pull request fixes #325.