Update to spice2x-25-04-25 (pre-apply)
> broken commit
This commit is contained in:
+121
-7
@@ -55,20 +55,39 @@ std::string Analog::getDisplayString(rawinput::RawInputManager *manager) {
|
||||
}
|
||||
case rawinput::MIDI: {
|
||||
auto midi = device->midiInfo;
|
||||
// update strings in button.cpp as well
|
||||
if (index < midi->controls_precision.size()) {
|
||||
return "MIDI PREC " + indexString + " (" + device->desc + ")";
|
||||
const int channel = (index / 32) + 1;
|
||||
const int cc_index = (index % 32);
|
||||
return fmt::format("MIDI Prec Ctrl Ch.{} CC#{} ({})", channel, cc_index, device->desc);
|
||||
} else if (index < midi->controls_precision.size() + midi->controls_single.size()) {
|
||||
return "MIDI CTRL " + indexString + " (" + device->desc + ")";
|
||||
const int index_rel = index - midi->controls_precision.size();
|
||||
const int channel = (index_rel / 44) + 1;
|
||||
int cc_index = (index_rel % 44);
|
||||
if (cc_index < 26) {
|
||||
cc_index += 0x46; // single byte range
|
||||
} else {
|
||||
cc_index = cc_index - 26 + 0x66; // undefined single byte range
|
||||
}
|
||||
return fmt::format("MIDI Ctrl Ch.{} CC#{} ({})", channel, cc_index, device->desc);
|
||||
} else if (index < midi->controls_precision.size() + midi->controls_single.size()
|
||||
+ midi->controls_onoff.size())
|
||||
{
|
||||
return "MIDI ONOFF " + indexString + " (" + device->desc + ")";
|
||||
} else if (index == midi->controls_precision.size() + midi->controls_single.size()
|
||||
+ midi->controls_onoff.size())
|
||||
const int index_rel = index - midi->controls_precision.size() - midi->controls_single.size();
|
||||
const int channel = (index_rel / 6) + 1;
|
||||
const int cc_index = (index_rel % 6) + 0x40;
|
||||
return fmt::format("MIDI OnOff Ch.{} CC#{} ({})", channel, cc_index, device->desc);
|
||||
} else if (index <
|
||||
midi->controls_precision.size() + midi->controls_single.size() + midi->controls_onoff.size() + midi->pitch_bend.size())
|
||||
{
|
||||
return "MIDI Pitch Bend (" + device->desc + ")";
|
||||
const int index_rel =
|
||||
index -
|
||||
midi->controls_precision.size() -
|
||||
midi->controls_single.size() -
|
||||
midi->controls_onoff.size();
|
||||
return fmt::format("MIDI Pitch Ch.{} ({})", index_rel + 1, device->desc);
|
||||
} else {
|
||||
return "MIDI Unknown " + indexString + " (" + device->desc + ")";
|
||||
return "MIDI Unknown Index " + indexString + " (" + device->desc + ")";
|
||||
}
|
||||
}
|
||||
case rawinput::DESTROYED:
|
||||
@@ -158,3 +177,98 @@ float Analog::normalizeAngle(float rads) {
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
float Analog::applyMultiplier(float value) {
|
||||
if (1 < this->multiplier) {
|
||||
// multiplier - just multiply the value and take the decimal part
|
||||
return normalizeAnalogValue(value * this->multiplier);
|
||||
} else if (this->multiplier < -1) {
|
||||
const unsigned short number_of_divisions = -this->multiplier;
|
||||
// divisor - need to take care of over/underflow
|
||||
if (0.75f < this->divisor_previous_value && value < 0.25f) {
|
||||
this->divisor_region = (this->divisor_region + 1) % number_of_divisions;
|
||||
} else if (this->divisor_previous_value < 0.25f && 0.75f < value) {
|
||||
if (1 <= this->divisor_region) {
|
||||
this->divisor_region -= 1;
|
||||
} else {
|
||||
this->divisor_region = number_of_divisions - 1;
|
||||
}
|
||||
}
|
||||
this->divisor_previous_value = value;
|
||||
return ((float)this->divisor_region + value) / (float)number_of_divisions;
|
||||
} else {
|
||||
// multiplier in [-1, 1] range is just treated as 1
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
float Analog::normalizeAnalogValue(float value) {
|
||||
// effectively the same as fmodf(value, 1.f)
|
||||
// for small values, this is MUCH faster than fmodf.
|
||||
float new_value = value;
|
||||
while (new_value > 1.f) {
|
||||
new_value -= 1.f;
|
||||
}
|
||||
while (new_value < 0.f) {
|
||||
new_value += 1.f;
|
||||
}
|
||||
return new_value;
|
||||
}
|
||||
|
||||
float Analog::applyDeadzone(float raw_value) {
|
||||
float value = raw_value;
|
||||
const auto deadzone = this->getDeadzone();
|
||||
if (deadzone > 0) {
|
||||
|
||||
// calculate values
|
||||
const auto delta = value - 0.5f;
|
||||
const auto dtlen = 1.f - deadzone;
|
||||
|
||||
// check mirror
|
||||
if (this->getDeadzoneMirror()) {
|
||||
|
||||
// deadzone on the edges
|
||||
if (dtlen != 0.f) {
|
||||
value = std::max(0.f, std::min(1.f, 0.5f + (delta / dtlen)));
|
||||
} else {
|
||||
value = 0.5f;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// deadzone around the middle
|
||||
const auto limit = deadzone * 0.5f;
|
||||
if (dtlen != 0.f) {
|
||||
if (delta > limit) {
|
||||
value = std::min(1.f, 0.5f + std::max(0.f, (delta - limit) / dtlen));
|
||||
} else if (delta < -limit) {
|
||||
value = std::max(0.f, 0.5f + std::min(0.f, (delta + limit) / dtlen));
|
||||
} else {
|
||||
value = 0.5f;
|
||||
}
|
||||
} else {
|
||||
value = 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (deadzone < 0) {
|
||||
|
||||
// invert for mirror
|
||||
if (this->getDeadzoneMirror()) {
|
||||
value = 1.f - value;
|
||||
}
|
||||
|
||||
// deadzone from minimum value
|
||||
if (deadzone > -1 && value > -deadzone) {
|
||||
value = std::min(1.f, (value + deadzone) / (1.f + deadzone));
|
||||
} else {
|
||||
value = 0.f;
|
||||
}
|
||||
|
||||
// revert value for mirror
|
||||
if (this->getDeadzoneMirror()) {
|
||||
value = 1.f - value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user