MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / ScanSong

Method ScanSong

Source/Compiler.cpp:950–1024  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

948}
949
950void 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 &note = 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;

Callers

nothing calls this directly

Calls 15

sizeFunction · 0.85
value_castFunction · 0.85
is_noteFunction · 0.85
fillMethod · 0.80
VisitSongsMethod · 0.80
GetPatternLengthMethod · 0.80
ForeachChannelMethod · 0.80
GetPatternMethod · 0.80
VisitInstrumentsMethod · 0.80
GetInstrumentTypeMethod · 0.80
ToMidiNoteMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected