Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
scale.h
1/*
2 * Copyright (c) 2014-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18#include "gui/menu_item/selection.h"
19#include "model/scale/preset_scales.h"
20#include "storage/flash_storage.h"
21
22namespace deluge::gui::menu_item::defaults {
23class DefaultScale final : public Selection {
24public:
25 using Selection::Selection;
26
27 void readCurrentValue() override {
28 this->setValue(scaleToOptionIndex(flashStorageCodeToScale(FlashStorage::defaultScale)));
29 }
30
31 void writeCurrentValue() override {
32 FlashStorage::defaultScale = scaleToFlashStorageCode(optionIndexToScale(static_cast<Scale>(this->getValue())));
33 }
34
35 void drawName() override { display->setScrollingText(getName().data()); }
36
37 deluge::vector<std::string_view> getOptions(OptType optType) override {
38 (void)optType;
39 deluge::vector<std::string_view> scales;
40 for (uint8_t i = 0; i < NUM_SCALELIKE; i++) {
41 if (i != USER_SCALE) {
42 scales.push_back(scalelikeNames[i]);
43 }
44 }
45 return scales;
46 }
47
48private:
49 // USER_SCALE is not available as a default, since it's not saved to flash storage,
50 // so we need to offset the index.
51 Scale optionIndexToScale(uint8_t index) {
52 if (index >= USER_SCALE) {
53 index += 1;
54 }
55 return static_cast<Scale>(index);
56 }
57 uint8_t scaleToOptionIndex(Scale scale) {
58 if (scale >= USER_SCALE) {
59 return scale - 1;
60 }
61 else {
62 return scale;
63 }
64 }
65};
66} // namespace deluge::gui::menu_item::defaults
virtual std::string_view getName() const
Get the actual name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:243
Definition selection.h:26
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition scale.h:27
void drawName() override
Draw the name we want to use when selecting this in a deluge::gui::menu_item::Submenu to the 7SEG.
Definition scale.h:35