diff --git a/src/mixer/playermanager.cpp b/src/mixer/playermanager.cpp index 8631178a3ab8..ce260fa1cae6 100644 --- a/src/mixer/playermanager.cpp +++ b/src/mixer/playermanager.cpp @@ -81,7 +81,7 @@ PlayerManager::PlayerManager(UserSettingsPointer pConfig, &PlayerManager::slotChangeNumAuxiliaries, Qt::DirectConnection); // This is parented to the PlayerManager so does not need to be deleted - m_pSamplerBank = new SamplerBank(this); + m_pSamplerBank = new SamplerBank(m_pConfig, this); m_cloneTimer.start(); } diff --git a/src/mixer/samplerbank.cpp b/src/mixer/samplerbank.cpp index eb6c6b634f1c..6561c1bf7c59 100644 --- a/src/mixer/samplerbank.cpp +++ b/src/mixer/samplerbank.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "control/controlpushbutton.h" #include "mixer/playermanager.h" @@ -10,8 +11,17 @@ #include "track/track.h" #include "util/assert.h" -SamplerBank::SamplerBank(PlayerManager* pPlayerManager) +namespace { + +const ConfigKey kConfigkeyLastImportExportDirectory( + "[Samplers]", "LastImportExportDirectory"); + +} // anonymous namespace + +SamplerBank::SamplerBank(UserSettingsPointer pConfig, + PlayerManager* pPlayerManager) : QObject(pPlayerManager), + m_pConfig(pConfig), m_pPlayerManager(pPlayerManager) { DEBUG_ASSERT(m_pPlayerManager); @@ -38,17 +48,27 @@ void SamplerBank::slotSaveSamplerBank(double v) { return; } + QString lastImportExportDirectory = m_pConfig->getValue( + kConfigkeyLastImportExportDirectory, + // When Mixxx exits samplers are auto-exported to the config directory. + // Let's choose a different location to avoid confusion. + QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); const QString xmlSuffix = QStringLiteral(".xml"); QString fileFilter = tr("Mixxx Sampler Banks (*%1)").arg(xmlSuffix); QString samplerBankPath = QFileDialog::getSaveFileName(nullptr, tr("Save Sampler Bank"), - QString(), + lastImportExportDirectory, fileFilter, &fileFilter); if (samplerBankPath.isEmpty()) { return; } + // Update the import/export directory + QFileInfo fileName(samplerBankPath); + m_pConfig->set(kConfigkeyLastImportExportDirectory, + ConfigValue(fileName.dir().absolutePath())); + // Check if '.xml' suffix needs to be added manually // https://bugreports.qt-project.org/browse/QTBUG-27186 if (!samplerBankPath.endsWith(xmlSuffix)) { @@ -116,14 +136,22 @@ void SamplerBank::slotLoadSamplerBank(double v) { return; } + QString lastImportExportDirectory = m_pConfig->getValue( + kConfigkeyLastImportExportDirectory, + QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); QString samplerBankPath = QFileDialog::getOpenFileName(nullptr, tr("Load Sampler Bank"), - QString(), + lastImportExportDirectory, tr("Mixxx Sampler Banks (*.xml)")); if (samplerBankPath.isEmpty()) { return; } + // Update the import/export directory + QFileInfo fileName(samplerBankPath); + m_pConfig->set(kConfigkeyLastImportExportDirectory, + ConfigValue(fileName.dir().absolutePath())); + if (!loadSamplerBankFromPath(samplerBankPath)) { QMessageBox::warning(nullptr, tr("Error Reading Sampler Bank"), diff --git a/src/mixer/samplerbank.h b/src/mixer/samplerbank.h index 748f2587abe9..3cab4a39aba0 100644 --- a/src/mixer/samplerbank.h +++ b/src/mixer/samplerbank.h @@ -1,6 +1,8 @@ #pragma once #include + +#include "preferences/usersettings.h" #include "util/memory.h" class ControlObject; @@ -13,7 +15,8 @@ class PlayerManager; class SamplerBank : public QObject { Q_OBJECT public: - SamplerBank(PlayerManager* pPlayerManager); + SamplerBank(UserSettingsPointer pConfig, + PlayerManager* pPlayerManager); ~SamplerBank() override; bool saveSamplerBankToPath(const QString& samplerBankPath); @@ -24,6 +27,7 @@ class SamplerBank : public QObject { void slotLoadSamplerBank(double v); private: + UserSettingsPointer m_pConfig; PlayerManager* m_pPlayerManager; std::unique_ptr m_pCOLoadBank; std::unique_ptr m_pCOSaveBank;