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

Pref > Controller: allow creating a new mapping with 'No Mapping' selected #4905

Merged
merged 6 commits into from
Sep 17, 2022
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
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 @@ -537,6 +542,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 @@ -556,6 +570,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 @@ -569,8 +584,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");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise we'd hit debug assertions in callFunctionOnObjects and ControllerScriptEngineBase::shutdown() when the new mapping applied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(peviously/2.3 both methods simly returned when there was no js engine)

m_scriptWrappedFunctionCache.clear();
m_incomingDataFunctions.clear();
m_scriptFunctionPrefixes.clear();
ControllerScriptEngineBase::shutdown();
if (m_pJSEngine) {
ControllerScriptEngineBase::shutdown();
}
}

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