| 408 | } |
| 409 | |
| 410 | void 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 ¬e) { |
| 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 | |
| 452 | void CFamiTrackerModule::RemoveUnusedDSamples() { |
| 453 | bool AssignUsed[MAX_INSTRUMENTS][NOTE_COUNT] = { }; |
no test coverage detected