Line data Source code
1 : #pragma once
2 :
3 : #include <Banks/Bank.hpp>
4 : #include <Control_Surface/Control_Surface_Class.hpp>
5 : #include <Def/Def.hpp>
6 :
7 : BEGIN_CS_NAMESPACE
8 :
9 : /// Class for transposing the address of @ref NoteButton and other MIDI elements.
10 : template <int8_t MinTransposition, int8_t MaxTransposition>
11 : class Transposer : public Bank<MaxTransposition - MinTransposition + 1> {
12 : public:
13 4 : Transposer(int8_t step = 1)
14 4 : : Bank<NumBanks>(step, -MinTransposition, MinTransposition) {
15 : static_assert(MinTransposition <= 0,
16 : "Error: the minimum transposition must be negative");
17 : static_assert(MaxTransposition >= 0,
18 : "Error: the maximum transposition must be positive");
19 4 : }
20 :
21 : /// Set the transposition.
22 : /// @param tp
23 : /// The new transposition in the range
24 : /// [ @p MinTransposition, @p MaxTransposition ].
25 : /// @note The @ref Bank::select() method expects a zero-based argument,
26 : /// which is cumbersome if the minimum transposition is nonzero.
27 8 : void setTransposition(int8_t tp) { this->select(tp - MinTransposition); }
28 :
29 : /// Get the transposition.
30 8 : int8_t getTransposition() const {
31 8 : return this->getSelection() + MinTransposition;
32 : }
33 :
34 : /// Get the transposition as a number of semitones.
35 8 : int8_t getTranspositionSemitones() const { return this->getOffset(); }
36 :
37 : static constexpr setting_t N = MaxTransposition - MinTransposition + 1;
38 : static constexpr setting_t NumBanks = N;
39 : };
40 :
41 : END_CS_NAMESPACE
|