| 551 | } |
| 552 | |
| 553 | void pressNote(uint8_t note, uint8_t channel, uint8_t velocity) { |
| 554 | // Remove existing similar note |
| 555 | heldNotes.erase(std::remove(heldNotes.begin(), heldNotes.end(), note), heldNotes.end()); |
| 556 | // Push note to end |
| 557 | heldNotes.push_back(note); |
| 558 | // Handle polyphony modes |
| 559 | if (channels > 1) { |
| 560 | if (polyMode == MPE_MODE) { |
| 561 | // Output channel equals MIDI channel |
| 562 | } |
| 563 | else { |
| 564 | channel = assignChannel(note); |
| 565 | } |
| 566 | } |
| 567 | // Handle monophonic modes |
| 568 | else { |
| 569 | channel = 0; |
| 570 | if (monoMode == LAST_PRIORITY_MODE) { |
| 571 | // Always play note |
| 572 | } |
| 573 | if (monoMode == FIRST_PRIORITY_MODE) { |
| 574 | if (heldNotes.size() > 1) |
| 575 | return; |
| 576 | } |
| 577 | if (monoMode == LOWEST_PRIORITY_MODE) { |
| 578 | uint8_t minNote = *std::min_element(heldNotes.begin(), heldNotes.end()); |
| 579 | if (note != minNote) |
| 580 | return; |
| 581 | } |
| 582 | if (monoMode == HIGHEST_PRIORITY_MODE) { |
| 583 | uint8_t maxNote = *std::max_element(heldNotes.begin(), heldNotes.end()); |
| 584 | if (note != maxNote) |
| 585 | return; |
| 586 | } |
| 587 | } |
| 588 | // Set note |
| 589 | notes[channel] = note; |
| 590 | gates[channel] = true; |
| 591 | velocities[channel] = velocity; |
| 592 | retriggerPulses[channel].trigger(1e-3); |
| 593 | } |
| 594 | |
| 595 | /** -1 velocity means unset. */ |
| 596 | void releaseNote(uint8_t note, int8_t channel, int8_t velocity) { |