LoadTraceTests112.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // REA_rodada112: opening a project, measured and reported (core/LoadTrace.h) — phase timing, a progress bar that only
  2. // moves forward with "Loading <name>... i/n", and samples on a missing drive / dead network share probed once per root.
  3. #include "core/LoadTrace.h"
  4. TEST (load112_progress_moves_forward_through_stages)
  5. {
  6. namespace lt = lynx::loadtrace;
  7. lt::begin ("song.flp");
  8. CHECK (lt::active());
  9. CHECK (lt::progress() == 0.0);
  10. lt::stage (0.30, 0.55, "Reading the samples...", "Reading {0}... {1}/{2}");
  11. CHECK (std::abs (lt::progress() - 0.30) < 1e-9);
  12. CHECK (lt::describe (lt::status()) == "Reading the samples...");
  13. lt::step (2, 4, "take 1.wav");
  14. CHECK (std::abs (lt::progress() - 0.425) < 1e-9);
  15. CHECK (lt::describe (lt::status()) == "Reading take 1.wav... 2/4");
  16. // a late item of an earlier slice never moves the bar back
  17. lt::stage (0.55, 0.90, "Loading plugins...", "Loading {0}... {1}/{2}");
  18. lt::step (0, 12, "Auto-Tune Pro", 1);
  19. CHECK (std::abs (lt::progress() - 0.55) < 1e-9);
  20. CHECK (lt::describe (lt::status()) == "Loading Auto-Tune Pro... 1/12");
  21. lt::step (3, 12, "Pro-Q 4", 4);
  22. CHECK (std::abs (lt::progress() - (0.55 + 0.35 * 3.0 / 12.0)) < 1e-9);
  23. CHECK (lt::describe (lt::status()) == "Loading Pro-Q 4... 4/12");
  24. const auto before = lt::progress();
  25. lt::stage (0.20, 0.30, "Reading the project...");
  26. CHECK (lt::progress() == before);
  27. lt::step (1, 1, {});
  28. CHECK (lt::progress() == before);
  29. // the template goes through the UI's translation
  30. lt::stage (0.55, 0.90, "Loading plugins...", "Loading {0}... {1}/{2}");
  31. lt::step (3, 12, "Pro-Q 4", 4);
  32. const auto pt = lt::describe (lt::status(), [] (const std::string& s) {
  33. return s == "Loading {0}... {1}/{2}" ? std::string ("Carregando {0}... {1}/{2}") : s;
  34. });
  35. CHECK (pt == "Carregando Pro-Q 4... 4/12");
  36. lt::end();
  37. CHECK (! lt::active());
  38. CHECK (lt::progress() == 1.0);
  39. }
  40. TEST (load112_phases_accumulate_and_report)
  41. {
  42. namespace lt = lynx::loadtrace;
  43. lt::begin ("vocal.flp");
  44. lt::add ("parse", 12.0);
  45. lt::add ("sample_decode", 100.0);
  46. lt::add ("sample_decode", 50.0);
  47. lt::add ("plugin_instantiate", 900.0);
  48. {
  49. const lt::Scope s ("rack_build");
  50. }
  51. lt::end();
  52. const auto phases = lt::phases();
  53. CHECK (phases.size() == 4);
  54. CHECK (phases[0].name == "parse"); // first-seen order
  55. CHECK (phases[1].name == "sample_decode" && phases[1].count == 2 && std::abs (phases[1].ms - 150.0) < 1e-9);
  56. CHECK (phases[3].name == "rack_build" && phases[3].count == 1 && phases[3].ms >= 0.0);
  57. const auto report = lt::reportLines();
  58. CHECK (report.find ("load_total_ms=") == 0);
  59. CHECK (report.find ("load_sample_decode_ms=150\n") != std::string::npos);
  60. CHECK (report.find ("load_sample_decode_count=2\n") != std::string::npos);
  61. CHECK (report.find ("load_plugin_instantiate_ms=900\n") != std::string::npos);
  62. // the log table: slowest first
  63. const auto table = lt::table();
  64. CHECK (table.find ("open: vocal.flp") == 0);
  65. CHECK (table.find ("plugin_instantiate") < table.find ("sample_decode"));
  66. CHECK (table.find ("sample_decode") < table.find ("parse"));
  67. // a new trace forgets the last one
  68. lt::begin ("next.flp");
  69. CHECK (lt::phases().empty());
  70. CHECK (lt::progress() == 0.0);
  71. lt::end();
  72. }
  73. TEST (load112_path_roots)
  74. {
  75. using lynx::loadtrace::pathRoot;
  76. CHECK (pathRoot ("K:\\LIWN-EP-ANTIGOS\\vocal\\take 1.wav") == "K:\\");
  77. CHECK (pathRoot ("k:/LIWN/take.wav") == "K:\\");
  78. CHECK (pathRoot ("K:") == "K:\\");
  79. CHECK (pathRoot ("\\\\Studio-PC\\Samples\\Vox\\a.wav") == "\\\\studio-pc\\samples\\");
  80. CHECK (pathRoot ("\\\\studio-pc\\samples") == "\\\\studio-pc\\samples\\");
  81. CHECK (pathRoot ("//nas/share/x.wav") == "\\\\nas\\share\\");
  82. CHECK (pathRoot ("\\\\server") == ""); // no share
  83. CHECK (pathRoot ("\\\\?\\C:\\long\\path.wav") == ""); // device paths are left to the file check
  84. CHECK (pathRoot ("Audio\\take.wav") == ""); // relative
  85. CHECK (pathRoot ("") == "");
  86. CHECK (pathRoot ("/mnt/k/take.wav") == "/mnt/");
  87. }
  88. TEST (load112_missing_drive_is_probed_once_per_root)
  89. {
  90. // the user's vocal projects keep their takes on an external drive (K:\) that is not plugged in: every sample
  91. // path tried several candidate locations, each a file query on the missing drive
  92. int rootQueries = 0;
  93. lynx::loadtrace::RootProbe probe ([&rootQueries] (const std::string& root) {
  94. ++rootQueries;
  95. return root == "C:\\";
  96. });
  97. for (int i = 0; i < 40; ++i)
  98. CHECK (! probe.rootAvailable ("K:\\LIWN-EP-ANTIGOS\\voz\\take " + std::to_string (i) + ".wav"));
  99. CHECK (probe.rootAvailable ("C:\\Users\\inliw\\Documents\\Image-Line\\FL Studio\\Projects\\kwe\\Audio\\a.wav"));
  100. CHECK (probe.rootAvailable ("c:/other.wav"));
  101. CHECK (! probe.rootAvailable ("\\\\old-pc\\samples\\kick.wav"));
  102. CHECK (! probe.rootAvailable ("\\\\OLD-PC\\Samples\\snare.wav"));
  103. CHECK (probe.rootAvailable ("relative\\take.wav")); // not a root question
  104. CHECK (rootQueries == 3); // K:\, C:\, \\old-pc\samples\ — once each
  105. CHECK (probe.probes() == 3);
  106. CHECK (probe.skipped() == 39 + 1);
  107. const auto missing = probe.missingRoots();
  108. CHECK (missing.size() == 2);
  109. // in the importer: samples on the missing drive cost no file query at all past the root probe
  110. flp::Project p;
  111. for (int i = 0; i < 12; ++i)
  112. p.channels.push_back ({ i, flp::ChannelType::sampler, "Vox " + std::to_string (i), "", "K:\\LIWN-EP-ANTIGOS\\voz\\take " + std::to_string (i) + ".wav", 1 });
  113. p.channels.push_back ({ 12, flp::ChannelType::sampler, "Kick", "", "%FLStudioData%\\k.wav", 1 });
  114. lynx::FlpImportOptions options;
  115. options.roots = { "C:\\FL", "C:\\FL\\Data", "C:\\User" };
  116. options.projectFolder = "C:\\Projects\\kwe";
  117. int fileQueries = 0, kQueries = 0;
  118. auto roots = std::make_shared<lynx::loadtrace::RootProbe> ([] (const std::string& root) { return root == "C:\\"; });
  119. options.fileExists = [&, roots] (const std::string& path) {
  120. if (! roots->rootAvailable (path))
  121. return false;
  122. ++fileQueries;
  123. kQueries += lynx::loadtrace::pathRoot (path) == "K:\\" ? 1 : 0;
  124. return path == "C:\\FL\\Data\\k.wav";
  125. };
  126. lynx::FlpImportReport report;
  127. options.report = &report;
  128. const auto s = lynx::importFlp (p, options);
  129. CHECK (kQueries == 0);
  130. CHECK (s.channels.size() == 13);
  131. CHECK (s.channels[12].instrument == lynx::InstrumentKind::sampler);
  132. CHECK (report.missingFiles.size() == 12); // still reported as missing, for the "Find missing files" dialog
  133. CHECK (fileQueries > 0);
  134. }