commit 3fd6a31153cfe9b191a342ae1d920f3c8e9e2e47
parent f343f60cc0ae1757f62675d6baa1f4faf34038a9
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Tue, 30 Jul 2024 15:56:54 +0200
add support for left shift for parameter unpacking from midi data
Diffstat:
4 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/source/jucePluginLib/controller.cpp b/source/jucePluginLib/controller.cpp
@@ -232,7 +232,7 @@ namespace pluginLib
auto* p = getParameter(i, _parameter.getPart());
const auto v = p == &_parameter ? _value : getParameterValue(p);
- _result |= it->getMaskedValue(v);
+ _result |= it->packValue(v);
}
return true;
diff --git a/source/jucePluginLib/midipacket.cpp b/source/jucePluginLib/midipacket.cpp
@@ -35,7 +35,7 @@ namespace pluginLib
m_hasParameters = true;
}
- const auto masked = static_cast<uint8_t>((0xff & d.paramMask) << d.paramShift);
+ const auto masked = d.packValue(0xff);
if((usedMask & masked) || !isNewParam)
{
@@ -94,7 +94,7 @@ namespace pluginLib
LOG("Failed to find value for parameter " << d.paramName << ", part " << d.paramPart);
return false;
}
- _dst[i] |= d.getMaskedValue(it->second);
+ _dst[i] |= d.packValue(it->second);
}
break;
case MidiDataType::Checksum:
@@ -216,8 +216,8 @@ namespace pluginLib
LOG("Failed to find named parameter " << d.paramName << " while parsing midi packet, midi byte " << i);
return false;
}
- const auto sMasked = (s >> d.paramShift) & d.paramMask;
- _addParamValueCallback(std::make_pair(d.paramPart, idx), static_cast<uint8_t>(sMasked));
+ const auto sUnpacked = d.unpackValue(s);
+ _addParamValueCallback(std::make_pair(d.paramPart, idx), sUnpacked);
}
break;
default:
diff --git a/source/jucePluginLib/midipacket.h b/source/jucePluginLib/midipacket.h
@@ -42,21 +42,27 @@ namespace pluginLib
std::string paramName;
uint8_t paramMask = 0xff;
- uint8_t paramShift = 0;
+ uint8_t paramShiftRight = 0; // right shift for unpacking from midi, left for packing
+ uint8_t paramShiftLeft = 0; // left shift for unpacking from midi, right for packing
uint8_t paramPart = AnyPart;
uint32_t checksumFirstIndex = 0;
uint32_t checksumLastIndex = 0;
uint8_t checksumInitValue = 0;
- uint8_t getMaskedValue(const uint8_t _unmasked) const
+ uint8_t packValue(const uint8_t _unmasked) const
{
- return static_cast<uint8_t>((_unmasked & paramMask) << paramShift);
+ return static_cast<uint8_t>(((_unmasked & paramMask) << paramShiftRight) >> paramShiftLeft);
+ }
+
+ uint8_t unpackValue(const uint8_t _masked) const
+ {
+ return ((_masked << paramShiftLeft) >> paramShiftRight) & paramMask;
}
bool doMasksOverlap(const MidiDataDefinition& _d) const
{
- return (getMaskedValue(0xff) & _d.getMaskedValue(0xff)) != 0;
+ return (packValue(0xff) & _d.packValue(0xff)) != 0;
}
};
diff --git a/source/jucePluginLib/parameterdescriptions.cpp b/source/jucePluginLib/parameterdescriptions.cpp
@@ -546,7 +546,8 @@ namespace pluginLib
}
const auto hasMask = entry.hasProperty("mask");
- const auto hasShift = entry.hasProperty("shift");
+ const auto hasRightShift = entry.hasProperty("shift");
+ const auto hasLeftShift = entry.hasProperty("shiftL");
const auto hasPart = entry.hasProperty("part");
if(hasMask)
@@ -560,15 +561,26 @@ namespace pluginLib
byte.paramMask = static_cast<uint8_t>(mask);
}
- if(hasShift)
+ if(hasRightShift)
{
const int shift = entry["shift"];
if(shift < 0 || shift > 7)
{
- _errors << "shift value needs to be between 0 and 7 but got " << shift << std::endl;
+ _errors << "right shift value needs to be between 0 and 7 but got " << shift << std::endl;
return;
}
- byte.paramShift = static_cast<uint8_t>(shift);
+ byte.paramShiftRight = static_cast<uint8_t>(shift);
+ }
+
+ if(hasLeftShift)
+ {
+ const int shift = entry["shiftL"];
+ if(shift < 0 || shift > 7)
+ {
+ _errors << "left shift value needs to be between 0 and 7 but got " << shift << std::endl;
+ return;
+ }
+ byte.paramShiftLeft = static_cast<uint8_t>(shift);
}
if(hasPart)