Skip to content

Commit

Permalink
fixup! (fix) Controller preferences: don't reload mapping after MIDI …
Browse files Browse the repository at this point in the history
…learn
  • Loading branch information
ronso0 committed Jan 28, 2025
1 parent 93b707e commit 235a41f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/controllers/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
}
Expand Down
47 changes: 43 additions & 4 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -264,6 +272,7 @@ void DlgPrefController::slotStopLearning() {
}
}

qWarning() << " x mapping ended";
// This will show the preferences -> enumMappings() etc.
emit mappingEnded();
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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";
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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?")) ==
Expand All @@ -669,17 +697,22 @@ 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);
}

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.";
Expand All @@ -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(
"<b>%1</b> already exists in user mapping folder.<br>"
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -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]"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 235a41f

Please sign in to comment.