|
| 1 | +// |
| 2 | +// Created by maria on 17/05/2025. |
| 3 | +// |
| 4 | + |
| 5 | +#include "DrumsLoader.h" |
| 6 | +// i hate sysex |
| 7 | + |
| 8 | +void Encore::RhythmEngine::DrumsLoader::CheckToms(const smf::MidiEvent &event) { |
| 9 | + if (event.isNoteOn()) { |
| 10 | + if (event[1] == 110) { |
| 11 | + YellowTom.emplace(event.tick, event.getLinkedEvent()->tick); |
| 12 | + } else if (event[1] == 111) { |
| 13 | + BlueTom.emplace(event.tick, event.getLinkedEvent()->tick); |
| 14 | + } else if (event[1] == 112) { |
| 15 | + GreenTom.emplace(event.tick, event.getLinkedEvent()->tick); |
| 16 | + }; |
| 17 | + ; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +[[nodiscard]] int |
| 22 | +Encore::RhythmEngine::DrumsLoader::GetNoteType(const smf::MidiEvent &event) { |
| 23 | + if (GetEventLane(Difficulty, event) == 4) { |
| 24 | + if (!GreenTom.empty()) { |
| 25 | + if (GreenTom.front().first <= event.tick) { |
| 26 | + return 0; |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + if (GetEventLane(Difficulty, event) == 3) { |
| 31 | + if (!BlueTom.empty()) { |
| 32 | + if (BlueTom.front().first <= event.tick) { |
| 33 | + return 0; |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + if (GetEventLane(Difficulty, event) == 2) { |
| 38 | + if (!YellowTom.empty()) { |
| 39 | + if (YellowTom.front().first <= event.tick) { |
| 40 | + return 0; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + if (GetEventLane(Difficulty, event) <= 1) { |
| 45 | + return 0; |
| 46 | + } |
| 47 | + return 1; |
| 48 | +} |
| 49 | +void Encore::RhythmEngine::DrumsLoader::CheckEvents(const smf::MidiEvent &event) { |
| 50 | + if (!chart.solos.empty()) { |
| 51 | + if (CurrentSolo < chart.solos.size() - 1 |
| 52 | + && chart.solos[CurrentSolo].StartTick + chart.solos[CurrentSolo].EndTick |
| 53 | + < event.tick) |
| 54 | + CurrentSolo++; |
| 55 | + } |
| 56 | + |
| 57 | + if (!chart.overdrive.empty()) { |
| 58 | + if (CurrentOverdrive < chart.overdrive.size() - 1 |
| 59 | + && chart.overdrive[CurrentOverdrive].StartTick |
| 60 | + + chart.overdrive[CurrentOverdrive].EndTick |
| 61 | + < event.tick) |
| 62 | + CurrentOverdrive++; |
| 63 | + } |
| 64 | +} |
| 65 | +void Encore::RhythmEngine::DrumsLoader::GetChartEvents(smf::MidiEventList track) { |
| 66 | + track.linkNotePairs(); |
| 67 | + for (int eventInt = 0; eventInt < track.size(); eventInt++) { |
| 68 | + smf::MidiEvent &event = track[eventInt]; |
| 69 | + if (event[1] == 116 && event.isNoteOn()) { |
| 70 | + chart.overdrive.emplace_back( |
| 71 | + event.tick, |
| 72 | + event.seconds, |
| 73 | + event.getLinkedEvent()->tick - event.tick, |
| 74 | + event.getLinkedEvent()->seconds - event.seconds |
| 75 | + ); |
| 76 | + } |
| 77 | + if (event[1] == 103 && event.isNoteOn()) { |
| 78 | + chart.solos.emplace_back( |
| 79 | + event.tick, |
| 80 | + event.seconds, |
| 81 | + event.getLinkedEvent()->tick - event.tick, |
| 82 | + event.getLinkedEvent()->seconds - event.seconds |
| 83 | + ); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +void Encore::RhythmEngine::DrumsLoader::CreateNote(const smf::MidiEvent &event) { |
| 88 | + int lengthTicks = event.getLinkedEvent()->tick - event.tick; |
| 89 | + double lengthSec = event.getLinkedEvent()->seconds - event.seconds; |
| 90 | + if (event.getLinkedEvent()->tick - event.tick < 170) { |
| 91 | + lengthTicks = 0; |
| 92 | + lengthSec = 0; |
| 93 | + } |
| 94 | + chart[GetEventLane(Difficulty, event)].emplace_back( |
| 95 | + event.tick, lengthTicks, event.seconds, lengthSec, GetNoteType(event) |
| 96 | + ); |
| 97 | + if (!chart.solos.empty()) { |
| 98 | + if (event.tick >= chart.solos[CurrentSolo].StartTick) { |
| 99 | + chart.solos[CurrentSolo].NoteCount++; |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +void Encore::RhythmEngine::DrumsLoader::GetNoteModifiers(smf::MidiEventList track) { |
| 105 | + track.linkNotePairs(); |
| 106 | + for (int eventInt = 0; eventInt < track.size(); eventInt++) { |
| 107 | + smf::MidiEvent &event = track[eventInt]; |
| 108 | + CheckToms(event); |
| 109 | + // can have events for things like overdrive here |
| 110 | + // ugh |
| 111 | + // can i just have notes work for now |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +void Encore::RhythmEngine::DrumsLoader::CheckModifiers(const smf::MidiEvent &event) { |
| 116 | + if (!BlueTom.empty()) { |
| 117 | + if (BlueTom.front().second <= event.tick) |
| 118 | + BlueTom.pop(); |
| 119 | + } |
| 120 | + if (!YellowTom.empty()) { |
| 121 | + if (YellowTom.front().second <= event.tick) |
| 122 | + YellowTom.pop(); |
| 123 | + } |
| 124 | + if (!GreenTom.empty()) { |
| 125 | + if (GreenTom.front().second <= event.tick) |
| 126 | + GreenTom.pop(); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +void Encore::RhythmEngine::DrumsLoader::GetNotes(smf::MidiEventList track) { |
| 131 | + track.linkNotePairs(); |
| 132 | + for (int eventInt = 0; eventInt < track.size(); eventInt++) { |
| 133 | + smf::MidiEvent &event = track[eventInt]; |
| 134 | + // im tired boss |
| 135 | + if (event[0] == 255) |
| 136 | + continue; |
| 137 | + CheckEvents(event); |
| 138 | + CheckModifiers(event); |
| 139 | + if (IsInPitchRange(Difficulty, event) && event.isNoteOn()) { |
| 140 | + CreateNote(event); |
| 141 | + } |
| 142 | + } |
| 143 | +} |
0 commit comments