94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "InterfaceMIDIInputElements.hpp"
|
|
#include "MIDIInputElementMatchers.hpp"
|
|
|
|
BEGIN_CS_NAMESPACE
|
|
|
|
template <MIDIMessageType Type>
|
|
class NoteCCKPValue : public MatchingMIDIInputElement<Type, TwoByteMIDIMatcher>,
|
|
public Interfaces::IValue {
|
|
public:
|
|
using Matcher = TwoByteMIDIMatcher;
|
|
|
|
NoteCCKPValue(MIDIAddress address)
|
|
: MatchingMIDIInputElement<Type, TwoByteMIDIMatcher>(address) {}
|
|
|
|
protected:
|
|
bool handleUpdateImpl(typename Matcher::Result match) {
|
|
bool newdirty = value != match.value;
|
|
value = match.value;
|
|
return newdirty;
|
|
}
|
|
|
|
void handleUpdate(typename Matcher::Result match) override {
|
|
dirty |= handleUpdateImpl(match);
|
|
}
|
|
|
|
public:
|
|
uint8_t getValue() const override { return value; }
|
|
|
|
void reset() override {
|
|
value = 0;
|
|
dirty = true;
|
|
}
|
|
|
|
private:
|
|
uint8_t value = 0;
|
|
};
|
|
|
|
using NoteValue = NoteCCKPValue<MIDIMessageType::NoteOn>;
|
|
using CCValue = NoteCCKPValue<MIDIMessageType::ControlChange>;
|
|
using KPValue = NoteCCKPValue<MIDIMessageType::KeyPressure>;
|
|
|
|
namespace Bankable {
|
|
|
|
template <MIDIMessageType Type, uint8_t BankSize>
|
|
class NoteCCKPValue : public BankableMatchingMIDIInputElement<
|
|
Type, BankableTwoByteMIDIMatcher<BankSize>>,
|
|
public Interfaces::IValue {
|
|
public:
|
|
using Matcher = BankableTwoByteMIDIMatcher<BankSize>;
|
|
|
|
NoteCCKPValue(BankConfig<BankSize> config, MIDIAddress address)
|
|
: BankableMatchingMIDIInputElement<Type, Matcher>({config, address}) {}
|
|
|
|
protected:
|
|
bool handleUpdateImpl(typename Matcher::Result match) {
|
|
bool newdirty = values[match.bankIndex] != match.value &&
|
|
match.bankIndex == this->getActiveBank();
|
|
values[match.bankIndex] = match.value;
|
|
return newdirty;
|
|
}
|
|
|
|
void handleUpdate(typename Matcher::Result match) override {
|
|
dirty |= handleUpdateImpl(match);
|
|
}
|
|
|
|
public:
|
|
uint8_t getValue() const override { return values[this->getActiveBank()]; }
|
|
uint8_t getValue(uint8_t bank) const { return values[bank]; }
|
|
|
|
void reset() override {
|
|
values = {{}};
|
|
dirty = true;
|
|
}
|
|
|
|
protected:
|
|
void onBankSettingChange() override { dirty = true; }
|
|
|
|
private:
|
|
AH::Array<uint8_t, BankSize> values = {{}};
|
|
};
|
|
|
|
template <uint8_t BankSize>
|
|
using NoteValue = NoteCCKPValue<MIDIMessageType::NoteOn, BankSize>;
|
|
template <uint8_t BankSize>
|
|
using CCValue = NoteCCKPValue<MIDIMessageType::ControlChange, BankSize>;
|
|
template <uint8_t BankSize>
|
|
using KPValue = NoteCCKPValue<MIDIMessageType::KeyPressure, BankSize>;
|
|
|
|
} // namespace Bankable
|
|
|
|
END_CS_NAMESPACE
|