Perf190rnCheck.inc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Round 190rn (0.1.32 perf round 10): the undo history's memory cap (AudioEngine::trimUndoHistory, core/SongBytes.h)
  2. // through a real engine. Included in the app class of Main.cpp; --perf190rntest <report> and --selftest "perf190rn".
  3. juce::String perf190rnCheck (juce::String& log)
  4. {
  5. using namespace lynx;
  6. juce::String result = "OK";
  7. const auto check = [&] (const juce::String& what, bool ok) {
  8. log << (ok ? "ok " : "FAIL ") << what << "\n";
  9. if (! ok && result == "OK")
  10. result = "ERROR " + what;
  11. };
  12. // the estimate follows what a copy holds: notes, curves, Patcher graphs, slot states
  13. {
  14. auto song = Song::makeDefault();
  15. song.patterns[0].notes.clear();
  16. const auto empty = songbytes::song (song);
  17. song.patterns[0].notes.resize (10000);
  18. const auto withNotes = songbytes::song (song);
  19. check ("estimate: 10,000 notes add their size", withNotes - empty == 10000 * sizeof (Note));
  20. song.patterns[0].notes[0].curves.edit().lane (NoteCurveLane::pitch) = { { 0, 0.0f }, { 96, 1.0f } };
  21. check ("estimate: a note's curves count", songbytes::song (song) > withNotes + sizeof (NoteCurves));
  22. song.mixer[1].effects.push_back ({});
  23. song.mixer[1].effects.back().state.resize (100000);
  24. check ("estimate: a slot's state counts", songbytes::song (song) > withNotes + 100000);
  25. song.channels[0].patcher.nodes.resize (3);
  26. check ("estimate: a Patcher graph's nodes count", songbytes::song (song) > withNotes + 100000 + 3 * sizeof (PatchNode));
  27. }
  28. // the cap: the oldest steps go, one always stays, undo / redo still walk what is kept
  29. {
  30. AudioEngine engine (false);
  31. auto song = Song::makeDefault();
  32. song.patterns[0].notes.resize (20000); // ~2 MB a step
  33. engine.setSong (std::move (song));
  34. const auto step = songbytes::song (engine.getSong());
  35. engine.setUndoBytesForTest (step * 5 + step / 2);
  36. for (int i = 0; i < 12; ++i)
  37. engine.editSong ([i] (Song& s) { s.patterns[0].notes[0].key = 30 + i; });
  38. const auto kept = engine.getHistoryPosition();
  39. log << " step " << juce::String ((double) step / 1048576.0, 2) << " MB, cap 5.5 steps: " << kept << " steps kept, "
  40. << juce::String ((double) engine.getUndoBytes() / 1048576.0, 2) << " MB\n";
  41. check ("cap: 5 of 12 steps kept", kept == 5);
  42. check ("cap: the history's bytes under the cap", engine.getUndoBytes() <= step * 5 + step / 2);
  43. check ("cap: the newest step undoes to the edit before it", (engine.undo(), engine.getSong().patterns[0].notes[0].key == 40));
  44. for (int i = 0; i < 10; ++i)
  45. engine.undo();
  46. check ("cap: undo stops at the oldest kept step", engine.getSong().patterns[0].notes[0].key == 36 && ! engine.canUndo());
  47. for (int i = 0; i < 10; ++i)
  48. engine.redo();
  49. check ("cap: redo walks back to the last edit", engine.getSong().patterns[0].notes[0].key == 41 && ! engine.canRedo());
  50. engine.setUndoBytesForTest (1);
  51. check ("cap: one step always stays", engine.getHistoryPosition() == 1 && engine.canUndo());
  52. engine.setUndoBytesForTest (std::size_t (1) << 30);
  53. engine.setUndoLevels (10); // (Settings' least)
  54. for (int i = 0; i < 14; ++i)
  55. engine.editSong ([i] (Song& s) { s.patterns[0].notes[0].key = 60 + i; });
  56. check ("steps: Settings' undo levels still cap the count", engine.getHistoryPosition() == 10);
  57. }
  58. return result;
  59. }