| 479 | } |
| 480 | |
| 481 | void releaseNote(uint8_t note) { |
| 482 | // Remove the note |
| 483 | auto it = std::find(heldNotes.begin(), heldNotes.end(), note); |
| 484 | if (it != heldNotes.end()) |
| 485 | heldNotes.erase(it); |
| 486 | // Hold note if pedal is pressed |
| 487 | if (pedal) |
| 488 | return; |
| 489 | // Turn off gate of all channels with note |
| 490 | for (int c = 0; c < channels; c++) { |
| 491 | if (notes[c] == note) { |
| 492 | gates[c] = false; |
| 493 | // this will stay low even when gates[c] = true |
| 494 | // is set by a note on before the gate is sent as low |
| 495 | gatesForceGap[c] = gateForceGaps; |
| 496 | } |
| 497 | } |
| 498 | // Set last note if monophonic |
| 499 | if (channels == 1) { |
| 500 | if (note == notes[0] && !heldNotes.empty()) { |
| 501 | uint8_t lastNote = heldNotes.back(); |
| 502 | notes[0] = lastNote; |
| 503 | gates[0] = true; |
| 504 | return; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void pressPedal() { |
| 510 | if (pedal) |