| 20 | } |
| 21 | |
| 22 | std::vector<Notes::Event> NoteOptions::process(const std::vector<Notes::Event>& inNoteEvents) |
| 23 | { |
| 24 | if (!mEnable) { |
| 25 | return inNoteEvents; |
| 26 | } |
| 27 | |
| 28 | std::vector<Notes::Event> processed_note_events; |
| 29 | |
| 30 | auto keyVector = _createKeyVector(mRootNote, mScaleType); |
| 31 | |
| 32 | processed_note_events.reserve(inNoteEvents.size()); |
| 33 | |
| 34 | for (const auto& note_event: inNoteEvents) { |
| 35 | if (note_event.pitch < mMinMidiNote || note_event.pitch > mMaxMidiNote) |
| 36 | continue; |
| 37 | |
| 38 | if (mScaleType == Chromatic) { |
| 39 | processed_note_events.push_back(note_event); |
| 40 | } else { |
| 41 | if (mSnapMode == Remove) { |
| 42 | if (_isInKey(note_event.pitch, keyVector)) |
| 43 | processed_note_events.push_back(note_event); |
| 44 | } else { |
| 45 | Notes::Event processed_note_event = note_event; |
| 46 | |
| 47 | // If pitch bends are more positive: adjust up, otherwise adjust down. |
| 48 | // Nothing is done if note is in key. |
| 49 | bool adjust_up = std::accumulate(note_event.bends.begin(), note_event.bends.end(), 0) >= 0; |
| 50 | processed_note_event.pitch = _getClosestMidiNoteInKey(note_event.pitch, keyVector, adjust_up); |
| 51 | |
| 52 | processed_note_events.push_back(processed_note_event); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return processed_note_events; |
| 58 | } |
| 59 | |
| 60 | bool NoteOptions::_isInKey(int inMidiNote, const std::vector<int>& inKeyArray) |
| 61 | { |
no outgoing calls
no test coverage detected