Skip to content

Commit

Permalink
Make BankConfig a template
Browse files Browse the repository at this point in the history
Allows specifying the default BankType for PBPotentiometer etc.
  • Loading branch information
tttapa committed Apr 9, 2020
1 parent eabfcde commit ac37291
Show file tree
Hide file tree
Showing 34 changed files with 96 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ template <uint8_t NumAddr>
class ManyAddressBank {
public:
ManyAddressBank(const ManyAddresses<NumAddr> &manyaddresses,
OutputBankConfig bank)
BaseOutputBankConfig bank)
: manyaddresses{manyaddresses}, bank{bank} {}

void lock() { manyaddresses.lock(), bank.lock(); }
Expand All @@ -29,7 +29,7 @@ class ManyAddressBankNoteButton
: public MIDIButton<ManyAddressBank<NumAddr>, DigitalNoteSender> {
public:
ManyAddressBankNoteButton(const ManyAddresses<NumAddr> &manyaddresses,
OutputBankConfig bank, pin_t pin,
OutputBankConfig<> bank, pin_t pin,
const DigitalNoteSender &sender = {})
: MIDIButton<ManyAddressBank<NumAddr>, DigitalNoteSender>{
{manyaddresses, bank},
Expand Down
6 changes: 3 additions & 3 deletions src/Banks/BankAddresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Bankable {

class SingleAddress : public OutputBankableMIDIAddress {
public:
SingleAddress(OutputBankConfig config, MIDIAddress address)
SingleAddress(BaseOutputBankConfig config, MIDIAddress address)
: OutputBankableMIDIAddress{config}, address{address} {}

MIDIAddress getBaseAddress() const { return address; }
Expand Down Expand Up @@ -54,7 +54,7 @@ class SingleAddressMultipleBanks {

class DualAddresses : public OutputBankableMIDIAddress {
public:
DualAddresses(OutputBankConfig config,
DualAddresses(BaseOutputBankConfig config,
const Array<MIDIAddress, 2> &addresses)
: OutputBankableMIDIAddress{config}, first(addresses[0]),
second(addresses[1]) {}
Expand All @@ -76,7 +76,7 @@ class DualAddresses : public OutputBankableMIDIAddress {
template <uint8_t nb_rows, uint8_t nb_cols>
class MatrixAddress : public OutputBankableMIDIAddress {
public:
MatrixAddress(OutputBankConfig config,
MatrixAddress(BaseOutputBankConfig config,
const AddressMatrix<nb_rows, nb_cols> &addresses,
MIDIChannelCN channelCN)
: OutputBankableMIDIAddress{config}, addresses{addresses},
Expand Down
39 changes: 31 additions & 8 deletions src/Banks/BankConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,53 @@ template <setting_t N>
class Bank;
class OutputBank;

template <BankType DefaultBankType>
struct OutputBankConfig;

/**
* @brief A struct for selecting the bank of BankableMIDIInput%s and the
* bank type.
*/
template <setting_t N>
struct BankConfig {
BankConfig(Bank<N> &bank, BankType type = CHANGE_ADDRESS)
: bank(bank), type(type) {}
class BaseBankConfig {
protected:
BaseBankConfig(Bank<N> &bank, BankType type) : bank(bank), type(type) {}

public:
Bank<N> &bank;
const BankType type;
};

/// @copydoc BaseBankConfig
template <setting_t N, BankType DefaultBankType = BankType::CHANGE_ADDRESS>
struct BankConfig : BaseBankConfig<N> {
BankConfig(Bank<N> &bank, BankType type = DefaultBankType)
: BaseBankConfig<N>(bank, type) {}
};

/**
* @brief A struct for selecting the bank of BankableMIDIOutput%s and the
* bank type.
*/
struct OutputBankConfig {
template <setting_t N>
OutputBankConfig(const BankConfig<N> &bankconfig)
: bank(bankconfig.bank), type(bankconfig.type) {}
OutputBankConfig(OutputBank &bank, BankType type = CHANGE_ADDRESS)
class BaseOutputBankConfig {
protected:
BaseOutputBankConfig(OutputBank &bank, BankType type)
: bank(bank), type(type) {}

public:
template <setting_t N>
BaseOutputBankConfig(BaseBankConfig<N> config)
: bank(config.bank), type(config.type) {}

OutputBank &bank;
const BankType type;
};

/// @copydoc BaseOutputBankConfig
template <BankType DefaultBankType = BankType::CHANGE_ADDRESS>
struct OutputBankConfig : BaseOutputBankConfig {
OutputBankConfig(OutputBank &bank, BankType type = DefaultBankType)
: BaseOutputBankConfig(bank, type) {}
};

END_CS_NAMESPACE
2 changes: 1 addition & 1 deletion src/Banks/BankableAddresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class OutputBankableMIDIAddress : public OutputBankableMIDIAddress_Base {
*
* @see OutputBankableMIDIAddress::OutputBankableMIDIAddress(Bank<N> &, BankType)
*/
OutputBankableMIDIAddress(const OutputBankConfig &config)
OutputBankableMIDIAddress(BaseOutputBankConfig config)
: OutputBankableMIDIAddress(config.bank, config.type) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Banks/BankableMIDIInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BankableMIDIInput : public DoublyLinkable<BankableMIDIInput<N>> {
*
* @see BankableMIDIInput::BankableMIDIInput(Bank<N> &, BankType)
*/
BankableMIDIInput(const BankConfig<N> &config)
BankableMIDIInput(BankConfig<N> config)
: BankableMIDIInput<N>(config.bank, config.type) {}

public:
Expand Down
4 changes: 2 additions & 2 deletions src/MIDI_Inputs/LEDs/NoteCCRangeLEDBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ template <uint8_t BankSize, uint8_t NumLEDs>
class NoteLEDBar : public GenericNoteCCRange<MIDIInputElementNote, 1, BankSize,
NoteCCLEDBarCallback<NumLEDs>> {
public:
NoteLEDBar(const BankConfig<BankSize> &config,
NoteLEDBar(BankConfig<BankSize> config,
const AH::DotBarDisplayLEDs<NumLEDs> &leds,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementNote, 1, BankSize,
Expand Down Expand Up @@ -152,7 +152,7 @@ template <uint8_t BankSize, uint8_t NumLEDs>
class CCLEDBar : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize,
NoteCCLEDBarCallback<NumLEDs>> {
public:
CCLEDBar(const BankConfig<BankSize> &config,
CCLEDBar(BankConfig<BankSize> config,
const AH::DotBarDisplayLEDs<NumLEDs> &leds,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementCC, 1, BankSize,
Expand Down
16 changes: 8 additions & 8 deletions src/MIDI_Inputs/LEDs/NoteCCRangeLEDs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ template <uint8_t RangeLen, uint8_t BankSize>
class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
BankSize, NoteCCLED<RangeLen>> {
public:
NoteRangeLEDs(const BankConfig<BankSize> &config,
NoteRangeLEDs(BankConfig<BankSize> config,
const PinList<RangeLen> &ledPins,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
Expand All @@ -214,7 +214,7 @@ template <uint8_t BankSize>
class NoteValueLED : public GenericNoteCCRange<MIDIInputElementNote, 1,
BankSize, NoteCCLED<1>> {
public:
NoteValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
NoteValueLED(BankConfig<BankSize> config, pin_t ledPin,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementNote, 1, BankSize, NoteCCLED<1>>{
config,
Expand All @@ -233,7 +233,7 @@ template <uint8_t RangeLen, uint8_t BankSize>
class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
BankSize, NoteCCLED<RangeLen>> {
public:
CCRangeLEDs(const BankConfig<BankSize> &config,
CCRangeLEDs(BankConfig<BankSize> config,
const PinList<RangeLen> &ledPins,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
Expand All @@ -248,7 +248,7 @@ template <uint8_t BankSize>
class CCValueLED
: public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>> {
public:
CCValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
CCValueLED(BankConfig<BankSize> config, pin_t ledPin,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>>{
config,
Expand Down Expand Up @@ -385,7 +385,7 @@ template <uint8_t RangeLen, uint8_t BankSize>
class NoteRangeLEDsPWM : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
BankSize, NoteCCLEDPWM<RangeLen>> {
public:
NoteRangeLEDsPWM(const BankConfig<BankSize> &config,
NoteRangeLEDsPWM(BankConfig<BankSize> config,
const PinList<RangeLen> &ledPins,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
Expand All @@ -400,7 +400,7 @@ template <uint8_t BankSize>
class NoteValueLEDPWM : public GenericNoteCCRange<MIDIInputElementNote, 1,
BankSize, NoteCCLEDPWM<1>> {
public:
NoteValueLEDPWM(const BankConfig<BankSize> &config, pin_t ledPin,
NoteValueLEDPWM(BankConfig<BankSize> config, pin_t ledPin,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementNote, 1, BankSize, NoteCCLEDPWM<1>>{
config,
Expand All @@ -413,7 +413,7 @@ template <uint8_t RangeLen, uint8_t BankSize>
class CCRangeLEDsPWM : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
BankSize, NoteCCLEDPWM<RangeLen>> {
public:
CCRangeLEDsPWM(const BankConfig<BankSize> &config,
CCRangeLEDsPWM(BankConfig<BankSize> config,
const PinList<RangeLen> &ledPins,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
Expand All @@ -428,7 +428,7 @@ template <uint8_t BankSize>
class CCValueLEDPWM
: public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLEDPWM<1>> {
public:
CCValueLEDPWM(const BankConfig<BankSize> &config, pin_t ledPin,
CCValueLEDPWM(BankConfig<BankSize> config, pin_t ledPin,
const MIDIAddress &address)
: GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLEDPWM<1>>{
config,
Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Inputs/MCU/VPotRing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ template <uint8_t NumBanks, class Callback = VPotEmptyCallback>
class GenericVPotRing : public VPotRing_Base<NumBanks, Callback>,
public BankableMIDIInput<NumBanks> {
public:
GenericVPotRing(const BankConfig<NumBanks> &config, uint8_t track,
GenericVPotRing(BankConfig<NumBanks> config, uint8_t track,
const MIDIChannelCN &channelCN, const Callback &callback)
: VPotRing_Base<NumBanks, Callback>{track, channelCN, callback},
BankableMIDIInput<NumBanks>{config} {}
Expand Down
6 changes: 3 additions & 3 deletions src/MIDI_Inputs/MCU/VU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class GenericVU : public VU_Base<NumBanks, Callback>,
* changes.
* Used for displaying the value on a range of LEDs etc.
*/
GenericVU(const BankConfig<NumBanks> &config, uint8_t track,
GenericVU(BankConfig<NumBanks> config, uint8_t track,
const MIDIChannelCN &channelCN, unsigned int decayTime,
const Callback &callback)
: VU_Base<NumBanks, Callback>{
Expand Down Expand Up @@ -371,7 +371,7 @@ class VU : public GenericVU<NumBanks> {
* in that case, you can set the decay time to zero to disable
* the decay.
*/
VU(const BankConfig<NumBanks> &config, uint8_t track,
VU(BankConfig<NumBanks> config, uint8_t track,
const MIDIChannelCN &channelCN,
unsigned int decayTime = VUDecay::Default)
: GenericVU<NumBanks>{
Expand All @@ -394,7 +394,7 @@ class VU : public GenericVU<NumBanks> {
* in that case, you can set the decay time to zero to disable
* the decay.
*/
VU(const BankConfig<NumBanks> &config, uint8_t track,
VU(BankConfig<NumBanks> config, uint8_t track,
unsigned int decayTime = VUDecay::Default)
: GenericVU<NumBanks>{
config, track, CHANNEL_1, decayTime, {},
Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MIDIButton : public MIDIOutputElement {
* @param sender
* The MIDI sender to use.
*/
MIDIButton(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
MIDIButton(BankAddress bankAddress, pin_t pin, const Sender &sender)
: address{bankAddress}, button{pin}, sender(sender) {}

void begin() override { button.begin(); }
Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIButtonLatched.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MIDIButtonLatched : public MIDIOutputElement {
* @param sender
* The MIDI sender to use.
*/
MIDIButtonLatched(const BankAddress &bankAddress, pin_t pin,
MIDIButtonLatched(BankAddress bankAddress, pin_t pin,
const Sender &sender)
: address{bankAddress}, button{pin}, sender{sender} {}

Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIButtonLatching.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MIDIButtonLatching : public MIDIOutputElement {
* @param sender
* The MIDI sender to use.
*/
MIDIButtonLatching(const BankAddress &bankAddress, pin_t pin,
MIDIButtonLatching(BankAddress bankAddress, pin_t pin,
const Sender &sender)
: address{bankAddress}, button{pin}, sender{sender} {}

Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIButtonMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MIDIButtonMatrix : public MIDIOutputElement,
* @param sender
* The MIDI sender to use.
*/
MIDIButtonMatrix(const BankAddress &bankAddress,
MIDIButtonMatrix(BankAddress bankAddress,
const PinList<nb_rows> &rowPins,
const PinList<nb_cols> &colPins, const Sender &sender)
: AH::ButtonMatrix<nb_rows, nb_cols>(rowPins, colPins),
Expand Down
2 changes: 1 addition & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIButtons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MIDIButtons : public MIDIOutputElement {
*
* @todo Documentation
*/
MIDIButtons(const BankAddress &bankAddress,
MIDIButtons(BankAddress bankAddress,
const Array<AH::Button, NumButtons> &buttons,
const RelativeMIDIAddress &incrementAddress,
const Sender &sender)
Expand Down
5 changes: 2 additions & 3 deletions src/MIDI_Outputs/Bankable/Abstract/MIDIChordButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class MIDIChordButton : public MIDIOutputElement {
* The MIDI sender to use.
*/
template <uint8_t N>
MIDIChordButton(const OutputBankConfig &config, pin_t pin,
const MIDIAddress &address, const Chord<N> &chord,
const Sender &sender)
MIDIChordButton(OutputBankConfig<> config, pin_t pin, MIDIAddress address,
const Chord<N> &chord, const Sender &sender)
: address{config, address}, button{pin},
newChord(AH::MakeUnique<Chord<N>>(chord)), sender{sender} {}

Expand Down
4 changes: 2 additions & 2 deletions src/MIDI_Outputs/Bankable/Abstract/MIDIFilteredAnalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MIDIFilteredAnalogAddressable : public MIDIOutputElement {
* @param sender
* The MIDI sender to use.
*/
MIDIFilteredAnalogAddressable(const BankAddress &bankAddress,
MIDIFilteredAnalogAddressable(BankAddress bankAddress,
pin_t analogPin, const Sender &sender)
: address{bankAddress}, filteredAnalog{analogPin}, sender(sender) {}

Expand Down Expand Up @@ -103,7 +103,7 @@ class MIDIFilteredAnalog : public MIDIOutputElement {
* @param sender
* The MIDI sender to use.
*/
MIDIFilteredAnalog(const BankAddress &bankAddress, pin_t analogPin,
MIDIFilteredAnalog(BankAddress bankAddress, pin_t analogPin,
const Sender &sender)
: address(bankAddress), filteredAnalog(analogPin), sender(sender) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MIDIIncrementDecrementButtons : public MIDIOutputElement {
*
* @todo Documentation
*/
MIDIIncrementDecrementButtons(const BankAddress &addresses,
MIDIIncrementDecrementButtons(BankAddress addresses,
const AH::IncrementDecrementButtons &buttons,
uint8_t multiplier,
const RelativeSender &relativeSender,
Expand Down
4 changes: 2 additions & 2 deletions src/MIDI_Outputs/Bankable/Abstract/MIDIRotaryEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MIDIRotaryEncoder : public MIDIOutputElement {
*
* @todo Documentation
*/
MIDIRotaryEncoder(const BankAddress &bankAddress,
MIDIRotaryEncoder(BankAddress bankAddress,
const EncoderPinList &pins,
uint8_t speedMultiply, uint8_t pulsesPerStep,
const Sender &sender)
Expand All @@ -37,7 +37,7 @@ class MIDIRotaryEncoder : public MIDIOutputElement {

// For tests only
#ifndef ARDUINO
MIDIRotaryEncoder(const BankAddress &bankAddress, const Encoder &encoder,
MIDIRotaryEncoder(BankAddress bankAddress, const Encoder &encoder,
uint8_t speedMultiply, uint8_t pulsesPerStep,
const Sender &sender)
: address(bankAddress), encoder{encoder},
Expand Down
3 changes: 1 addition & 2 deletions src/MIDI_Outputs/Bankable/CCButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class CCButton : public MIDIButton<SingleAddress, DigitalCCSender> {
* @param sender
* The MIDI sender to use.
*/
CCButton(const OutputBankConfig &config, pin_t pin,
const MIDIAddress &address,
CCButton(OutputBankConfig<> config, pin_t pin, MIDIAddress address,
const DigitalCCSender &sender = {})
: MIDIButton{{config, address}, pin, sender} {}
};
Expand Down
7 changes: 3 additions & 4 deletions src/MIDI_Outputs/Bankable/CCButtonLatched.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ class CCButtonLatched
* @param sender
* The MIDI sender to use.
*/
CCButtonLatched(const BankConfig<NumBanks> &config, pin_t pin,
const MIDIAddress &address,
CCButtonLatched(BankConfig<NumBanks> config, pin_t pin, MIDIAddress address,
const DigitalCCSender &sender = {})
: MIDIButtonLatched<NumBanks, SingleAddress, DigitalCCSender>{
{config, address}, pin, sender} {}
: MIDIButtonLatched<NumBanks, SingleAddress, DigitalCCSender>(
{config, address}, pin, sender) {}
};

} // namespace Bankable
Expand Down
3 changes: 1 addition & 2 deletions src/MIDI_Outputs/Bankable/CCButtonLatching.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class CCButtonLatching
* @param sender
* The MIDI sender to use.
*/
CCButtonLatching(const OutputBankConfig &config, pin_t pin,
const MIDIAddress &address,
CCButtonLatching(OutputBankConfig<> config, pin_t pin, MIDIAddress address,
const DigitalCCSender &sender = {})
: MIDIButtonLatching<SingleAddress, DigitalCCSender>{
{config, address}, pin, sender} {}
Expand Down
3 changes: 1 addition & 2 deletions src/MIDI_Outputs/Bankable/CCButtonMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class CCButtonMatrix
* @param sender
* The MIDI sender to use.
*/
CCButtonMatrix(const OutputBankConfig &config,
const PinList<nb_rows> &rowPins,
CCButtonMatrix(OutputBankConfig<> config, const PinList<nb_rows> &rowPins,
const PinList<nb_cols> &colPins,
const AddressMatrix<nb_rows, nb_cols> &controllers,
MIDIChannelCN channelCN, const DigitalCCSender &sender = {})
Expand Down
Loading

0 comments on commit ac37291

Please sign in to comment.