Browse Source

Hotfix #288: FL presets of the stock synths open the stock synth (Browser), and the window menus list Toxic / GMS / Morphine presets

Issue #288 (Linux, 0.1.31.1): a Sytrus preset clicked in the Browser opened "a 3x Osc", and the plugin's own preset menu
changed nothing.
- Browser: an .fst / .gmsynth of a synth LYNX converts still became LYNX's own synth with an approximation of the sound
  (synthFromFlPreset, from before LYNX played Sytrus, Harmor, GMS... natively). natives::presetKind (the plugin the file
  names, imported as channelFromPreset does; .tbio / .gmsynth / .mrp by type) and natives::channelFromAnyPreset now open
  the generator itself with the preset loaded and named after it (FL's Browser), through the rack's add (its window opens).
  A 3x Osc channel preset opens a 3x Osc. A preset LYNX can't read keeps the old fallback.
- "Send to selected channel or focused plugin" (and Shift+Up / Down) puts a preset of the selected channel's own generator
  into that channel (FL: "Content will be sent to the selected Channel"); LYNX's own generator presets too.
- The channel window's preset list read only .fst files, so Toxic Biohazard (.tbio), GMS (.gmsynth) and Morphine (.mrp)
  showed none of FL's presets: natives::presetExtensionOf.

Checked on Linux against FL 2026's own preset folders (--backlog190rctest): 31 engines, the Browser opens the engine for all
28 with preset files, every window menu with more than one row loads a preset (sound changed, channel named after it).
Not fixed here (0.1.33 queue): Sytrus states older than version 17 (412 of FL's 984 Sytrus presets) and some old Ogun
states are not read; the menu says "This preset could not be read" and the Browser keeps the approximation for them.
Tests: hotfix190rc_288_preset_kind_by_extension, hotfix190rc_288_preset_extension_of_kind.
Ka1-S 1 week ago
parent
commit
2a05c0bf02

+ 64 - 0
src/core/NativeEngines.cpp

@@ -259,6 +259,70 @@ std::optional<ChannelDef> channelFromPresetFile (InstrumentKind kind, const std:
     return engine != nullptr ? channelFromPreset (kind, *engine, path, access) : std::nullopt;
 }
 
+std::optional<InstrumentKind> presetKind (const std::string& path, const FlAccess& access)
+{
+    if (endsWith (path, ".tbio"))
+        return InstrumentKind::toxic;
+    if (endsWith (path, ".gmsynth"))
+        return InstrumentKind::gms;
+    if (endsWith (path, ".mrp"))
+        return InstrumentKind::morphine;
+    if (! endsWith (path, ".fst"))
+        return std::nullopt;
+    const auto bytes = readPreset (path, access);
+    if (bytes.empty())
+        return std::nullopt;
+    try
+    {
+        auto project = flp::parseProject (bytes, true);
+        if (project.channels.empty() || project.channels.front().pluginName.empty())
+            return std::nullopt;
+        // imported as channelFromPreset does (the import's own table of FL's generators decides the engine)
+        auto& c = project.channels.front();
+        if (c.type == flp::ChannelType::unknown)
+            c.type = flp::ChannelType::instrument;
+        c.mixerTrack = -1;
+        const auto song = importFlp (project, importOptions (access));
+        if (song.channels.empty())
+            return std::nullopt;
+        const auto kind = song.channels.front().instrument;
+        if (kind == InstrumentKind::midiOut || instrumentEngine (kind) != nullptr)
+            return kind;
+    }
+    catch (const flp::Error&)
+    {
+    }
+    return std::nullopt;
+}
+
+std::optional<ChannelDef> channelFromAnyPreset (const std::string& path, const std::string& presetName, const FlAccess& access)
+{
+    const auto kind = presetKind (path, access);
+    if (! kind)
+        return std::nullopt;
+    ChannelDef blank;
+    blank.instrument = *kind;
+    if (const auto* engine = instrumentEngine (*kind))
+        blank.name = engine->name;
+    // FL's wrapper loads the preset into a new instance: the plugin's state from the file, the channel's defaults
+    auto def = withPreset (blank, path, presetName, access);
+    if (! def || def->instrument != *kind)
+        return std::nullopt;
+    def->mixerTrack = 0;
+    return def;
+}
+
+std::string presetExtensionOf (InstrumentKind kind)
+{
+    switch (kind)
+    {
+        case InstrumentKind::toxic: return ".tbio";
+        case InstrumentKind::gms: return ".gmsynth";
+        case InstrumentKind::morphine: return ".mrp";
+        default: return ".fst";
+    }
+}
+
 std::string presetFolderOf (InstrumentKind kind)
 {
     if (kind == InstrumentKind::midiOut)

+ 14 - 0
src/core/NativeEngines.h

@@ -75,10 +75,24 @@ std::string defaultPresetPath (const std::string& presetFolder, bool generator,
 // of a channel window, round 167o).
 std::optional<ChannelDef> channelFromPresetFile (InstrumentKind kind, const std::string& path, const FlAccess& fl);
 
+// Issue #288 (round 190rc): the generator a preset file of FL's belongs to, whatever the folder it sits in: the plugin
+// an .fst names (event 0xC9: Sytrus, Harmor, 3x Osc, MIDI Out...; a channel preset of "Channel presets\3x Osc" too), or
+// Toxic's .tbio, GMS' .gmsynth, Morphine's .mrp. nullopt when it is not a generator LYNX plays natively (a hosted
+// plugin's .fst, an effect's, a damaged file).
+std::optional<InstrumentKind> presetKind (const std::string& path, const FlAccess& fl);
+// A new channel of that generator with the preset loaded and named after it (`presetName`; FL names the channel after
+// the preset), as FL's Browser opens a generator preset in a new channel. The mixer insert is left to the caller.
+std::optional<ChannelDef> channelFromAnyPreset (const std::string& path, const std::string& presetName, const FlAccess& fl);
+
 // The folder under Plugin presets\Generators that holds a channel kind's presets ("" = none): the engines above and
 // MIDI Out (the ◀ ▶ arrows of a channel window, round 167o).
 std::string presetFolderOf (InstrumentKind kind);
 
+// The file type of a kind's presets in its folder (issue #288, round 190rc): Toxic Biohazard's ".tbio", GMS' ".gmsynth",
+// Morphine's ".mrp", the others FL's ".fst". The channel window's preset list showed only .fst files, so these three
+// engines' menus held none of FL's presets.
+std::string presetExtensionOf (InstrumentKind kind);
+
 // Channel `current` with preset file `path` loaded, as FL does it from the ◀ ▶ arrows: the instrument's state comes
 // from the preset (MIDI Out keeps its channel and port), the channel keeps its own settings (mixer insert, volume, pan,
 // Misc tab, colour...) and takes the preset's name. nullopt when the file can't be read for that kind.

+ 54 - 0
src/ui/BrowserComponent.cpp

@@ -7188,6 +7188,24 @@ void BrowserComponent::openFile (const juce::File& file)
                 juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Preset"), message);
             return;
         }
+        // issue #288 (round 190rc): a preset of a generator LYNX plays natively (Sytrus, Harmor, 3x Osc, GMS...) opens that
+        // generator with the preset loaded, named after it, as FL's Browser does; it used to become LYNX's synth with an
+        // approximation of the sound ("it opens a 3x Osc")
+        if (auto native = natives::channelFromAnyPreset (file.getFullPathName().toStdString(), file.getFileNameWithoutExtension().toStdString(),
+                                                         flStudioAccess()))
+        {
+            if (onAddInstrument != nullptr)
+                onAddInstrument (std::move (*native));
+            else
+            {
+                engine.editSong ([&native] (Song& s) {
+                    native->mixerTrack = s.claimFreeInsert();
+                    s.channels.push_back (std::move (*native));
+                });
+                engine.setSelectedChannel ((int) engine.getSong().channels.size() - 1);
+            }
+            return;
+        }
         juce::MemoryBlock data;
 
         if (! file.loadFileAsData (data))
@@ -7597,6 +7615,42 @@ void BrowserComponent::sendToSelected (const juce::File& file)
                       : genpresetui::isPresetFile (file) || file.hasFileExtension ("fst;gmsynth") ? Item::generatorPreset
                                                                                                     : Item::other;
     const auto focused = ! PluginWindows::openPlugins().empty();
+    // issue #288 (round 190rc): a preset of the selected channel's own generator goes into that channel (FL's "Send to
+    // selected channel or focused plugin", and Shift+Up / Down through a preset folder); another generator's preset
+    // still opens a new channel
+    if (item == Item::generatorPreset)
+    {
+        const auto channel = engine.getSelectedChannel();
+        const auto& song = engine.getSong();
+        if (channel >= 0 && channel < (int) song.channels.size())
+        {
+            const auto& current = song.channels[(std::size_t) channel];
+            if (genpresetui::isPresetFile (file))
+            {
+                if (const auto own = genpresetui::read (file); own && own->kind == current.instrument)
+                {
+                    juce::String error;
+                    if (! genpresetui::loadInto (engine, channel, file, error) && error.isNotEmpty())
+                        showNote (error);
+                    return;
+                }
+            }
+            else if (const auto path = file.getFullPathName().toStdString(); natives::presetKind (path, flStudioAccess()) == current.instrument)
+            {
+                if (auto loaded = natives::withPreset (current, path, file.getFileNameWithoutExtension().toStdString(), flStudioAccess()))
+                {
+                    const auto kind = current.instrument;
+                    engine.editSong ([channel, kind, c = std::move (*loaded)] (Song& s) {
+                        if (channel < (int) s.channels.size() && s.channels[(std::size_t) channel].instrument == kind)
+                            s.channels[(std::size_t) channel] = c;
+                    });
+                }
+                else
+                    showNote (tr ("This preset could not be read: {0}", { file.getFileNameWithoutExtension() }));
+                return;
+            }
+        }
+    }
     switch (decide (item, selectedChannelKind(), focused))
     {
         case Action::sampleIntoSelected:

+ 2 - 1
src/ui/ChannelSettings.cpp

@@ -6486,7 +6486,8 @@ private:
         {
             const auto folder = natives::presetFolderOf (kind);
             presets = folder.empty() ? std::vector<presetcycle::Preset>()
-                                     : presetcycle::listPresets (presetcycle::pluginPresetFolders (flStudioAccess().roots, true, folder));
+                                     : presetcycle::listPresets (presetcycle::pluginPresetFolders (flStudioAccess().roots, true, folder),
+                                                                 natives::presetExtensionOf (kind)); // (issue #288: .tbio, .gmsynth, .mrp too)
             // LYNX's own bank after FL's presets (round 168n): the only presets without FL Studio
             const auto& bank = banks::bankOf (kind);
             for (int i = 0; i < (int) bank.size(); ++i)

+ 27 - 0
tests/Hotfix190rcPresetsTests.inc

@@ -0,0 +1,27 @@
+// Round 190rc, issue #288 (hotfix candidate): FL presets of LYNX's native generators open that generator (not LYNX's synth
+// approximation), and the channel window's preset list holds Toxic's .tbio, GMS' .gmsynth and Morphine's .mrp.
+// The app's --backlog190rctest walks every engine's presets with FL's own files.
+
+#include "core/NativeEngines.h"
+
+// #288: a preset's generator from the file (no FL needed for the extension-only kinds)
+TEST (hotfix190rc_288_preset_kind_by_extension)
+{
+    using namespace lynx;
+    natives::FlAccess none;
+    CHECK (natives::presetKind ("/x/Bass.tbio", none) == InstrumentKind::toxic);
+    CHECK (natives::presetKind ("/x/Pad.gmsynth", none) == InstrumentKind::gms);
+    CHECK (natives::presetKind ("/x/Choir.mrp", none) == InstrumentKind::morphine);
+    CHECK (! natives::presetKind ("/x/Kick.wav", none).has_value());
+    CHECK (! natives::presetKind ("/x/Missing.fst", none).has_value()); // (nothing to read)
+}
+
+TEST (hotfix190rc_288_preset_extension_of_kind)
+{
+    using namespace lynx;
+    CHECK (natives::presetExtensionOf (InstrumentKind::toxic) == ".tbio");
+    CHECK (natives::presetExtensionOf (InstrumentKind::gms) == ".gmsynth");
+    CHECK (natives::presetExtensionOf (InstrumentKind::morphine) == ".mrp");
+    CHECK (natives::presetExtensionOf (InstrumentKind::sytrus) == ".fst");
+    CHECK (natives::presetExtensionOf (InstrumentKind::harmor) == ".fst");
+}

+ 1 - 0
tests/tests.cpp

@@ -18136,3 +18136,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Issues190qoTests.inc" // round 190qo: issues #270 (typing keyboard layouts), #271 (SoundFont slide velocity)
 #include "Discord1124_190quTests.inc" // round 190qu (0.1.32): Discord 11-24 (automation lanes, Split by channel, Track-only, Simple)
 #include "Hotfix190rcFlpDataTests.inc" // round 190rc: the .flp export writes the project data folder only when it is on this computer (FL 2026: "Invalid project data folder")
+#include "Hotfix190rcPresetsTests.inc" // round 190rc: issue #288, FL presets of the native generators open the generator itself