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

Method LoadInstruments

Source/FamiTrackerDocIO.cpp:507–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505}
506
507void CFamiTrackerDocIO::LoadInstruments(CFamiTrackerModule &modfile, int ver) {
508 /*
509 * Version changes
510 *
511 * 2 - Extended DPCM octave range
512 * 3 - Added settings to the arpeggio sequence
513 *
514 */
515
516 // Number of instruments
517 const int Count = AssertRange(file_.GetBlockInt(), 0, CInstrumentManager::MAX_INSTRUMENTS, "Instrument count");
518 auto &Manager = *modfile.GetInstrumentManager();
519
520 for (int i = 0; i < Count; ++i) {
521 // Instrument index
522 int index = AssertRange(file_.GetBlockInt(), 0, CInstrumentManager::MAX_INSTRUMENTS - 1, "Instrument index");
523
524 // Read instrument type and create an instrument
525 inst_type_t Type = (inst_type_t)file_.GetBlockChar();
526 auto pInstrument = Manager.CreateNew(Type); // // //
527
528 try {
529 // Load the instrument
530 AssertFileData(pInstrument.get() != nullptr, "Failed to create instrument");
531 FTEnv.GetInstrumentService()->GetInstrumentIO(Type, err_lv_)->ReadFromModule(*pInstrument, file_); // // //
532 // Read name
533 int size = AssertRange(file_.GetBlockInt(), 0, CInstrument::INST_NAME_MAX, "Instrument name length");
534 char Name[CInstrument::INST_NAME_MAX + 1] = { };
535 file_.GetBlock(Name, size);
536 pInstrument->SetName(Name);
537 Manager.InsertInstrument(index, std::move(pInstrument)); // // // this registers the instrument content provider
538 }
539 catch (CModuleException &e) {
540 file_.SetDefaultFooter(e);
541 e.AppendError("At instrument " + conv::from_int_hex(index, 2) + ',');
542 Manager.RemoveInstrument(index);
543 throw e;
544 }
545 }
546}
547
548void CFamiTrackerDocIO::SaveInstruments(const CFamiTrackerModule &modfile, int ver) {
549 // A bug in v0.3.0 causes a crash if this is not 2, so change only when that ver is obsolete!

Callers

nothing calls this directly

Calls 15

from_int_hexFunction · 0.85
GetBlockIntMethod · 0.80
GetBlockCharMethod · 0.80
CreateNewMethod · 0.80
ReadFromModuleMethod · 0.80
GetInstrumentServiceMethod · 0.80
SetNameMethod · 0.80
SetDefaultFooterMethod · 0.80
AppendErrorMethod · 0.80
GetInstrumentManagerMethod · 0.45
getMethod · 0.45
GetInstrumentIOMethod · 0.45

Tested by

no test coverage detected