# HG changeset patch # User Andrew McPherson # Date 1395411591 0 # Node ID 239b039d3000361d7cc267a480032f12364a5cc6 # Parent 0deac2806a7b4db3b90a940601e9f4cec88d8d0d Add "clear settings" feature diff -r 0deac2806a7b -r 239b039d3000 Source/GUI/ControlWindowMainComponent.cpp --- a/Source/GUI/ControlWindowMainComponent.cpp Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/GUI/ControlWindowMainComponent.cpp Fri Mar 21 14:19:51 2014 +0000 @@ -742,15 +742,16 @@ return; // Update the identifier to say we've matched the current state of the segments lastSegmentUniqueIdentifier_ = controller_->midiSegmentUniqueIdentifier(); - + // Save the current selected index in case we later remove it int currentlySelectedIndex = keyboardZoneTabbedComponent->getCurrentTabIndex(); + KeyboardZoneComponent* currentlySelectedComponent = static_cast (keyboardZoneTabbedComponent->getTabContentComponent(currentlySelectedIndex)); MidiKeyboardSegment* currentlySelectedSegment = 0; if(currentlySelectedComponent != 0) currentlySelectedSegment = currentlySelectedComponent->keyboardSegment(); bool selectedNewTab = false; - + // First, go through the segments and create tabs as needed int maxNumSegments = controller_->midiSegmentsCount(); for(int i = 0; i < maxNumSegments; i++) { @@ -761,7 +762,7 @@ // Look for this segment among the tabs we already have for(int tab = 0; tab < keyboardZoneTabbedComponent->getNumTabs(); tab++) { KeyboardZoneComponent *component = static_cast (keyboardZoneTabbedComponent->getTabContentComponent(tab)); - if(component->keyboardSegment() == segment) { + if(component->keyboardSegment() == segment && component->keyboardZone() == segment->outputPort()) { // Found it... matched = true; break; @@ -771,7 +772,7 @@ if(!matched) { KeyboardZoneComponent *newComponent = new KeyboardZoneComponent(); newComponent->setMainApplicationController(controller_); - newComponent->setKeyboardSegment(segment); + newComponent->setKeyboardSegment(segment, segment->outputPort()); char name[16]; #ifdef _MSC_VER @@ -798,25 +799,29 @@ bool matched = false; for(int i = 0; i < maxNumSegments; i++) { - if(segment == controller_->midiSegment(i)) { + if(segment == controller_->midiSegment(i) && component->keyboardZone() == segment->outputPort()) { matched = true; break; } } if(segment == 0 || !matched) { - //std::cout << "Removing tab for nonexistent segment " << segment << endl; - + // This tab holds a nonexistent segment and should be removed + keyboardZoneTabbedComponent->removeTab(tab); + if(currentlySelectedSegment == segment) { // The currently selected tab has been removed. Select the prior one. - if(currentlySelectedIndex > 0) - keyboardZoneTabbedComponent->setCurrentTabIndex(currentlySelectedIndex - 1); + if(currentlySelectedIndex > 0) { + int indexToSelect = currentlySelectedIndex - 1; + if(indexToSelect >= keyboardZoneTabbedComponent->getNumTabs()) + indexToSelect = keyboardZoneTabbedComponent->getNumTabs() - 1; + if(indexToSelect < 0) + indexToSelect = 0; + keyboardZoneTabbedComponent->setCurrentTabIndex(indexToSelect); + } else keyboardZoneTabbedComponent->setCurrentTabIndex(0); } - // This tab holds a nonexistent segment and should be removed - keyboardZoneTabbedComponent->removeTab(tab); - // And we have to start over again since the tab indexing has changed tab = 0; } diff -r 0deac2806a7b -r 239b039d3000 Source/GUI/KeyboardZoneComponent.h --- a/Source/GUI/KeyboardZoneComponent.h Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/GUI/KeyboardZoneComponent.h Fri Mar 21 14:19:51 2014 +0000 @@ -58,8 +58,9 @@ } } - void setKeyboardSegment(MidiKeyboardSegment *segment) { + void setKeyboardSegment(MidiKeyboardSegment *segment, int zone) { keyboardSegment_ = segment; + keyboardZone_ = zone; mappingListComponent->setKeyboardSegment(keyboardSegment_); if(controller_ != 0) { synchronize(true); @@ -69,6 +70,7 @@ MidiKeyboardSegment* keyboardSegment() { return keyboardSegment_; } + int keyboardZone() { return keyboardZone_; } // TextEditor listener methods void textEditorTextChanged(TextEditor &editor) {} @@ -128,6 +130,7 @@ MainApplicationController *controller_; // Pointer to the main application controller MidiKeyboardSegment *keyboardSegment_; // Pointer to the segment this component controls + int keyboardZone_; // Which zone this corresponds to (for UI sync purposes) std::vector midiOutputDeviceIDs_; int lastSelectedMidiOutputID_; //[/UserVariables] diff -r 0deac2806a7b -r 239b039d3000 Source/GUI/MainWindow.cpp --- a/Source/GUI/MainWindow.cpp Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/GUI/MainWindow.cpp Fri Mar 21 14:19:51 2014 +0000 @@ -192,7 +192,7 @@ case kCommandClearPreset: result.setInfo("Clear Settings", "Clears the current settings", presetsCategory, 0); result.setTicked(false); - result.setActive(false); + result.setActive(true); break; case kCommandOpenPreset: result.setInfo("Open Preset...", "Opens an existing preset", presetsCategory, 0); @@ -301,6 +301,14 @@ switch (info.commandID) { case kCommandClearPreset: + // Display an alert to confirm the user wants to delete this mapping + AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon, + "Clear settings", + "Are you sure you want to clear all zones and mappings?", + String::empty, + String::empty, + 0, + ModalCallbackFunction::forComponent(alertBoxResultChosen, this)); break; case kCommandOpenPreset: controller_.loadPresetWithDialog(); @@ -344,3 +352,10 @@ return true; } + +// Called when user clicks a result in the alert box to confirm deletion +void MainWindow::alertBoxResultChosen(int result, MainWindow *item) { + if(result != 0) { + item->clearPreset(); + } +} diff -r 0deac2806a7b -r 239b039d3000 Source/GUI/MainWindow.h --- a/Source/GUI/MainWindow.h Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/GUI/MainWindow.h Fri Mar 21 14:19:51 2014 +0000 @@ -97,6 +97,12 @@ // Perform a command bool perform (const InvocationInfo& info); + // Callback for alert box + static void alertBoxResultChosen(int result, MainWindow *item); + + // Clear preset (called from alert box + void clearPreset() { controller_.clearPreset(); } + /* Note: Be careful if you override any DocumentWindow methods - the base class uses a lot of them, so by overriding you might break its functionality. It's best to do all your work in your content component instead, but if diff -r 0deac2806a7b -r 239b039d3000 Source/MainApplicationController.cpp --- a/Source/MainApplicationController.cpp Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/MainApplicationController.cpp Fri Mar 21 14:19:51 2014 +0000 @@ -536,6 +536,16 @@ return mainElement.writeToFile(outputFile, ""); } +// Clear the current preset and restore default settings +void MainApplicationController::clearPreset() { + midiInputController_.removeAllSegments(); + midiOutputController_.disableAllPorts(); + segmentCounter_ = 0; + + // Re-add a new segment, starting at 0 + midiSegmentAdd(); +} + #ifdef ENABLE_TOUCHKEYS_SENSOR_TEST // Start testing the TouchKeys sensors. Returns true on success. bool MainApplicationController::touchkeySensorTestStart(const char *path, int firstKey) { diff -r 0deac2806a7b -r 239b039d3000 Source/MainApplicationController.h --- a/Source/MainApplicationController.h Fri Mar 21 12:53:50 2014 +0000 +++ b/Source/MainApplicationController.h Fri Mar 21 14:19:51 2014 +0000 @@ -341,6 +341,9 @@ bool loadPresetWithDialog(); #endif + // Clears the current preset and restores default settings to zones/mappings + void clearPreset(); + #ifdef ENABLE_TOUCHKEYS_SENSOR_TEST // *** TouchKeys sensor testing methods *** // Start testing the TouchKeys sensors