From 2f6d9b6d03f0732aa0133472a48805a58cfc15f9 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Wed, 26 Feb 2020 20:03:41 +0100 Subject: [PATCH] Further optimize update_visible_items --- midi2cv/menu/menu.cc | 19 +++++++++---------- midi2cv/settings.h | 10 ---------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/midi2cv/menu/menu.cc b/midi2cv/menu/menu.cc index 8e7ea05..a481e44 100644 --- a/midi2cv/menu/menu.cc +++ b/midi2cv/menu/menu.cc @@ -51,25 +51,24 @@ void Menu::update_visible_items() this->visibleItems[i] = NULL; } + uint8_t newIndexSelectedItem = 0; + // find out which items are visible and only add these to the list. for (size_t i = 0; i < itemCount; i++) { if (this->items[i]->visible()) { + if(currentlySelectedItem && this->items[i] == currentlySelectedItem) { + newIndexSelectedItem = this->visibleItemCount; + } this->visibleItems[this->visibleItemCount++] = this->items[i]; } + } // if our visibleitem changed, chances are that the index of the selected item has changed: if (currentlySelectedItem && this->visibleItems[this->selectedVisibleItem] != currentlySelectedItem) { - int8_t delta = 0; - // the index of our visible item has changed. - // go through the list of visible items and find it! - for (size_t i = 0; i < this->visibleItemCount; i++) { - if (this->visibleItems[i] == currentlySelectedItem) { - delta = this->selectedVisibleItem - i; - this->selectedVisibleItem = this->currentEditingVisibleItem = i; - break; - } - } + int8_t delta = this->selectedVisibleItem - newIndexSelectedItem; + this->selectedVisibleItem = this->currentEditingVisibleItem = newIndexSelectedItem; + this->currentVisibleScrollStart -= delta; CONSTRAIN(this->currentVisibleScrollStart, 0, this->visibleItemCount); CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount); diff --git a/midi2cv/settings.h b/midi2cv/settings.h index fb20b4b..ebef03b 100644 --- a/midi2cv/settings.h +++ b/midi2cv/settings.h @@ -25,16 +25,6 @@ class Settings { void SavePersistentData(); void SaveState(); - /*inline const ChannelCalibrationData& calibration_data(int channel) const - { - return persistent_data_.channel_calibration_data[channel]; - } - - inline ChannelCalibrationData* mutable_calibration_data(int channel) - { - return &persistent_data_.channel_calibration_data[channel]; - }*/ - inline const State& state() const { return state_;