LCOV - code coverage report
Current view: top level - src - MidiManager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 36 36
Test Date: 2026-03-03 00:31:37 Functions: 100.0 % 4 4

            Line data    Source code
       1              : #include "MidiManager.h"
       2              : 
       3           14 : MidiManager::MidiManager(VoiceManager& vm)
       4            7 :     : voiceManager(vm) {
       5            7 : }
       6              : 
       7           13 : void MidiManager::processBlock(MidiBuffer& midiMessages) {
       8              :     int drumCh[4], melCh[3];
       9           65 :     for (int v = 0; v < 4; ++v) drumCh[v] = voiceManager.getDrumChannel(v);
      10           52 :     for (int i = 0; i < 3; ++i) melCh[i] = voiceManager.getMelodicChannel(i);
      11              : 
      12           31 :     for (const auto meta : midiMessages) {
      13           18 :         const auto msg = meta.getMessage();
      14           18 :         const int ch = msg.getChannel();
      15           18 :         const int note = msg.getNoteNumber();
      16              : 
      17           18 :         if (msg.isMidiClock()) {
      18            6 :             midiClockPulse.fetch_add(1, std::memory_order_relaxed);
      19            6 :             continue;
      20              :         }
      21              : 
      22              :         // Drum voices: each voice matches channel + fixed note.
      23           12 :         if (msg.isNoteOn()) {
      24           10 :             const int voice = VoiceManager::matchDrumVoice(ch, note, drumCh);
      25           10 :             if (voice >= 0) {
      26            5 :                 ch10RawHitNote.store(note, std::memory_order_relaxed);
      27            5 :                 ch10RawHitCount.fetch_add(1, std::memory_order_relaxed);
      28            5 :                 drumVoiceHitCount[voice].fetch_add(1, std::memory_order_relaxed);
      29            5 :                 continue;
      30              :             }
      31            5 :         }
      32              : 
      33              :         // Melodic tracks: index 0-2 → tracks 1-3.
      34            7 :         const int track = VoiceManager::matchMelodicVoice(ch, melCh);
      35            7 :         if (track < 0) continue;
      36              : 
      37            6 :         const int trackIdx = track + 1; // indices 1-3 used
      38              : 
      39            6 :         if (msg.isNoteOn()) {
      40            4 :             activeNotes[trackIdx].insert(note);
      41            4 :             channelNoteOnNote[trackIdx].store(note, std::memory_order_relaxed);
      42            4 :             channelNoteOnCount[trackIdx].fetch_add(1, std::memory_order_relaxed);
      43            4 :         }
      44            2 :         else if (msg.isNoteOff()) {
      45            2 :             activeNotes[trackIdx].erase(note);
      46            2 :         }
      47              : 
      48           12 :         channelHighestNote[trackIdx].store(
      49            6 :             activeNotes[trackIdx].empty() ? -1 : *activeNotes[trackIdx].rbegin(),
      50              :             std::memory_order_relaxed);
      51           18 :     }
      52           13 : }
        

Generated by: LCOV version 2.4-0