Skip to content

Commit

Permalink
Merge pull request #4905 from ronso0/pref-controller-apply-wizard
Browse files Browse the repository at this point in the history
Pref > Controller: allow creating a new mapping with 'No Mapping' selected
  • Loading branch information
daschuer authored Sep 17, 2022
2 parents 9776a74 + ea61944 commit eddade7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/controllers/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ void ControllerManager::slotApplyMapping(Controller* pController,
closeController(pController);
// Unset the controller mapping for this controller
m_pConfig->remove(key);
emit mappingApplied(false);
return;
}

Expand All @@ -432,8 +433,10 @@ void ControllerManager::slotApplyMapping(Controller* pController,

if (bEnabled) {
openController(pController);
emit mappingApplied(pController->isMappable());
} else {
closeController(pController);
emit mappingApplied(false);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/controllers/controllermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ControllerManager : public QObject {
void requestSetUpDevices();
void requestShutdown();
void requestInitialize();
void mappingApplied(bool applied);

public slots:
void updateControllerList();
Expand Down
28 changes: 22 additions & 6 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ DlgPrefController::DlgPrefController(
&DlgPrefController::applyMapping,
m_pControllerManager.get(),
&ControllerManager::slotApplyMapping);
// Update GUI
connect(m_pControllerManager.get(),
&ControllerManager::mappingApplied,
this,
&DlgPrefController::enableWizardAndIOTabs);

// Open script file links
connect(m_ui.labelLoadedMappingScriptFileLinks,
Expand Down Expand Up @@ -162,6 +167,8 @@ void DlgPrefController::showLearningWizard() {
if (!m_pMapping) {
m_pMapping = std::shared_ptr<LegacyControllerMapping>(new LegacyMidiControllerMapping());
emit applyMapping(m_pController, m_pMapping, true);
// shortcut for creating and assigning required I/O table models
slotShowMapping(m_pMapping);
}

// Note that DlgControllerLearning is set to delete itself on close using
Expand Down Expand Up @@ -471,10 +478,8 @@ void DlgPrefController::slotUpdate() {

// If the controller is not mappable, disable the input and output mapping
// sections and the learning wizard button.
bool isMappable = m_pController->isMappable();
m_ui.btnLearningWizard->setEnabled(isMappable);
m_ui.inputMappingsTab->setEnabled(isMappable);
m_ui.outputMappingsTab->setEnabled(isMappable);
enableWizardAndIOTabs(m_pController->isMappable() && m_pController->isOpen());

// When slotUpdate() is run for the first time, this bool keeps slotPresetSelected()
// from setting a false-postive 'dirty' flag when updating the fresh GUI.
m_GuiInitialized = true;
Expand Down Expand Up @@ -541,6 +546,15 @@ QUrl DlgPrefController::helpUrl() const {
return QUrl(MIXXX_MANUAL_CONTROLLERS_URL);
}

void DlgPrefController::enableWizardAndIOTabs(bool enable) {
// We always enable the Wizard button if this is a MIDI controller so we can
// create a new mapping from scratch with 'No Mapping'
const auto* midiController = qobject_cast<MidiController*>(m_pController);
m_ui.btnLearningWizard->setEnabled(midiController != nullptr);
m_ui.inputMappingsTab->setEnabled(enable);
m_ui.outputMappingsTab->setEnabled(enable);
}

QString DlgPrefController::mappingPathFromIndex(int index) const {
if (index == 0) {
// "No Mapping" item
Expand All @@ -560,6 +574,7 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
if (m_GuiInitialized) {
setDirty(true);
}
enableWizardAndIOTabs(false);
}
} else { // User picked a mapping
m_ui.chkEnabledDevice->setEnabled(true);
Expand All @@ -573,8 +588,9 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
}

// Check if the mapping is different from the configured mapping
if (m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()) != mappingPath) {
if (m_GuiInitialized &&
m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()) != mappingPath) {
setDirty(true);
}

Expand Down
1 change: 1 addition & 0 deletions src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DlgPrefController : public DlgPreferencePage {
void slotShowMapping(std::shared_ptr<LegacyControllerMapping> mapping);
/// Called when the Controller Learning Wizard is closed.
void slotStopLearning();
void enableWizardAndIOTabs(bool enable);

// Input mappings
void addInputMapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ bool ControllerScriptEngineLegacy::initialize() {
}

void ControllerScriptEngineLegacy::shutdown() {
callFunctionOnObjects(m_scriptFunctionPrefixes, "shutdown");
// There is no js engine if the mapping was not loaded from a file but by
// creating a new, empty mapping LegacyMidiControllerMapping with the wizard
if (m_pJSEngine) {
callFunctionOnObjects(m_scriptFunctionPrefixes, "shutdown");
}
m_scriptWrappedFunctionCache.clear();
m_incomingDataFunctions.clear();
m_scriptFunctionPrefixes.clear();
ControllerScriptEngineBase::shutdown();
if (m_pJSEngine) {
ControllerScriptEngineBase::shutdown();
}
}

bool ControllerScriptEngineLegacy::handleIncomingData(const QByteArray& data) {
Expand Down

0 comments on commit eddade7

Please sign in to comment.