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 steamline #14112

Open
wants to merge 9 commits into
base: 2.5
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/controllers/midi/midicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "controllers/scripting/legacy/controllerscriptenginelegacy.h"
#include "defs_urls.h"
#include "errordialoghandler.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_midicontroller.cpp"
#include "util/make_const_iterator.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ void MidiController::createOutputHandlers() {
if (m_logBase().isDebugEnabled()) {
failures.append(errorLog);
} else if (PlayerManager::isDeckGroup(group, &deckNum)) {
int numDecks = PlayerManager::numDecks();
int numDecks = PlayerInfo::instance().numDecks();
if (deckNum <= numDecks) {
failures.append(errorLog);
}
Expand Down
4 changes: 3 additions & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ void CoreServices::initialize(QApplication* pApp) {
// Load tracks in args.qlMusicFiles (command line arguments) into player
// 1 and 2:
const QList<QString>& musicFiles = m_cmdlineArgs.getMusicFiles();
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) {
if (SoundSourceProxy::isFileNameSupported(musicFiles.at(i))) {
m_pPlayerManager->slotLoadToDeck(musicFiles.at(i), i + 1);
}
Expand Down
5 changes: 2 additions & 3 deletions src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ AutoDJProcessor::AutoDJProcessor(

// TODO(rryan) listen to signals from PlayerManager and add/remove as decks
// are created.
for (unsigned int i = 0; i < pPlayerManager->numberOfDecks(); ++i) {
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.

// Shouldn't be possible.
VERIFY_OR_DEBUG_ASSERT(pPlayer) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion src/library/banshee/bansheeplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "library/dao/trackschema.h"
#include "library/queryutil.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_bansheeplaylistmodel.cpp"
#include "track/track.h"
Expand Down Expand Up @@ -363,6 +364,6 @@ QString BansheePlaylistModel::getTrackLocation(const QModelIndex& index) const {

bool BansheePlaylistModel::isColumnInternal(int column) {
return (column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
(PlayerManager::numPreviewDecks() == 0 &&
(PlayerInfo::instance().numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)));
}
3 changes: 2 additions & 1 deletion src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "library/queryutil.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_baseexternalplaylistmodel.cpp"
#include "track/track.h"
Expand Down Expand Up @@ -82,7 +83,7 @@ TrackId BaseExternalPlaylistModel::getTrackId(const QModelIndex& index) const {

bool BaseExternalPlaylistModel::isColumnInternal(int column) {
return column == fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_TRACKID) ||
(PlayerManager::numPreviewDecks() == 0 &&
(PlayerInfo::instance().numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW));
}

Expand Down
3 changes: 2 additions & 1 deletion src/library/baseexternaltrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "library/dao/trackschema.h"
#include "library/queryutil.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_baseexternaltrackmodel.cpp"
#include "track/track.h"
Expand Down Expand Up @@ -110,7 +111,7 @@ TrackId BaseExternalTrackModel::doGetTrackId(const TrackPointer& pTrack) const {

bool BaseExternalTrackModel::isColumnInternal(int column) {
return column == fieldIndex(LIBRARYTABLE_ID) ||
(PlayerManager::numPreviewDecks() == 0 &&
(PlayerInfo::instance().numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW));
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ QAbstractItemDelegate* BaseTrackTableModel::delegateForColumn(
return new BPMDelegate(pTableView);
} else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED)) {
return new CheckboxDelegate(pTableView, QStringLiteral("LibraryPlayedCheckbox"));
} else if (PlayerManager::numPreviewDecks() > 0 &&
} else if (PlayerInfo::instance().numPreviewDecks() > 0 &&
index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) {
return new PreviewButtonDelegate(pTableView, index);
} else if (index == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COMMENT)) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ bool BrowseTableModel::isColumnSortable(int column) const {
QAbstractItemDelegate* BrowseTableModel::delegateForColumn(const int i, QObject* pParent) {
WLibraryTableView* pTableView = qobject_cast<WLibraryTableView*>(pParent);
DEBUG_ASSERT(pTableView);
if (PlayerManager::numPreviewDecks() > 0 && i == COLUMN_PREVIEW) {
if (PlayerInfo::instance().numPreviewDecks() > 0 && i == COLUMN_PREVIEW) {
return new PreviewButtonDelegate(pTableView, i);
}
return nullptr;
Expand Down
12 changes: 6 additions & 6 deletions src/library/dao/autodjcratesdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ bool AutoDJCratesDAO::updateAutoDjPlaylistReferences() {
// Incorporate all tracks loaded into decks.
// Each track has to be done as a separate database query, in case the same
// track is loaded into multiple decks.
int iDecks = (int) PlayerManager::numDecks();
for (int i = 0; i < iDecks; ++i) {
int numDecks = PlayerInfo::instance().numDecks();
for (int i = 0; i < numDecks; ++i) {
QString group = PlayerManager::groupForDeck(i);
TrackPointer pTrack = PlayerInfo::instance().getTrackInfo(group);
if (pTrack) {
Expand Down Expand Up @@ -1103,8 +1103,8 @@ void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& group,
}
// This counts as an auto-DJ reference. The idea is to prevent tracks that
// are loaded into a deck from being randomly chosen.
unsigned int numDecks = PlayerManager::numDecks();
for (unsigned int i = 0; i < numDecks; ++i) {
int numDecks = PlayerInfo::instance().numDecks();
for (int i = 0; i < numDecks; ++i) {
if (group == PlayerManager::groupForDeck(i)) {
// Update the number of auto-DJ-playlist references to this track.
QSqlQuery oQuery(m_database);
Expand All @@ -1131,8 +1131,8 @@ void AutoDJCratesDAO::playerInfoTrackUnloaded(const QString& group,
}
// This counts as an auto-DJ reference. The idea is to prevent tracks that
// are loaded into a deck from being randomly chosen.
unsigned int numDecks = PlayerManager::numDecks();
for (unsigned int i = 0; i < numDecks; ++i) {
int numDecks = PlayerInfo::instance().numDecks();
for (int i = 0; i < numDecks; ++i) {
if (group == PlayerManager::groupForDeck(i)) {
// Get rid of the ID of the track in this deck.
QSqlQuery oQuery(m_database);
Expand Down
3 changes: 2 additions & 1 deletion src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "library/queryutil.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_librarytablemodel.cpp"

Expand Down Expand Up @@ -77,7 +78,7 @@ bool LibraryTableModel::isColumnInternal(int column) {
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_CHANNELS) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
(PlayerInfo::instance().numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
Expand Down
3 changes: 2 additions & 1 deletion src/library/trackset/tracksettablemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "library/trackset/tracksettablemodel.h"

#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_tracksettablemodel.cpp"

Expand All @@ -18,7 +19,7 @@ bool TrackSetTableModel::isColumnInternal(int column) {
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
(PlayerManager::numPreviewDecks() == 0 &&
(PlayerInfo::instance().numPreviewDecks() == 0 &&
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW)) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
Expand Down
24 changes: 21 additions & 3 deletions src/mixer/playerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ constexpr int kPlayingDeckUpdateIntervalMillis = 2000;

PlayerInfo* s_pPlayerInfo = nullptr;

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

} // namespace

PlayerInfo::PlayerInfo()
: m_pCOxfader(new ControlProxy("[Master]","crossfader", this)),
: m_xfader(kMasterGroup, QStringLiteral("crossfader")),
m_numDecks(kAppGroup, QStringLiteral("num_decks")),
m_numSamplers(kAppGroup, QStringLiteral("num_samplers")),
m_numPreviewDecks(kAppGroup, QStringLiteral("num_preview_decks")),
m_currentlyPlayingDeck(-1) {
startTimer(kPlayingDeckUpdateIntervalMillis);
}
Expand Down Expand Up @@ -135,15 +141,15 @@ void PlayerInfo::updateCurrentPlayingDeck() {
CSAMPLE_GAIN xfl, xfr;
// TODO: supply correct parameters to the function. If the hamster style
// for the crossfader is enabled, the result is currently wrong.
EngineXfader::getXfadeGains(m_pCOxfader->get(),
EngineXfader::getXfadeGains(m_xfader.get(),
1.0,
0.0,
MIXXX_XFADER_ADDITIVE,
false,
&xfl,
&xfr);

for (int i = 0; i < (int)PlayerManager::numDecks(); ++i) {
for (int i = 0; i < numDecks(); ++i) {
DeckControls* pDc = getDeckControls(i);

if (pDc->m_play.get() == 0.0) {
Expand Down Expand Up @@ -213,3 +219,15 @@ void PlayerInfo::clearControlCache() {
}
m_deckControlList.clear();
}

int PlayerInfo::numDecks() const {
return static_cast<int>(m_numDecks.get());
}

int PlayerInfo::numPreviewDecks() const {
return static_cast<int>(m_numPreviewDecks.get());
}

int PlayerInfo::numSamplers() const {
return static_cast<int>(m_numSamplers.get());
}
21 changes: 15 additions & 6 deletions src/mixer/playerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <QMutex>
#include <QObject>

#include "control/controlproxy.h"
#include "control/pollingcontrolproxy.h"
#include "track/track_decl.h"

class PlayerInfo : public QObject {
Expand All @@ -24,6 +24,10 @@ class PlayerInfo : public QObject {
bool isTrackLoaded(const TrackPointer& pTrack) const;
bool isFileLoaded(const QString& track_location) const;

int numDecks() const;
int numPreviewDecks() const;
int numSamplers() const;

signals:
void currentPlayingDeckChanged(int deck);
void currentPlayingTrackChanged(TrackPointer pTrack);
Expand All @@ -39,10 +43,10 @@ class PlayerInfo : public QObject {
m_orientation(group, "orientation") {
}

ControlProxy m_play;
ControlProxy m_pregain;
ControlProxy m_volume;
ControlProxy m_orientation;
PollingControlProxy m_play;
PollingControlProxy m_pregain;
PollingControlProxy m_volume;
PollingControlProxy m_orientation;
};

void clearControlCache();
Expand All @@ -54,7 +58,12 @@ class PlayerInfo : public QObject {
~PlayerInfo() override;

mutable QMutex m_mutex;
ControlProxy* m_pCOxfader;

PollingControlProxy m_xfader;
PollingControlProxy m_numDecks;
PollingControlProxy m_numSamplers;
PollingControlProxy m_numPreviewDecks;

// QMap is faster than QHash for small count of elements < 50
QMap<QString, TrackPointer> m_loadedTrackMap;
QAtomicInt m_currentlyPlayingDeck;
Expand Down
Loading
Loading