Deluge Firmware 1.3.0
Build date: 2026.03.02
Loading...
Searching...
No Matches
iterance_divisor.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/note_row/selected_note_row.h"
19#include "gui/views/instrument_clip_view.h"
20#include "model/clip/instrument_clip.h"
21#include "model/instrument/kit.h"
22#include "model/model_stack.h"
23#include "model/note/note_row.h"
24#include "model/song/song.h"
25#include <cstdint>
26
27namespace deluge::gui::menu_item::note_row {
28class IteranceDivisor final : public SelectedNoteRow {
29public:
30 using SelectedNoteRow::SelectedNoteRow;
31
32 [[nodiscard]] int32_t getMaxValue() const override { return 8; }
33 [[nodiscard]] int32_t getMinValue() const override { return 1; }
34
38 void beginSession(MenuItem* navigatedBackwardFrom = nullptr) final override { readValueAgain(); }
39
40 void readCurrentValue() override {
41 char modelStackMemory[MODEL_STACK_MAX_SIZE];
42 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
43 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
44
45 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
46 NoteRow* noteRow = modelStackWithNoteRow->getNoteRowAllowNull();
47 Iterance iterance = noteRow->iteranceValue;
48 if (iterance == kDefaultIteranceValue) {
49 // if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
50 // so we can make edits from here
51 iterance = kCustomIteranceValue;
52 }
53 int32_t divisor = iterance.divisor;
54 this->setValue(std::clamp<int32_t>(divisor, 1, 8));
55 updateDisplay();
56 }
57 }
58 void writeCurrentValue() override {
59 int32_t val = this->getValue();
60 char modelStackMemory[MODEL_STACK_MAX_SIZE];
61 ModelStackWithTimelineCounter* modelStack = currentSong->setupModelStackWithCurrentClip(modelStackMemory);
62 ModelStackWithNoteRow* modelStackWithNoteRow = getIndividualNoteRow(modelStack);
63
64 if (modelStackWithNoteRow->getNoteRowAllowNull() != nullptr) {
65 NoteRow* noteRow = modelStackWithNoteRow->getNoteRowAllowNull();
66 Iterance iterance = noteRow->iteranceValue;
67 if (iterance == kDefaultIteranceValue) {
68 // if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
69 // so we can make edits from here
70 iterance = kCustomIteranceValue;
71 }
72 int32_t mask = (1 << val) - 1; // Creates a mask where the first 'divisor' bits are 1
73 // Wipe the bits whose index is greater than the current divisor value
74 int32_t newIteranceSteps = ((iterance.toInt() & 0xFF) & mask);
75 instrumentClipView.setNoteRowIteranceWithFinalValue(Iterance{(uint8_t)val, newIteranceSteps});
76 }
77 }
78};
79} // namespace deluge::gui::menu_item::note_row
Definition model_stack.h:189
Definition model_stack.h:129
Definition note_row.h:99
void readValueAgain() override
Definition value.h:90
void beginSession(MenuItem *navigatedBackwardFrom=nullptr) final override
Begin an editing session with this menu item.
Definition iterance_divisor.h:38
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition iterance_divisor.h:40
Definition selected_note_row.h:29
Definition iterance.h:23