PluginState190azTests.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Round 190az: a hosted plugin gets its saved settings once, when its instance is created. A project opened over
  2. // another one with the same plugin in the same channel / slot kept the first project's running instance, so it played
  3. // (and at the next save, stored) the first project's settings: --vst2test's second render, peak_gain_0.4=0.1.
  4. namespace pluginstate190az
  5. {
  6. struct Silent final : lynx::Instrument
  7. {
  8. void prepare (double) noexcept override {}
  9. void noteOn (int, float) noexcept override {}
  10. void noteOff (int) noexcept override {}
  11. void allNotesOff() noexcept override {}
  12. void render (float*, float*, int, float, float) noexcept override {}
  13. };
  14. struct Pass final : lynx::Effect
  15. {
  16. void prepare (double) noexcept override {}
  17. void reset() noexcept override {}
  18. void process (float*, float*, int, const lynx::EffectParams&, double) noexcept override {}
  19. };
  20. // a project as it comes from a file: every channel and slot is a new one (new instance tags)
  21. inline lynx::Song project (const std::string& instrumentState, const std::string& effectState)
  22. {
  23. auto s = lynx::Song::makeDefault();
  24. auto& c = s.channels[0];
  25. c.instrument = lynx::InstrumentKind::plugin;
  26. c.plugin = {};
  27. c.plugin.id = "VST-Test";
  28. c.plugin.state = instrumentState;
  29. lynx::EffectSlot slot;
  30. slot.kind = lynx::EffectKind::plugin;
  31. slot.plugin.id = "VST-Effect";
  32. slot.plugin.state = effectState;
  33. s.mixer[1].effects.clear();
  34. s.mixer[1].effects.push_back (slot);
  35. return s;
  36. }
  37. struct Made
  38. {
  39. std::vector<std::string> instruments, effects; // the saved settings each created instance was given
  40. lynx::RackState::Factories factories()
  41. {
  42. lynx::RackState::Factories f;
  43. f.pluginInstruments = [this] (const lynx::PluginRef& ref, double) -> std::shared_ptr<lynx::Instrument> {
  44. instruments.push_back (ref.state);
  45. return std::make_shared<Silent>();
  46. };
  47. f.pluginEffects = [this] (const lynx::PluginRef& ref, double) -> std::shared_ptr<lynx::Effect> {
  48. effects.push_back (ref.state);
  49. return std::make_shared<Pass>();
  50. };
  51. return f;
  52. }
  53. };
  54. } // namespace pluginstate190az
  55. TEST (pluginstate190az_a_project_opened_over_another_gets_its_own_plugin_settings)
  56. {
  57. using namespace pluginstate190az;
  58. Made made;
  59. const auto f = made.factories();
  60. auto state = lynx::RackState::build (project ("gain 0.1", "wet 0.1"), nullptr, 48000.0, f);
  61. CHECK (made.instruments == std::vector<std::string> { "gain 0.1" } && made.effects == std::vector<std::string> { "wet 0.1" });
  62. const auto* firstInstrument = state->instruments[0].get();
  63. const auto* firstEffect = state->effects[1][0].get();
  64. // the same plugins in the same places, saved with other settings: new instances, created with those settings
  65. state = lynx::RackState::build (project ("gain 0.4", "wet 0.4"), state.get(), 48000.0, f);
  66. CHECK (made.instruments == (std::vector<std::string> { "gain 0.1", "gain 0.4" }));
  67. CHECK (made.effects == (std::vector<std::string> { "wet 0.1", "wet 0.4" }));
  68. CHECK (state->instruments[0].get() != firstInstrument && state->effects[1][0].get() != firstEffect);
  69. // only one of the two differs: only that one is created again
  70. state = lynx::RackState::build (project ("gain 0.4", "wet 0.9"), state.get(), 48000.0, f);
  71. CHECK (made.instruments.size() == 2 && made.effects.size() == 3 && made.effects.back() == "wet 0.9");
  72. state = lynx::RackState::build (project ("gain 0.9", "wet 0.9"), state.get(), 48000.0, f);
  73. CHECK (made.instruments.size() == 3 && made.instruments.back() == "gain 0.9" && made.effects.size() == 3);
  74. // a project with no saved settings for the plugin (its defaults) over one that has them
  75. state = lynx::RackState::build (project ({}, {}), state.get(), 48000.0, f);
  76. CHECK (made.instruments.size() == 4 && made.instruments.back().empty() && made.effects.size() == 4 && made.effects.back().empty());
  77. }
  78. TEST (pluginstate190az_the_same_saved_settings_keep_the_running_plugins)
  79. {
  80. using namespace pluginstate190az;
  81. Made made;
  82. const auto f = made.factories();
  83. auto state = lynx::RackState::build (project ("gain 0.1", "wet 0.1"), nullptr, 48000.0, f);
  84. const auto* instrument = state->instruments[0].get();
  85. const auto* effect = state->effects[1][0].get();
  86. // the song arrives as new channels and slots with what the running plugins were created from (a session's
  87. // snapshot, the same file again): nothing is created
  88. state = lynx::RackState::build (project ("gain 0.1", "wet 0.1"), state.get(), 48000.0, f);
  89. CHECK (made.instruments.size() == 1 && made.effects.size() == 1);
  90. CHECK (state->instruments[0].get() == instrument && state->effects[1][0].get() == effect);
  91. }
  92. TEST (pluginstate190az_a_channel_and_a_slot_keep_their_plugin_whatever_the_song_saved)
  93. {
  94. using namespace pluginstate190az;
  95. Made made;
  96. const auto f = made.factories();
  97. auto song = project ("saved first", "saved first");
  98. auto state = lynx::RackState::build (song, nullptr, 48000.0, f);
  99. const auto* instrument = state->instruments[0].get();
  100. const auto* effect = state->effects[1][0].get();
  101. // the settings were captured for a save, then an undo brings back the song with the older ones: the same channel
  102. // and slot (copies keep their instance), so the running plugins and what was set in their windows stay
  103. auto saved = song;
  104. saved.channels[0].plugin.state = "saved later";
  105. saved.mixer[1].effects[0].plugin.state = "saved later";
  106. state = lynx::RackState::build (saved, state.get(), 48000.0, f);
  107. state = lynx::RackState::build (song, state.get(), 48000.0, f);
  108. CHECK (made.instruments.size() == 1 && made.effects.size() == 1);
  109. CHECK (state->instruments[0].get() == instrument && state->effects[1][0].get() == effect);
  110. // also when they moved in their lists in the same edit (issue #32)
  111. auto moved = saved;
  112. moved.channels.insert (moved.channels.begin(), lynx::Song::makeDefault().channels[1]);
  113. lynx::EffectSlot eq;
  114. eq.kind = lynx::EffectKind::eq;
  115. moved.mixer[1].effects.insert (moved.mixer[1].effects.begin(), eq);
  116. state = lynx::RackState::build (moved, state.get(), 48000.0, f);
  117. CHECK (made.instruments.size() == 1 && made.effects.size() == 1);
  118. CHECK (state->instruments[1].get() == instrument && state->effects[1][1].get() == effect);
  119. }