| 1224 | } |
| 1225 | |
| 1226 | bool CMainFrame::LoadInstrument(unsigned Index, const CStringW &filename) { // // // |
| 1227 | const auto err = [this] (int ID) { |
| 1228 | AfxMessageBox(ID, MB_ICONERROR); |
| 1229 | return false; |
| 1230 | }; |
| 1231 | |
| 1232 | if (Index != INVALID_INSTRUMENT) { |
| 1233 | if (CSimpleFile file {static_cast<LPCWSTR>(filename), std::ios::in | std::ios::binary}) { |
| 1234 | // FTI instruments files |
| 1235 | const std::string_view INST_HEADER = "FTI"; |
| 1236 | // const char INST_VERSION[] = "2.4"; |
| 1237 | |
| 1238 | const unsigned I_CURRENT_VER_MAJ = 2; // // // 050B |
| 1239 | const unsigned I_CURRENT_VER_MIN = 5; // // // 050B |
| 1240 | |
| 1241 | // Signature |
| 1242 | if (file.ReadStringN(INST_HEADER.size()) != INST_HEADER) |
| 1243 | return err(IDS_INSTRUMENT_FILE_FAIL); |
| 1244 | |
| 1245 | // Version |
| 1246 | unsigned iInstMaj = conv::from_digit(file.ReadInt8()); |
| 1247 | if (file.ReadInt8() != '.') |
| 1248 | return err(IDS_INST_VERSION_UNSUPPORTED); |
| 1249 | unsigned iInstMin = conv::from_digit(file.ReadInt8()); |
| 1250 | if (std::tie(iInstMaj, iInstMin) > std::tie(I_CURRENT_VER_MAJ, I_CURRENT_VER_MIN)) |
| 1251 | return err(IDS_INST_VERSION_UNSUPPORTED); |
| 1252 | |
| 1253 | return GetDoc().Locked([&] { |
| 1254 | try { |
| 1255 | auto *pManager = GetDoc().GetModule()->GetInstrumentManager(); |
| 1256 | inst_type_t InstType = static_cast<inst_type_t>(file.ReadInt8()); |
| 1257 | if (auto pInstrument = pManager->CreateNew(InstType != INST_NONE ? InstType : INST_2A03)) { |
| 1258 | pInstrument->OnBlankInstrument(); |
| 1259 | FTEnv.GetInstrumentService()->GetInstrumentIO(InstType, FTEnv.GetSettings()->Version.iErrorLevel)-> |
| 1260 | ReadFromFTI(*pInstrument, file, iInstMaj * 10 + iInstMin); // // // |
| 1261 | return pManager->InsertInstrument(Index, std::move(pInstrument)); |
| 1262 | } |
| 1263 | |
| 1264 | AfxMessageBox(L"Failed to create instrument", MB_ICONERROR); |
| 1265 | return false; |
| 1266 | } |
| 1267 | catch (CModuleException &e) { |
| 1268 | if (FTEnv.GetSettings()->Version.iErrorLevel > MODULE_ERROR_DEFAULT) |
| 1269 | e.AppendFooter("\n\nTry lowering the module error level in the configuration menu."); |
| 1270 | AfxMessageBox(conv::to_wide(e.GetErrorString()).data(), MB_ICONERROR); |
| 1271 | return false; |
| 1272 | } |
| 1273 | }); |
| 1274 | } |
| 1275 | return err(IDS_FILE_OPEN_ERROR); |
| 1276 | } |
| 1277 | return err(IDS_INST_LIMIT); |
| 1278 | } |
| 1279 | |
| 1280 | std::shared_ptr<CInstrument> CMainFrame::GetSelectedInstrument() const { // // // |
| 1281 | int index = GetSelectedInstrumentIndex(); |
no test coverage detected