-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Beats: Remove legacy BeatIterator class in favor of std iterator #4411
Conversation
8bbf954
to
98ae786
Compare
The custom, legacy iterator API was only used for rendering beats on the waveform and for importing beats from Serato BeatGrids. Since the new iterator API is way more powerful and can be used with the iterator-based functions from `<algorithm>`, it makes sense to replace the only occurrence and then remove the old API entirely.
98ae786
to
80a9247
Compare
Ok, ready to review. |
80a9247
to
98ed207
Compare
@@ -79,8 +81,8 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) { | |||
|
|||
int beatCount = 0; | |||
|
|||
while (it->hasNext()) { | |||
double beatPosition = it->next().toEngineSamplePos(); | |||
for (; it != trackBeats->clatest() && *it <= endPosition; ++it) { |
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.
Sorry for jumping in here, after merging #4255, but it I have discovered now that I have not fully understand the concept of clatest() and cend()
Unfortunately there are zero comments in beats.h explaining this. Can you catch up that in this PR?
I think I have read the original commit as if clatest()++ = cend() but It turns out that this is wrong.
Maybe we can improve the naming a bit.
Here, I have hard time to understand how the new code id equivalent to the old.
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 added some comments to beats.h
in 9480561.
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.
Basically the it != clatest()
check prevents an integer overflow here.
Ah Ok, thank you for the comments. The confusing part was/is that this "violates" some regular laws around iterators. Normally you should never access the end() iterator value and never continue to iterate it, because the result is undefined and is a risk for a segfault. This is done here regularly, because clatest takes this role. This was the source if my confusion. I also expect that various helper functions will follow the normal iterator rules, which leads to dificult understand call trees and side effects. How about introducing two type of iterators? Alternatively we may rename the clatest() to cend() and introduce a new one cAnotatonEnd() or something that expresses the implication that it is appropriate to fetch beats after the end of the anotaded beats. |
My reasoning was that Hence,
Yes, I'm open to rename |
Thank you to consider this.
My idea was that we have two or more types of iterators for the differen ways to iterate over the beats. All of them can use begin() and end() as you may expect from any iterator and specialized for the range you need. Maybe we can also introduce different container types as "view" in the original container. Like "all annotated beats view" "all beat view unlimited" "measures view" "downbeat view" or whatever we need. Just an idea ... |
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.
LGTM
Merge? What do you think to the "view" idea? |
Yup.
I don't think we need two different classes, but maybe a dedicated iterator for beat markers could make sense. In general, we already have that because you can iterate over the beat marker vector instead of iterating over individual beats. I need to think about that some more. However, I can open a PR which renames the methods as a first step soon. |
Thank you. |
The custom, legacy iterator API was only used for rendering beats on the
waveform and for importing beats from Serato BeatGrids.
Since the new iterator API is way more powerful and can be used
with the iterator-based functions from
<algorithm>
, it makes sense toreplace the only occurrence and then remove the old API entirely.
Based on #4255.