Line data Source code
1 : #pragma once
2 :
3 : #include "BankableMIDIOutput.hpp"
4 :
5 : BEGIN_CS_NAMESPACE
6 :
7 : namespace Bankable {
8 :
9 : class SingleAddress : public BankableMIDIOutput {
10 : public:
11 18 : SingleAddress(OutputBankConfig config, MIDICNChannelAddress address)
12 18 : : BankableMIDIOutput{config}, address{address} {}
13 :
14 20 : MIDICNChannelAddress getBaseAddress() const { return address; }
15 :
16 20 : MIDICNChannelAddress getActiveAddress() const {
17 20 : return getBaseAddress() + getAddressOffset();
18 : }
19 :
20 : private:
21 : MIDICNChannelAddress address;
22 : };
23 :
24 : class TwoSingleAddresses : public BankableMIDIOutput {
25 : public:
26 1 : TwoSingleAddresses(OutputBankConfig config,
27 : const Array<MIDICNChannelAddress, 2> &addresses)
28 1 : : BankableMIDIOutput{config}, addresses(addresses) {}
29 :
30 0 : MIDICNChannelAddress getBaseAddress(uint8_t i) const {
31 0 : return addresses[i];
32 : }
33 :
34 0 : MIDICNChannelAddress getActiveAddress(uint8_t i) const {
35 0 : return getBaseAddress(i) + getAddressOffset();
36 : }
37 :
38 : private:
39 : Array<MIDICNChannelAddress, 2> addresses;
40 : };
41 :
42 : template <uint8_t nb_rows, uint8_t nb_cols>
43 : class MatrixAddress : public BankableMIDIOutput {
44 : public:
45 3 : MatrixAddress(OutputBankConfig config,
46 : const AddressMatrix<nb_rows, nb_cols> &addresses,
47 : MIDICNChannel channelCN)
48 3 : : BankableMIDIOutput{config}, addresses{addresses}, channelCN{
49 6 : channelCN} {}
50 :
51 4 : uint8_t getBaseAddress(uint8_t row, uint8_t col) const {
52 4 : return addresses[row][col];
53 : }
54 :
55 4 : MIDICNChannelAddress getActiveAddress(uint8_t row, uint8_t col) const {
56 4 : MIDICNChannelAddress address = {getBaseAddress(row, col), channelCN};
57 4 : return address + getAddressOffset();
58 : }
59 :
60 : private:
61 : AddressMatrix<nb_rows, nb_cols> addresses;
62 : MIDICNChannel channelCN;
63 : };
64 :
65 : namespace ManyAddresses {
66 :
67 : /**
68 : * @tparam NumBanks
69 : * The number of bank settings the bank has.
70 : */
71 : template <uint8_t NumBanks>
72 : class ManyAddresses : public ManyAddressesMIDIOutput {
73 : public:
74 : /**
75 : * @brief Constructor.
76 : *
77 : * @param bank
78 : * The bank to add this element to.
79 : * @param addresses
80 : * The list of alternative addresses.
81 : */
82 5 : ManyAddresses(const Bank<NumBanks> &bank,
83 : const Array<MIDICNChannelAddress, NumBanks> &addresses)
84 5 : : ManyAddressesMIDIOutput{bank}, addresses{addresses} {}
85 :
86 0 : MIDICNChannelAddress getActiveAddress() const {
87 0 : return addresses[getSelection()];
88 : }
89 :
90 : private:
91 : Array<MIDICNChannelAddress, NumBanks> addresses;
92 : };
93 :
94 : /**
95 : * @tparam NumBanks
96 : * The number of bank settings the bank has.
97 : */
98 : template <uint8_t NumBanks>
99 : class TwoManyAddresses : public BankableMIDIOutput {
100 : public:
101 1 : TwoManyAddresses(
102 : OutputBankConfig config,
103 : const Array2D<MIDICNChannelAddress, 2, NumBanks> &addresses)
104 1 : : BankableMIDIOutput{config}, addresses{addresses} {}
105 :
106 0 : MIDICNChannelAddress getActiveAddress(uint8_t i) const {
107 0 : return addresses[i][getSelection()];
108 : }
109 :
110 : private:
111 : Array2D<MIDICNChannelAddress, 2, NumBanks> addresses;
112 : };
113 :
114 : template <uint8_t NumBanks, uint8_t nb_rows, uint8_t nb_cols>
115 : class ManyMatrixAddresses : public BankableMIDIOutput {
116 : public:
117 3 : ManyMatrixAddresses(
118 : OutputBankConfig config,
119 : const Array<AddressMatrix<nb_rows, nb_cols>, NumBanks> &addresses,
120 : const Array<MIDICNChannel, NumBanks> &channelCNs)
121 6 : : BankableMIDIOutput{config}, addresses{addresses}, channelCNs{
122 9 : channelCNs} {}
123 :
124 4 : MIDICNChannelAddress getActiveAddress(uint8_t row, uint8_t col) const {
125 8 : return {addresses[getSelection()][row][col],
126 4 : channelCNs[getSelection()]};
127 : }
128 :
129 : private:
130 : Array<AddressMatrix<nb_rows, nb_cols>, NumBanks> addresses;
131 : Array<MIDICNChannel, NumBanks> channelCNs;
132 : };
133 :
134 : } // namespace ManyAddresses
135 : } // namespace Bankable
136 :
137 : END_CS_NAMESPACE
|