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

Method RemoveUnusedDSamples

Source/FamiTrackerModule.cpp:452–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

450}
451
452void CFamiTrackerModule::RemoveUnusedDSamples() {
453 bool AssignUsed[MAX_INSTRUMENTS][NOTE_COUNT] = { };
454
455 auto &Manager = *GetDSampleManager();
456 auto &InstManager = *GetInstrumentManager();
457
458 for (int i = 0; i < MAX_DSAMPLES; ++i) {
459 if (Manager.IsSampleUsed(i)) {
460 bool Used = false;
461 VisitSongs([&] (const CSongData &song) {
462 for (unsigned int Frame = 0; Frame < song.GetFrameCount(); ++Frame) {
463 unsigned int Pattern = song.GetFramePattern(Frame, apu_subindex_t::dpcm);
464 for (unsigned int Row = 0; Row < song.GetPatternLength(); ++Row) {
465 const auto &Note = song.GetPatternData(apu_subindex_t::dpcm, Pattern, Row); // // //
466 int Index = Note.Instrument;
467 if (!is_note(Note.Note) || Index == MAX_INSTRUMENTS)
468 continue; // // //
469 if (InstManager.GetInstrumentType(Index) != INST_2A03)
470 continue;
471 AssignUsed[Index][Note.ToMidiNote()] = true;
472 auto pInst = std::static_pointer_cast<CInstrument2A03>(InstManager.GetInstrument(Index));
473 if (pInst->GetSampleIndex(Note.ToMidiNote()) == i)
474 Used = true;
475 }
476 }
477 });
478 if (!Used)
479 Manager.RemoveDSample(i);
480 }
481 }
482 // also remove unused assignments
483 InstManager.VisitInstruments([&] (CInstrument &inst, std::size_t i) {
484 if (auto pInst = dynamic_cast<CInstrument2A03 *>(&inst))
485 for (int n = 0; n < NOTE_COUNT; ++n)
486 if (!AssignUsed[i][n])
487 pInst->SetSampleIndex(n, CInstrument2A03::NO_DPCM);
488 });
489}

Callers 1

Calls 12

is_noteFunction · 0.85
IsSampleUsedMethod · 0.80
GetPatternLengthMethod · 0.80
GetInstrumentTypeMethod · 0.80
ToMidiNoteMethod · 0.80
RemoveDSampleMethod · 0.80
VisitInstrumentsMethod · 0.80
SetSampleIndexMethod · 0.80
GetFrameCountMethod · 0.45
GetFramePatternMethod · 0.45
GetInstrumentMethod · 0.45
GetSampleIndexMethod · 0.45

Tested by

no test coverage detected