Issue165Tests.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Round 190gm, issue #165 (karatmep232, Linux, video): a slide note that starts on the same step as a note. FL 2026
  2. // glides that note to the slide note's key over the slide note's length (the user's video, 0:04-0:08: B4 and a C#5
  3. // slide note on one step, the guitar bends up); LYNX sorted the slide before the note's "on", found no sounding voice
  4. // and dropped the slide, so the note stayed flat.
  5. TEST (issue165_a_slide_comes_after_the_notes_that_start_on_its_sample)
  6. {
  7. using namespace lynx;
  8. EventBuffer b;
  9. auto add = [&b] (NoteEvent::Type type, int key, int offset) {
  10. NoteEvent e;
  11. e.type = type;
  12. e.channel = 0;
  13. e.key = key;
  14. e.sampleOffset = offset;
  15. b.add (e);
  16. };
  17. add (NoteEvent::Type::slide, 73, 100); // (the order the scheduler emits them in: the slide note first)
  18. add (NoteEvent::Type::on, 71, 100);
  19. add (NoteEvent::Type::off, 69, 100);
  20. add (NoteEvent::Type::on, 60, 50);
  21. b.sortByOffset();
  22. CHECK (b.size() == 4);
  23. CHECK (b[0].sampleOffset == 50 && b[0].type == NoteEvent::Type::on);
  24. // on the same sample: the note that ends, the note that starts, then the slide that bends it
  25. CHECK (b[1].type == NoteEvent::Type::off && b[1].key == 69);
  26. CHECK (b[2].type == NoteEvent::Type::on && b[2].key == 71);
  27. CHECK (b[3].type == NoteEvent::Type::slide && b[3].key == 73);
  28. }
  29. namespace issue165
  30. {
  31. // an instrument that writes down what the rack asks of it, in order
  32. struct Recorder final : lynx::Instrument
  33. {
  34. std::vector<std::string> calls;
  35. void prepare (double) noexcept override {}
  36. void noteOn (int key, float) noexcept override { calls.push_back ("on " + std::to_string (key)); }
  37. void noteOff (int) noexcept override {}
  38. void allNotesOff() noexcept override {}
  39. void render (float*, float*, int, float, float) noexcept override {}
  40. void slideTo (int key, float, float) noexcept override { calls.push_back ("slide " + std::to_string (key)); }
  41. };
  42. } // namespace issue165
  43. TEST (issue165_a_slide_note_on_the_step_of_a_note_reaches_the_instrument_after_it)
  44. {
  45. using namespace lynx;
  46. Song song;
  47. song.mixer = Song::defaultMixer (2);
  48. ChannelDef c;
  49. c.instrument = InstrumentKind::plugin;
  50. c.plugin.id = "recorder";
  51. song.channels.push_back (c);
  52. song.patterns.emplace_back();
  53. Note b4;
  54. b4.key = 71;
  55. b4.start = ppq;
  56. b4.length = ppq * 2;
  57. Note slide; // the user's C#5 slide note, on B4's step
  58. slide.key = 73;
  59. slide.start = ppq;
  60. slide.length = ppq / 4;
  61. slide.slide = true;
  62. song.patterns[0].notes = { slide, b4 };
  63. song.patterns[0].lengthTicks = (std::int64_t) (ppq * 4);
  64. song.mode = PlayMode::pattern;
  65. auto rec = std::make_shared<issue165::Recorder>();
  66. RackState::Factories f;
  67. f.pluginInstruments = [rec] (const PluginRef&, double) { return std::shared_ptr<Instrument> (rec); };
  68. auto state = RackState::build (song, nullptr, 44100.0, f);
  69. RackRenderer renderer;
  70. renderer.prepare (44100.0, 256);
  71. const auto tps = song.bpm / 60.0 * ppq / 44100.0;
  72. std::vector<float> l (256), r (256);
  73. for (int done = 0; done < 44100; done += 256)
  74. renderer.process (state.get(), true, done * tps, 256, l.data(), r.data(), nullptr);
  75. CHECK (rec->calls.size() >= 2);
  76. if (rec->calls.size() >= 2)
  77. {
  78. CHECK (rec->calls[0] == "on 71");
  79. CHECK (rec->calls[1] == "slide 73");
  80. }
  81. }
  82. // What it sounds like: a note with a slide note a whole tone up on its own step ends a whole tone up (+200 cents), as a
  83. // slide note that starts inside the note always did
  84. TEST (issue165_a_note_glides_to_a_slide_note_that_starts_with_it)
  85. {
  86. using namespace lynx;
  87. ChannelDef synth;
  88. synth.instrument = InstrumentKind::synth;
  89. Note held;
  90. held.key = 60;
  91. held.length = ppq * 8;
  92. held.velocity = 0.8f;
  93. Note slide;
  94. slide.key = 62;
  95. slide.start = 0; // the note's own step
  96. slide.length = ppq / 4;
  97. slide.slide = true;
  98. const auto base = issue14::pitchAt (issue14::renderPattern (synth, { held }, 0.0f, 1.5), 1.0);
  99. const auto slid = issue14::pitchAt (issue14::renderPattern (synth, { slide, held }, 0.0f, 1.5), 1.0);
  100. CHECK (base > 0.0);
  101. CHECK (std::abs (issue14::cents (base, slid) - 200.0) < 15.0);
  102. // a slide note that starts inside the note (the case that already worked) still lands on the same pitch
  103. slide.start = ppq / 2;
  104. const auto later = issue14::pitchAt (issue14::renderPattern (synth, { held, slide }, 0.0f, 1.5), 1.0);
  105. CHECK (std::abs (issue14::cents (base, later) - 200.0) < 15.0);
  106. }