Deluge Firmware
1.3.0
Build date: 2026.08.23
Toggle main menu visibility
Loading...
Searching...
No Matches
iterance_divisor.h
1
/*
2
* Copyright (c) 2024 Sean Ditny / Raúl Muñoz
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
18
#pragma once
19
#include "gui/menu_item/integer.h"
20
#include "gui/menu_item/note/selected_note.h"
21
#include "gui/views/instrument_clip_view.h"
22
#include "model/clip/instrument_clip.h"
23
#include "model/note/note.h"
24
#include "model/note/note_row.h"
25
#include <cstdint>
26
27
namespace
deluge::gui::menu_item::note {
28
class
IteranceDivisor
final :
public
SelectedNote
{
29
public
:
30
using
SelectedNote::SelectedNote;
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
Note
* leftMostNote = instrumentClipView.getLeftMostNotePressed();
42
43
if
(leftMostNote) {
44
Iterance
iterance = leftMostNote->getIterance();
45
if
(iterance == kDefaultIteranceValue) {
46
// if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
47
// so we can make edits from here
48
iterance = kCustomIteranceValue;
49
}
50
int32_t divisor = iterance.divisor;
51
this->setValue(std::clamp<int32_t>(divisor, 1, 8));
52
}
53
}
54
void
writeCurrentValue()
override
{
55
int32_t val = this->getValue();
56
Note
* leftMostNote = instrumentClipView.getLeftMostNotePressed();
57
if
(leftMostNote) {
58
Iterance
iterance = leftMostNote->getIterance();
59
if
(iterance == kDefaultIteranceValue) {
60
// if we end up here in this menu, convert OFF to the default CUSTOM value 1of1
61
// so we can make edits from here
62
iterance = kCustomIteranceValue;
63
}
64
int32_t mask = (1 << val) - 1;
// Creates a mask where the first 'divisor' bits are 1
65
// Wipe the bits whose index is greater than the current divisor value
66
int32_t newIteranceSteps = ((iterance.toInt() & 0xFF) & mask);
67
instrumentClipView.adjustNoteIteranceWithFinalValue(
Iterance
{(uint8_t)val, newIteranceSteps});
68
}
69
}
70
};
71
}
// namespace deluge::gui::menu_item::note
Note
Definition
note.h:24
deluge::gui::menu_item::Value< int32_t >::readValueAgain
void readValueAgain() override
Definition
value.h:90
deluge::gui::menu_item::note::IteranceDivisor
Definition
iterance_divisor.h:28
deluge::gui::menu_item::note::IteranceDivisor::beginSession
void beginSession(MenuItem *navigatedBackwardFrom=nullptr) final override
Begin an editing session with this menu item.
Definition
iterance_divisor.h:38
deluge::gui::menu_item::note::IteranceDivisor::readCurrentValue
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition
iterance_divisor.h:40
deluge::gui::menu_item::note::SelectedNote
Definition
selected_note.h:25
Iterance
Definition
iterance.h:25