| 81 | } |
| 82 | |
| 83 | void process(const ProcessArgs& args) override { |
| 84 | if (!divider.process()) |
| 85 | return; |
| 86 | |
| 87 | midi::Message msg; |
| 88 | while (midiInput.tryPop(&msg, args.frame)) { |
| 89 | processMessage(msg); |
| 90 | } |
| 91 | |
| 92 | // Step channels |
| 93 | for (int id = 0; id < mapLen; id++) { |
| 94 | int cc = ccs[id]; |
| 95 | if (cc < 0) |
| 96 | continue; |
| 97 | // Get Module |
| 98 | Module* module = paramHandles[id].module; |
| 99 | if (!module) |
| 100 | continue; |
| 101 | // Get ParamQuantity from ParamHandle |
| 102 | int paramId = paramHandles[id].paramId; |
| 103 | ParamQuantity* paramQuantity = module->paramQuantities[paramId]; |
| 104 | if (!paramQuantity) |
| 105 | continue; |
| 106 | if (!paramQuantity->isBounded()) |
| 107 | continue; |
| 108 | // Set filter from param value if filter is uninitialized |
| 109 | if (!filterInitialized[id]) { |
| 110 | valueFilters[id].out = paramQuantity->getScaledValue(); |
| 111 | filterInitialized[id] = true; |
| 112 | continue; |
| 113 | } |
| 114 | // Check if CC has been set by the MIDI device |
| 115 | if (values[cc] < 0) |
| 116 | continue; |
| 117 | float value = values[cc] / 127.f; |
| 118 | |
| 119 | // Detect MIDI CC buttons |
| 120 | if (smooth && std::fabs(valueFilters[id].out - value) < 1.f) { |
| 121 | // Smooth value with filter |
| 122 | value = valueFilters[id].process(args.sampleTime * divider.getDivision(), value); |
| 123 | } |
| 124 | else { |
| 125 | // Jump filter value, don't filter |
| 126 | valueFilters[id].out = value; |
| 127 | } |
| 128 | |
| 129 | // Scale and snap value based on ParamQuantity |
| 130 | value = paramQuantity->fromScaled(value); |
| 131 | if (paramQuantity->snapEnabled) |
| 132 | value = std::round(value); |
| 133 | // Set param value without Engine smoothing, since it is already filtered. |
| 134 | APP->engine->setParamValue(module, paramId, value); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void processMessage(const midi::Message& msg) { |
| 139 | // DEBUG("MIDI: %01x %01x %02x %02x", msg.getStatus(), msg.getChannel(), msg.getNote(), msg.getValue()); |
nothing calls this directly
no test coverage detected