فهرست منبع

Patcher passes the mod wheel, CCs, aftertouch and pitch wheel to the plugins inside; round doc 164e: FL's native generators ignore the mod wheel

Ka1-S 1 ماه پیش
والد
کامیت
8e2c1df064
5فایلهای تغییر یافته به همراه208 افزوده شده و 0 حذف شده
  1. 66 0
      docs/analise/REA_rodada164e-modwheel.md
  2. 26 0
      src/core/Patcher.cpp
  3. 8 0
      src/core/Patcher.h
  4. 107 0
      tests/Misc164mTests.inc
  5. 1 0
      tests/tests.cpp

+ 66 - 0
docs/analise/REA_rodada164e-modwheel.md

@@ -0,0 +1,66 @@
+# Round 164e (misc164m): the mod wheel and aftertouch on native instruments
+
+2026-10-27. Brief: "LYNX's Sampler, Synth and the FL-engine instruments respond to CC1 (and aftertouch) where FL's do
+(sampler162 left it plugin-only) — map like FL does per instrument". Evidence markers: [DECOMP] disassembly /
+decompilation of FL's own DLLs (objdump, Ghidra 12 headless, our scripts in tmp/misc164m/gh); [EXEC] FL's DLLs loaded
+unmodified by our own harness (tmp/misc164m/run/mi.c, from round 41's ms.c: CreatePlugInstance with a fake host that
+logs every host Dispatcher call, `midi=<n>,<msg>` calls the plugin's MIDIIn); [STR] strings; [DOC] web; [TEST] tests in
+tests/Misc164mTests.inc.
+
+## 1. How FL gets a controller's mod wheel to a plugin
+
+- FL's plugin SDK: a plugin receives raw MIDI (CCs, channel pressure) only through `TFruityPlug::MIDIIn` (vtable slot
+  16), and only after asking for it with the host dispatcher `FHD_WantMIDIInput` (id 5, "switch in Value"). Notes come
+  through TriggerVoice, the channel pitch / pitch wheel through the voice's Final.Pitch.
+- [EXEC] At creation, FL's **Fruity Wrapper** (VST/VST3/CLAP host) calls host dispatcher 5; the Patcher implements
+  MIDIIn. No native generator calls 5 (logged for MiniSynth, GMS, Morphine, Toxic Biohazard, Sawer, Sakura, PoiZone,
+  DirectWave, FL Slayer, 3x Osc, Wasp).
+- [DECOMP] MIDIIn (slot 16) of every Delphi generator shell (VMT found from CreatePlugInstance, tmp script
+  `midiin.py`): **abstract** (Delphi's abstract-error stub) for 3x Osc, Autogun, BassDrum, BeepMap, Drumaxx, Drumpad,
+  FL Keys, FLEX, FPC, Fruit Kick, Fruity DX10, DrumSynth Live, Granulizer, Slicer, Slicer 2, Slicex, Harmless, Harmor,
+  Kepler, Kepler Exo, MIDI Out, Ogun, Plucked!, PoiZone, Sakura, SoundFont Player, Sytrus, Transistor Bass, Wave
+  Traveller (calling it would raise run-time error 210, so FL never does). Implemented: Fruity Wrapper, Patcher,
+  ReWired, Wasp / Wasp XT, Sawer (it hands the message to its engine).
+- [DECOMP] The C++ "framework" generators (MiniSynth, GMS, Morphine, Toxic Biohazard, and the engines behind Sawer /
+  PoiZone / Sakura) have a MIDIIn and a CC table (value / 127 at `+0x1268`, pressure at `+0x166c`, the per-plugin CC
+  handlers: MiniSynth CC 1 → mod wheel `+0x39d8`, GMS CC 1 → `+0x3a14`, Toxic/Sawer/PoiZone sustain / reset /
+  MIDI-learn), but the request for MIDI input (`Dispatcher(5, 0, 1)`) and the forwarding to the engine are gated by a
+  module flag (`+0x52b`) that is 0 in FL's generator builds (`+0x52a` = 0 = generator: plugin flags 0x200011).
+- [EXEC] Even when MIDIIn is called directly with CC 1 = 127 and channel pressure 64, the engine's CC table entry and
+  pressure stay 0 (MiniSynth, GMS, Morphine, Toxic Biohazard: engine at shell `+0x228`, proved by the note's velocity
+  100/127 = 0.7874 landing in its velocity table) — the generator path only forwards notes to the shell's keyboard.
+- [STR] FL's remote-control targets include "Omni - Mod wheel (Wrapper)" (FLEngine_x64.dll): the focused **wrapper**'s
+  mod wheel. [DOC] Novation's FLkey notes and the Image-Line forum ("every single native synth ignores the mod wheel")
+  agree: CC 1 has no default function in FL; it is linked by hand (right-click a control › Link to controller).
+
+**Conclusion.** In FL 2026 no native generator — Sampler / audio clips (channel), 3x Osc, Sytrus, Harmor, Harmless,
+GMS, Morphine, MiniSynth, PoiZone, Toxic Biohazard, Sakura, Sawer, DirectWave, FL Slayer, DX10, Kepler, Ogun, Transistor
+Bass, the drum generators… — responds to the mod wheel or to aftertouch by itself. Their engines' "mod wheel" /
+"aftertouch" sources (Sakura's matrix, GMS's matrix rows, PoiZone's MW destination, Toxic's and Sawer's MIDI matrix,
+DirectWave's "Mod Wheel" source, DX10's mod wheel) are fed in FL only by their own on-screen controls / automation
+(PoiZone's wheel = parameter 157, Slayer's = parameter 28) or stay 0. LYNX already behaves the same: its native engines
+ignore CC 1 / pressure (`Instrument::controlChange` default), hosted plugins get the raw message (round 162c), and
+"Link to MIDI controller" (any knob's right-click) is FL's way to put the mod wheel on a native parameter.
+
+## 2. What changed
+
+- **Patcher** (`src/core/Patcher.*`): FL's Patcher implements MIDIIn and passes MIDI to the plugins inside; LYNX's
+  Patcher passed the live notes but dropped the mod wheel, the other CCs, channel pressure and the pitch wheel. Now
+  `PatcherInstrument::midiMessage / pitchBend / controlChange` reach the instruments cabled to "From LYNX" notes (a
+  VST inside a Patcher gets its mod wheel and aftertouch; LYNX's Sampler / Synth inside bend by the channel's range).
+  [TEST `misc164m_patcher_passes_live_controllers_to_its_instruments`]
+- Native engines unchanged on purpose. [TEST `misc164m_native_engines_keep_ignoring_the_mod_wheel_like_fl`: a Sakura
+  patch with mod wheel → level keeps the wheel at 0 whatever CC 1 does.]
+
+## 3. Not done / notes
+
+- LYNX's SoundFont player moves its "Mod wheel" knob from a live CC 1 (round 158 choice). FL's SoundFont Player has
+  no MIDI input (MIDIIn abstract), so this is a LYNX extra, left as it is.
+- The sustain pedal (CC 64) is not handled for LYNX's native instruments; FL's channel handles it on the host side
+  (not checked in this round).
+- Not checked with FL running and a real controller: this PC has no MIDI loopback (Windows MIDI Services runs but no
+  loopback endpoint exists; installing one needs the user). The evidence is the code path above and the harness runs.
+
+## Where I stopped
+
+- Done: research (above), Patcher forwarding + tests. Build/test/landing: see the commit list in the final report.

+ 26 - 0
src/core/Patcher.cpp

@@ -608,6 +608,29 @@ void Graph::noteOffPort (int port, int key, int midiChannel) noexcept
         deliver (patchMidiPortPin (port), false, key, 0.0f, midiChannel);
         deliver (patchMidiPortPin (port), false, key, 0.0f, midiChannel);
 }
 }
 
 
