MCPcopy Create free account
hub / github.com/VCVRack/Befaco / process

Method process

src/Atte.cpp:72–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 }
71
72 void process(const ProcessArgs& args) override {
73
74 const bool updateLights = lightDivider.process();
75 const float deltaTime = args.sampleTime * lightDivider.getDivision();
76
77 const float normalledVoltage = normalledVoltages[normalledVoltageIdx];
78 float_4 previousChannelNormalledVoltage[4] = {normalledVoltage, normalledVoltage, normalledVoltage, normalledVoltage};
79 int previousChannelPolyphony = 1;
80
81 // loop over the 4 channels
82 for (int channel = 0; channel < NUM_CHANNELS; channel += 1) {
83 // polyphony setting is normalled from the previous channel
84 const int numPolyphonyEngines = std::max(1, inputs[A_INPUT + channel].isConnected() ? inputs[A_INPUT + channel].getChannels() : previousChannelPolyphony);
85 previousChannelPolyphony = numPolyphonyEngines;
86
87 // loop over the polyphony engines
88 for (int c = 0; c < numPolyphonyEngines; c += 4) {
89
90 float_4 inA = inputs[A_INPUT + channel].getNormalPolyVoltageSimd<float_4>(previousChannelNormalledVoltage[c / 4], c);
91 const float gainMode = (params[MODE_A_PARAM + channel].getValue() ? 1.f : -1.f);
92 outputs[A_OUTPUT + channel].setVoltageSimd(inA * gainMode * params[GAIN_A_PARAM + channel].getValue(), c);
93
94 previousChannelNormalledVoltage[c / 4] = inA;
95 }
96
97 outputs[A_OUTPUT + channel].setChannels(numPolyphonyEngines);
98
99 if (updateLights) {
100 if (numPolyphonyEngines > 1) {
101 lights[A_LIGHT + 0 + channel * 3].setBrightness(0.f);
102 lights[A_LIGHT + 1 + channel * 3].setBrightness(0.f);
103 float sum = 0.f;
104 for (int c = 0; c < numPolyphonyEngines; c += 4) {
105 sum += std::pow(outputs[A_OUTPUT + channel].getVoltage(c), 2);
106 }
107 lights[A_LIGHT + 2 + channel * 3].setBrightness(std::sqrt(sum / numPolyphonyEngines) / 10.f);
108 }
109 else {
110 // green for positive voltage, red for negative voltage
111 lights[A_LIGHT + 0 + channel * 3].setSmoothBrightness(outputs[A_OUTPUT + channel].getVoltage() < 0.f ? -outputs[A_OUTPUT + channel].getVoltage() / 10.f : 0.f, deltaTime);
112 lights[A_LIGHT + 1 + channel * 3].setSmoothBrightness(outputs[A_OUTPUT + channel].getVoltage() > 0.f ? +outputs[A_OUTPUT + channel].getVoltage() / 10.f : 0.f, deltaTime);
113 lights[A_LIGHT + 2 + channel * 3].setBrightness(0.f);
114 }
115 }
116 }
117 }
118
119 json_t* dataToJson() override {
120 json_t* rootJ = json_object();

Callers

nothing calls this directly

Calls 2

getChannelsMethod · 0.80
getValueMethod · 0.80

Tested by

no test coverage detected