[go: up one dir, main page]

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

Added id to Clip #7617

Closed
wants to merge 1 commit into from
Closed

Conversation

igorkorsukov
Copy link
Collaborator

No description provided.

TrackId() : mValue(-1) {}
explicit TrackId (long value) : mValue(value) {}
TrackId() = default;
explicit TrackId (int64_t value) : mValue(value) {}

bool operator == (const TrackId &other) const

Choose a reason for hiding this comment

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

You’ve got == and <, but no !=. If someone tries to check if two TrackIds aren’t equal, they’ll be out of luck.
Add an operator!= for consistency, or if you're feeling fancy, use std::strong_ordering if you're on C++20.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an AU3 class, it is designed as designed.
We do not refactor or improve AU3 classes.
We only make the minimum necessary changes to apply them to AU4

Choose a reason for hiding this comment

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

So who and how do we decide what is considered minimum?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the author of the changes is obvious. He knows what he needs to change minimally in AU3 to achieve his goal. If he didn't do something, then it's probably not necessary to achieve the goal.

TrackId() : mValue(-1) {}
explicit TrackId (long value) : mValue(value) {}
TrackId() = default;
explicit TrackId (int64_t value) : mValue(value) {}

Choose a reason for hiding this comment

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

Nice!! (good use of explicit)

private:
long mValue;
int64_t mValue = -1;

Choose a reason for hiding this comment

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

-1 is used here as a "special" value, but this can be risky if the rest of the code doesn’t expect it. Plus, there's no guarantee that TrackId is always initialised properly if someone bypasses the constructors.
Why not use std::optional<int64_t> for mValue instead to make it clear when the ID is valid or not, or make sure that the class can’t be misused without proper initialisation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

private:
long mValue;
int64_t mValue = -1;

Choose a reason for hiding this comment

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

Stop using -1 as a “magic” value to represent an uninitialized state. This can be confusing and easily misinterpreted as a valid ID. Instead, use std::optional<int64_t>, which explicitly shows whether the ID is set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tell us more here, usually they don't use optinal for ID because they need performance, very often they search by ID, for example... What is your experience using optinal in such cases?

TrackId() : mValue(-1) {}
explicit TrackId (long value) : mValue(value) {}
TrackId() = default;
explicit TrackId (int64_t value) : mValue(value) {}

bool operator == (const TrackId &other) const

Choose a reason for hiding this comment

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

Add the missing comparison operators. Defining and < leaves TrackId with incomplete comparisons.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -220,10 +220,14 @@ double WaveClipChannel::GetStretchRatio() const
return GetClip().GetStretchRatio();
}


static int64_t s_lastClipId = 0;

WaveClip::WaveClip(size_t width,

Choose a reason for hiding this comment

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

WaveClip::WaveClip(size_t width, const SampleBlockFactoryPtr &factory, sampleFormat format, int rate)
: mId(++s_lastClipId), mRate(rate), mSequences(width) {
assert(width > 0);
}
In the constructor, initialize member variables directly in the initializer list rather than in the body. For instance, mId, mRate, and mSequences.resize(width) should ideally be in the initializer list:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made in accordance with the current AU3 style

@@ -27,10 +26,10 @@ Au3WaveTrack* DomAccessor::findWaveTrack(Au3Project& prj, const Au3TrackId& au3t
return dynamic_cast<Au3WaveTrack*>(findTrack(prj, au3trackId));
}

std::shared_ptr<Au3WaveClip> DomAccessor::findWaveClip(Au3WaveTrack* track, uint64_t au3ClipId)
std::shared_ptr<Au3WaveClip> DomAccessor::findWaveClip(Au3WaveTrack* track, int64_t au3ClipId)
{
for (const std::shared_ptr<Au3WaveClip>& interval : track->Intervals()) {
Copy link
@GrigorasGabriel36 GrigorasGabriel36 Oct 25, 2024

Choose a reason for hiding this comment

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

Using auto shortens things up and still keeps everything clear, especially when the types get a bit lengthy.
Also the type here does not bring and benefit as you are not using the type...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why do you think it's better to use auto? it's not clear what type we're dealing with when we review or read the code

@grliszas14
Copy link
Contributor

I like that and I know that we wanted to do this thing from a long time but we simply couldn't, but:
I'd like to merge that PR only after a good testing from QA - I just opened this build quickly and immediately noticed that I can't copy clips to any place except an empty space. There are a lot of things that can get broken here (and we won't notice it) and also it's highly probable that it conflicts with most of our PR's that await for QA (so when we resolve conflicts we won't know where to quickly look for the bugs it those are found)

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

Successfully merging this pull request may close these issues.

5 participants