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 "gui/menu_item/unpatched_param.h"
19#include "gui/ui/sound_editor.h"
20#include "hid/display/display.h"
21#include "hid/display/oled.h"
22#include "modulation/arpeggiator_rhythms.h"
23#include <sys/_intsup.h>
24
25namespace deluge::gui::menu_item::arpeggiator {
26class Rhythm final : public UnpatchedParam {
27public:
28 using UnpatchedParam::UnpatchedParam;
29
30 [[nodiscard]] int32_t getMinValue() const override { return 0; }
31 [[nodiscard]] int32_t getMaxValue() const override { return kMaxPresetArpRhythm; }
32
33 void drawValue() override { display->setScrollingText(arpRhythmPatternNames[this->getValue()]); }
34
35 void drawInteger(int32_t textWidth, int32_t textHeight, int32_t yPixel) override {
36 char name[12];
37 // Index: Name
38 snprintf(name, sizeof(name), "%d: %s", this->getValue(), arpRhythmPatternNames[this->getValue()]);
39
40 deluge::hid::display::oled_canvas::Canvas& canvas = hid::display::OLED::main;
41 canvas.drawStringCentred(name, yPixel + OLED_MAIN_TOPMOST_PIXEL, textWidth, textHeight);
42 }
43
44 void renderInHorizontalMenu(int32_t startX, int32_t width, int32_t startY, int32_t height) override {
45 deluge::hid::display::oled_canvas::Canvas& image = deluge::hid::display::OLED::main;
46
47 renderColumnLabel(startX, width, startY);
48
49 // Render current value
50
51 DEF_STACK_STRING_BUF(shortOpt, kShortStringBufferSize);
52 if (soundEditor.editingKit() && !soundEditor.editingGateDrumRow()) {
53 shortOpt.append(arpRhythmPatternNames[this->getValue()]);
54 }
55 else {
56 char name[12];
57 // Index:Name
58 snprintf(name, sizeof(name), "%d: %s", this->getValue(), arpRhythmPatternNames[this->getValue()]);
59 shortOpt.append(name);
60 }
61
62 int32_t pxLen;
63 // Trim characters from the end until it fits.
64 while ((pxLen = image.getStringWidthInPixels(shortOpt.c_str(), kTextSpacingY)) >= width) {
65 shortOpt.truncate(shortOpt.size() - 1);
66 }
67 // Padding to center the string. If we can't center exactly, 1px right is better than 1px left.
68 int32_t pad = (width + 1 - pxLen) / 2;
69 image.drawString(shortOpt.c_str(), startX + pad, startY + kTextSpacingY + 2, kTextSpacingX, kTextSpacingY, 0,
70 startX + width - kTextSpacingX);
71 }
72
73 bool isRelevant(ModControllableAudio* modControllable, int32_t whichThing) override {
74 return !soundEditor.editingCVOrMIDIClip() && !soundEditor.editingNonAudioDrumRow();
75 }
76};
77
78} // namespace deluge::gui::menu_item::arpeggiator
Definition mod_controllable_audio.h:47
bool isRelevant(ModControllableAudio *modControllable, int32_t whichThing) override
Check if this MenuItem should show up in a containing deluge::gui::menu_item::Submenu.
Definition rhythm.h:73
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