Skip to content

Commit

Permalink
samplers: remember last import/export directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Dec 8, 2021
1 parent 53d9683 commit 9c66ff4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mixer/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
34 changes: 31 additions & 3 deletions src/mixer/samplerbank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>

#include "control/controlpushbutton.h"
#include "mixer/playermanager.h"
Expand All @@ -10,8 +11,17 @@
#include "track/track.h"
#include "util/assert.h"

SamplerBank::SamplerBank(PlayerManager* pPlayerManager)
namespace {

const ConfigKey kConfigkeyLastImportExportDirectory(
"[Samplers]", "last_import_export_directory");

} // anonymous namespace

SamplerBank::SamplerBank(UserSettingsPointer pConfig,
PlayerManager* pPlayerManager)
: QObject(pPlayerManager),
m_pConfig(pConfig),
m_pPlayerManager(pPlayerManager) {
DEBUG_ASSERT(m_pPlayerManager);

Expand All @@ -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)) {
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 5 additions & 1 deletion src/mixer/samplerbank.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <QObject>

#include "preferences/usersettings.h"
#include "util/memory.h"

class ControlObject;
Expand All @@ -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);
Expand All @@ -24,6 +27,7 @@ class SamplerBank : public QObject {
void slotLoadSamplerBank(double v);

private:
UserSettingsPointer m_pConfig;
PlayerManager* m_pPlayerManager;
std::unique_ptr<ControlObject> m_pCOLoadBank;
std::unique_ptr<ControlObject> m_pCOSaveBank;
Expand Down

0 comments on commit 9c66ff4

Please sign in to comment.