+template <typename F>
+void Graph::forNoteTargets (F&& f) noexcept
+{
+    if (pinTargets.empty())
+        return;
+    for (const auto& t : pinTargets[0])
+        if (auto& i = nodes[(std::size_t) t.node]->instrument)
+            f (*i);
+}
+
+void Graph::midiMessage (const std::uint8_t* bytes, int size) noexcept
+{
+    forNoteTargets ([&] (Instrument& i) { i.midiMessage (bytes, size); });
+}
+void Graph::pitchBend (float semitones) noexcept
+{
+    forNoteTargets ([&] (Instrument& i) { i.pitchBend (semitones); });
+}
+void Graph::controlChange (int cc, float value) noexcept
+{
+    forNoteTargets ([&] (Instrument& i) { i.controlChange (cc, value); });
+}
+
 bool Graph::takesMidiPort (int port) const noexcept
 bool Graph::takesMidiPort (int port) const noexcept
 {
 {
     return port >= 0 && port < patchMidiPorts && ! pinTargets[(std::size_t) patchMidiPortPin (port)].empty();
     return port >= 0 && port < patchMidiPorts && ! pinTargets[(std::size_t) patchMidiPortPin (port)].empty();
@@ -905,6 +928,9 @@ public:
     void noteOn (int key, float velocity) noexcept override { graph.noteOn (key, velocity); }
     void noteOn (int key, float velocity) noexcept override { graph.noteOn (key, velocity); }
     void noteOff (int key) noexcept override { graph.noteOff (key); }
     void noteOff (int key) noexcept override { graph.noteOff (key); }
     void allNotesOff() noexcept override { graph.allNotesOff(); }
     void allNotesOff() noexcept override { graph.allNotesOff(); }
+    void midiMessage (const std::uint8_t* bytes, int size) noexcept override { graph.midiMessage (bytes, size); }
+    void pitchBend (float semitones) noexcept override { graph.pitchBend (semitones); }
+    void controlChange (int cc, float value) noexcept override { graph.controlChange (cc, value); }
     void noteOnMidi (int key, float velocity, int midiChannel) noexcept override { graph.noteOnMidi (key, velocity, midiChannel); }
     void noteOnMidi (int key, float velocity, int midiChannel) noexcept override { graph.noteOnMidi (key, velocity, midiChannel); }
     void noteOffMidi (int key, int midiChannel) noexcept override { graph.noteOffMidi (key, midiChannel); }
     void noteOffMidi (int key, int midiChannel) noexcept override { graph.noteOffMidi (key, midiChannel); }
     void noteOnPort (int port, int key, float velocity, int midiChannel) noexcept override { graph.noteOnPort (port, key, velocity, midiChannel); }
     void noteOnPort (int port, int key, float velocity, int midiChannel) noexcept override { graph.noteOnPort (port, key, velocity, midiChannel); }

+ 8 - 0
src/core/Patcher.h

@@ -100,6 +100,12 @@ public:
     void noteOnPort (int port, int key, float velocity, int midiChannel) noexcept;
     void noteOnPort (int port, int key, float velocity, int midiChannel) noexcept;
     void noteOffPort (int port, int key, int midiChannel) noexcept;
     void noteOffPort (int port, int key, int midiChannel) noexcept;
     bool takesMidiPort (int port) const noexcept;
     bool takesMidiPort (int port) const noexcept;
+    // a controller's mod wheel, other CCs, channel pressure and pitch wheel played into the Patcher's channel (round
+    // 164e): like FL's Patcher (it takes MIDI input and passes it on), the instruments cabled to "From LYNX" notes get
+    // them as if they were the channel (hosted plugins the MIDI message, LYNX's samplers the bend)
+    void midiMessage (const std::uint8_t* bytes, int size) noexcept;
+    void pitchBend (float semitones) noexcept;
+    void controlChange (int cc, float value) noexcept;
     void allNotesOff() noexcept;
     void allNotesOff() noexcept;
     void slideTo (int key, float cents, float samples) noexcept;
     void slideTo (int key, float cents, float samples) noexcept;
     void setNextNoteExpression (float pan, float cents, bool porta) noexcept;
     void setNextNoteExpression (float pan, float cents, bool porta) noexcept;
@@ -126,6 +132,8 @@ public:
 
 
 private:
 private:
     struct Node;
     struct Node;
+    template <typename F>
+    void forNoteTargets (F&& f) noexcept;
     struct AudioWire;
     struct AudioWire;
     struct ControlWire;
     struct ControlWire;
     struct Values;
     struct Values;

+ 107 - 0
tests/Misc164mTests.inc

@@ -0,0 +1,107 @@
+// Round 164e (misc164m): the mod wheel and aftertouch on native instruments (docs/analise/REA_rodada164e-modwheel.md)
+
+namespace misc164m
+{
+// records the live controllers it receives
+struct Spy final : lynx::Instrument
+{
+    int messages = 0, lastStatus = 0, lastData1 = -1, controls = 0, lastCc = -1;
+    float bend = 0.0f, lastValue = -1.0f;
+    void prepare (double) noexcept override {}
+    void noteOn (int, float) noexcept override {}
+    void noteOff (int) noexcept override {}
+    void allNotesOff() noexcept override {}
+    void render (float*, float*, int, float, float) noexcept override {}
+    void midiMessage (const std::uint8_t* bytes, int size) noexcept override
+    {
+        ++messages;
+        lastStatus = size > 0 ? bytes[0] : 0;
+        lastData1 = size > 1 ? bytes[1] : -1;
+    }
+    void pitchBend (float semitones) noexcept override { bend = semitones; }
+    void controlChange (int cc, float value) noexcept override
+    {
+        ++controls;
+        lastCc = cc;
+        lastValue = value;
+    }
+};
+} // namespace misc164m
+
+TEST (misc164m_patcher_passes_live_controllers_to_its_instruments)
+{
+    // FL's Patcher takes MIDI input (its TFruityPlug MIDIIn is implemented, unlike FL's native generators) and passes
+    // it to the plugins cabled to "From FL Studio": the mod wheel / CCs / pressure / bend reach a plugin inside it
+    using namespace patcher162;
+    lynx::ChannelDef channel;
+    channel.instrument = lynx::InstrumentKind::patcher;
+    channel.patcher.nodes = { generatorNode (lynx::InstrumentKind::synth), generatorNode (lynx::InstrumentKind::synth) };
+    channel.patcher.wires = { midi (lynx::patchFromHost, 0, 0, 0), patcher141::audio (0, lynx::patchToHost), patcher141::audio (1, lynx::patchToHost) };
+    std::vector<std::shared_ptr<misc164m::Spy>> spies;
+    auto f = lynx::patcher::builtInFactories (48000.0);
+    f.instrument = [&spies] (const lynx::ChannelDef&) {
+        spies.push_back (std::make_shared<misc164m::Spy>());
+        return std::shared_ptr<lynx::Instrument> (spies.back());
+    };
+    auto i = lynx::patcher::makeInstrument (channel, 48000.0, f);
+    CHECK (spies.size() == 2u);
+    if (spies.size() != 2u)
+        return;
+    const std::uint8_t wheel[3] { 0xB0, 1, 100 }, pressure[2] { 0xD0, 90 };
+    i->midiMessage (wheel, 3);
+    i->controlChange (1, 100.0f / 127.0f);
+    i->midiMessage (pressure, 2);
+    i->pitchBend (-1.5f);
+    const auto& cabled = *spies[0];
+    CHECK (cabled.messages == 2 && cabled.lastStatus == 0xD0 && cabled.lastData1 == 90);
+    CHECK (cabled.controls == 1 && cabled.lastCc == 1 && std::abs (cabled.lastValue - 100.0f / 127.0f) < 1e-6f);
+    CHECK (cabled.bend == -1.5f);
+    // a generator not cabled to the notes gets none of it, like its notes
+    CHECK (spies[1]->messages == 0 && spies[1]->controls == 0 && spies[1]->bend == 0.0f);
+}
+
+TEST (misc164m_native_engines_keep_ignoring_the_mod_wheel_like_fl)
+{
+    // [EXEC] FL's native generators never ask for MIDI input (no FHD_WantMIDIInput at creation; PoiZone, Sakura, 3x Osc…
+    // leave MIDIIn abstract) and MiniSynth / GMS / Morphine / Toxic Biohazard leave their CC table at 0 even when MIDIIn
+    // is called directly: CC 1 does nothing until it is linked. Sakura's engine has a "mod wheel" matrix source (fed only
+    // by its VST host): routed to the level (10^(2·m)·0.05) it stays at 0 in FL, so the note plays at 0.05 with or
+    // without the wheel (a wheel at 127 would make it 100 times louder).
+    auto channel = [] {
+        lynx::ChannelDef c;
+        c.instrument = lynx::InstrumentKind::sakura;
+        c.modelParams.assign (146, 0.0f);
+        const std::pair<int, float> values[] { { 0, 0.375f }, { 1, 0.5f }, { 3, 0.5f }, { 4, 1.0f }, { 6, 0.95f }, { 9, 0.3f },
+                                               { 11, 0.95f }, { 14, 0.3f }, { 18, 0.5f }, { 19, 0.5f }, { 27, 0.5f }, { 28, 1.0f },
+                                               { 29, 0.7f }, { 31, 1.0f }, { 32, 0.5f } };
+        for (const auto& [i, v] : values)
+            c.modelParams[(std::size_t) i] = v;
+        return c;
+    };
+    auto render = [&] (bool routed, bool wheel) {
+        auto c = channel();
+        if (routed)
+            c.modelParams[79] = 3.0f, c.modelParams[80] = 1.0f, c.modelParams[82] = 1.0f; // slot 1: mod wheel → level
+        auto inst = lynx::makeInstrument (lynx::InstrumentKind::sakura);
+        inst->prepare (48000.0);
+        inst->configure (c, 120.0);
+        if (wheel)
+        {
+            const std::uint8_t m[3] { 0xB0, 1, 127 };
+            inst->midiMessage (m, 3);
+            inst->controlChange (1, 1.0f);
+        }
+        inst->noteOn (60, 0.8f);
+        std::vector<float> l (9600), r (9600);
+        for (int s = 0; s < 9600; s += 256)
+            inst->render (l.data() + s, r.data() + s, std::min (256, 9600 - s), 1.0f, 1.0f);
+        double e = 0.0;
+        for (const auto v : l)
+            e += (double) v * v;
+        return e;
+    };
+    CHECK (render (false, false) > 1e-3);                 // the patch sounds
+    CHECK (render (false, true) == render (false, false)); // the wheel changes nothing
+    const auto routed = render (true, false);
+    CHECK (routed > 0.0 && routed < render (false, false) && render (true, true) == routed); // routed: the wheel stays 0
+}

+ 1 - 0
tests/tests.cpp

@@ -16035,6 +16035,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "CrashReport159Tests.inc"
 #include "CrashReport159Tests.inc"
 #include "Sampler162Tests.inc"
 #include "Sampler162Tests.inc"
 #include "Workflow163cTests.inc"
 #include "Workflow163cTests.inc"
+#include "Misc164mTests.inc"
 #include "Theme162Tests.inc"
 #include "Theme162Tests.inc"
 #include "PluginPresets162Tests.inc"
 #include "PluginPresets162Tests.inc"
 #include "Look162Tests.inc"
 #include "Look162Tests.inc"