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

Num deck streamline #14112

Open
wants to merge 11 commits into
base: 2.5
Choose a base branch
from
Open

Num deck streamline #14112

wants to merge 11 commits into from

Conversation

daschuer
Copy link
Member

@daschuer daschuer commented Jan 3, 2025

This mainly fixes a lifetime issue with the non owning

static QAtomicPointer<ControlProxy> PlayerManager::m_pCOPNumDecks;

Since it is non owning it can become dangling. I have fixed it by moving it as a PollingControlProxy to the singleton PlayerInfo class

auto deck1 = m_pPlayerManager->getDeck(1);
auto deck1 = m_pPlayerManager->getDeck(0);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Member Author

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);
Copy link
Member Author

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

@daschuer daschuer changed the base branch from main to 2.5 January 3, 2025 16:40
Comment on lines 39 to 40
// 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;
Copy link
Member

Choose a reason for hiding this comment

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

Why this replacement?

Copy link
Member Author

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.

@@ -14,10 +14,16 @@ constexpr int kPlayingDeckUpdateIntervalMillis = 2000;

PlayerInfo* s_pPlayerInfo = nullptr;

const QString kAppGroup = QStringLiteral("[App]");
const QString kMasterGroup = QStringLiteral("[Master]");
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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.

@daschuer
Copy link
Member Author

This should be now ready

@ronso0 ronso0 changed the title Num deck steamline Num deck streamline Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants