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

Method LoadSequences

Source/FamiTrackerDocIO.cpp:580–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578}
579
580void CFamiTrackerDocIO::LoadSequences(CFamiTrackerModule &modfile, int ver) {
581 unsigned int Count = AssertRange(file_.GetBlockInt(), 0, MAX_SEQUENCES * (int)SEQ_COUNT, "2A03 sequence count");
582 AssertRange<MODULE_ERROR_OFFICIAL>(Count, 0U, static_cast<unsigned>(MAX_SEQUENCES * SEQ_COUNT - 1), "2A03 sequence count"); // // //
583
584 auto &Manager = *modfile.GetInstrumentManager();
585
586 if (ver == 1) {
587 for (unsigned int i = 0; i < Count; ++i) {
588 COldSequence Seq;
589 (void)AssertRange(file_.GetBlockInt(), 0, MAX_SEQUENCES - 1, "Sequence index");
590 unsigned int SeqCount = static_cast<unsigned char>(file_.GetBlockChar());
591 AssertRange(SeqCount, 0U, static_cast<unsigned>(MAX_SEQUENCE_ITEMS - 1), "Sequence item count");
592 for (unsigned int j = 0; j < SeqCount; ++j) {
593 char Value = file_.GetBlockChar();
594 Seq.AddItem(file_.GetBlockChar(), Value);
595 }
596 m_vTmpSequences.push_back(Seq); // // //
597 }
598 }
599 else if (ver == 2) {
600 for (unsigned int i = 0; i < Count; ++i) {
601 COldSequence Seq; // // //
602 unsigned int Index = AssertRange(file_.GetBlockInt(), 0, MAX_SEQUENCES - 1, "Sequence index");
603 auto Type = static_cast<sequence_t>((unsigned)AssertRange(file_.GetBlockInt(), 0, (int)SEQ_COUNT - 1, "Sequence type"));
604 unsigned int SeqCount = static_cast<unsigned char>(file_.GetBlockChar());
605 AssertRange(SeqCount, 0U, static_cast<unsigned>(MAX_SEQUENCE_ITEMS - 1), "Sequence item count");
606 for (unsigned int j = 0; j < SeqCount; ++j) {
607 char Value = file_.GetBlockChar();
608 Seq.AddItem(file_.GetBlockChar(), Value);
609 }
610 Manager.SetSequence(INST_2A03, Type, Index, Seq.Convert(Type)); // // //
611 }
612 }
613 else if (ver >= 3) {
614 CSequenceManager *pManager = Manager.GetSequenceManager(INST_2A03); // // //
615 int Indices[MAX_SEQUENCES * SEQ_COUNT];
616 sequence_t Types[MAX_SEQUENCES * SEQ_COUNT];
617
618 for (unsigned int i = 0; i < Count; ++i) {
619 unsigned int Index = Indices[i] = AssertRange(file_.GetBlockInt(), 0, MAX_SEQUENCES - 1, "Sequence index");
620 auto Type = Types[i] = static_cast<sequence_t>((unsigned)AssertRange(file_.GetBlockInt(), 0, (int)SEQ_COUNT - 1, "Sequence type"));
621 try {
622 unsigned char SeqCount = file_.GetBlockChar();
623 // AssertRange(SeqCount, 0, MAX_SEQUENCE_ITEMS, "Sequence item count");
624 auto pSeq = std::make_unique<CSequence>(Type);
625 pSeq->SetItemCount(SeqCount < MAX_SEQUENCE_ITEMS ? SeqCount : MAX_SEQUENCE_ITEMS);
626
627 unsigned int LoopPoint = AssertRange<MODULE_ERROR_STRICT>(
628 file_.GetBlockInt(), -1, static_cast<int>(SeqCount), "Sequence loop point");
629 // Work-around for some older files
630 if (LoopPoint != SeqCount)
631 pSeq->SetLoopPoint(LoopPoint);
632
633 if (ver == 4) {
634 int ReleasePoint = file_.GetBlockInt();
635 int Settings = file_.GetBlockInt();
636 pSeq->SetReleasePoint(AssertRange<MODULE_ERROR_STRICT>(
637 ReleasePoint, -1, static_cast<int>(SeqCount) - 1, "Sequence release point"));

Callers

nothing calls this directly

Calls 15

value_castFunction · 0.85
from_intFunction · 0.85
GetBlockIntMethod · 0.80
GetBlockCharMethod · 0.80
AddItemMethod · 0.80
ConvertMethod · 0.80
SetItemCountMethod · 0.80
SetLoopPointMethod · 0.80
SetReleasePointMethod · 0.80
SetSettingMethod · 0.80
SetItemMethod · 0.80
GetCollectionMethod · 0.80

Tested by

no test coverage detected