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 24 : SingleAddress(BaseOutputBankConfig config, MIDIAddress address)
12 24 : : OutputBankableMIDIAddress{config}, address{address} {}
13 :
14 32 : MIDIAddress getBaseAddress() const { return address; }
15 :
16 32 : MIDIAddress getActiveAddress() const {
17 32 : 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 1 : : 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 nb_rows, uint8_t nb_cols>
77 : class MatrixAddress : public OutputBankableMIDIAddress {
78 : public:
79 3 : MatrixAddress(BaseOutputBankConfig config,
80 : const AddressMatrix<nb_rows, nb_cols> &addresses,
81 : MIDIChannelCN 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 4 : return address + getAddressOffset();
92 4 : }
93 :
94 : private:
95 : AddressMatrix<nb_rows, nb_cols> addresses;
96 : MIDIChannelCN 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 5 : ManyAddresses(const Bank<NumBanks> &bank,
117 : const Array<MIDIAddress, NumBanks> &addresses)
118 5 : : 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]}, second{addresses[1]} {}
136 :
137 0 : MIDIAddress getFirstActiveAddress() const { return first[getSelection()]; }
138 0 : MIDIAddress getSecondActiveAddress() const {
139 0 : return second[getSelection()];
140 : }
141 :
142 : private:
143 : Array<MIDIAddress, NumBanks> first, second;
144 : };
145 :
146 : template <uint8_t NumBanks, uint8_t nb_rows, uint8_t nb_cols>
147 : class ManyMatrixAddresses : public ManyAddresses_Base {
148 : public:
149 3 : ManyMatrixAddresses(
150 : const Bank<NumBanks> &bank,
151 : const Array<AddressMatrix<nb_rows, nb_cols>, NumBanks> &addresses,
152 : const Array<MIDIChannelCN, NumBanks> &channelCNs)
153 6 : : ManyAddresses_Base{bank}, addresses{addresses}, channelCNs{
154 9 : channelCNs} {}
155 :
156 4 : MIDIAddress getActiveAddress(uint8_t row, uint8_t col) const {
157 8 : return {addresses[getSelection()][row][col],
158 4 : channelCNs[getSelection()]};
159 : }
160 :
161 : private:
162 : Array<AddressMatrix<nb_rows, nb_cols>, NumBanks> addresses;
163 : Array<MIDIChannelCN, NumBanks> channelCNs;
164 : };
165 :
166 : } // namespace ManyAddresses
167 : } // namespace Bankable
168 :
169 : END_CS_NAMESPACE
|