Skip to content

Commit

Permalink
Custom Control Map beta
Browse files Browse the repository at this point in the history
  • Loading branch information
203Null committed Dec 2, 2024
1 parent 272fcb4 commit 460baa9
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 111 deletions.
2 changes: 1 addition & 1 deletion applications/CustomControlMap/Actions/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define TAG "UAD Actions"

bool UAD::ExecuteAction(ActionInfo* actionInfo, cb0r_t actionData, ActionEvent* actionEvent)
bool UADRuntime::ExecuteAction(ActionInfo* actionInfo, cb0r_t actionData, ActionEvent* actionEvent)
{
if(actionInfo->depth > 5)
{
Expand Down
4 changes: 2 additions & 2 deletions applications/CustomControlMap/Actions/color/ColorEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ColorEffect
}


static bool KeyEvent(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
static bool KeyEvent(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
{
MLOGV(TAG, "KeyEvent");
if(keyInfo->state != KeyState::PRESSED && keyInfo->state != KeyState::RELEASED) return false;
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace ColorEffect
}


static void Initialization(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData)
static void Initialization(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData)
{
struct ColorEffectData data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace KeyboardAction
}


static bool KeyEvent(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
static bool KeyEvent(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
{
MLOGV(TAG, "KeyEvent");
if(keyInfo->state != KeyState::PRESSED && keyInfo->state != KeyState::RELEASED) return false;
Expand Down
88 changes: 54 additions & 34 deletions applications/CustomControlMap/Actions/layer/LayerAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace LayerAction
LayerActionType type;
LayerActionOption option;
bool relative;
uint8_t layer;
int8_t layer;
};

static bool LoadData(cb0r_t actionData, LayerAction* action)
Expand All @@ -35,17 +35,26 @@ namespace LayerAction
action->option = (LayerActionOption)((cbor_data.value >> 8) & 0x0F);
action->relative = (bool)((cbor_data.value >> 15) & 0x01);

if(!cb0r_get(actionData, 2, &cbor_data) || cbor_data.type != CB0R_INT)
if(!cb0r_get(actionData, 2, &cbor_data) || (cbor_data.type != CB0R_INT && cbor_data.type != CB0R_NEG))
{
MLOGE(TAG, "Failed to get action data 1");
return false;
}
action->layer = cbor_data.value;

if(cbor_data.type == CB0R_INT)
{
action->layer = cbor_data.value;
}
else if(cbor_data.type == CB0R_NEG)
{
action->layer = -1 - cbor_data.value;
}

return true;
}


static bool KeyEvent(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
static bool KeyEvent(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
{
if(keyInfo->state != KeyState::PRESSED && keyInfo->state != KeyState::RELEASED) return false;

Expand All @@ -61,22 +70,27 @@ namespace LayerAction
if(data.relative)
{
targetLayer = actionInfo->layer + data.layer;
MLOGD(TAG, "Current Layer: %d, Offset: %d, Target Layer: %d", actionInfo->layer, data.layer, targetLayer);
}
else
{
MLOGD(TAG, "Target Layer: %d", targetLayer);
}

if(targetLayer < 0 || targetLayer >= UAD->layerCount)
if(targetLayer < 0 || targetLayer >= uadRT->layerCount)
{
MLOGE(TAG, "Invalid target layer");
return false;
}

UAD::LayerInfoType targetLayerInfo;
UADRuntime::LayerInfoType targetLayerInfo;
if(data.type == LayerActionType::ACTIVE)
{
targetLayerInfo = UAD::LayerInfoType::ACTIVE;
targetLayerInfo = UADRuntime::LayerInfoType::ACTIVE;
}
else if(data.type == LayerActionType::PASSTHROUGH)
{
targetLayerInfo = UAD::LayerInfoType::PASSTHROUGH;
targetLayerInfo = UADRuntime::LayerInfoType::PASSTHROUGH;
}
else
{
Expand All @@ -85,30 +99,31 @@ namespace LayerAction
}

bool targetLayerState;
if(data.option == LayerActionOption::ENABLE)
{
targetLayerState = true;
}
else if(data.option == LayerActionOption::DISABLE)
{
targetLayerState = false;
}
else if(data.option == LayerActionOption::TOGGLE)
{
targetLayerState = !UAD->GetLayerState(targetLayer, targetLayerInfo);
// Save togged state to register
UAD->SetRegister(actionInfo, targetLayerState);
}
else
{
MLOGE(TAG, "Invalid option");
return false;
}


// Process Key Event
if(keyInfo->state == KeyState::PRESSED)
{
UAD->SetLayerState(targetLayer, targetLayerInfo, targetLayerState);
if(data.option == LayerActionOption::ENABLE)
{
targetLayerState = true;
}
else if(data.option == LayerActionOption::DISABLE)
{
targetLayerState = false;
}
else if(data.option == LayerActionOption::TOGGLE)
{
targetLayerState = !uadRT->GetLayerState(targetLayer, targetLayerInfo);
// Save togged state to register
uadRT->SetRegister(actionInfo, targetLayerState);
}
else
{
MLOGE(TAG, "Invalid option");
return false;
}

uadRT->SetLayerState(targetLayer, targetLayerInfo, targetLayerState);
return true;
}
else if(data.mode == LayerActionMode::MOMENTARY && keyInfo->state == KeyState::RELEASED)
Expand All @@ -117,21 +132,26 @@ namespace LayerAction
// Flip Back!
if(data.option == LayerActionOption::ENABLE)
{
targetLayerState = true;
targetLayerState = false;
}
else if(data.option == LayerActionOption::DISABLE)
{
targetLayerState = false;
targetLayerState = true;
}
else if(data.option == LayerActionOption::TOGGLE)
{
// Load Toggle State from register
uint32_t registerValue;
UAD->GetRegister(actionInfo, &registerValue);
uadRT->GetRegister(actionInfo, &registerValue);
targetLayerState = !(bool)registerValue;
}

UAD->SetLayerState(targetLayer, targetLayerInfo, targetLayerState);
else
{
MLOGE(TAG, "Invalid option");
return false;
}

uadRT->SetLayerState(targetLayer, targetLayerInfo, targetLayerState);
return true;
}

Expand Down
15 changes: 8 additions & 7 deletions applications/CustomControlMap/Actions/midi/MidiAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace MidiAction
return (uint8_t)cbor_data.value;
}

static bool KeyEvent(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo) {
static bool KeyEvent(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo) {
MLOGV(TAG, "KeyEvent - Data Length: %d", actionData->length);
if (keyInfo->state != PRESSED && keyInfo->state != RELEASED && keyInfo->state != AFTERTOUCH)
{
Expand All @@ -59,6 +59,7 @@ namespace MidiAction
}

uint8_t signature = GetData(actionData, 0);
uint8_t channel = signature & 0x0F;

// MLOGV(TAG, "Data: %d, %d, %d", data.data0, data.data1, data.data2);
switch ((signature & 0xF0))
Expand All @@ -70,12 +71,12 @@ namespace MidiAction

if (keyInfo->state == PRESSED) // Velocity sensing is disabled && key press action
{
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, signature & 0x0F, note & 0x7F, velocity));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, channel, note & 0x7F, velocity));
return true;
}
else if (keyInfo->state == RELEASED)
{
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, signature & 0x0F, note & 0x7F, 0));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, channel, note & 0x7F, 0));
return true;
}
return false;
Expand All @@ -85,17 +86,17 @@ namespace MidiAction
uint8_t note = GetData(actionData, 1);
if (keyInfo->state == AFTERTOUCH)
{
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::AfterTouch, signature & 0x0F, note & 0x7F, keyInfo->velocity.to7bits()));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::AfterTouch, channel, note & 0x7F, keyInfo->velocity.to7bits()));
return true;
}
else if (keyInfo->state == PRESSED)
{
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::AfterTouch, signature & 0x0F, note & 0x7F, keyInfo->velocity.to7bits()));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::AfterTouch, channel, note & 0x7F, keyInfo->velocity.to7bits()));
return true;
}
else if(keyInfo->state == RELEASED)
{
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, signature & 0x0F, note & 0x7F, 0));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::NoteOn, channel, note & 0x7F, 0));
return true;
}
return false;
Expand All @@ -106,7 +107,7 @@ namespace MidiAction
{
uint8_t control = GetData(actionData, 1);
uint8_t value = GetData(actionData, 2);
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::ControlChange, signature & 0x0F, control, value));
MatrixOS::MIDI::Send(MidiPacket(0, EMidiStatus::ControlChange, channel, control, value));
return true;
}
return false;
Expand Down
40 changes: 26 additions & 14 deletions applications/CustomControlMap/Actions/wrap/WrapAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,50 @@ namespace WrapAction
MLOGE(TAG, "Failed to get action data %d", 1);
return false;
}
action->layer = cbor_data.value;
if(cbor_data.type == CB0R_NEG)

