| 948 | } |
| 949 | |
| 950 | void CCompiler::ScanSong() |
| 951 | { |
| 952 | // Scan and optimize song |
| 953 | // |
| 954 | |
| 955 | // Re-assign instruments |
| 956 | m_iAssignedInstruments.clear(); // // // |
| 957 | |
| 958 | // TODO: remove these |
| 959 | m_bSequencesUsed2A03.fill({ }); |
| 960 | m_bSequencesUsedVRC6.fill({ }); |
| 961 | m_bSequencesUsedN163.fill({ }); |
| 962 | m_bSequencesUsedS5B.fill({ }); |
| 963 | |
| 964 | const inst_type_t INST[] = {INST_2A03, INST_VRC6, INST_N163, INST_S5B}; // // // |
| 965 | decltype(m_bSequencesUsed2A03) *used[] = {&m_bSequencesUsed2A03, &m_bSequencesUsedVRC6, &m_bSequencesUsedN163, &m_bSequencesUsedS5B}; |
| 966 | |
| 967 | bool inst_used[MAX_INSTRUMENTS] = { }; // // // |
| 968 | |
| 969 | auto &Im = *m_pModule->GetInstrumentManager(); |
| 970 | |
| 971 | // // // Scan patterns in entire module |
| 972 | m_pModule->VisitSongs([&] (const CSongData &song) { |
| 973 | int PatternLength = song.GetPatternLength(); |
| 974 | m_ChannelOrder.ForeachChannel([&] (stChannelID j) { |
| 975 | for (int k = 0; k < MAX_PATTERN; ++k) |
| 976 | for (int l = 0; l < PatternLength; ++l) { |
| 977 | const auto ¬e = song.GetPattern(j, k).GetNoteOn(l); |
| 978 | if (note.Instrument < std::size(inst_used)) // // // |
| 979 | inst_used[note.Instrument] = true; |
| 980 | } |
| 981 | }); |
| 982 | }); |
| 983 | |
| 984 | Im.VisitInstruments([&] (const CInstrument &inst, std::size_t i) { |
| 985 | if (inst_used[i]) { // // // |
| 986 | // List of used instruments |
| 987 | m_iAssignedInstruments.push_back(i); |
| 988 | |
| 989 | // Create a list of used sequences |
| 990 | inst_type_t it = Im.GetInstrumentType(i); // // // |
| 991 | for (size_t z = 0; z < std::size(used); ++z) if (it == INST[z]) { |
| 992 | auto pInstrument = static_cast<const CSeqInstrument *>(&inst); |
| 993 | for (auto j : enum_values<sequence_t>()) |
| 994 | if (pInstrument->GetSeqEnable(j)) |
| 995 | (*used[z])[pInstrument->GetSeqIndex(j)][(unsigned)j] = true; |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | }); |
| 1000 | |
| 1001 | // See which samples are used |
| 1002 | m_iSamplesUsed = 0; |
| 1003 | |
| 1004 | m_bSamplesAccessed.fill({ }); // // // |
| 1005 | |
| 1006 | // Get DPCM channel index |
| 1007 | unsigned int Instrument = 0; |
nothing calls this directly
no test coverage detected