Issue282Check.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Round 190qs (issue #282, "FL Studio Trial + LYNX problem": Slicex and SoundFont Player gone in FL after Export to FL
  2. // Studio). FL marks a plugin it saved while that plugin was a trial (plugin record 0xD4 flag 0x80, core/FlWrapper.h
  3. // flTrialSaved) and keeps such a plugin locked where it is still a trial. The mark goes back with the plugin it was
  4. // saved with, through a .lynx save too, and the export report says so; LYNX's own records never carry it. FL's
  5. // Patcher used as a generator goes back as FL's Patcher (its whole graph), not as its main synth. Included in the app
  6. // class (--selftest).
  7. static juce::String issue282Check (juce::String& log)
  8. {
  9. using namespace lynx;
  10. auto song = Song::makeDefault();
  11. song.channels.resize (1);
  12. song.channels[0].name = "Lead";
  13. song.channels[0].instrument = InstrumentKind::threeosc;
  14. EffectSlot fx;
  15. fx.kind = EffectKind::fruityLimiter;
  16. fx.flOrigin = { "Fruity Limiter", flpexport::fruityLimiterDefaultState(), 0 };
  17. song.mixer[1].effects.push_back (fx);
  18. flpexport::stampOrigins (song);
  19. auto exportOf = [] (const Song& s, int& notes) {
  20. flpexport::Options options;
  21. flpexport::Report report;
  22. auto p = flp::parseProject (flpexport::exportFlp (s, options, report));
  23. notes = (int) std::count_if (report.notes.begin(), report.notes.end(),
  24. [] (const std::string& n) { return n.find ("saved by a trial of FL Studio") != std::string::npos; });
  25. return p;
  26. };
  27. auto flags = [] (const flp::Project& p, int& channel, int& slot) {
  28. channel = p.channels.empty() ? -1 : p.channels[0].wrapperFlags;
  29. slot = -1;
  30. for (const auto& m : p.mixer)
  31. if (m.index == 1 && ! m.slots.empty())
  32. slot = m.slots[0].wrapperFlags;
  33. };
  34. int notes = 0, channel = 0, slot = 0;
  35. auto p = exportOf (song, notes);
  36. flags (p, channel, slot);
  37. log << "LYNX's records: channel " << juce::String::toHexString (channel) << ", slot " << juce::String::toHexString (slot) << "\n";
  38. if (flTrialSaved (channel) || flTrialSaved (slot) || notes != 0)
  39. return "ERROR LYNX's own records carry FL's trial mark";
  40. // as a trial of FL saves them, imported, saved as .lynx and opened again, exported
  41. p.channels[0].wrapperFlags = 0x1d0;
  42. for (auto& m : p.mixer)
  43. if (m.index == 1 && ! m.slots.empty())
  44. m.slots[0].wrapperFlags = 0x1c0;
  45. FlpImportOptions options;
  46. options.fileExists = [] (const std::string&) { return true; };
  47. juce::String error;
  48. const auto reopened = ProjectFile::fromJson (ProjectFile::toJson (importFlp (flp::parseProject (flp::writeProject (p)), options)), error);
  49. if (! reopened || reopened->channels.size() != 1 || reopened->mixer.size() < 2 || reopened->mixer[1].effects.size() != 1)
  50. return "ERROR the trial-saved project did not come back from .lynx (" + error + ")";
  51. if (! reopened->channels[0].flOrigin.trialSaved || ! reopened->mixer[1].effects[0].flOrigin.trialSaved)
  52. return "ERROR the trial mark is lost in .lynx";
  53. flags (exportOf (*reopened, notes), channel, slot);
  54. log << "FL's trial records back: channel " << juce::String::toHexString (channel) << ", slot " << juce::String::toHexString (slot)
  55. << ", report notes " << notes << "\n";
  56. if (channel != 0x1d0 || slot != 0x1c0 || notes != 2)
  57. return "ERROR the trial-saved plugins did not go back as FL saved them";
  58. auto replaced = *reopened;
  59. replaced.channels[0].instrument = InstrumentKind::sampler;
  60. replaced.channels[0].samplePath = "C:/x.wav";
  61. replaced.channels[0].pluginState.clear();
  62. flags (exportOf (replaced, notes), channel, slot);
  63. if (channel != 0x150 || slot != 0x1c0 || notes != 1)
  64. return "ERROR a channel that holds another instrument kept the old plugin's trial mark";
  65. // FL's Patcher as a generator (when FL Studio is here): FL's Patcher with its own state
  66. const auto& fl = flStudioAccess();
  67. if (! fl.roots.data.empty())
  68. {
  69. const auto file = juce::File (juce::String::fromUTF8 (fl.roots.data.c_str())).getChildFile ("System/Render tests/Patcher (generator).flp");
  70. juce::MemoryBlock bytes;
  71. if (file.loadFileAsData (bytes))
  72. {
  73. const std::vector<std::uint8_t> data ((const std::uint8_t*) bytes.getData(), (const std::uint8_t*) bytes.getData() + bytes.getSize());
  74. const auto original = flp::parseProject (data);
  75. const auto imported = importFlp (original, options);
  76. const auto out = exportOf (imported, notes);
  77. const auto patcher = [] (const flp::Project& q) {
  78. return std::find_if (q.channels.begin(), q.channels.end(), [] (const flp::Channel& c) { return c.pluginName == "Patcher"; });
  79. };
  80. const auto a = patcher (original), b = patcher (out);
  81. log << "Patcher (generator): " << (b != out.channels.end() ? "Patcher" : "not Patcher") << "\n";
  82. if (a != original.channels.end() && (b == out.channels.end() || b->pluginState != a->pluginState))
  83. return "ERROR FL's Patcher generator did not go back as FL's Patcher";
  84. }
  85. }
  86. return "OK";
  87. }