if (cbor_data.type == CB0R_INT)
{
action->layer = cbor_data.value;
}
else if(cbor_data.type == CB0R_NEG)
{
action->layer -= 1;
action->layer = -1 - cbor_data.value;
}

if(!cb0r_get(actionData, 3, &cbor_data) || (cbor_data.type != CB0R_INT && cbor_data.type != CB0R_NEG))
{
MLOGE(TAG, "Failed to get action data %d", 2);
return false;
}
action->x = cbor_data.value;
if(cbor_data.type == CB0R_NEG)

if(cbor_data.type == CB0R_INT)
{
action->x = cbor_data.value;
}
else if(cbor_data.type == CB0R_NEG)
{
action->x -= 1;
action->x = -1 - cbor_data.value;
}

if(!cb0r_get(actionData, 4, &cbor_data) || (cbor_data.type != CB0R_INT && cbor_data.type != CB0R_NEG))
{
MLOGE(TAG, "Failed to get action data %d", 3);
return false;
}
action->y = cbor_data.value;
if(cbor_data.type == CB0R_NEG)

if(cbor_data.type == CB0R_INT)
{
action->y = cbor_data.value;
}
else if(cbor_data.type == CB0R_NEG)
{
action->y -= 1;
action->y = -1 - cbor_data.value;
}

