LCOV - code coverage report
Current view: top level - src/Def - Cable.hpp (source / functions) Coverage Total Hit
Test: 73449d9b107c772cf65493691543348214e5d5eb Lines: 100.0 % 8 8
Test Date: 2026-06-06 17:44:35 Functions: 100.0 % 5 5
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 USB Cable numbers.
      12              :  */
      13              : class Cable {
      14              :   public:
      15              :     /**
      16              :      * @brief   Create a MIDI Cable object.
      17              :      * 
      18              :      * @param   zeroBasedCable
      19              :      *          The zero-based cable (0 is the first cable).
      20              :      */
      21          746 :     explicit constexpr Cable(uint8_t zeroBasedCable)
      22          746 :         : zeroBasedCable(zeroBasedCable) {}
      23              : 
      24              :     /**
      25              :      * @brief   Get the cable as an integer.
      26              :      * 
      27              :      * @return  The zero-based cable (0 is the first cable).
      28              :      */
      29         1296 :     constexpr uint8_t getRaw() const { return zeroBasedCable; }
      30              : 
      31              :     /**
      32              :      * @brief   Get the cable as an integer.
      33              :      * 
      34              :      * @return  The one-based cable (1 is the first cable).
      35              :      */
      36           17 :     constexpr uint8_t getOneBased() const { return zeroBasedCable + 1; }
      37              : 
      38              :     /**
      39              :      * @brief   Create a cable.
      40              :      * 
      41              :      * @param   oneBasedCable
      42              :      *          The cable number (1 is the first cable).
      43              :      */
      44              :     static constexpr Cable createCable(uint8_t oneBasedCable) {
      45              :         return Cable {static_cast<uint8_t>(oneBasedCable - 1)};
      46              :     }
      47              : 
      48              :     /**
      49              :      * @brief   Check if two cables are the same.
      50              :      * 
      51              :      * @param   rhs
      52              :      *          The other cable to compare this cable to.
      53              :      */
      54          318 :     constexpr bool operator==(const Cable &rhs) const {
      55          318 :         return this->zeroBasedCable == rhs.zeroBasedCable;
      56              :     }
      57              : 
      58              :     /**
      59              :      * @brief   Check if two cables are the different.
      60              :      * 
      61              :      * @param   rhs
      62              :      *          The other cable to compare this cable to.
      63              :      */
      64           33 :     constexpr bool operator!=(const Cable &rhs) const {
      65           33 :         return this->zeroBasedCable != rhs.zeroBasedCable;
      66              :     }
      67              : 
      68              :     /**
      69              :      * @brief   Add an offset.
      70              :      * 
      71              :      * @param   rhs
      72              :      *          The offset to add to this cable.
      73              :      */
      74              :     Cable &operator+=(uint8_t rhs) {
      75              :         this->zeroBasedCable += rhs;
      76              :         return *this;
      77              :     }
      78              : 
      79              :     /**
      80              :      * @brief   Add an offset to a cable.
      81              :      * 
      82              :      * @param   rhs
      83              :      *          The offset to add to the cable.
      84              :      */
      85              :     Cable operator+(uint8_t rhs) const {
      86              :         Cable copy = *this;
      87              :         copy += rhs;
      88              :         return copy;
      89              :     }
      90              : 
      91              :     /**
      92              :      * @brief   Subtract an offset.
      93              :      * 
      94              :      * @param   rhs
      95              :      *          The offset to subtract from this cable.
      96              :      */
      97              :     Cable &operator-=(uint8_t rhs) {
      98              :         this->zeroBasedCable -= rhs;
      99              :         return *this;
     100              :     }
     101              : 
     102              :     /**
     103              :      * @brief   Subtract an offset from a cable.
     104              :      * 
     105              :      * @param   rhs
     106              :      *          The offset to subtract from the cable.
     107              :      */
     108              :     Cable operator-(uint8_t rhs) const {
     109              :         Cable copy = *this;
     110              :         copy -= rhs;
     111              :         return copy;
     112              :     }
     113              : 
     114              :   private:
     115              :     uint8_t zeroBasedCable : 4;
     116              : };
     117              : 
     118              : constexpr Cable Cable_1 = Cable::createCable(1);
     119              : constexpr Cable Cable_2 = Cable::createCable(2);
     120              : constexpr Cable Cable_3 = Cable::createCable(3);
     121              : constexpr Cable Cable_4 = Cable::createCable(4);
     122              : constexpr Cable Cable_5 = Cable::createCable(5);
     123              : constexpr Cable Cable_6 = Cable::createCable(6);
     124              : constexpr Cable Cable_7 = Cable::createCable(7);
     125              : constexpr Cable Cable_8 = Cable::createCable(8);
     126              : constexpr Cable Cable_9 = Cable::createCable(9);
     127              : constexpr Cable Cable_10 = Cable::createCable(10);
     128              : constexpr Cable Cable_11 = Cable::createCable(11);
     129              : constexpr Cable Cable_12 = Cable::createCable(12);
     130              : constexpr Cable Cable_13 = Cable::createCable(13);
     131              : constexpr Cable Cable_14 = Cable::createCable(14);
     132              : constexpr Cable Cable_15 = Cable::createCable(15);
     133              : constexpr Cable Cable_16 = Cable::createCable(16);
     134              : 
     135              : constexpr Cable CABLE_1 CS_DEPREC("Use Cable_1 instead") = Cable_1;
     136              : constexpr Cable CABLE_2 CS_DEPREC("Use Cable_2 instead") = Cable_2;
     137              : constexpr Cable CABLE_3 CS_DEPREC("Use Cable_3 instead") = Cable_3;
     138              : constexpr Cable CABLE_4 CS_DEPREC("Use Cable_4 instead") = Cable_4;
     139              : constexpr Cable CABLE_5 CS_DEPREC("Use Cable_5 instead") = Cable_5;
     140              : constexpr Cable CABLE_6 CS_DEPREC("Use Cable_6 instead") = Cable_6;
     141              : constexpr Cable CABLE_7 CS_DEPREC("Use Cable_7 instead") = Cable_7;
     142              : constexpr Cable CABLE_8 CS_DEPREC("Use Cable_8 instead") = Cable_8;
     143              : constexpr Cable CABLE_9 CS_DEPREC("Use Cable_9 instead") = Cable_9;
     144              : constexpr Cable CABLE_10 CS_DEPREC("Use Cable_10 instead") = Cable_10;
     145              : constexpr Cable CABLE_11 CS_DEPREC("Use Cable_11 instead") = Cable_11;
     146              : constexpr Cable CABLE_12 CS_DEPREC("Use Cable_12 instead") = Cable_12;
     147              : constexpr Cable CABLE_13 CS_DEPREC("Use Cable_13 instead") = Cable_13;
     148              : constexpr Cable CABLE_14 CS_DEPREC("Use Cable_14 instead") = Cable_14;
     149              : constexpr Cable CABLE_15 CS_DEPREC("Use Cable_15 instead") = Cable_15;
     150              : constexpr Cable CABLE_16 CS_DEPREC("Use Cable_16 instead") = Cable_16;
     151              : 
     152              : Print &operator<<(Print &, Cable);
     153              : 
     154              : END_CS_NAMESPACE
        

Generated by: LCOV version 2.4-beta