LCOV - code coverage report
Current view: top level - src/Banks - BankAddresses.hpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 27 37 73.0 %
Date: 2024-11-09 15:32:27 Functions: 13 23 56.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "BankableAddresses.hpp"
       4             : 
       5             : BEGIN_CS_NAMESPACE
       6             : 
       7             : namespace Bankable {
       8             : 
       9             : class SingleAddress : public OutputBankableMIDIAddress {
      10             :   public:
      11          26 :     SingleAddress(BaseOutputBankConfig config, MIDIAddress address)
      12          26 :         : OutputBankableMIDIAddress(config), address(address) {}
      13             : 
      14          32 :     MIDIAddress getBaseAddress() const { return address; }
      15             : 
      16          32 :     MIDIAddress getActiveAddress() const {
      17          64 :         return getBaseAddress() + getAddressOffset();
      18             :     }
      19             : 
      20             :   private:
      21             :     MIDIAddress address;
      22             : };
      23             : 
      24             : template <uint8_t N>
      25             : class SingleAddressMultipleBanks {
      26             :   public:
      27             :     SingleAddressMultipleBanks(const Array<OutputBankableMIDIAddress, N> &banks,
      28             :                                MIDIAddress address)
      29             :         : banks(banks), address(address) {}
      30             : 
      31             :     MIDIAddress getBaseAddress() const { return address; }
      32             : 
      33             :     MIDIAddress getActiveAddress() const {
      34             :         auto address = getBaseAddress();
      35             :         for (const OutputBankableMIDIAddress &bank : banks)
      36             :             address += bank.getAddressOffset();
      37             :         return address;
      38             :     }
      39             : 
      40             :     void lock() {
      41             :         for (OutputBankableMIDIAddress &bank : banks)
      42             :             bank.lock();
      43             :     }
      44             : 
      45             :     void unlock() {
      46             :         for (OutputBankableMIDIAddress &bank : banks)
      47             :             bank.unlock();
      48             :     }
      49             : 
      50             :   private:
      51             :     Array<OutputBankableMIDIAddress, N> banks;
      52             :     MIDIAddress address;
      53             : };
      54             : 
      55             : class DualAddresses : public OutputBankableMIDIAddress {
      56             :   public:
      57           1 :     DualAddresses(BaseOutputBankConfig config,
      58             :                   const Array<MIDIAddress, 2> &addresses)
      59           2 :         : OutputBankableMIDIAddress(config), first(addresses[0]),
      60           2 :           second(addresses[1]) {}
      61             : 
      62           0 :     MIDIAddress getFirstBaseAddress() const { return first; }
      63           0 :     MIDIAddress getSecondBaseAddress() const { return second; }
      64             : 
      65           0 :     MIDIAddress getFirstActiveAddress() const {
      66           0 :         return getFirstBaseAddress() + getAddressOffset();
      67             :     }
      68           0 :     MIDIAddress getSecondActiveAddress() const {
      69           0 :         return getSecondBaseAddress() + getAddressOffset();
      70             :     }
      71             : 
      72             :   private:
      73             :     MIDIAddress first, second;
      74             : };
      75             : 
      76             : template <uint8_t NumRows, uint8_t NumCols>
      77             : class MatrixAddress : public OutputBankableMIDIAddress {
      78             :   public:
      79           3 :     MatrixAddress(BaseOutputBankConfig config,
      80             :                   const AddressMatrix<NumRows, NumCols> &addresses,
      81             :                   MIDIChannelCable channelCN)
      82           3 :         : OutputBankableMIDIAddress(config), addresses(addresses),
      83           6 :           channelCN(channelCN) {}
      84             : 
      85           4 :     uint8_t getBaseAddress(uint8_t row, uint8_t col) const {
      86           4 :         return addresses[row][col];
      87             :     }
      88             : 
      89           4 :     MIDIAddress getActiveAddress(uint8_t row, uint8_t col) const {
      90           4 :         MIDIAddress address = {getBaseAddress(row, col), channelCN};
      91           8 :         return address + getAddressOffset();
      92             :     }
      93             : 
      94             :   private:
      95             :     AddressMatrix<NumRows, NumCols> addresses;
      96             :     MIDIChannelCable channelCN;
      97             : };
      98             : 
      99             : namespace ManyAddresses {
     100             : 
     101             : /**
     102             :  * @tparam  NumBanks
     103             :  *          The number of bank settings the bank has.
     104             :  */
     105             : template <uint8_t NumBanks>
     106             : class ManyAddresses : public ManyAddresses_Base {
     107             :   public:
     108             :     /**
     109             :      * @brief   Constructor.
     110             :      * 
     111             :      * @param   bank
     112             :      *          The bank to add this element to.
     113             :      * @param   addresses
     114             :      *          The list of alternative addresses.
     115             :      */
     116           8 :     ManyAddresses(const Bank<NumBanks> &bank,
     117             :                   const Array<MIDIAddress, NumBanks> &addresses)
     118           8 :         : ManyAddresses_Base(bank), addresses(addresses) {}
     119             : 
     120           0 :     MIDIAddress getActiveAddress() const { return addresses[getSelection()]; }
     121             : 
     122             :   private:
     123             :     Array<MIDIAddress, NumBanks> addresses;
     124             : };
     125             : 
     126             : /**
     127             :  * @tparam  NumBanks
     128             :  *          The number of bank settings the bank has.
     129             :  */
     130             : template <uint8_t NumBanks>
     131             : class DualManyAddresses : public ManyAddresses_Base {
     132             :   public:
     133           1 :     DualManyAddresses(const Bank<NumBanks> &bank,
     134             :                       const Array2D<MIDIAddress, 2, NumBanks> &addresses)
     135           1 :         : ManyAddresses_Base(bank), first {addresses[0]},
     136           2 :           second {addresses[1]} {}
     137             : 
     138           0 :     MIDIAddress getFirstActiveAddress() const { return first[getSelection()]; }
     139           0 :     MIDIAddress getSecondActiveAddress() const {
     140           0 :         return second[getSelection()];
     141             :     }
     142             : 
     143             :   private:
     144             :     Array<MIDIAddress, NumBanks> first, second;
     145             : };
     146             : 
     147             : template <uint8_t NumBanks, uint8_t NumRows, uint8_t NumCols>
     148             : class ManyMatrixAddresses : public ManyAddresses_Base {
     149             :   public:
     150           3 :     ManyMatrixAddresses(
     151             :         const Bank<NumBanks> &bank,
     152             :         const Array<AddressMatrix<NumRows, NumCols>, NumBanks> &addresses,
     153             :         const Array<MIDIChannelCable, NumBanks> &channelCNs)
     154           3 :         : ManyAddresses_Base(bank), addresses(addresses),
     155           6 :           channelCNs(channelCNs) {}
     156             : 
     157           4 :     MIDIAddress getActiveAddress(uint8_t row, uint8_t col) const {
     158           4 :         return {addresses[getSelection()][row][col],
     159           8 :                 channelCNs[getSelection()]};
     160             :     }
     161             : 
     162             :   private:
     163             :     Array<AddressMatrix<NumRows, NumCols>, NumBanks> addresses;
     164             :     Array<MIDIChannelCable, NumBanks> channelCNs;
     165             : };
     166             : 
     167             : } // namespace ManyAddresses
     168             : } // namespace Bankable
     169             : 
     170             : END_CS_NAMESPACE

Generated by: LCOV version 1.15