return true;
}

static bool KeyEvent(UAD* UAD, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
static bool KeyEvent(UADRuntime* uadRT, ActionInfo* actionInfo, cb0r_t actionData, KeyInfo* keyInfo)
{
WrapAction data;
if(!LoadData(actionData, &data))
Expand All @@ -87,7 +99,7 @@ namespace WrapAction
if(data.relativeLayer == true)
{
int8_t newLayer = newAction.layer + data.layer;
if(newLayer < 0 || newLayer >= UAD->layerCount)
if(newLayer < 0 || newLayer >= uadRT->layerCount)
{
MLOGE(TAG, "Relative Layer out of range");
return false;
Expand Down Expand Up @@ -115,9 +127,9 @@ namespace WrapAction

newAction.depth++;

UAD::ActionEvent actionEvent = {.type = UAD::ActionEventType::KEYEVENT, .keyInfo = keyInfo};
UAD->ExecuteActions(&newAction, &actionEvent);
UAD->ExecuteEffects(&newAction, &actionEvent);
UADRuntime::ActionEvent actionEvent = {.type = UADRuntime::ActionEventType::KEYEVENT, .keyInfo = keyInfo};
uadRT->ExecuteActions(&newAction, &actionEvent);
uadRT->ExecuteEffects(&newAction, &actionEvent);
return true;
}
};
Loading

0 comments on commit 460baa9

Please sign in to comment.