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

          Line data    Source code
       1             : /* ✔ */
       2             : 
       3             : #pragma once
       4             : 
       5             : #include <AH/Arduino-Wrapper.h> // Print
       6             : #include <Settings/NamespaceSettings.hpp>
       7             : 
       8             : BEGIN_CS_NAMESPACE
       9             : 
      10             : /** 
      11             :  * A type-safe class for MIDI channels.
      12             :  */
      13             : class Channel {
      14             :   public:
      15             :     /**
      16             :      * @brief   Create a MIDI Channel object.
      17             :      * 
      18             :      * @param   zeroBasedChannel
      19             :      *          The zero-based channel (0 is the first channel).
      20             :      */
      21         459 :     explicit constexpr Channel(uint8_t zeroBasedChannel)
      22         459 :         : zeroBasedChannel(zeroBasedChannel) {}
      23             : 
      24             :     /**
      25             :      * @brief   Get the channel as an integer.
      26             :      * 
      27             :      * @return  The zero-based channel (0 is the first channel).
      28             :      */
      29         666 :     constexpr uint8_t getRaw() const { return zeroBasedChannel; }
      30             : 
      31             :     /**
      32             :      * @brief   Get the channel as an integer.
      33             :      * 
      34             :      * @return  The one-based channel (1 is the first channel).
      35             :      */
      36          10 :     constexpr uint8_t getOneBased() const { return zeroBasedChannel + 1; }
      37             : 
      38             :     /**
      39             :      * @brief   Create a channel.
      40             :      * 
      41             :      * @param   oneBasedChannel
      42             :      *          The channel number (1 is the first channel).
      43             :      */
      44             :     static constexpr Channel createChannel(uint8_t oneBasedChannel) {
      45             :         return Channel {uint8_t(oneBasedChannel - 1)};
      46             :     }
      47             : 
      48             :     /**
      49             :      * @brief   Check if two channels are the same.
      50             :      * 
      51             :      * @param   rhs
      52             :      *          The other channel to compare this channel to.
      53             :      */
      54          47 :     constexpr bool operator==(const Channel &rhs) const {
      55          47 :         return this->zeroBasedChannel == rhs.zeroBasedChannel;
      56             :     }
      57             : 
      58             :     /**
      59             :      * @brief   Check if two channels are the different.
      60             :      * 
      61             :      * @param   rhs
      62             :      *          The other channel to compare this channel to.
      63             :      */
      64             :     constexpr bool operator!=(const Channel &rhs) const {
      65             :         return this->zeroBasedChannel != rhs.zeroBasedChannel;
      66             :     }
      67             : 
      68             :     /**
      69             :      * @brief   Add an offset.
      70             :      * 
      71             :      * @param   rhs
      72             :      *          The offset to add to this channel.
      73             :      */
      74          13 :     Channel &operator+=(uint8_t rhs) {
      75          13 :         this->zeroBasedChannel += rhs;
      76          13 :         return *this;
      77             :     }
      78             : 
      79             :     /**
      80             :      * @brief   Add an offset to a channel.
      81             :      * 
      82             :      * @param   rhs
      83             :      *          The offset to add to the channel.
      84             :      */
      85          13 :     Channel operator+(uint8_t rhs) const {
      86          13 :         Channel copy = *this;
      87          13 :         copy += rhs;
      88          13 :         return copy;
      89             :     }
      90             : 
      91             :     /**
      92             :      * @brief   Subtract an offset.
      93             :      * 
      94             :      * @param   rhs
      95             :      *          The offset to subtract from this channel.
      96             :      */
      97           4 :     Channel &operator-=(uint8_t rhs) {
      98           4 :         this->zeroBasedChannel -= rhs;
      99           4 :         return *this;
     100             :     }
     101             : 
     102             :     /**
     103             :      * @brief   Subtract an offset from a channel.
     104             :      * 
     105             :      * @param   rhs
     106             :      *          The offset to subtract from the channel.
     107             :      */
     108           4 :     Channel operator-(uint8_t rhs) const {
     109           4 :         Channel copy = *this;
     110           4 :         copy -= rhs;
     111           4 :         return copy;
     112             :     }
     113             : 
     114             :   private:
     115             :     uint8_t zeroBasedChannel : 4;
     116             : };
     117             : 
     118             : constexpr Channel Channel_1 = Channel::createChannel(1);
     119             : constexpr Channel Channel_2 = Channel::createChannel(2);
     120             : constexpr Channel Channel_3 = Channel::createChannel(3);
     121             : constexpr Channel Channel_4 = Channel::createChannel(4);
     122             : constexpr Channel Channel_5 = Channel::createChannel(5);
     123             : constexpr Channel Channel_6 = Channel::createChannel(6);
     124             : constexpr Channel Channel_7 = Channel::createChannel(7);
     125             : constexpr Channel Channel_8 = Channel::createChannel(8);
     126             : constexpr Channel Channel_9 = Channel::createChannel(9);
     127             : constexpr Channel Channel_10 = Channel::createChannel(10);
     128             : constexpr Channel Channel_11 = Channel::createChannel(11);
     129             : constexpr Channel Channel_12 = Channel::createChannel(12);
     130             : constexpr Channel Channel_13 = Channel::createChannel(13);
     131             : constexpr Channel Channel_14 = Channel::createChannel(14);
     132             : constexpr Channel Channel_15 = Channel::createChannel(15);
     133             : constexpr Channel Channel_16 = Channel::createChannel(16);
     134             : 
     135             : #ifndef CHANNEL_1 // ArduinoCore-renesas defines this
     136             : constexpr Channel CHANNEL_1 CS_DEPREC("Use Channel_1 instead") = Channel_1;
     137             : constexpr Channel CHANNEL_2 CS_DEPREC("Use Channel_2 instead") = Channel_2;
     138             : constexpr Channel CHANNEL_3 CS_DEPREC("Use Channel_3 instead") = Channel_3;
     139             : constexpr Channel CHANNEL_4 CS_DEPREC("Use Channel_4 instead") = Channel_4;
     140             : constexpr Channel CHANNEL_5 CS_DEPREC("Use Channel_5 instead") = Channel_5;
     141             : constexpr Channel CHANNEL_6 CS_DEPREC("Use Channel_6 instead") = Channel_6;
     142             : constexpr Channel CHANNEL_7 CS_DEPREC("Use Channel_7 instead") = Channel_7;
     143             : constexpr Channel CHANNEL_8 CS_DEPREC("Use Channel_8 instead") = Channel_8;
     144             : constexpr Channel CHANNEL_9 CS_DEPREC("Use Channel_9 instead") = Channel_9;
     145             : constexpr Channel CHANNEL_10 CS_DEPREC("Use Channel_10 instead") = Channel_10;
     146             : constexpr Channel CHANNEL_11 CS_DEPREC("Use Channel_11 instead") = Channel_11;
     147             : constexpr Channel CHANNEL_12 CS_DEPREC("Use Channel_12 instead") = Channel_12;
     148             : constexpr Channel CHANNEL_13 CS_DEPREC("Use Channel_13 instead") = Channel_13;
     149             : constexpr Channel CHANNEL_14 CS_DEPREC("Use Channel_14 instead") = Channel_14;
     150             : constexpr Channel CHANNEL_15 CS_DEPREC("Use Channel_15 instead") = Channel_15;
     151             : constexpr Channel CHANNEL_16 CS_DEPREC("Use Channel_16 instead") = Channel_16;
     152             : #endif
     153             : 
     154             : Print &operator<<(Print &, Channel);
     155             : 
     156             : END_CS_NAMESPACE

Generated by: LCOV version 1.15