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

Method RemoveUnusedInstruments

Source/FamiTrackerModule.cpp:410–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410void CFamiTrackerModule::RemoveUnusedInstruments() {
411 bool used[MAX_INSTRUMENTS] = { }; // // //
412
413 VisitSongs([&] (const CSongData &song) { // // //
414 int length = song.GetPatternLength();
415 GetChannelOrder().ForeachChannel([&] (stChannelID Channel) {
416 for (unsigned int Frame = 0; Frame < song.GetFrameCount(); ++Frame)
417 song.GetPatternOnFrame(Channel, Frame).VisitRows(length, [&] (const stChanNote &note) {
418 if (note.Instrument < MAX_INSTRUMENTS)
419 used[note.Instrument] = true;
420 });
421 });
422 });
423
424 auto *pManager = GetInstrumentManager();
425
426 pManager->VisitInstruments([&] (CInstrument &, std::size_t i) {
427 if (!used[i])
428 pManager->RemoveInstrument(i);
429 });
430
431 const inst_type_t inst[] = {INST_2A03, INST_VRC6, INST_N163, INST_S5B};
432
433 // Also remove unused sequences
434 for (unsigned int i = 0; i < MAX_SEQUENCES; ++i)
435 for (auto j : enum_values<sequence_t>()) // // //
436 for (auto c : inst)
437 if (auto pSeq = pManager->GetSequence(c, j, i); pSeq && pSeq->GetItemCount() > 0) { // // //
438 bool Used = false;
439 for (int k = 0; k < MAX_INSTRUMENTS; ++k) {
440 if (pManager->HasInstrument(k) && pManager->GetInstrumentType(k) == c) {
441 auto pInstrument = std::static_pointer_cast<CSeqInstrument>(pManager->GetInstrument(k));
442 if (pInstrument->GetSeqIndex(j) == i && pInstrument->GetSeqEnable(j)) { // // //
443 Used = true; break;
444 }
445 }
446 }
447 if (!Used)
448 pSeq->Clear(); // // //
449 }
450}
451
452void CFamiTrackerModule::RemoveUnusedDSamples() {
453 bool AssignUsed[MAX_INSTRUMENTS][NOTE_COUNT] = { };

Callers 1

Calls 14

GetPatternLengthMethod · 0.80
ForeachChannelMethod · 0.80
VisitRowsMethod · 0.80
VisitInstrumentsMethod · 0.80
HasInstrumentMethod · 0.80
GetInstrumentTypeMethod · 0.80
GetFrameCountMethod · 0.45
RemoveInstrumentMethod · 0.45
GetSequenceMethod · 0.45
GetItemCountMethod · 0.45
GetInstrumentMethod · 0.45
GetSeqIndexMethod · 0.45

Tested by

no test coverage detected