-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Num deck streamline #14112
base: 2.5
Are you sure you want to change the base?
Num deck streamline #14112
Conversation
…c lifetime issues.
auto deck1 = m_pPlayerManager->getDeck(1); | ||
auto deck1 = m_pPlayerManager->getDeck(0); |
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.
our [ChannelN]
COs are 1-based while this is now 0-based. Is that really an improvement? I'm concerned this will cause confusion and off-by-one errors later.
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 point out the downside of the change.
The benefit is that it now matches PlayerManager::groupForDeck(i)
and pevents cases where we have to + 1 before the call and - 1 after it.
Like here: (I will also place an inline comment)
for (int i = 0; i < m_pPlayerManager->numberOfSamplers(); ++i) {
In addition there was a naming clash with Index vs. Number.
In general we should stick to the rule to use 0 based counting inside the code base and 1 base in all user visible cases.
Please have a second look. If you still think we should keep the 1 based index here I will fix the issue in that direction.
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.
Thank you for the explanation. I see the tension there. I too prefer 0-based indexing. I will take a second look.
QString group = PlayerManager::groupForDeck(i); | ||
BaseTrackPlayer* pPlayer = pPlayerManager->getPlayer(group); | ||
for (int i = 0; i < pPlayerManager->numberOfDecks(); ++i) { | ||
BaseTrackPlayer* pPlayer = pPlayerManager->getDeckBase(i); |
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.
Here we benefit form the 0 base.
for (unsigned int i = 0; i < m_pPlayerManager->numSamplers(); ++i) { | ||
Sampler* pSampler = m_pPlayerManager->getSampler(i + 1); | ||
for (int i = 0; i < m_pPlayerManager->numberOfSamplers(); ++i) { | ||
Sampler* pSampler = m_pPlayerManager->getSampler(i); |
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.
Here we benefit form the 0 based index
src/mixer/playermanager.h
Outdated
// Get the deck by its deck number. Decks are numbered starting with 1. | ||
virtual Deck* getDeck(unsigned int player) const = 0; | ||
// Get the deck by its deck index | ||
virtual BaseTrackPlayer* getDeckBase(int deckIndex) const = 0; |
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.
Why this replacement?
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.
This interface allows the unittest to return a mocked Deck instead of the real one. I will add a comment. Before getPlayer()
has been used, which requires a QString group for lookup. I will add a comment.
53ab2c0
to
b47a282
Compare
Co-authored-by: Swiftb0y <[email protected]>
b47a282
to
6ec70aa
Compare
@@ -14,10 +14,16 @@ constexpr int kPlayingDeckUpdateIntervalMillis = 2000; | |||
|
|||
PlayerInfo* s_pPlayerInfo = nullptr; | |||
|
|||
const QString kAppGroup = QStringLiteral("[App]"); | |||
const QString kMasterGroup = QStringLiteral("[Master]"); |
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.
Can we use [Main]
instead here? I believe the [Master]
group is deprecated
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.
That's nothing we can do in a stable branch. We need to introduce an alias. I don't want to do it in this PR. Let's keep it separate.
@@ -155,9 +155,8 @@ AutoDJProcessor::AutoDJProcessor( | |||
|
|||
// TODO(rryan) listen to signals from PlayerManager and add/remove as decks |
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 know it's not related to your change, but anything we can do about this 10yo+ TODO?
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.
Done.
for (int i = 0; i < (int)m_pPlayerManager->numDecks() && i < musicFiles.count(); ++i) { | ||
const int numTracks = std::min(m_pPlayerManager->numberOfDecks(), | ||
static_cast<int>(musicFiles.count())); | ||
for (int i = 0; i < numTracks; ++i) { |
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.
What's the benefit of preincr vs postincr? Is this preferred?
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++
was the original one preferred in C and the origin of the name for C++. In C++ itself ++i
is preferred if possible, because it returns the incremented value and not the original one which is considered to be faster in case of complex types, because the original one does not need to be kept in memory. In this particular case the optimized machine code will most likely be the same anyway because the return value is not used.
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.
Thanks for the detailed explanation. I knew about the usecase where using the value, but I was wondering if there is reason why you would use this form when the value is irrelevant. Is that something we should unify? I know we have a few for-loop which use the two form, beside no apparent reason for switching between the two forms
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 really mind. Both is correct and readable in this case IMHO.
…ware of new decks.
This should be now ready |
This mainly fixes a lifetime issue with the non owning
Since it is non owning it can become dangling. I have fixed it by moving it as a PollingControlProxy to the singleton PlayerInfo class