Skip to content

Commit

Permalink
debug controller mapping loading/learning
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 30, 2025
1 parent 7ff97ee commit 7e9fb65
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 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
48 changes: 45 additions & 3 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,31 @@ 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 @@ -265,6 +273,7 @@ void DlgPrefController::slotStopLearning() {
}
}

qWarning() << " x mapping ended";
// This will show() -> slotUpdate() -> enumerateMappings() etc.
emit mappingEnded();
}
Expand Down Expand Up @@ -411,6 +420,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 @@ -463,15 +474,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 @@ -500,6 +517,9 @@ MappingInfo DlgPrefController::enumerateMappingsFromEnumerator(
}

void DlgPrefController::slotUpdate() {
qWarning() << " *";
qWarning() << " * slotUpdate";
qWarning() << " *";
enumerateMappings(m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()));
// Force updating the controller settings
Expand Down Expand Up @@ -624,7 +644,10 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
// would wipe those so we need to make sure to return before
// LegacyControllerMappingFileHandler::loadMapping()
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 @@ -637,6 +660,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 @@ -649,6 +673,12 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {

// Check if the mapping is different from the configured mapping
if (m_GuiInitialized) {
if (m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()) == mappingFilePath) {
qWarning() << " ** conf path == new path";
} else {
qWarning() << " ** conf path != new path, setDirty";
}
if (m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()) != mappingFilePath) {
setDirty(true);
Expand All @@ -660,9 +690,11 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
}
}

qWarning() << " ** apply changes";
applyMappingChanges();
bool previousMappingSaved = false;
if (m_pMapping && m_pMapping->isDirty()) {
qWarning() << " ** map dirty, save?";
if (QMessageBox::question(this,
tr("Mapping has been edited"),
tr("Do you want to save the changes?")) ==
Expand All @@ -681,9 +713,12 @@ 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";
}
slotShowMapping(pMapping);
}
Expand All @@ -692,6 +727,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.";
Expand All @@ -713,6 +749,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 @@ -758,8 +795,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 @@ -772,10 +811,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 @@ -792,6 +833,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 7e9fb65

Please sign in to comment.