From 235a41feffce2118f647e2d9fcefcf080648a4ac Mon Sep 17 00:00:00 2001 From: ronso0 Date: Tue, 28 Jan 2025 14:43:43 +0100 Subject: [PATCH] fixup! (fix) Controller preferences: don't reload mapping after MIDI learn --- src/controllers/controllermanager.cpp | 6 +++ src/controllers/dlgprefcontroller.cpp | 47 +++++++++++++++++-- ...legacymidicontrollermappingfilehandler.cpp | 2 +- src/preferences/dialog/dlgpreferences.cpp | 3 ++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/controllers/controllermanager.cpp b/src/controllers/controllermanager.cpp index e5cba1c27c4..e68fb3baf47 100644 --- a/src/controllers/controllermanager.cpp +++ b/src/controllers/controllermanager.cpp @@ -429,6 +429,12 @@ void ControllerManager::slotApplyMapping(Controller* pController, return; } + qWarning() << " ."; + qWarning() << " ."; + qWarning() << " x ConMan slotApplyMapping" << pMapping->filePath(); + qWarning() << " ."; + qWarning() << " ."; + VERIFY_OR_DEBUG_ASSERT(!pMapping->isDirty()) { qWarning() << "Mapping is dirty, changes might be lost on restart!"; } diff --git a/src/controllers/dlgprefcontroller.cpp b/src/controllers/dlgprefcontroller.cpp index 1b1de31dc3e..2f3328175a0 100644 --- a/src/controllers/dlgprefcontroller.cpp +++ b/src/controllers/dlgprefcontroller.cpp @@ -236,22 +236,30 @@ void DlgPrefController::slotStopLearning() { emit mappingEnded(); return; } + qWarning() << " x"; + qWarning() << " x stop learning"; + qWarning() << " x"; + qWarning() << " x apply"; applyMappingChanges(); if (m_pMapping->filePath().isEmpty()) { + qWarning() << " x path empty"; // This mapping was created when the learning wizard was started if (m_pMapping->isDirty()) { + qWarning() << " x map dirty, ask for name"; QString mappingName = askForMappingName(); QString mappingPath = mappingNameToPath(m_pUserDir, mappingName); m_pMapping->setName(mappingName); if (m_pMapping->saveMapping(mappingPath)) { - qDebug() << "Mapping saved as" << mappingPath; + qDebug() << " x Mapping saved as____" << mappingPath; m_pMapping->setFilePath(mappingPath); + qDebug() << " x check path:" << m_pMapping->filePath(); m_pMapping->setDirty(false); + qDebug() << " x applyMap, enum"; emit applyMapping(m_pController, m_pMapping, true); enumerateMappings(mappingPath); } else { - qDebug() << "Failed to save mapping as" << mappingPath; + qWarning() << " x map NOT saved"; // Discard the new mapping and disable the controller m_pMapping.reset(); emit applyMapping(m_pController, m_pMapping, false); @@ -264,6 +272,7 @@ void DlgPrefController::slotStopLearning() { } } + qWarning() << " x mapping ended"; // This will show the preferences -> enumMappings() etc. emit mappingEnded(); } @@ -410,6 +419,8 @@ void DlgPrefController::enumerateMappings(const QString& selectedMappingPath) { m_ui.comboBoxMapping->blockSignals(true); QString currentMappingFilePath = mappingFilePathFromIndex(m_ui.comboBoxMapping->currentIndex()); m_ui.comboBoxMapping->clear(); + qWarning() << " --"; + qWarning() << " -- enum mappings" << selectedMappingPath; // qDebug() << "Enumerating mappings for controller" << m_pController->getName(); @@ -462,15 +473,21 @@ void DlgPrefController::enumerateMappings(const QString& selectedMappingPath) { } QString newMappingFilePath = mappingFilePathFromIndex(index); if (index == -1) { + qWarning() << " --> path not found"; m_ui.chkEnabledDevice->setEnabled(false); m_ui.groupBoxSettings->setVisible(false); } else { + qWarning() << " --> path FOUND" << index; m_ui.comboBoxMapping->setCurrentIndex(index); m_ui.chkEnabledDevice->setEnabled(true); } m_ui.comboBoxMapping->blockSignals(false); if (newMappingFilePath != currentMappingFilePath) { + qWarning() << " --> current != new" << newMappingFilePath; + qWarning() << " --> select"; slotMappingSelected(index); + } else { + qWarning() << " --> current != new" << newMappingFilePath << ", return"; } } @@ -499,15 +516,18 @@ MappingInfo DlgPrefController::enumerateMappingsFromEnumerator( } void DlgPrefController::slotUpdate() { + qWarning() << " *"; + qWarning() << " * slot update (sender" << sender(); + qWarning() << " *"; enumerateMappings(m_pControllerManager->getConfiguredMappingFileForDevice( m_pController->getName())); // Force updating the controller settings slotMappingSelected(m_ui.comboBoxMapping->currentIndex()); + // TODO // enumeratePresets() calls slotPresetSelected() which will tick the 'Enabled' // checkbox if there is a valid mapping saved in the mixxx.cfg file. // However, the checkbox should only be checked if the device is currently enabled. - // TODO fix in slotPresetSelected() m_ui.chkEnabledDevice->setChecked(m_pController->isOpen()); // If the controller is not mappable, disable the input and output mapping @@ -615,7 +635,10 @@ QString DlgPrefController::mappingFilePathFromIndex(int index) const { void DlgPrefController::slotMappingSelected(int chosenIndex) { QString mappingFilePath = mappingFilePathFromIndex(chosenIndex); + qWarning() << " **"; + qWarning() << " ** slot map selected" << chosenIndex << mappingFilePath; if (mappingFilePath.isEmpty()) { // User picked "No Mapping" item + qWarning() << " ** path empty"; m_ui.chkEnabledDevice->setEnabled(false); if (m_ui.chkEnabledDevice->isChecked()) { @@ -628,6 +651,7 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) { m_ui.groupBoxSettings->setVisible(false); } else { // User picked a mapping + qWarning() << " ** path" << mappingFilePath; m_ui.chkEnabledDevice->setEnabled(true); if (!m_ui.chkEnabledDevice->isChecked()) { @@ -642,15 +666,19 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) { // Check if the mapping is different from the configured mapping if (m_pControllerManager->getConfiguredMappingFileForDevice( m_pController->getName()) == mappingFilePath) { + qWarning() << " ** conf path == new path, return"; return; } else { + qWarning() << " ** conf path != new path, setDirty"; setDirty(true); } } + qWarning() << " ** apply changes"; applyMappingChanges(); bool previousMappingSaved = false; if (isDirty() && m_pMapping && m_pMapping->isDirty()) { + qWarning() << " ** dirty + map dirty, save?"; if (QMessageBox::question(this, tr("Mapping has been edited"), tr("Do you want to save the changes?")) == @@ -669,10 +697,14 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) { } if (previousMappingSaved) { + qWarning() << " ** prev saved -> enum"; // We might have saved the previous preset with a new name, so update // the preset combobox. enumerateMappings(mappingFilePath); + } else { + qWarning() << " ** prev NOT saved"; } + qWarning() << " ** -> show"; slotShowMapping(pMapping); } @@ -680,6 +712,7 @@ bool DlgPrefController::saveMapping() { VERIFY_OR_DEBUG_ASSERT(m_pMapping) { return false; } + qWarning() << " * saveMapping"; if (!m_pMapping->isDirty()) { qDebug() << "Mapping is not dirty, no need to save it."; @@ -701,6 +734,7 @@ bool DlgPrefController::saveMapping() { // If this is a user mapping, ask whether to overwrite or save with new name. // Optionally, tick checkbox to always overwrite this mapping in the current session. if (isUserMapping && saveAsNew) { + qWarning() << " * -> overwrite?"; QString overwriteTitle = tr("Mapping already exists."); QString overwriteLabel = tr( "%1 already exists in user mapping folder.
" @@ -738,8 +772,10 @@ bool DlgPrefController::saveMapping() { // * saving a user mapping with a new name. // The name will be used as display name and file name. if (!saveAsNew) { + qWarning() << " * not 'new' / overwrite"; newFilePath = oldFilePath; } else { + qWarning() << " * ask for name"; mappingName = askForMappingName(mappingName); newFilePath = mappingNameToPath(m_pUserDir, mappingName); if (mappingName.isEmpty()) { @@ -752,10 +788,12 @@ bool DlgPrefController::saveMapping() { } if (!m_pMapping->saveMapping(newFilePath)) { + qWarning() << " * Failed to save mapping as" << newFilePath; qDebug() << "Failed to save mapping as" << newFilePath; return false; + } else { + qWarning() << " * Mapping saved assss" << newFilePath; } - qDebug() << "Mapping saved as" << newFilePath; m_pMapping->setFilePath(newFilePath); m_pMapping->setDirty(false); @@ -772,6 +810,7 @@ QString DlgPrefController::askForMappingName(const QString& prefilledName) const "special characters."); QString fileExistsLabel = tr("A mapping file with that name already exists."); // Only allow the name to contain letters, numbers, whitespaces and _-+()/ + // TODO also allow umlauts äöü and other diacritics éè etc.? static const QRegularExpression rxRemove = QRegularExpression( QStringLiteral("[^[(a-zA-Z0-9\\_\\-\\+\\(\\)\\/|\\s]")); diff --git a/src/controllers/midi/legacymidicontrollermappingfilehandler.cpp b/src/controllers/midi/legacymidicontrollermappingfilehandler.cpp index 4003763d595..a24ee6bf103 100644 --- a/src/controllers/midi/legacymidicontrollermappingfilehandler.cpp +++ b/src/controllers/midi/legacymidicontrollermappingfilehandler.cpp @@ -224,7 +224,7 @@ LegacyMidiControllerMappingFileHandler::load(const QDomElement& root, bool LegacyMidiControllerMappingFileHandler::save(const LegacyMidiControllerMapping& mapping, const QString& fileName) const { - qDebug() << "Saving mapping" << mapping.name() << "to" << fileName; + qDebug() << " *** Saving mappingggggg" << mapping.name() << "to" << fileName; QDomDocument doc = buildRootWithScripts(mapping); addControlsToDocument(mapping, &doc); return writeDocument(doc, fileName); diff --git a/src/preferences/dialog/dlgpreferences.cpp b/src/preferences/dialog/dlgpreferences.cpp index 47b96b9fa06..0506db2d1af 100644 --- a/src/preferences/dialog/dlgpreferences.cpp +++ b/src/preferences/dialog/dlgpreferences.cpp @@ -403,6 +403,9 @@ void DlgPreferences::onShow() { // Move is also needed on linux. move(newX, newY); + qWarning() << " x"; + qWarning() << " x x x x x SHOW => emit showDlg"; + qWarning() << " x"; // Notify children that we are about to show. emit showDlg(); }