LCOV - code coverage report
Current view: top level - src/Banks - Transposer.hpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 7 7 100.0 %
Date: 2024-11-09 15:32:27 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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

Generated by: LCOV version 1.15