Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
rhythm.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 "definitions_cxx.hpp"
19#include "gui/menu_item/arpeggiator/midi_cv/arp_integer.h"
21#include "gui/ui/sound_editor.h"
22#include "hid/display/oled.h"
23#include "model/song/song.h"
24#include "modulation/arpeggiator_rhythms.h"
25
26namespace deluge::gui::menu_item::arpeggiator::midi_cv {
27class Rhythm final : public ArpNonSoundInteger {
28public:
29 using ArpNonSoundInteger::ArpNonSoundInteger;
30 void readCurrentValue() override {
31 this->setValue(computeCurrentValueForUnsignedMenuItem(soundEditor.currentArpSettings->rhythm));
32 }
33 void writeCurrentValue() override {
34 int32_t value = computeFinalValueForUnsignedMenuItem(this->getValue());
35 soundEditor.currentArpSettings->rhythm = value;
36 }
37
38 void drawValue() override { display->setScrollingText(arpRhythmPatternNames[this->getValue()]); }
39
40 void drawInteger(int32_t textWidth, int32_t textHeight, int32_t yPixel) override {
41 deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main;
42
43 canvas.drawStringCentred(arpRhythmPatternNames[this->getValue()], yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth,
44 textHeight);
45 }
46
47 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
48 deluge::hid::display::oled_canvas::Canvas& image = deluge::hid::display::OLED::main;
49
50 renderColumnLabel(startX, width, startY);
51
52 // Render current value
53
54 DEF_STACK_STRING_BUF(shortOpt, kShortStringBufferSize);
55 if (soundEditor.editingKit() && !soundEditor.editingGateDrumRow()) {
56 shortOpt.append(arpRhythmPatternNames[this->getValue()]);
57 }
58 else {
59 char name[12];
60 // Index:Name
61 snprintf(name, sizeof(name), "%d: %s", this->getValue(), arpRhythmPatternNames[this->getValue()]);
62 shortOpt.append(name);
63 }
64 int32_t pxLen;
65 // Trim characters from the end until it fits.
66 while ((pxLen = image.getStringWidthInPixels(shortOpt.c_str(), kTextSpacingY)) >= width) {
67 shortOpt.truncate(shortOpt.size() - 1);
68 }
69 // Padding to center the string. If we can't center exactly, 1px right is better than 1px left.
70 int32_t pad = (width + 1 - pxLen) / 2;
71 image.drawString(shortOpt.c_str(), startX + pad, startY + kTextSpacingY + 2, kTextSpacingX, kTextSpacingY, 0,
72 startX + width - kTextSpacingX);
73 }
74};
75} // namespace deluge::gui::menu_item::arpeggiator::midi_cv
const deluge::l10n::String name
Default name for use on OLED for deluge::gui::menu_item::Submenu s.
Definition menu_item.h:239
void readCurrentValue() override
Like readValueAgain, but does not redraw.
Definition rhythm.h:30
void drawStringCentred(char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos=OLED_MAIN_WIDTH_PIXELS/2)
Definition canvas.cpp:189