| 504 | #define CHECK_COLON() CHECK_SYMBOL(":") |
| 505 | |
| 506 | void CTextExport::ImportFile(const fs::path &FileName, CFamiTrackerDoc &Doc) { |
| 507 | // begin a new document |
| 508 | if (!Doc.OnNewDocument()) |
| 509 | throw std::runtime_error {"Unable to create new Famitracker document."}; |
| 510 | |
| 511 | // parse the file |
| 512 | Tokenizer t(FileName); // // // |
| 513 | |
| 514 | auto &modfile = *Doc.GetModule(); // // // |
| 515 | auto &InstManager = *modfile.GetInstrumentManager(); |
| 516 | |
| 517 | unsigned int dpcm_index = 0; |
| 518 | unsigned int dpcm_size = 0; |
| 519 | std::shared_ptr<ft0cc::doc::dpcm_sample> dpcm_sample; // // // |
| 520 | unsigned int track = 0; |
| 521 | unsigned int pattern = 0; |
| 522 | int N163count = -1; // // // |
| 523 | bool UseGroove[MAX_TRACKS] = {}; // // // |
| 524 | while (!t.Finished()) { |
| 525 | // read first token on line |
| 526 | if (t.IsEOL()) continue; // blank line |
| 527 | CStringA command = t.ReadToken().MakeUpper(); // // // |
| 528 | |
| 529 | int c = 0; |
| 530 | for (; c < CT_COUNT; ++c) |
| 531 | if (command == CT[c]) break; |
| 532 | |
| 533 | //DEBUG_OUT("Command read: %s\n", command); |
| 534 | switch (c) { |
| 535 | case CT_COMMENTLINE: |
| 536 | t.FinishLine(); |
| 537 | break; |
| 538 | case CT_TITLE: |
| 539 | modfile.SetModuleName(LPCSTR(t.ReadToken())); |
| 540 | t.ReadEOL(); |
| 541 | break; |
| 542 | case CT_AUTHOR: |
| 543 | modfile.SetModuleArtist(LPCSTR(t.ReadToken())); |
| 544 | t.ReadEOL(); |
| 545 | break; |
| 546 | case CT_COPYRIGHT: |
| 547 | modfile.SetModuleCopyright(LPCSTR(t.ReadToken())); |
| 548 | t.ReadEOL(); |
| 549 | break; |
| 550 | case CT_COMMENT: |
| 551 | { |
| 552 | auto sComment = std::string {modfile.GetComment()}; // // // |
| 553 | if (!sComment.empty()) |
| 554 | sComment += "\r\n"; |
| 555 | sComment += t.ReadToken(); |
| 556 | modfile.SetComment(sComment, modfile.ShowsCommentOnOpen()); |
| 557 | t.ReadEOL(); |
| 558 | } |
| 559 | break; |
| 560 | case CT_MACHINE: |
| 561 | modfile.SetMachine(enum_cast<machine_t>(static_cast<std::uint8_t>(t.ReadInt(0, 1)))); |
| 562 | t.ReadEOL(); |
| 563 | break; |
no test coverage detected