cs-midi/MIDI_Inputs/PBValue.hpp

76 lines
2.0 KiB
C++

#pragma once
#include "InterfaceMIDIInputElements.hpp"
#include "MIDIInputElementMatchers.hpp"
BEGIN_CS_NAMESPACE
class PBValue : public MatchingMIDIInputElement<MIDIMessageType::PitchBend,
PitchBendMIDIMatcher>,
public Interfaces::IValue14 {
public:
using Matcher = PitchBendMIDIMatcher;
PBValue(MIDIChannelCable address) : MatchingMIDIInputElement(address) {}
protected:
void handleUpdate(typename Matcher::Result match) override {
dirty |= value != match.value;
value = match.value;
}
public:
uint16_t getValue() const override { return value; }
void reset() override {
value = 0;
dirty = true;
}
private:
uint16_t value = 0;
};
namespace Bankable {
template <uint8_t BankSize>
class PBValue
: public BankableMatchingMIDIInputElement<
MIDIMessageType::PitchBend, BankablePitchBendMIDIMatcher<BankSize>>,
public Interfaces::IValue14 {
public:
constexpr static auto MessageType = MIDIMessageType::PitchBend;
using Matcher = BankablePitchBendMIDIMatcher<BankSize>;
using Parent = BankableMatchingMIDIInputElement<MessageType, Matcher>;
PBValue(BankConfig<BankSize, BankType::ChangeChannel> config,
MIDIChannelCable address)
: Parent({config, address}) {}
protected:
void handleUpdate(typename Matcher::Result match) override {
dirty |= values[match.bankIndex] != match.value &&
match.bankIndex == this->getActiveBank();
values[match.bankIndex] = match.value;
}
public:
uint16_t getValue() const override { return values[this->getActiveBank()]; }
uint16_t getValue(uint8_t bank) const { return values[bank]; }
void reset() override {
values = {{}};
dirty = true;
}
protected:
void onBankSettingChange() override { dirty = true; }
private:
AH::Array<uint16_t, BankSize> values = {{}};
};
} // namespace Bankable
END_CS_NAMESPACE