Skip to content

Commit

Permalink
Chaops: memory selector uses simple voltages and supports wraparound.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed Nov 28, 2024
1 parent 04d881b commit a49d08b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/chaops_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ namespace Sapphire
{
using namespace std;

float v = getControlValue(MEMORY_SELECT_PARAM, MEMORY_SELECT_ATTEN, MEMORY_SELECT_CV_INPUT, 0, MemoryCount-1);
// Use modular wraparound and snap to nearest integer in the allowed index range 0..15.
// FIXFIXFIX - eliminate pre-clamping so modular wraparound is more useful.
int index = max(0u, static_cast<unsigned>(round(v)) % MemoryCount);

float cv = inputs[MEMORY_SELECT_CV_INPUT].getVoltageSum();
float slider = params[MEMORY_SELECT_PARAM].getValue();
float attenu = 2 * params[MEMORY_SELECT_ATTEN].getValue();
if (isLowSensitive(MEMORY_SELECT_ATTEN))
attenu /= AttenuverterLowSensitivityDenom;
slider += attenu * cv;
int index = max(0u, static_cast<unsigned>(round(slider)) % MemoryCount);
return index;
}

Expand Down

0 comments on commit a49d08b

Please sign in to comment.