Skip to content

Commit

Permalink
Merge pull request #12809 from ronso0/sampler-creationn-revert
Browse files Browse the repository at this point in the history
Revert "Samplers: don't create unneeded empty samplers during startup"
  • Loading branch information
daschuer committed Feb 15, 2024
2 parents 5c45ae5 + daf5ead commit cf55d2b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 48 deletions.
7 changes: 1 addition & 6 deletions src/mixer/playermanager.cpp
Expand Up @@ -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() {
Expand Down
63 changes: 23 additions & 40 deletions src/mixer/samplerbank.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(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();
Expand Down
3 changes: 1 addition & 2 deletions src/mixer/samplerbank.h
Expand Up @@ -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);
Expand Down

0 comments on commit cf55d2b

Please sign in to comment.