Skip to content

Commit

Permalink
Refactor KKS base class, remove templated numKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
nrb0 committed Feb 10, 2018
1 parent 7a86f43 commit 42ec2a9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
2 changes: 2 additions & 0 deletions inc/cabl/devices/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class Device

virtual size_t numOfLedArrays() const = 0;

virtual size_t currentOctave() const { return 0; }

virtual void setButtonLed(Button, const Color&);

virtual void setKeyLed(unsigned, const Color&);
Expand Down
26 changes: 24 additions & 2 deletions src/devices/ni/KompleteKontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ const uint8_t kKK_ledsDataSize = 25;

const uint8_t kKK_epOut = 0x02;
const uint8_t kKK_epInput = 0x84;

size_t getInitialOctave(const sl::cabl::KompleteKontrolBase::NUM_KEYS numKeys)
{
using namespace sl::cabl;

switch (numKeys)
{
case KompleteKontrolBase::KEYS_25:
return 48;
case KompleteKontrolBase::KEYS_49:
case KompleteKontrolBase::KEYS_61:
return 36;
default:
return 21;
}
}

} // namespace

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -243,9 +260,13 @@ enum class KompleteKontrolBase::Button : uint8_t

//--------------------------------------------------------------------------------------------------

KompleteKontrolBase::KompleteKontrolBase()
: m_isDirtyLeds(true)
KompleteKontrolBase::KompleteKontrolBase(const NUM_KEYS numKeys)
: m_numKeys(static_cast<unsigned>(numKeys))
, m_ledsKeysSize(m_numKeys * 3U)
, m_ledsKeys(new uint8_t[m_ledsKeysSize])
, m_isDirtyLeds(true)
, m_isDirtyKeyLeds(true)
, m_firstOctave(getInitialOctave(numKeys))
#if defined(_WIN32) || defined(__APPLE__) || defined(__linux)
, m_pMidiOut(new RtMidiOut)
, m_pMidiIn(new RtMidiIn)
Expand Down Expand Up @@ -311,6 +332,7 @@ KompleteKontrolBase::KompleteKontrolBase()

KompleteKontrolBase::~KompleteKontrolBase()
{
delete[] m_ledsKeys;
#if defined(_WIN32) || defined(__APPLE__) || defined(__linux)
m_pMidiOut->closePort();
m_pMidiIn->closePort();
Expand Down
79 changes: 50 additions & 29 deletions src/devices/ni/KompleteKontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class KompleteKontrolBase : public Device
{

public:
KompleteKontrolBase();

enum NUM_KEYS
{
KEYS_25 = 25,
KEYS_49 = 49,
KEYS_61 = 61,
KEYS_88 = 88
};

KompleteKontrolBase(NUM_KEYS numKeys);
~KompleteKontrolBase() override;

void setButtonLed(Device::Button, const Color&) override;
Expand All @@ -36,6 +45,11 @@ class KompleteKontrolBase : public Device

TextDisplay* textDisplay(size_t displayIndex_) override;

unsigned numKeys() const
{
return m_numKeys;
}

size_t numOfGraphicDisplays() const override
{
return 0;
Expand All @@ -56,6 +70,21 @@ class KompleteKontrolBase : public Device
return 0;
}

size_t currentOctave() const override
{
return m_firstOctave;
}

unsigned ledDataSize() const
{
return m_ledsKeysSize;
}

uint8_t* ledsKeysData()
{
return &m_ledsKeys[0];
}

bool tick() override;

private:
Expand Down Expand Up @@ -83,17 +112,16 @@ class KompleteKontrolBase : public Device
bool isButtonPressed(Button button) const noexcept;
bool isButtonPressed(const Transfer&, Button button_) const noexcept;

virtual unsigned numKeys() const = 0;
virtual unsigned ledDataSize() const = 0;
virtual uint8_t* ledsKeysData() = 0;

static void midiInCallback(double timeStamp, std::vector<unsigned char>* message, void* userData);

NullCanvas m_displayDummy;
tRawData m_leds;
tRawData m_buttons;
std::bitset<kKK_nButtons> m_buttonStates;
unsigned m_numKeys;
unsigned m_encoderValues[kKK_nEncoders];
unsigned m_ledsKeysSize;
uint8_t* m_ledsKeys;

bool m_isDirtyLeds;
bool m_isDirtyKeyLeds;
Expand All @@ -110,36 +138,29 @@ class KompleteKontrolBase : public Device

//--------------------------------------------------------------------------------------------------

template <uint8_t NKEYS>
class KompleteKontrol final : public KompleteKontrolBase
class KompleteKontrolS25 final : public KompleteKontrolBase
{
public:
static constexpr unsigned kKK_keysLedDataSize = NKEYS * 3U;

unsigned numKeys() const override
{
return NKEYS;
}
unsigned ledDataSize() const override
{
return kKK_keysLedDataSize;
}

private:
uint8_t* ledsKeysData() override
{
return &m_ledsKeys[0];
}
KompleteKontrolS25() : KompleteKontrolBase(KEYS_25) {}
};

uint8_t m_ledsKeys[kKK_keysLedDataSize];
class KompleteKontrolS49 final : public KompleteKontrolBase
{
public:
KompleteKontrolS49() : KompleteKontrolBase(KEYS_49) {}
};

//--------------------------------------------------------------------------------------------------
class KompleteKontrolS61 final : public KompleteKontrolBase
{
public:
KompleteKontrolS61() : KompleteKontrolBase(KEYS_61) {}
};

using KompleteKontrolS25 = KompleteKontrol<25>;
using KompleteKontrolS49 = KompleteKontrol<49>;
using KompleteKontrolS61 = KompleteKontrol<61>;
using KompleteKontrolS88 = KompleteKontrol<88>;
class KompleteKontrolS88 final : public KompleteKontrolBase
{
public:
KompleteKontrolS88() : KompleteKontrolBase(KEYS_88) {}
};

//--------------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 42ec2a9

Please sign in to comment.