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

fix deletion of effect chain presets created in current session #11886

Merged
merged 6 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/effects/presets/effectchainpreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) {
EffectChainPreset::EffectChainPreset(const EffectChain* chain)
: m_name(chain->presetName()),
m_mixMode(chain->mixMode()),
m_dSuper(chain->getSuperParameter()) {
m_dSuper(chain->getSuperParameter()),
m_readOnly(false) {
for (const auto& pEffectSlot : chain->getEffectSlots()) {
m_effectPresets.append(EffectPresetPointer(new EffectPreset(pEffectSlot)));
}
Expand All @@ -59,14 +60,16 @@ EffectChainPreset::EffectChainPreset(const EffectChain* chain)
EffectChainPreset::EffectChainPreset(EffectManifestPointer pManifest)
: m_name(pManifest->displayName()),
m_mixMode(EffectChainMixMode::DrySlashWet),
m_dSuper(pManifest->metaknobDefault()) {
m_dSuper(pManifest->metaknobDefault()),
m_readOnly(false) {
m_effectPresets.append(EffectPresetPointer(new EffectPreset(pManifest)));
}

EffectChainPreset::EffectChainPreset(EffectPresetPointer pEffectPreset)
: m_name(pEffectPreset->id()),
m_mixMode(EffectChainMixMode::DrySlashWet),
m_dSuper(pEffectPreset->metaParameter()) {
m_dSuper(pEffectPreset->metaParameter()),
m_readOnly(false) {
m_effectPresets.append(pEffectPreset);
}

Expand Down
16 changes: 10 additions & 6 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ EffectChainPresetPointer EffectChainPresetManager::quickEffectPresetAtIndex(
return m_quickEffectChainPresetsSorted.at(index);
}

void EffectChainPresetManager::importPreset() {
bool EffectChainPresetManager::importPreset() {
QStringList fileNames = QFileDialog::getOpenFileNames(nullptr,
tr("Import effect chain preset"),
QDir::homePath(),
tr("Mixxx Effect Chain Presets") + QStringLiteral(" (*") +
kXmlFileExtension + QStringLiteral(")"));

bool presetsImported = false;
QString importFailedText = tr("Error importing effect chain preset");
QString importFailedInformativeText = tr("Error importing effect chain preset \"%1\"");
for (int i = 0; i < fileNames.size(); ++i) {
Expand Down Expand Up @@ -186,11 +187,13 @@ void EffectChainPresetManager::importPreset() {
m_quickEffectChainPresetsSorted.append(pPreset);
emit effectChainPresetListUpdated();
emit quickEffectChainPresetListUpdated();
presetsImported = true;
} else {
QMessageBox::critical(
nullptr, importFailedText, importFailedInformativeText.arg(filePath));
}
}
return presetsImported;
}

void EffectChainPresetManager::exportPreset(const QString& chainPresetName) {
Expand Down Expand Up @@ -242,9 +245,9 @@ void EffectChainPresetManager::exportPreset(const QString& chainPresetName) {
file.close();
}

void EffectChainPresetManager::renamePreset(const QString& oldName) {
bool EffectChainPresetManager::renamePreset(const QString& oldName) {
VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(oldName)) {
return;
return false;
}
if (m_effectChainPresets.value(oldName)->isReadOnly()) {
QMessageBox msgBox;
Expand All @@ -254,7 +257,7 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
.arg(oldName));
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
return;
return false;
}

QString newName;
Expand All @@ -272,7 +275,7 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
&okay)
.trimmed();
if (!okay) {
return;
return false;
}

if (newName.isEmpty()) {
Expand All @@ -299,7 +302,7 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
m_effectChainPresets.take(newName);
pPreset->setName(oldName);
m_effectChainPresets.insert(oldName, pPreset);
return;
return false;
}

QString directoryPath = m_pConfig->getSettingsPath() + kEffectChainPresetDirectory;
Expand Down Expand Up @@ -328,6 +331,7 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
m_quickEffectChainPresetsSorted.replace(index, pPreset);
emit quickEffectChainPresetListUpdated();
}
return true;
}

bool EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
Expand Down
4 changes: 2 additions & 2 deletions src/effects/presets/effectchainpresetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class EffectChainPresetManager : public QObject {
int quickEffectPresetIndex(EffectChainPresetPointer pChainPreset) const;
EffectChainPresetPointer quickEffectPresetAtIndex(int index) const;

void importPreset();
bool importPreset();
void exportPreset(const QString& chainPresetName);
void renamePreset(const QString& oldName);
bool renamePreset(const QString& oldName);
bool deletePreset(const QString& chainPresetName);

void resetToDefaults();
Expand Down
38 changes: 24 additions & 14 deletions src/preferences/dialog/dlgprefeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ void DlgPrefEffects::setupChainListView(QListView* pListView) {
//TODO: prevent drops of duplicate items
pListView->setDefaultDropAction(Qt::CopyAction);
connect(pListView->selectionModel(),
&QItemSelectionModel::currentRowChanged,
&QItemSelectionModel::selectionChanged,
this,
&DlgPrefEffects::slotChainPresetSelected);
&DlgPrefEffects::slotChainPresetSelectionChanged);
pListView->installEventFilter(this);
}

Expand Down Expand Up @@ -205,19 +205,20 @@ void DlgPrefEffects::effectsTableItemSelected(const QModelIndex& selected) {
effectType->setText(EffectsBackend::translatedBackendName(pManifest->backendType()));
}

void DlgPrefEffects::slotChainPresetSelected(const QModelIndex& selected) {
void DlgPrefEffects::slotChainPresetSelectionChanged(const QItemSelection& selected) {
VERIFY_OR_DEBUG_ASSERT(m_pFocusedChainList) {
return;
}
// Clear the info box and return if the index is invalid, e.g. after clearCurrentIndex()
// in eventFilter()
if (!selected.isValid() ||
m_pFocusedChainList->selectionModel()->selectedRows(0).count() > 1) {
auto* pSelModel = m_pFocusedChainList->selectionModel();
auto selIndices = pSelModel->selectedIndexes();
if (selIndices.count() != 1) {
clearChainInfoDisableButtons();
return;
}

QString chainPresetName = selected.model()->data(selected).toString();
QString chainPresetName = selIndices.first().data().toString();
EffectChainPresetPointer pChainPreset = m_pChainPresetManager->getPreset(chainPresetName);
if (pChainPreset == nullptr || pChainPreset->isEmpty()) {
return;
Expand Down Expand Up @@ -246,8 +247,9 @@ void DlgPrefEffects::slotChainPresetSelected(const QModelIndex& selected) {
}

void DlgPrefEffects::slotImportPreset() {
m_pChainPresetManager->importPreset();
loadChainPresetLists();
if (m_pChainPresetManager->importPreset()) {
loadChainPresetLists();
}
}

void DlgPrefEffects::slotExportPreset() {
Expand All @@ -266,12 +268,17 @@ void DlgPrefEffects::slotRenamePreset() {
return;
}
saveChainPresetLists();
bool presetsRenamed = false;
const auto& selectedIndices = m_pFocusedChainList->selectionModel()->selectedIndexes();
for (const auto& index : selectedIndices) {
const QString& selectedPresetName = m_pFocusedChainList->model()->data(index).toString();
m_pChainPresetManager->renamePreset(selectedPresetName);
if (m_pChainPresetManager->renamePreset(selectedPresetName)) {
presetsRenamed = true;
}
}
if (presetsRenamed) {
loadChainPresetLists();
}
loadChainPresetLists();
}

void DlgPrefEffects::slotDeletePreset() {
Expand All @@ -293,21 +300,26 @@ void DlgPrefEffects::slotDeletePreset() {
pUnfocusedChainList->model());
auto unfocusedChainStringList = pUnfocusedModel->stringList();

bool updateAndSavePresetLists = false;
const auto& selectedIndices = m_pFocusedChainList->selectionModel()->selectedIndexes();
for (const auto& index : selectedIndices) {
QString selectedPresetName =
m_pFocusedChainList->model()->data(index).toString();
if (!unfocusedChainStringList.contains(selectedPresetName)) {
if (m_pChainPresetManager->deletePreset(selectedPresetName)) {
focusedChainStringList.removeAll(selectedPresetName);
updateAndSavePresetLists = true;
}
} else {
focusedChainStringList.removeAll(selectedPresetName);
updateAndSavePresetLists = true;
}
}

pFocusedModel->setStringList(focusedChainStringList);
saveChainPresetLists();
if (updateAndSavePresetLists) {
pFocusedModel->setStringList(focusedChainStringList);
saveChainPresetLists();
}
}

bool DlgPrefEffects::eventFilter(QObject* object, QEvent* event) {
Expand Down Expand Up @@ -343,7 +355,6 @@ bool DlgPrefEffects::eventFilter(QObject* object, QEvent* event) {
currIndex,
QItemSelectionModel::ClearAndSelect);
}
return true;
} else if (pEffectList) {
m_pFocusedEffectList = pEffectList;
unfocusedEffectList()->selectionModel()->clearSelection();
Expand All @@ -355,7 +366,6 @@ bool DlgPrefEffects::eventFilter(QObject* object, QEvent* event) {
pEffectList->selectionModel()->clearCurrentIndex();
pEffectList->selectRow(currIndex.row());
}
return true;
}
}
return DlgPreferencePage::eventFilter(object, event);
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgprefeffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DlgPrefEffects : public DlgPreferencePage, public Ui::DlgPrefEffectsDlg {

private slots:
void effectsTableItemSelected(const QModelIndex& selected);
void slotChainPresetSelected(const QModelIndex& selected);
void slotChainPresetSelectionChanged(const QItemSelection& selected);
void slotImportPreset();
void slotExportPreset();
void slotRenamePreset();
Expand Down
5 changes: 5 additions & 0 deletions src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void WEffectChainPresetButton::populateMenu() {
m_pChainPresetManager->updatePreset(m_pChain);
});
}
if (!presetIsReadOnly && !m_pChain->presetName().isEmpty()) {
m_pMenu->addAction(tr("Rename Preset"), this, [this]() {
m_pChainPresetManager->renamePreset(m_pChain->presetName());
});
}
m_pMenu->addAction(tr("Save As New Preset..."), this, [this]() {
m_pChainPresetManager->savePresetAndReload(m_pChain);
});
Expand Down