Skip to content

Add default default octave depending on KK model #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there's a better name for this

{
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])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c style array creation, since you're using pointers for data writing I didn't change this to a vector

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a shared_ptr with the array is an option here

, 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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete based destruction. A bit ugly, maybe there's a better way to do this

#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