WrapperMidi181cTests.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Round 181c: the wrapper options a plugin gets when it is created must not wait for a reload once they change.
  2. namespace wrappermidi181c
  3. {
  4. struct Silent final : lynx::Instrument
  5. {
  6. void prepare (double) noexcept override {}
  7. void noteOn (int, float) noexcept override {}
  8. void noteOff (int) noexcept override {}
  9. void allNotesOff() noexcept override {}
  10. void render (float*, float*, int, float, float) noexcept override {}
  11. };
  12. struct Pass final : lynx::Effect
  13. {
  14. void prepare (double) noexcept override {}
  15. void reset() noexcept override {}
  16. void process (float*, float*, int, const lynx::EffectParams&, double) noexcept override {}
  17. };
  18. inline lynx::Song song()
  19. {
  20. auto s = lynx::Song::makeDefault();
  21. auto& c = s.channels[0];
  22. c.instrument = lynx::InstrumentKind::plugin;
  23. c.plugin = {};
  24. c.plugin.id = "VST-Test";
  25. lynx::EffectSlot slot;
  26. slot.kind = lynx::EffectKind::plugin;
  27. slot.plugin.id = "VST-Effect";
  28. s.mixer[1].effects.clear();
  29. s.mixer[1].effects.push_back (slot);
  30. return s;
  31. }
  32. } // namespace wrappermidi181c
  33. TEST (wrapper181c_midi_options_reach_a_new_instance_of_the_plugin)
  34. {
  35. using namespace wrappermidi181c;
  36. int instruments = 0, effects = 0;
  37. lynx::RackState::Factories f;
  38. f.pluginInstruments = [&] (const lynx::PluginRef&, double) -> std::shared_ptr<lynx::Instrument> { ++instruments; return std::make_shared<Silent>(); };
  39. f.pluginEffects = [&] (const lynx::PluginRef&, double) -> std::shared_ptr<lynx::Effect> { ++effects; return std::make_shared<Pass>(); };
  40. const std::function<void (lynx::PluginRef&)> changes[] = {
  41. [] (lynx::PluginRef& r) { r.releaseVelocity = ! r.releaseVelocity; },
  42. [] (lynx::PluginRef& r) { r.sendBendRange = ! r.sendBendRange; },
  43. [] (lynx::PluginRef& r) { r.bendRange = 24; },
  44. [] (lynx::PluginRef& r) { r.modXAftertouch = ! r.modXAftertouch; },
  45. [] (lynx::PluginRef& r) { r.allNotesOffOnStop = ! r.allNotesOffOnStop; },
  46. [] (lynx::PluginRef& r) { r.resetOnFlush = ! r.resetOnFlush; },
  47. [] (lynx::PluginRef& r) { r.sendLoopPosition = ! r.sendLoopPosition; },
  48. };
  49. auto s = song();
  50. auto state = lynx::RackState::build (s, nullptr, 48000.0, f);
  51. CHECK (instruments == 1 && effects == 1);
  52. // nothing changed: the running plugins stay
  53. state = lynx::RackState::build (s, state.get(), 48000.0, f);
  54. CHECK (instruments == 1 && effects == 1);
  55. int wantedInstruments = 1, wantedEffects = 1;
  56. for (const auto& change : changes)
  57. {
  58. change (s.channels[0].plugin);
  59. state = lynx::RackState::build (s, state.get(), 48000.0, f);
  60. CHECK (instruments == ++wantedInstruments && effects == wantedEffects);
  61. change (s.mixer[1].effects[0].plugin);
  62. state = lynx::RackState::build (s, state.get(), 48000.0, f);
  63. CHECK (instruments == wantedInstruments && effects == ++wantedEffects);
  64. }
  65. // an option read while the plugin runs doesn't cost a re-creation
  66. s.channels[0].plugin.notifyRender = ! s.channels[0].plugin.notifyRender;
  67. state = lynx::RackState::build (s, state.get(), 48000.0, f);
  68. CHECK (instruments == wantedInstruments && effects == wantedEffects);
  69. }