From daf5eaddf2782c23b5cf6da39049d44e98b3a2e9 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Tue, 13 Feb 2024 10:26:24 +0100 Subject: [PATCH] Revert "Samplers: don't create unneeded empty samplers during startup" This reverts commit cf9b4816add835ff5eee561141eabec771a16c56. --- src/mixer/playermanager.cpp | 7 +---- src/mixer/samplerbank.cpp | 63 ++++++++++++++----------------------- src/mixer/samplerbank.h | 3 +- 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/src/mixer/playermanager.cpp b/src/mixer/playermanager.cpp index 08cbbdf66b8..a70dc1f32d5 100644 --- a/src/mixer/playermanager.cpp +++ b/src/mixer/playermanager.cpp @@ -450,12 +450,7 @@ void PlayerManager::addDeckInner() { } void PlayerManager::loadSamplers() { - // This is only called by CoreServices during startup to restore - // samplers from the previous session. - // We don't want it to create more players than necessary. - bool dontCreateEmptySamplers = true; - m_pSamplerBank->loadSamplerBankFromPath(getDefaultSamplerPath(m_pConfig), - dontCreateEmptySamplers); + m_pSamplerBank->loadSamplerBankFromPath(getDefaultSamplerPath(m_pConfig)); } void PlayerManager::addSampler() { diff --git a/src/mixer/samplerbank.cpp b/src/mixer/samplerbank.cpp index 647cc269634..4e03f6cdea7 100644 --- a/src/mixer/samplerbank.cpp +++ b/src/mixer/samplerbank.cpp @@ -165,8 +165,7 @@ void SamplerBank::slotLoadSamplerBank(double v) { } } -bool SamplerBank::loadSamplerBankFromPath(const QString& samplerBankPath, - bool dontCreateEmptySamplers) { +bool SamplerBank::loadSamplerBankFromPath(const QString& samplerBankPath) { // The user has picked a new directory via a file dialog. This means the // system sandboxer (if we are sandboxed) has granted us permission to this // folder. We don't need access to this file on a regular basis so we do not @@ -196,47 +195,31 @@ bool SamplerBank::loadSamplerBankFromPath(const QString& samplerBankPath, return false; } - const auto samplerNodes = root.childNodes(); - if (samplerNodes.isEmpty()) { - return true; - } - for (int i = 0; i < samplerNodes.size(); i++) { - QDomNode n = samplerNodes.at(i); - QDomElement e = n.toElement(); - if (e.isNull() || e.tagName() != "sampler") { - continue; - } + QDomNode n = root.firstChild(); - const QString group = e.attribute("group", ""); - const QString location = e.attribute("location", ""); - int samplerNum; - - if (group.isEmpty() || !m_pPlayerManager->isSamplerGroup(group, &samplerNum)) { - continue; - } - - // During startup we only increase the sampler count if there is - // a track to be loaded. This avoids - // * creating more sampler players than strictly necessary - // * an unnecessary large Load To > Sampler N submenu in the track menu - if (dontCreateEmptySamplers && location.isEmpty()) { - continue; - } - - // Later on, when the user loads a samplers file manually, we - // want to eject loaded tracks if the file's sample slot is empty. - // We also create new players even if they are not present in the - // GUI to not drop tracks loaded to invisible samplers when saving - // the samplers file. - if (static_cast(m_pPlayerManager->numSamplers()) < samplerNum) { - m_pCONumSamplers->set(samplerNum); - } + while (!n.isNull()) { + QDomElement e = n.toElement(); - if (location.isEmpty()) { - m_pPlayerManager->slotLoadTrackToPlayer(TrackPointer(), group, false); - } else { - m_pPlayerManager->slotLoadLocationToPlayer(location, group, false); + if (!e.isNull()) { + if (e.tagName() == "sampler") { + QString group = e.attribute("group", ""); + QString location = e.attribute("location", ""); + int samplerNum; + + if (!group.isEmpty() && m_pPlayerManager->isSamplerGroup(group, &samplerNum)) { + if (m_pPlayerManager->numSamplers() < (unsigned)samplerNum) { + m_pCONumSamplers->set(samplerNum); + } + + if (location.isEmpty()) { + m_pPlayerManager->slotLoadTrackToPlayer(TrackPointer(), group, false); + } else { + m_pPlayerManager->slotLoadLocationToPlayer(location, group, false); + } + } + } } + n = n.nextSibling(); } file.close(); diff --git a/src/mixer/samplerbank.h b/src/mixer/samplerbank.h index 0f787e089d2..5234f045f71 100644 --- a/src/mixer/samplerbank.h +++ b/src/mixer/samplerbank.h @@ -19,8 +19,7 @@ class SamplerBank : public QObject { PlayerManager* pPlayerManager); bool saveSamplerBankToPath(const QString& samplerBankPath); - bool loadSamplerBankFromPath(const QString& samplerBankPath, - bool dontCreateEmptySamplers = false); + bool loadSamplerBankFromPath(const QString& samplerBankPath); private slots: void slotSaveSamplerBank(double v);