Skip to content

Commit

Permalink
implement get macro led intensity command
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jan 21, 2024
1 parent 5de6bd6 commit e287c11
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@ juce::MidiMessage LumatoneSysEx::createTableSysEx(juce::uint8 boardIndex, juce::
return msg;
}

juce::Colour LumatoneSysEx::parseLedIntensity8Bit(const juce::uint8 *data)
{
return juce::Colour::fromRGB(
*data << 4 | *(data + 1),
*(data + 3) << 4 | *(data + 2),
*(data + 5) << 4 | *(data + 4)
);
}

// Checks if message is a valid Lumatone firmware response and is expected length, then runs supplied unpacking function or returns an error code
FirmwareSupport::Error LumatoneSysEx::unpackIfValid(const juce::MidiMessage& response, size_t numBytes, std::function<FirmwareSupport::Error(const juce::uint8*)> unpackFunction)
FirmwareSupport::Error LumatoneSysEx::isValid(const juce::MidiMessage &response, size_t numBytes)
{
auto status = messageIsValidLumatoneResponse(response);
if (status != FirmwareSupport::Error::noError)
Expand All @@ -102,6 +109,16 @@ FirmwareSupport::Error LumatoneSysEx::unpackIfValid(const juce::MidiMessage& res
if (status != FirmwareSupport::Error::noError)
return status;

return FirmwareSupport::Error::noError;
}

// Checks if message is a valid Lumatone firmware response and is expected length, then runs supplied unpacking function or returns an error code
FirmwareSupport::Error LumatoneSysEx::unpackIfValid(const juce::MidiMessage& response, size_t numBytes, std::function<FirmwareSupport::Error(const juce::uint8*)> unpackFunction)
{
auto status = isValid(response, numBytes);
if (status != FirmwareSupport::Error::noError)
return status;

return unpackFunction(&response.getSysExData()[PAYLOAD_INIT]);
}

Expand Down Expand Up @@ -185,6 +202,7 @@ FirmwareSupport::Error LumatoneSysEx::unpack12BitDataFrom4Bit(const juce::MidiMe

return unpackIfValid(msg, numBytes, unpack);
}

bool LumatoneSysEx::messageIsResponseToMessage(const juce::MidiMessage& answer, const juce::MidiMessage& originalMessage)
{
// Only for SysEx messages
Expand Down Expand Up @@ -635,3 +653,16 @@ FirmwareSupport::Error LumatoneSysEx::unpackGetExpressionPedalSensitivityRespons

return status;
}

FirmwareSupport::Error LumatoneSysEx::unpackGetMacroLightIntensityResponse(const juce::MidiMessage &response, juce::Colour &activeColour, juce::Colour &inactiveColour)
{
auto status = isValid(response, 12);
if (status != FirmwareSupport::Error::noError)
return status;

const juce::uint8* payload = &response.getSysExData()[PAYLOAD_INIT];
activeColour = parseLedIntensity8Bit(payload);
inactiveColour = parseLedIntensity8Bit(payload + 6);

return FirmwareSupport::Error::noError;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ static juce::MidiMessage createExtendedMacroColourSysEx(juce::uint8 cmd, int red
// Create a SysEx message encoding a table with a defined size
static juce::MidiMessage createTableSysEx(juce::uint8 boardIndex, juce::uint8 cmd, juce::uint8 tableSize, const juce::uint8 table[]);

// Returns colour parsed from 6 nibbles of RGB LED intensity data
static juce::Colour parseLedIntensity8Bit(const juce::uint8* data);

// Checks if message is a valid Lumatone firmware response and is expected length, then runs supplied unpacking function or returns an error code
// Checks if message is a valid Lumatone firmware response and is expected length,
static FirmwareSupport::Error isValid(const juce::MidiMessage& response, size_t numBytes);

// Checks message validity, then runs supplied unpacking function or returns an error code
static FirmwareSupport::Error unpackIfValid(const juce::MidiMessage& response, size_t numBytes, std::function<FirmwareSupport::Error(const juce::uint8*)> unpackFunction);

// Generic unpacking of octave data from a SysEx message
Expand Down Expand Up @@ -157,6 +162,8 @@ static FirmwareSupport::Error unpackGetPresetFlagsResponse(const juce::MidiMessa
// For CMD 48h response: get expression pedal sensitivity
static FirmwareSupport::Error unpackGetExpressionPedalSensitivityResponse(const juce::MidiMessage& response, int& sensitivity);

static FirmwareSupport::Error unpackGetMacroLightIntensityResponse(const juce::MidiMessage& response, juce::Colour& activeColour, juce::Colour& inactiveColour);

// Message is an answer to a sent message yes/no
static bool messageIsResponseToMessage(const juce::MidiMessage& answer, const juce::MidiMessage& originalMessage);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,11 @@ void LumatoneFirmwareDriver::sendGetExpressionPedalSensitivity()
sendSysExRequest(0, GET_EXPRESSION_PEDAL_SENSITIVIY);
}

void LumatoneFirmwareDriver::sendGetMacroLightIntensity()
{
sendSysExRequest(0, GET_MACRO_LIGHT_INTENSITY);
}

/*
==============================================================================
Low-level SysEx calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ class LumatoneFirmwareDriver : public HajuMidiDriver

// For CMD 48h response: get expression pedal sensitivity
void sendGetExpressionPedalSensitivity();

// For CMD 49h: Get Macro button colours
void sendGetMacroLightIntensity();

// TODO CMD 49h-4Eh

Expand Down

0 comments on commit e287c11

Please sign in to comment.