Issue116DetachedTests.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Round 190i, issue #116: FL's "Detached" plugin window flag in the .flp (plugin record 0xD4, flags bit 0x4
  2. // [EXEC + DATA FL 2026: docs/analise/REA_rodada190i.md]) <-> PluginRef::detached.
  3. namespace issue116d
  4. {
  5. lynx::ForeignPlugin vst (const char* name, std::uint32_t id)
  6. {
  7. lynx::ForeignPlugin f;
  8. f.format = lynx::ForeignPlugin::Format::vst2;
  9. f.vst2Id = id;
  10. f.name = name;
  11. return f;
  12. }
  13. // a hosted instrument on channel 0 and a hosted effect on insert 1, both as imported from FL (their wrapper records)
  14. lynx::Song song (bool channelDetached, bool effectDetached, int channelFlags)
  15. {
  16. using namespace lynx;
  17. auto s = Song::makeDefault();
  18. s.channels.resize (1);
  19. auto& c = s.channels[0];
  20. c.instrument = InstrumentKind::plugin;
  21. c.plugin.name = "Drums";
  22. c.plugin.foreign = vst ("Drums", 0x44524D31);
  23. c.plugin.detached = channelDetached;
  24. c.flWrapperFlags = channelFlags;
  25. EffectSlot fx;
  26. fx.kind = EffectKind::plugin;
  27. fx.plugin.name = "Echo";
  28. fx.plugin.foreign = vst ("Echo", 0x4543484F);
  29. fx.plugin.detached = effectDetached;
  30. fx.smartDisable = false;
  31. s.mixer[1].effects.push_back (fx);
  32. return s;
  33. }
  34. flp::Project written (const lynx::Song& s)
  35. {
  36. lynx::flpexport::Options options;
  37. lynx::flpexport::Report report;
  38. return flp::parseProject (lynx::flpexport::exportFlp (s, options, report));
  39. }
  40. lynx::Song back (const flp::Project& p)
  41. {
  42. lynx::FlpImportOptions o;
  43. o.fileExists = [] (const std::string&) { return true; };
  44. return lynx::importFlp (p, o);
  45. }
  46. // the imported song's channel 0 / insert 1 slot 0 plugin: 1 detached, 0 docked, −1 not there
  47. int channelDetached (const lynx::Song& s)
  48. {
  49. return s.channels.empty() ? -1 : (int) s.channels[0].plugin.detached;
  50. }
  51. int effectDetached (const lynx::Song& s)
  52. {
  53. return s.mixer.size() < 2 || s.mixer[1].effects.empty() ? -1 : (int) s.mixer[1].effects[0].plugin.detached;
  54. }
  55. int channelFlags (const flp::Project& p)
  56. {
  57. return p.channels.empty() ? -1 : p.channels[0].wrapperFlags;
  58. }
  59. int slotFlags (const flp::Project& p)
  60. {
  61. for (const auto& m : p.mixer)
  62. if (m.index == 1 && ! m.slots.empty())
  63. return m.slots[0].wrapperFlags;
  64. return -1;
  65. }
  66. } // namespace issue116d
  67. TEST (issue116_flp_detached_flag_round_trips)
  68. {
  69. using namespace issue116d;
  70. CHECK (lynx::flDetached (0x155) && ! lynx::flDetached (0x151) && ! lynx::flDetached (-1));
  71. CHECK (lynx::withFlDetached (0x151, true) == 0x155 && lynx::withFlDetached (0x155, false) == 0x151);
  72. // docked (the default): FL's flags without 0x4 — a generator wrapper 0x150, an effect wrapper 0x140
  73. auto p = written (song (false, false, -1));
  74. CHECK (channelFlags (p) == 0x150 && slotFlags (p) == 0x140);
  75. auto s = back (p);
  76. CHECK (channelDetached (s) == 0 && effectDetached (s) == 0);
  77. // detached: bit 0x4 on each plugin's own record, and back
  78. p = written (song (true, false, -1));
  79. CHECK (channelFlags (p) == 0x154 && slotFlags (p) == 0x140);
  80. s = back (p);
  81. CHECK (channelDetached (s) == 1 && effectDetached (s) == 0);
  82. p = written (song (false, true, -1));
  83. CHECK (channelFlags (p) == 0x150 && slotFlags (p) == 0x144);
  84. s = back (p);
  85. CHECK (channelDetached (s) == 0 && effectDetached (s) == 1);
  86. // FL's other flags of an imported channel stay (0x1 visible, 0x20 smart disable); LYNX's Detached decides 0x4:
  87. // imported detached and docked again in LYNX, or the other way round
  88. CHECK (channelFlags (written (song (false, false, 0x175))) == 0x171);
  89. CHECK (channelFlags (written (song (true, false, 0x171))) == 0x175);
  90. // a channel that is not a hosted plugin keeps the flags it was imported with, 0x4 included (LYNX's own editors
  91. // have no Detached state to set it from)
  92. auto sampler = lynx::Song::makeDefault();
  93. sampler.channels.resize (1);
  94. sampler.channels[0].instrument = lynx::InstrumentKind::sampler;
  95. sampler.channels[0].samplePath = "C:/x.wav";
  96. sampler.channels[0].flWrapperFlags = 0x54;
  97. CHECK (channelFlags (written (sampler)) == 0x54);
  98. }