| 505 | } |
| 506 | |
| 507 | void 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 | |
| 548 | void 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! |
nothing calls this directly
no test coverage detected