| 71 | } |
| 72 | |
| 73 | void process(const ProcessArgs& args) override { |
| 74 | midi::Message msg; |
| 75 | while (midiInput.tryPop(&msg, args.frame)) { |
| 76 | processMessage(msg); |
| 77 | } |
| 78 | |
| 79 | int channels = mpeMode ? 16 : 1; |
| 80 | |
| 81 | for (int id = 0; id < 16; id++) { |
| 82 | if (!outputs[CC_OUTPUT + id].isConnected()) |
| 83 | continue; |
| 84 | outputs[CC_OUTPUT + id].setChannels(channels); |
| 85 | |
| 86 | int8_t cc = learnedCcs[id]; |
| 87 | if (cc < 0) { |
| 88 | outputs[CC_OUTPUT + id].clearVoltages(); |
| 89 | continue; |
| 90 | } |
| 91 | |
| 92 | for (int c = 0; c < channels; c++) { |
| 93 | int16_t cellValue = int16_t(ccValues[cc][c]) * 128; |
| 94 | if (lsbMode && cc < 32) |
| 95 | cellValue += ccValues[cc + 32][c]; |
| 96 | // Maximum value for 14-bit CC should be MSB=127 LSB=0, not MSB=127 LSB=127, because this is the maximum value that 7-bit controllers can send. |
| 97 | float value = float(cellValue) / (128 * 127); |
| 98 | // Support negative values because the gamepad MIDI driver generates nonstandard 8-bit CC values. |
| 99 | value = clamp(value, -1.f, 1.f); |
| 100 | |
| 101 | // Detect behavior from MIDI buttons. |
| 102 | if (smooth && std::fabs(valueFilters[id][c].out - value) < 1.f) { |
| 103 | // Smooth value with filter |
| 104 | valueFilters[id][c].process(args.sampleTime, value); |
| 105 | } |
| 106 | else { |
| 107 | // Jump value |
| 108 | valueFilters[id][c].out = value; |
| 109 | } |
| 110 | outputs[CC_OUTPUT + id].setVoltage(valueFilters[id][c].out * 10.f, c); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | void processMessage(const midi::Message& msg) { |
| 116 | switch (msg.getStatus()) { |
nothing calls this directly
no test coverage detected