Sets the number of polyphony channels. Also clears voltages of higher channels. If disconnected, this does nothing (`channels` remains 0). If 0 is given, `channels` is set to 1 but all voltages are cleared. */
| 192 | If 0 is given, `channels` is set to 1 but all voltages are cleared. |
| 193 | */ |
| 194 | void setChannels(int channels) noexcept { |
| 195 | // If disconnected, keep the number of channels at 0. |
| 196 | if (this->channels == 0) { |
| 197 | return; |
| 198 | } |
| 199 | // Set higher channel voltages to 0 |
| 200 | for (int c = channels; c < this->channels; c++) { |
| 201 | if (c >= PORT_MAX_CHANNELS) |
| 202 | __builtin_unreachable(); |
| 203 | voltages[c] = 0.f; |
| 204 | } |
| 205 | // Don't allow caller to set port as disconnected |
| 206 | if (channels == 0) { |
| 207 | channels = 1; |
| 208 | } |
| 209 | this->channels = channels; |
| 210 | } |
| 211 | |
| 212 | /** Returns the number of channels. |
| 213 | If the port is disconnected, it has 0 channels. |