Prechádzať zdrojové kódy

Missing files window: search/relocate missing samples, list missing plugins (WIP)

Ka1-S 1 mesiac pred
rodič
commit
a1fdff93eb

+ 2 - 0
CMakeLists.txt

@@ -27,6 +27,7 @@ add_library(lynx_core STATIC
     src/core/Templates.cpp
     src/core/FlWrapper.cpp
     src/core/FlPluginDb.cpp
+    src/core/MissingFiles.cpp
     src/core/FlEffects.cpp
     src/core/Effector.cpp
     src/core/FlSamplers.cpp
@@ -211,6 +212,7 @@ if(LYNX_BUILD_APP)
         src/ui/NoteToolDialogs.cpp
         src/ui/ToolWindow.cpp
         src/ui/HistoryPanel.cpp
+        src/ui/MissingFilesDialog.cpp
         src/ui/QuickAddPalette.cpp)
 
     target_include_directories(LYNX PRIVATE third_party/asiosdk/common)

+ 32 - 0
resources/i18n/pt-BR.txt

@@ -1226,3 +1226,35 @@ countries: br
 "Choose a sample..." = "Escolher um sample..."
 "Remove the sample" = "Remover o sample"
 "Source sample" = "Sample de origem"
+
+# --- Missing files window (round 81)
+"Missing files" = "Arquivos ausentes"
+"Missing files..." = "Arquivos ausentes..."
+"Apply ({0})" = "Aplicar ({0})"
+"Close without changes" = "Fechar sem alterar"
+"Every sample has a place. Apply to use them." = "Todos os samples foram encontrados. Aplique para usá-los."
+"Found automatically ({0})" = "Encontrados automaticamente ({0})"
+"Locate..." = "Localizar..."
+"Nothing is missing: every sample and plugin this project uses was found." = "Nada está faltando: todos os samples e plugins deste projeto foram encontrados."
+"Plugins ({0})" = "Plugins ({0})"
+"Remember the folders I search" = "Lembrar as pastas que eu pesquisar"
+"Replaced by: {0}" = "Substituído por: {0}"
+"Samples ({0})" = "Samples ({0})"
+"Search a folder (and its sub-folders) for the missing samples" = "Procurar os samples ausentes numa pasta (e subpastas)"
+"Search folder..." = "Procurar em pasta..."
+"Search stopped." = "Busca interrompida."
+"Searching {0}... {1} files looked at" = "Procurando em {0}... {1} arquivos verificados"
+"Skipped: stays silent" = "Ignorado: fica em silêncio"
+"Where is {0}?" = "Onde está {0}?"
+"this project" = "este projeto"
+"your search folders" = "suas pastas de busca"
+"{0} file(s) were found automatically in another folder." = "{0} arquivo(s) encontrado(s) automaticamente em outra pasta."
+"{0} found, {1} still missing" = "{0} encontrado(s), {1} ainda ausente(s)"
+"{0} more found in the same folder" = "mais {0} encontrado(s) na mesma pasta"
+"{0} plugin(s) are not installed (or not scanned): LYNX put something in their place." = "{0} plugin(s) não instalado(s) (ou não escaneado(s)): o LYNX colocou algo no lugar."
+"{0} sample(s) used by {1} could not be found on this PC." = "{0} sample(s) usado(s) por {1} não foi(foram) encontrado(s) neste PC."
+"{0} still missing, {1} found" = "{0} ainda ausente(s), {1} encontrado(s)"
+"Built-in synth (a preset chosen by the channel name)" = "Synth interno (um preset escolhido pelo nome do canal)"
+"Nothing: the slot was left out of the mixer" = "Nada: o slot ficou fora do Mixer"
+"Silence: the channel keeps the plugin's settings until it is installed" = "Silêncio: o canal guarda as configurações do plugin até ele ser instalado"
+"Bypassed: the slot keeps the plugin's settings until it is installed" = "Desativado: o slot guarda as configurações do plugin até ele ser instalado"

+ 2 - 0
scripts/build-local.sh

@@ -26,6 +26,8 @@ CORE="$CORE src/core/StartupSound.cpp"
 CORE="$CORE src/core/ThreeOsc.cpp"
 # FL Studio integration: plugin database and sample relocation (read-only)
 CORE="$CORE src/core/FlPluginDb.cpp"
+# missing files of an opened project: search and relocation (round 81)
+CORE="$CORE src/core/MissingFiles.cpp"
 # spectral waveforms (band analysis, multi-resolution peak cache)
 CORE="$CORE src/core/WaveAnalysis.cpp"
 # FL's Plucked!, Sawer and BeepMap engines (REA round 65)

+ 1 - 0
scripts/build-windows-zig.sh

@@ -98,6 +98,7 @@ APP_SOURCES+=(src/ui/HintBar.cpp src/ui/Toolbar.cpp)
 APP_SOURCES+=(src/core/ThreeOsc.cpp)
 # onboarding: FL Studio integration (plugin database, sample relocation), background scan, setup wizard
 APP_SOURCES+=(src/core/FlPluginDb.cpp src/engine/FlStudio.cpp src/ui/SetupWizard.cpp)
+APP_SOURCES+=(src/core/MissingFiles.cpp src/ui/MissingFilesDialog.cpp)
 # spectral waveforms: band analysis, background cache and drawing
 APP_SOURCES+=(src/core/WaveAnalysis.cpp src/ui/WaveformView.cpp)
 # FL's Plucked!, Sawer and BeepMap engines (REA round 65)

+ 4 - 0
src/Main.cpp

@@ -22,6 +22,7 @@
 #include "ui/SetupWizard.h"
 #include "engine/FlStudio.h"
 #include "ui/HistoryPanel.h"
+#include "ui/MissingFilesDialog.h"
 #include "ui/NoteToolDialogs.h"
 #include "ui/ParametricEqEditor.h"
 #include "ui/Splash.h"
@@ -1418,6 +1419,9 @@ private:
             saveAlert (lynx::MainComponent::makeAboutWindow(), "-about.png");
             saveAlert (lynx::makeNameAndColourDialog (lynx::tr ("Rename pattern"), "Pattern 2", lynx::lynxPalette()[6]), "-rename.png");
             saveWindow (lynx::makeSetupWizardContent (offline, {}, {}), "-setup.png");
+            saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 0, 1), "-missing-files.png");
+            saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 1), "-missing-plugins.png");
+            saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 2), "-missing-found.png");
 
             if (! offline.getSong().automations.empty())
             {

+ 32 - 6
src/core/FlpImport.cpp

@@ -587,10 +587,25 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
     std::optional<std::string> drumSynthDll; // the user's DrumSynth Live engine DLL, once checked ("" = not usable)
 
     // a sample on this PC: where the project says, else re-rooted from another PC's folders or next to the project
-    auto locateSample = [&] (const std::string& flPath) {
-        const auto found = locateFlSample (flPath, options.roots, options.projectFolder, options.fileExists);
-        if (! found.empty() && found != resolveFlPath (flPath, options.roots) && options.report != nullptr)
+    // (`sampleUser` names what uses the sample, for the missing-files list; `record` false for paths only probed)
+    std::string sampleUser;
+    auto locateSample = [&] (const std::string& flPath, bool record = true) {
+        auto found = locateFlSample (flPath, options.roots, options.projectFolder, options.fileExists);
+        const auto saved = resolveFlPath (flPath, options.roots);
+        if (found.empty())
+        {
+            if (const auto chosen = relocatedPath (options.relocations, saved); ! chosen.empty() && options.fileExists && options.fileExists (chosen))
+                return chosen;
+            if (record && options.report != nullptr)
+                addMissingFile (options.report->missingFiles, saved, sampleUser);
+        }
+        else if (found != saved && options.report != nullptr)
+        {
             ++options.report->relocatedSamples;
+            if (record && std::none_of (options.report->relocatedFiles.begin(), options.report->relocatedFiles.end(),
+                                        [&] (const auto& r) { return r.first == saved; }))
+                options.report->relocatedFiles.push_back ({ saved, found });
+        }
         return found;
     };
 
@@ -604,6 +619,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
 
         ChannelDef def;
         def.name = c.name.empty() ? "Channel " + std::to_string (c.index + 1) : c.name;
+        sampleUser = (c.type == flp::ChannelType::audioClip ? "Audio clip: " : "") + def.name;
         def.instrument = guessInstrument (def.name, c.type);
 
         // FL synthesizer that becomes the internal synth: a preset matching the name (in FLEX, the name
@@ -757,6 +773,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
         // FL generators with samples (REA_rodada9): DirectWave becomes a multi-sample sampler; FPC is
         // split into one channel per pad at the end of the import (notes go to the pad by key)
         auto existing = [&] (std::string path) { return locateSample (path); };
+        auto installed = [&] (std::string path) { return locateSample (path, false); }; // FL's own data (FL Keys wavetables)
 
         // DirectWave: the exact engine (REA_rodada72); the multi-sample sampler stays as the fallback
         bool directWaveExact = false;
@@ -852,7 +869,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
         bool flKeysExact = false;
         if (c.pluginName == "FL Keys" && options.readFile && ! options.roots.factoryData.empty())
             flKeysExact = flkeys::importChannel (def, c.pluginState, options.roots.factoryData + "\\Plugins\\Fruity\\Generators\\FL Keys\\Wavtables",
-                                                 options.readFile, existing, options.saveEmbedded);
+                                                 options.readFile, installed, options.saveEmbedded);
         if (c.pluginName == "FL Keys" && ! flKeysExact && options.readFile && ! options.roots.factoryData.empty())
             if (const auto set = flKeysSet (c.pluginState))
             {
@@ -870,7 +887,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
 
                 std::vector<SampleZone> zones;
                 for (auto z : flKeysZones (wti, folder, rawData, options.saveEmbedded))
-                    if (z.path = existing (z.path); ! z.path.empty())
+                    if (z.path = installed (z.path); ! z.path.empty())
                         zones.push_back (std::move (z));
 
                 if (! zones.empty())
@@ -919,7 +936,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             }
             else if (const auto sound = drumSynthLiveSound (c.pluginState))
                 for (const auto& candidate : drumSampleCandidates (*sound))
-                    if (auto path = existing (candidate); ! path.empty())
+                    if (auto path = locateSample (candidate, false); ! path.empty())
                     {
                         def.instrument = InstrumentKind::sampler;
                         def.samplePath = std::move (path);
@@ -1907,10 +1924,19 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                                 fx.samplePath = path;
                                 break;
                             }
+                        for (const auto& path : candidates) // located by the user (the "Missing files" window)
+                            if (const auto chosen = relocatedPath (options.relocations, path);
+                                fx.samplePath.empty() && ! chosen.empty() && options.fileExists && options.fileExists (chosen))
+                                fx.samplePath = chosen;
                         if (options.report != nullptr && ! parsed->tracks.empty())
                         {
                             if (fx.samplePath.empty())
+                            {
                                 ++options.report->missingSamples;
+                                if (! candidates.empty() && ! candidates.front().empty())
+                                    addMissingFile (options.report->missingFiles, candidates.front(),
+                                                    (insert.name.empty() ? "Insert " + std::to_string (insert.index) : insert.name) + ": " + slot.plugin);
+                            }
                             if (parsed->edited())
                                 ++options.report->droppedEffects[slot.plugin + " (edits not reproduced: plays the original sample)"];
                             else if (fx.kind == EffectKind::newtime)

+ 6 - 0
src/core/FlpImport.h

@@ -5,6 +5,7 @@
 #include <optional>
 #include <string>
 
+#include "core/MissingFiles.h"
 #include "core/Song.h"
 #include "flp/Flp.h"
 
@@ -31,6 +32,8 @@ struct FlpImportReport
     std::map<std::string, int> droppedEffects; // effects with no equivalent (removed from the mixer)
     int missingSamples = 0;
     int relocatedSamples = 0; // found on this PC at another place than the project saved (core/FlPluginDb.h)
+    std::vector<MissingFile> missingFiles; // the samples not found, with the channels/effects that use them (core/MissingFiles.h)
+    std::vector<std::pair<std::string, std::string>> relocatedFiles; // saved path → the copy found elsewhere on this PC
 };
 
 struct FlpImportOptions
@@ -47,6 +50,9 @@ struct FlpImportOptions
 
     FlpImportReport* report = nullptr; // optional
 
+    // Samples the user located (the "Missing files" window): saved path (FL's variables resolved) → file to use instead.
+    std::map<std::string, std::string> relocations;
+
     bool threeOscAsSynth = false; // 3x Osc → the built-in synth conversion instead of FL's engine (the synth's preset menu)
 };
 

+ 305 - 0
src/core/MissingFiles.cpp

@@ -0,0 +1,305 @@
+#include "core/MissingFiles.h"
+
+#include <algorithm>
+#include <cctype>
+#include <set>
+
+namespace lynx
+{
+namespace
+{
+bool isSeparator (char c) { return c == '\\' || c == '/'; }
+
+// lower-case, one kind of separator, no trailing separator: two spellings of the same path compare equal
+std::string pathKey (const std::string& path)
+{
+    std::string key;
+    key.reserve (path.size());
+    for (const auto c : path)
+        key.push_back (isSeparator (c) ? '/' : (char) std::tolower ((unsigned char) c));
+    while (key.size() > 1 && key.back() == '/')
+        key.pop_back();
+    return key;
+}
+
+std::vector<std::string> pathParts (const std::string& path)
+{
+    std::vector<std::string> parts;
+    std::string part;
+    for (const auto c : pathKey (path))
+    {
+        if (c == '/')
+        {
+            if (! part.empty())
+                parts.push_back (part);
+            part.clear();
+        }
+        else
+            part.push_back (c);
+    }
+    if (! part.empty())
+        parts.push_back (part);
+    return parts;
+}
+
+std::string channelUser (const ChannelDef& c)
+{
+    return c.instrument == InstrumentKind::audioClip ? "Audio clip: " + c.name : c.name;
+}
+
+bool usesChannelSample (InstrumentKind kind)
+{
+    return kind == InstrumentKind::sampler || kind == InstrumentKind::audioClip || kind == InstrumentKind::granulizer
+           || kind == InstrumentKind::threeosc;
+}
+
+template <typename Fn>
+void forEachEffectSlot (std::vector<EffectSlot>& chain, Fn&& fn)
+{
+    for (auto& slot : chain)
+    {
+        fn (slot);
+        for (auto& branch : slot.branches)
+            forEachEffectSlot (branch.chain, fn);
+    }
+}
+} // namespace
+
+std::string pathFileName (const std::string& path)
+{
+    auto end = path.size();
+    while (end > 0 && isSeparator (path[end - 1]))
+        --end;
+    auto start = end;
+    while (start > 0 && ! isSeparator (path[start - 1]))
+        --start;
+    return path.substr (start, end - start);
+}
+
+void addMissingFile (std::vector<MissingFile>& list, const std::string& path, const std::string& user)
+{
+    if (path.empty())
+        return;
+    const auto key = pathKey (path);
+    auto it = std::find_if (list.begin(), list.end(), [&] (const MissingFile& m) { return pathKey (m.path) == key; });
+    if (it == list.end())
+    {
+        list.push_back ({ path, {}, {}, false });
+        it = list.end() - 1;
+    }
+    if (! user.empty() && std::find (it->usedBy.begin(), it->usedBy.end(), user) == it->usedBy.end())
+        it->usedBy.push_back (user);
+}
+
+std::vector<MissingFile> findMissingSamples (const Song& song, const std::function<bool (const std::string&)>& fileExists)
+{
+    std::vector<MissingFile> list;
+    if (! fileExists)
+        return list;
+
+    std::map<std::string, bool> known; // each file is checked once
+    auto gone = [&] (const std::string& path) {
+        if (path.empty())
+            return false;
+        const auto key = pathKey (path);
+        if (const auto it = known.find (key); it != known.end())
+            return it->second;
+        return known[key] = ! fileExists (path);
+    };
+
+    for (const auto& c : song.channels)
+    {
+        if (usesChannelSample (c.instrument) && gone (c.samplePath))
+            addMissingFile (list, c.samplePath, channelUser (c));
+        if (c.instrument != InstrumentKind::flkeys)
+            for (const auto& z : c.zones)
+                if (gone (z.path))
+                    addMissingFile (list, z.path, c.name);
+    }
+
+    for (std::size_t t = 0; t < song.mixer.size(); ++t)
+    {
+        auto chain = song.mixer[t].effects; // (a copy: the walker takes non-const slots)
+        const auto track = song.mixer[t].name.empty() ? (t == 0 ? std::string ("Master") : "Insert " + std::to_string (t)) : song.mixer[t].name;
+        forEachEffectSlot (chain, [&] (EffectSlot& slot) {
+            if (gone (slot.samplePath))
+                addMissingFile (list, slot.samplePath, track + ": effect");
+        });
+    }
+    return list;
+}
+
+int relocationScore (const std::string& missingPath, const std::string& candidate)
+{
+    const auto a = pathParts (missingPath), b = pathParts (candidate);
+    if (a.empty() || b.empty() || a.back() != b.back())
+        return 0;
+    int score = 1;
+    for (std::size_t i = 2; i <= std::min (a.size(), b.size()) && a[a.size() - i] == b[b.size() - i]; ++i)
+        ++score;
+    return score;
+}
+
+int relocateByName (std::vector<MissingFile>& missing, const std::vector<std::string>& candidates)
+{
+    std::map<std::string, std::vector<const std::string*>> byName;
+    for (const auto& c : candidates)
+        byName[pathKey (pathFileName (c))].push_back (&c);
+
+    int found = 0;
+    for (auto& m : missing)
+    {
+        if (! m.found.empty() || m.skipped)
+            continue;
+        const auto it = byName.find (pathKey (pathFileName (m.path)));
+        if (it == byName.end())
+            continue;
+        int best = 0;
+        for (const auto* c : it->second)
+            if (const auto s = relocationScore (m.path, *c); s > best)
+            {
+                best = s;
+                m.found = *c;
+            }
+        found += best > 0 ? 1 : 0;
+    }
+    return found;
+}
+
+std::vector<std::string> searchFolderForMissing (const std::vector<MissingFile>& missing, const std::string& folder,
+                                                 const std::function<void (const std::string&, const std::function<bool (const std::string&, bool)>&)>& listFolder,
+                                                 std::size_t maxEntries, const std::function<bool()>& cancelled)
+{
+    std::set<std::string> wanted;
+    for (const auto& m : missing)
+        if (m.found.empty() && ! m.skipped)
+            wanted.insert (pathKey (pathFileName (m.path)));
+
+    std::vector<std::string> hits;
+    if (wanted.empty() || folder.empty() || ! listFolder)
+        return hits;
+
+    std::vector<std::string> pending { folder };
+    std::set<std::string> visited;
+    std::size_t entries = 0;
+    auto stop = false;
+
+    while (! pending.empty() && ! stop)
+    {
+        const auto current = pending.back();
+        pending.pop_back();
+        if (! visited.insert (pathKey (current)).second)
+            continue;
+
+        listFolder (current, [&] (const std::string& path, bool isFolder) {
+            if ((maxEntries > 0 && ++entries > maxEntries) || (cancelled && cancelled()))
+            {
+                stop = true;
+                return false;
+            }
+            if (isFolder)
+                pending.push_back (path);
+            else if (wanted.count (pathKey (pathFileName (path))) != 0)
+                hits.push_back (path);
+            return true;
+        });
+    }
+    return hits;
+}
+
+std::map<std::string, std::string> relocationMap (const std::vector<MissingFile>& missing)
+{
+    std::map<std::string, std::string> map;
+    for (const auto& m : missing)
+        if (! m.found.empty() && ! m.skipped)
+            map[m.path] = m.found;
+    return map;
+}
+
+std::string relocatedPath (const std::map<std::string, std::string>& relocations, const std::string& path)
+{
+    if (path.empty() || relocations.empty())
+        return {};
+    if (const auto it = relocations.find (path); it != relocations.end())
+        return it->second;
+    const auto key = pathKey (path);
+    for (const auto& [from, to] : relocations)
+        if (pathKey (from) == key)
+            return to;
+    return {};
+}
+
+int applyRelocations (Song& song, const std::map<std::string, std::string>& relocations)
+{
+    std::map<std::string, std::string> byKey;
+    for (const auto& [from, to] : relocations)
+        byKey[pathKey (from)] = to;
+
+    int changed = 0;
+    auto relocate = [&] (std::string& path) {
+        if (path.empty())
+            return;
+        if (const auto it = byKey.find (pathKey (path)); it != byKey.end() && it->second != path)
+        {
+            path = it->second;
+            ++changed;
+        }
+    };
+
+    for (auto& c : song.channels)
+    {
+        if (usesChannelSample (c.instrument))
+            relocate (c.samplePath);
+        if (c.instrument != InstrumentKind::flkeys)
+            for (auto& z : c.zones)
+                relocate (z.path);
+    }
+    for (auto& track : song.mixer)
+        forEachEffectSlot (track.effects, [&] (EffectSlot& slot) { relocate (slot.samplePath); });
+    return changed;
+}
+
+std::vector<std::string> parseFolderList (const std::string& text)
+{
+    std::vector<std::string> folders;
+    std::set<std::string> seen;
+    std::string line;
+    auto flush = [&] {
+        while (! line.empty() && (line.back() == '\r' || line.back() == ' ' || line.back() == '\t'))
+            line.pop_back();
+        const auto start = line.find_first_not_of (" \t");
+        line = start == std::string::npos ? std::string() : line.substr (start);
+        if (! line.empty() && seen.insert (pathKey (line)).second)
+            folders.push_back (line);
+        line.clear();
+    };
+    for (const auto c : text)
+    {
+        if (c == '\n')
+            flush();
+        else
+            line.push_back (c);
+    }
+    flush();
+    return folders;
+}
+
+std::string folderListText (const std::vector<std::string>& folders)
+{
+    std::string text;
+    for (const auto& f : folders)
+        text += f + "\n";
+    return text;
+}
+
+void rememberFolder (std::vector<std::string>& folders, const std::string& folder, std::size_t limit)
+{
+    if (folder.empty())
+        return;
+    const auto key = pathKey (folder);
+    folders.erase (std::remove_if (folders.begin(), folders.end(), [&] (const std::string& f) { return pathKey (f) == key; }), folders.end());
+    folders.insert (folders.begin(), folder);
+    if (limit > 0 && folders.size() > limit)
+        folders.resize (limit);
+}
+} // namespace lynx

+ 75 - 0
src/core/MissingFiles.h

@@ -0,0 +1,75 @@
+#pragma once
+
+// Missing files of an opened project (like FL Studio's "missing samples" message, interpreted): which samples a
+// project uses that aren't on this PC, where they might be now (a search by file name in folders the user picks),
+// and how to point the project at the found copies. Does not depend on JUCE so it can be tested in isolation:
+// the file system is reached through the callbacks the caller passes.
+
+#include <functional>
+#include <map>
+#include <string>
+#include <vector>
+
+#include "core/Song.h"
+
+namespace lynx
+{
+// One file a project references that doesn't exist on this PC.
+struct MissingFile
+{
+    std::string path;                // as the project saved it (FL's variables already resolved)
+    std::vector<std::string> usedBy; // "Kick", "Audio clip: Vocals", "Insert 3: Newtone" (English, for display)
+    std::string found;               // the copy picked on this PC ("" = still missing)
+    bool skipped = false;            // the user chose to leave it missing
+};
+
+// A plugin a project uses that isn't installed (or wasn't scanned) here, and what LYNX put in its place.
+struct MissingPlugin
+{
+    std::string name;
+    std::vector<std::string> usedBy;
+    std::string replacement; // English, for display ("Built-in synth", "Removed from the mixer"...)
+};
+
+// The last component of a path saved on Windows or elsewhere ('\\' and '/' both separate).
+std::string pathFileName (const std::string& path);
+
+// Adds `user` to the entry for `path` (one entry per path, case-insensitive on the separators and letters).
+void addMissingFile (std::vector<MissingFile>& list, const std::string& path, const std::string& user);
+
+// The user samples a .lynx song references that `fileExists` says are gone: channel samples (sampler, audio clip,
+// Granulizer, 3x Osc custom wave), sampler zones (not FL Keys' installation wavetables) and effect samples
+// (Newtone/Newtime). FL Studio installation data some engines keep in samplePath (DLLs, wave folders) is left out.
+std::vector<MissingFile> findMissingSamples (const Song& song, const std::function<bool (const std::string&)>& fileExists);
+
+// How well a found file matches a missing path: 0 = different file name; otherwise 1 + the number of trailing folder
+// names they share ("Drums\Kicks\kick.wav" vs ".../Kicks/kick.wav" = 2). Case-insensitive.
+int relocationScore (const std::string& missingPath, const std::string& candidate);
+
+// For each missing file not yet found or skipped, picks the best candidate by `relocationScore` (ties: the first).
+// Returns how many were newly found.
+int relocateByName (std::vector<MissingFile>& missing, const std::vector<std::string>& candidates);
+
+// Lists, recursively, the files under `folder` whose names match a missing file (the search a dialog runs).
+// `listFolder(folder, onEntry)` reports each entry as (path, isFolder); `onEntry` returning false stops the walk.
+// `maxEntries` bounds the walk (0 = no bound); `cancelled` is polled between entries.
+std::vector<std::string> searchFolderForMissing (const std::vector<MissingFile>& missing, const std::string& folder,
+                                                 const std::function<void (const std::string&, const std::function<bool (const std::string&, bool)>&)>& listFolder,
+                                                 std::size_t maxEntries = 0, const std::function<bool()>& cancelled = {});
+
+// original path → found path, for the files that were found.
+std::map<std::string, std::string> relocationMap (const std::vector<MissingFile>& missing);
+
+// The new place of `path` in a relocation map (same file whatever the case or separators), "" when not relocated.
+std::string relocatedPath (const std::map<std::string, std::string>& relocations, const std::string& path);
+
+// Points every reference to a relocated file at its new place (channel samples, zones, effect samples, also inside
+// parallel containers); a channel whose sampler had lost its sample keeps its kind. Returns how many references changed.
+int applyRelocations (Song& song, const std::map<std::string, std::string>& relocations);
+
+// The search folders list as saved (one folder per line): duplicates and empty lines dropped, order kept.
+std::vector<std::string> parseFolderList (const std::string& text);
+std::string folderListText (const std::vector<std::string>& folders);
+// Adds `folder` at the front (most recent first), keeping at most `limit` entries.
+void rememberFolder (std::vector<std::string>& folders, const std::string& folder, std::size_t limit = 20);
+} // namespace lynx

+ 40 - 1
src/engine/AudioEngine.cpp

@@ -822,7 +822,7 @@ void AudioEngine::publishSelection()
     extraLiveCount.store (extra);
 }
 
-bool AudioEngine::importFlpFile (const juce::File& file, juce::String& error)
+bool AudioEngine::importFlpFile (const juce::File& file, juce::String& error, const std::map<std::string, std::string>& relocations, bool asEdit)
 {
     juce::MemoryBlock data;
 
@@ -867,12 +867,51 @@ bool AudioEngine::importFlpFile (const juce::File& file, juce::String& error)
 
         importReport = {};
         options.report = &importReport;
+        options.relocations = relocations;
         auto imported = importFlp (project, options);
+
+        // the project's third-party plugins, to say which channel/insert used each one that is missing
+        struct Use
+        {
+            std::string name, user;
+            bool instrument;
+        };
+        std::vector<Use> uses;
+        for (const auto& c : imported.channels)
+            if (c.plugin.foreign.format != ForeignPlugin::Format::none)
+                uses.push_back ({ c.plugin.foreign.name, c.name, true });
+        for (std::size_t t = 0; t < imported.mixer.size(); ++t)
+            for (const auto& fx : imported.mixer[t].effects)
+                if (fx.kind == EffectKind::plugin && fx.plugin.foreign.format != ForeignPlugin::Format::none)
+                    uses.push_back ({ fx.plugin.foreign.name, imported.mixer[t].name.empty() ? (t == 0 ? std::string ("Master") : "Insert " + std::to_string (t))
+                                                                                            : imported.mixer[t].name,
+                                      false });
+
         juce::StringArray missing;
         juce::StringArray matched;
         plugins.adoptFlPlugins (imported, &missing, &matched);
         missingPlugins = missing;
         matchedPlugins = matched;
+        missingPluginDetails.clear();
+        for (const auto& name : missing)
+        {
+            MissingPlugin m;
+            m.name = name.toStdString();
+            for (const auto& u : uses)
+                if (u.name == m.name)
+                {
+                    if (std::find (m.usedBy.begin(), m.usedBy.end(), u.user) == m.usedBy.end())
+                        m.usedBy.push_back (u.user);
+                    m.replacement = u.instrument ? "Built-in synth (a preset chosen by the channel name)" : "Nothing: the slot was left out of the mixer";
+                }
+            missingPluginDetails.push_back (std::move (m));
+        }
+
+        if (asEdit)
+        {
+            editSong ([&imported] (Song& s) { s = std::move (imported); });
+            return true;
+        }
 
         stop();
         rewind();

+ 7 - 2
src/engine/AudioEngine.h

@@ -50,6 +50,8 @@ public:
     const juce::StringArray& getMatchedPlugins() const noexcept { return matchedPlugins; }
     // What the last imported .flp converted, approximated or left out.
     const FlpImportReport& getImportReport() const noexcept { return importReport; }
+    // The last imported .flp's plugins that were not found, with what uses them and what LYNX put in their place.
+    const std::vector<MissingPlugin>& getMissingPluginDetails() const noexcept { return missingPluginDetails; }
 
     // Live instances (to open the plugin window). nullptr if not a plugin.
     std::shared_ptr<Instrument> getChannelInstrument (int channel) const;
@@ -156,8 +158,10 @@ public:
     void setChannelSelection (std::vector<int> channels, int primary);
 
     // Imports a .flp, locating the FL installation to find the samples.
-    // Returns false and fills `error` on failure.
-    bool importFlpFile (const juce::File& file, juce::String& error);
+    // Returns false and fills `error` on failure. `relocations` (saved sample path → file to use) are the samples
+    // the user located; with `asEdit` the result replaces the song as one undoable step instead of a new project.
+    bool importFlpFile (const juce::File& file, juce::String& error, const std::map<std::string, std::string>& relocations = {},
+                        bool asEdit = false);
 
     // Renders without an audio device. Writes to `output` if not nullptr.
     // After `seconds`, continues for up to `tailSeconds` while there is still sound.
@@ -276,6 +280,7 @@ private:
     PluginHost plugins;
     juce::StringArray missingPlugins, matchedPlugins;
     FlpImportReport importReport;
+    std::vector<MissingPlugin> missingPluginDetails;
     RenderStats lastRenderStats;
     class ChannelRackProcessor* rackProcessor = nullptr; // graph node (owner: the graph)
 

+ 101 - 1
src/ui/I18nData.h

@@ -3662,6 +3662,106 @@ inline constexpr unsigned char ptBR[] = {
 114, 32, 117, 109, 32, 115, 97, 109, 112, 108, 101, 46, 46, 46, 34, 10, 34, 82, 101, 109, 111, 118, 101, 32,
 116, 104, 101, 32, 115, 97, 109, 112, 108, 101, 34, 32, 61, 32, 34, 82, 101, 109, 111, 118, 101, 114, 32, 111,
 32, 115, 97, 109, 112, 108, 101, 34, 10, 34, 83, 111, 117, 114, 99, 101, 32, 115, 97, 109, 112, 108, 101, 34,
-32, 61, 32, 34, 83, 97, 109, 112, 108, 101, 32, 100, 101, 32, 111, 114, 105, 103, 101, 109, 34, 10,
+32, 61, 32, 34, 83, 97, 109, 112, 108, 101, 32, 100, 101, 32, 111, 114, 105, 103, 101, 109, 34, 10, 10, 35,
+32, 45, 45, 45, 32, 77, 105, 115, 115, 105, 110, 103, 32, 102, 105, 108, 101, 115, 32, 119, 105, 110, 100, 111,
+119, 32, 40, 114, 111, 117, 110, 100, 32, 56, 49, 41, 10, 34, 77, 105, 115, 115, 105, 110, 103, 32, 102, 105,
+108, 101, 115, 34, 32, 61, 32, 34, 65, 114, 113, 117, 105, 118, 111, 115, 32, 97, 117, 115, 101, 110, 116, 101,
+115, 34, 10, 34, 77, 105, 115, 115, 105, 110, 103, 32, 102, 105, 108, 101, 115, 46, 46, 46, 34, 32, 61, 32,
+34, 65, 114, 113, 117, 105, 118, 111, 115, 32, 97, 117, 115, 101, 110, 116, 101, 115, 46, 46, 46, 34, 10, 34,
+65, 112, 112, 108, 121, 32, 40, 123, 48, 125, 41, 34, 32, 61, 32, 34, 65, 112, 108, 105, 99, 97, 114, 32,
+40, 123, 48, 125, 41, 34, 10, 34, 67, 108, 111, 115, 101, 32, 119, 105, 116, 104, 111, 117, 116, 32, 99, 104,
+97, 110, 103, 101, 115, 34, 32, 61, 32, 34, 70, 101, 99, 104, 97, 114, 32, 115, 101, 109, 32, 97, 108, 116,
+101, 114, 97, 114, 34, 10, 34, 69, 118, 101, 114, 121, 32, 115, 97, 109, 112, 108, 101, 32, 104, 97, 115, 32,
+97, 32, 112, 108, 97, 99, 101, 46, 32, 65, 112, 112, 108, 121, 32, 116, 111, 32, 117, 115, 101, 32, 116, 104,
+101, 109, 46, 34, 32, 61, 32, 34, 84, 111, 100, 111, 115, 32, 111, 115, 32, 115, 97, 109, 112, 108, 101, 115,
+32, 102, 111, 114, 97, 109, 32, 101, 110, 99, 111, 110, 116, 114, 97, 100, 111, 115, 46, 32, 65, 112, 108, 105,
+113, 117, 101, 32, 112, 97, 114, 97, 32, 117, 115, 195, 161, 45, 108, 111, 115, 46, 34, 10, 34, 70, 111, 117,
+110, 100, 32, 97, 117, 116, 111, 109, 97, 116, 105, 99, 97, 108, 108, 121, 32, 40, 123, 48, 125, 41, 34, 32,
+61, 32, 34, 69, 110, 99, 111, 110, 116, 114, 97, 100, 111, 115, 32, 97, 117, 116, 111, 109, 97, 116, 105, 99,
+97, 109, 101, 110, 116, 101, 32, 40, 123, 48, 125, 41, 34, 10, 34, 76, 111, 99, 97, 116, 101, 46, 46, 46,
+34, 32, 61, 32, 34, 76, 111, 99, 97, 108, 105, 122, 97, 114, 46, 46, 46, 34, 10, 34, 78, 111, 116, 104,
+105, 110, 103, 32, 105, 115, 32, 109, 105, 115, 115, 105, 110, 103, 58, 32, 101, 118, 101, 114, 121, 32, 115, 97,
+109, 112, 108, 101, 32, 97, 110, 100, 32, 112, 108, 117, 103, 105, 110, 32, 116, 104, 105, 115, 32, 112, 114, 111,
+106, 101, 99, 116, 32, 117, 115, 101, 115, 32, 119, 97, 115, 32, 102, 111, 117, 110, 100, 46, 34, 32, 61, 32,
+34, 78, 97, 100, 97, 32, 101, 115, 116, 195, 161, 32, 102, 97, 108, 116, 97, 110, 100, 111, 58, 32, 116, 111,
+100, 111, 115, 32, 111, 115, 32, 115, 97, 109, 112, 108, 101, 115, 32, 101, 32, 112, 108, 117, 103, 105, 110, 115,
+32, 100, 101, 115, 116, 101, 32, 112, 114, 111, 106, 101, 116, 111, 32, 102, 111, 114, 97, 109, 32, 101, 110, 99,
+111, 110, 116, 114, 97, 100, 111, 115, 46, 34, 10, 34, 80, 108, 117, 103, 105, 110, 115, 32, 40, 123, 48, 125,
+41, 34, 32, 61, 32, 34, 80, 108, 117, 103, 105, 110, 115, 32, 40, 123, 48, 125, 41, 34, 10, 34, 82, 101,
+109, 101, 109, 98, 101, 114, 32, 116, 104, 101, 32, 102, 111, 108, 100, 101, 114, 115, 32, 73, 32, 115, 101, 97,
+114, 99, 104, 34, 32, 61, 32, 34, 76, 101, 109, 98, 114, 97, 114, 32, 97, 115, 32, 112, 97, 115, 116, 97,
+115, 32, 113, 117, 101, 32, 101, 117, 32, 112, 101, 115, 113, 117, 105, 115, 97, 114, 34, 10, 34, 82, 101, 112,
+108, 97, 99, 101, 100, 32, 98, 121, 58, 32, 123, 48, 125, 34, 32, 61, 32, 34, 83, 117, 98, 115, 116, 105,
+116, 117, 195, 173, 100, 111, 32, 112, 111, 114, 58, 32, 123, 48, 125, 34, 10, 34, 83, 97, 109, 112, 108, 101,
+115, 32, 40, 123, 48, 125, 41, 34, 32, 61, 32, 34, 83, 97, 109, 112, 108, 101, 115, 32, 40, 123, 48, 125,
+41, 34, 10, 34, 83, 101, 97, 114, 99, 104, 32, 97, 32, 102, 111, 108, 100, 101, 114, 32, 40, 97, 110, 100,
+32, 105, 116, 115, 32, 115, 117, 98, 45, 102, 111, 108, 100, 101, 114, 115, 41, 32, 102, 111, 114, 32, 116, 104,
+101, 32, 109, 105, 115, 115, 105, 110, 103, 32, 115, 97, 109, 112, 108, 101, 115, 34, 32, 61, 32, 34, 80, 114,
+111, 99, 117, 114, 97, 114, 32, 111, 115, 32, 115, 97, 109, 112, 108, 101, 115, 32, 97, 117, 115, 101, 110, 116,
+101, 115, 32, 110, 117, 109, 97, 32, 112, 97, 115, 116, 97, 32, 40, 101, 32, 115, 117, 98, 112, 97, 115, 116,
+97, 115, 41, 34, 10, 34, 83, 101, 97, 114, 99, 104, 32, 102, 111, 108, 100, 101, 114, 46, 46, 46, 34, 32,
+61, 32, 34, 80, 114, 111, 99, 117, 114, 97, 114, 32, 101, 109, 32, 112, 97, 115, 116, 97, 46, 46, 46, 34,
+10, 34, 83, 101, 97, 114, 99, 104, 32, 115, 116, 111, 112, 112, 101, 100, 46, 34, 32, 61, 32, 34, 66, 117,
+115, 99, 97, 32, 105, 110, 116, 101, 114, 114, 111, 109, 112, 105, 100, 97, 46, 34, 10, 34, 83, 101, 97, 114,
+99, 104, 105, 110, 103, 32, 123, 48, 125, 46, 46, 46, 32, 123, 49, 125, 32, 102, 105, 108, 101, 115, 32, 108,
+111, 111, 107, 101, 100, 32, 97, 116, 34, 32, 61, 32, 34, 80, 114, 111, 99, 117, 114, 97, 110, 100, 111, 32,
+101, 109, 32, 123, 48, 125, 46, 46, 46, 32, 123, 49, 125, 32, 97, 114, 113, 117, 105, 118, 111, 115, 32, 118,
+101, 114, 105, 102, 105, 99, 97, 100, 111, 115, 34, 10, 34, 83, 107, 105, 112, 112, 101, 100, 58, 32, 115, 116,
+97, 121, 115, 32, 115, 105, 108, 101, 110, 116, 34, 32, 61, 32, 34, 73, 103, 110, 111, 114, 97, 100, 111, 58,
+32, 102, 105, 99, 97, 32, 101, 109, 32, 115, 105, 108, 195, 170, 110, 99, 105, 111, 34, 10, 34, 87, 104, 101,
+114, 101, 32, 105, 115, 32, 123, 48, 125, 63, 34, 32, 61, 32, 34, 79, 110, 100, 101, 32, 101, 115, 116, 195,
+161, 32, 123, 48, 125, 63, 34, 10, 34, 116, 104, 105, 115, 32, 112, 114, 111, 106, 101, 99, 116, 34, 32, 61,
+32, 34, 101, 115, 116, 101, 32, 112, 114, 111, 106, 101, 116, 111, 34, 10, 34, 121, 111, 117, 114, 32, 115, 101,
+97, 114, 99, 104, 32, 102, 111, 108, 100, 101, 114, 115, 34, 32, 61, 32, 34, 115, 117, 97, 115, 32, 112, 97,
+115, 116, 97, 115, 32, 100, 101, 32, 98, 117, 115, 99, 97, 34, 10, 34, 123, 48, 125, 32, 102, 105, 108, 101,
+40, 115, 41, 32, 119, 101, 114, 101, 32, 102, 111, 117, 110, 100, 32, 97, 117, 116, 111, 109, 97, 116, 105, 99,
+97, 108, 108, 121, 32, 105, 110, 32, 97, 110, 111, 116, 104, 101, 114, 32, 102, 111, 108, 100, 101, 114, 46, 34,
+32, 61, 32, 34, 123, 48, 125, 32, 97, 114, 113, 117, 105, 118, 111, 40, 115, 41, 32, 101, 110, 99, 111, 110,
+116, 114, 97, 100, 111, 40, 115, 41, 32, 97, 117, 116, 111, 109, 97, 116, 105, 99, 97, 109, 101, 110, 116, 101,
+32, 101, 109, 32, 111, 117, 116, 114, 97, 32, 112, 97, 115, 116, 97, 46, 34, 10, 34, 123, 48, 125, 32, 102,
+111, 117, 110, 100, 44, 32, 123, 49, 125, 32, 115, 116, 105, 108, 108, 32, 109, 105, 115, 115, 105, 110, 103, 34,
+32, 61, 32, 34, 123, 48, 125, 32, 101, 110, 99, 111, 110, 116, 114, 97, 100, 111, 40, 115, 41, 44, 32, 123,
+49, 125, 32, 97, 105, 110, 100, 97, 32, 97, 117, 115, 101, 110, 116, 101, 40, 115, 41, 34, 10, 34, 123, 48,
+125, 32, 109, 111, 114, 101, 32, 102, 111, 117, 110, 100, 32, 105, 110, 32, 116, 104, 101, 32, 115, 97, 109, 101,
+32, 102, 111, 108, 100, 101, 114, 34, 32, 61, 32, 34, 109, 97, 105, 115, 32, 123, 48, 125, 32, 101, 110, 99,
+111, 110, 116, 114, 97, 100, 111, 40, 115, 41, 32, 110, 97, 32, 109, 101, 115, 109, 97, 32, 112, 97, 115, 116,
+97, 34, 10, 34, 123, 48, 125, 32, 112, 108, 117, 103, 105, 110, 40, 115, 41, 32, 97, 114, 101, 32, 110, 111,
+116, 32, 105, 110, 115, 116, 97, 108, 108, 101, 100, 32, 40, 111, 114, 32, 110, 111, 116, 32, 115, 99, 97, 110,
+110, 101, 100, 41, 58, 32, 76, 89, 78, 88, 32, 112, 117, 116, 32, 115, 111, 109, 101, 116, 104, 105, 110, 103,
+32, 105, 110, 32, 116, 104, 101, 105, 114, 32, 112, 108, 97, 99, 101, 46, 34, 32, 61, 32, 34, 123, 48, 125,
+32, 112, 108, 117, 103, 105, 110, 40, 115, 41, 32, 110, 195, 163, 111, 32, 105, 110, 115, 116, 97, 108, 97, 100,
+111, 40, 115, 41, 32, 40, 111, 117, 32, 110, 195, 163, 111, 32, 101, 115, 99, 97, 110, 101, 97, 100, 111, 40,
+115, 41, 41, 58, 32, 111, 32, 76, 89, 78, 88, 32, 99, 111, 108, 111, 99, 111, 117, 32, 97, 108, 103, 111,
+32, 110, 111, 32, 108, 117, 103, 97, 114, 46, 34, 10, 34, 123, 48, 125, 32, 115, 97, 109, 112, 108, 101, 40,
+115, 41, 32, 117, 115, 101, 100, 32, 98, 121, 32, 123, 49, 125, 32, 99, 111, 117, 108, 100, 32, 110, 111, 116,
+32, 98, 101, 32, 102, 111, 117, 110, 100, 32, 111, 110, 32, 116, 104, 105, 115, 32, 80, 67, 46, 34, 32, 61,
+32, 34, 123, 48, 125, 32, 115, 97, 109, 112, 108, 101, 40, 115, 41, 32, 117, 115, 97, 100, 111, 40, 115, 41,
+32, 112, 111, 114, 32, 123, 49, 125, 32, 110, 195, 163, 111, 32, 102, 111, 105, 40, 102, 111, 114, 97, 109, 41,
+32, 101, 110, 99, 111, 110, 116, 114, 97, 100, 111, 40, 115, 41, 32, 110, 101, 115, 116, 101, 32, 80, 67, 46,
+34, 10, 34, 123, 48, 125, 32, 115, 116, 105, 108, 108, 32, 109, 105, 115, 115, 105, 110, 103, 44, 32, 123, 49,
+125, 32, 102, 111, 117, 110, 100, 34, 32, 61, 32, 34, 123, 48, 125, 32, 97, 105, 110, 100, 97, 32, 97, 117,
+115, 101, 110, 116, 101, 40, 115, 41, 44, 32, 123, 49, 125, 32, 101, 110, 99, 111, 110, 116, 114, 97, 100, 111,
+40, 115, 41, 34, 10, 34, 66, 117, 105, 108, 116, 45, 105, 110, 32, 115, 121, 110, 116, 104, 32, 40, 97, 32,
+112, 114, 101, 115, 101, 116, 32, 99, 104, 111, 115, 101, 110, 32, 98, 121, 32, 116, 104, 101, 32, 99, 104, 97,
+110, 110, 101, 108, 32, 110, 97, 109, 101, 41, 34, 32, 61, 32, 34, 83, 121, 110, 116, 104, 32, 105, 110, 116,
+101, 114, 110, 111, 32, 40, 117, 109, 32, 112, 114, 101, 115, 101, 116, 32, 101, 115, 99, 111, 108, 104, 105, 100,
+111, 32, 112, 101, 108, 111, 32, 110, 111, 109, 101, 32, 100, 111, 32, 99, 97, 110, 97, 108, 41, 34, 10, 34,
+78, 111, 116, 104, 105, 110, 103, 58, 32, 116, 104, 101, 32, 115, 108, 111, 116, 32, 119, 97, 115, 32, 108, 101,
+102, 116, 32, 111, 117, 116, 32, 111, 102, 32, 116, 104, 101, 32, 109, 105, 120, 101, 114, 34, 32, 61, 32, 34,
+78, 97, 100, 97, 58, 32, 111, 32, 115, 108, 111, 116, 32, 102, 105, 99, 111, 117, 32, 102, 111, 114, 97, 32,
+100, 111, 32, 77, 105, 120, 101, 114, 34, 10, 34, 83, 105, 108, 101, 110, 99, 101, 58, 32, 116, 104, 101, 32,
+99, 104, 97, 110, 110, 101, 108, 32, 107, 101, 101, 112, 115, 32, 116, 104, 101, 32, 112, 108, 117, 103, 105, 110,
+39, 115, 32, 115, 101, 116, 116, 105, 110, 103, 115, 32, 117, 110, 116, 105, 108, 32, 105, 116, 32, 105, 115, 32,
+105, 110, 115, 116, 97, 108, 108, 101, 100, 34, 32, 61, 32, 34, 83, 105, 108, 195, 170, 110, 99, 105, 111, 58,
+32, 111, 32, 99, 97, 110, 97, 108, 32, 103, 117, 97, 114, 100, 97, 32, 97, 115, 32, 99, 111, 110, 102, 105,
+103, 117, 114, 97, 195, 167, 195, 181, 101, 115, 32, 100, 111, 32, 112, 108, 117, 103, 105, 110, 32, 97, 116, 195,
+169, 32, 101, 108, 101, 32, 115, 101, 114, 32, 105, 110, 115, 116, 97, 108, 97, 100, 111, 34, 10, 34, 66, 121,
+112, 97, 115, 115, 101, 100, 58, 32, 116, 104, 101, 32, 115, 108, 111, 116, 32, 107, 101, 101, 112, 115, 32, 116,
+104, 101, 32, 112, 108, 117, 103, 105, 110, 39, 115, 32, 115, 101, 116, 116, 105, 110, 103, 115, 32, 117, 110, 116,
+105, 108, 32, 105, 116, 32, 105, 115, 32, 105, 110, 115, 116, 97, 108, 108, 101, 100, 34, 32, 61, 32, 34, 68,
+101, 115, 97, 116, 105, 118, 97, 100, 111, 58, 32, 111, 32, 115, 108, 111, 116, 32, 103, 117, 97, 114, 100, 97,
+32, 97, 115, 32, 99, 111, 110, 102, 105, 103, 117, 114, 97, 195, 167, 195, 181, 101, 115, 32, 100, 111, 32, 112,
+108, 117, 103, 105, 110, 32, 97, 116, 195, 169, 32, 101, 108, 101, 32, 115, 101, 114, 32, 105, 110, 115, 116, 97,
+108, 97, 100, 111, 34, 10,
 };
 } // namespace lynx::i18n::data

+ 81 - 1
src/ui/MainComponent.cpp

@@ -5,6 +5,7 @@
 #include "core/EditorPolish.h"
 
 #include "ui/HistoryPanel.h"
+#include "ui/MissingFilesDialog.h"
 #include "ui/QuickAddPalette.h"
 #include "ui/ToolWindow.h"
 #include "ui/WindowOwner.h"
@@ -2101,12 +2102,13 @@ void MainComponent::importFlp (const juce::File& file)
         }
 
         currentFile = juce::File(); // imported: "Save" asks where to write the .lynx
+        importedFlpFile = file;
         projectName = file.getFileNameWithoutExtension();
         rememberRecent (file);
         importedSuffix = " " + tr ("(imported from FL Studio)");
         updateTitle();
 
-        showImportReport();
+        showMissingFiles (true);
     }
 }
 
@@ -2125,10 +2127,87 @@ void MainComponent::openLynxProject (const juce::File& file)
     engine.rewind();
     engine.setSong (std::move (*song));
     currentFile = file;
+    importedFlpFile = juce::File();
     projectName = file.getFileNameWithoutExtension();
     importedSuffix = {};
     rememberRecent (file);
     updateTitle();
+
+    if (persistent)
+        showMissingFiles (true);
+}
+
+void MainComponent::showMissingFiles (bool afterOpening)
+{
+    MissingFilesInfo info;
+    info.projectName = projectName;
+    const auto fromFlp = importedFlpFile.existsAsFile() && currentFile == juce::File();
+    const auto exists = [] (const std::string& path) { return juce::File::isAbsolutePath (juce::String::fromUTF8 (path.c_str())) && juce::File (juce::String::fromUTF8 (path.c_str())).existsAsFile(); };
+
+    if (fromFlp)
+    {
+        // the import dropped the samples it couldn't find: its report keeps them (minus the ones located since)
+        const auto& report = engine.getImportReport();
+        for (const auto& m : report.missingFiles)
+            info.files.push_back (m);
+        info.plugins = engine.getMissingPluginDetails();
+        info.autoRelocated = report.relocatedFiles;
+        info.searchFolders.add (importedFlpFile.getParentDirectory().getFullPathName());
+    }
+    else
+    {
+        const auto& song = engine.getSong();
+        info.files = findMissingSamples (song, exists);
+        auto& host = engine.getPluginHost();
+        auto addPlugin = [&info] (const PluginRef& ref, const std::string& user, const char* replacement) {
+            const auto name = ref.name.empty() ? ref.id : ref.name;
+            auto it = std::find_if (info.plugins.begin(), info.plugins.end(), [&] (const MissingPlugin& p) { return p.name == name; });
+            if (it == info.plugins.end())
+                it = info.plugins.insert (info.plugins.end(), MissingPlugin { name, {}, replacement });
+            if (std::find (it->usedBy.begin(), it->usedBy.end(), user) == it->usedBy.end())
+                it->usedBy.push_back (user);
+        };
+        for (const auto& c : song.channels)
+            if (c.instrument == InstrumentKind::plugin && ! c.plugin.id.empty() && host.find (juce::String::fromUTF8 (c.plugin.id.c_str())) == nullptr)
+                addPlugin (c.plugin, c.name, "Silence: the channel keeps the plugin's settings until it is installed");
+        for (std::size_t t = 0; t < song.mixer.size(); ++t)
+            for (const auto& fx : song.mixer[t].effects)
+                if (fx.kind == EffectKind::plugin && ! fx.plugin.id.empty() && host.find (juce::String::fromUTF8 (fx.plugin.id.c_str())) == nullptr)
+                    addPlugin (fx.plugin, song.mixer[t].name.empty() ? (t == 0 ? std::string ("Master") : "Insert " + std::to_string (t)) : song.mixer[t].name,
+                               "Bypassed: the slot keeps the plugin's settings until it is installed");
+        if (currentFile.existsAsFile())
+            info.searchFolders.add (currentFile.getParentDirectory().getFullPathName());
+    }
+
+    if (afterOpening && info.files.empty() && info.plugins.empty())
+    {
+        if (fromFlp)
+            showImportReport();
+        return;
+    }
+
+    auto safe = juce::Component::SafePointer<MainComponent> (this);
+    const auto flp = fromFlp ? importedFlpFile : juce::File();
+    showMissingFilesDialog (
+        std::move (info),
+        [safe, flp] (const std::map<std::string, std::string>& relocations) {
+            if (safe == nullptr)
+                return;
+            if (flp != juce::File())
+            {
+                // FL import: imported again with the located samples (the channels become samplers, slices are read...)
+                juce::String error;
+                if (! safe->engine.importFlpFile (flp, error, relocations, true))
+                    juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
+            }
+            else
+                safe->engine.editSong ([&relocations] (Song& s) { applyRelocations (s, relocations); });
+            safe->updateTitle();
+        },
+        [safe, afterOpening, fromFlp] {
+            if (safe != nullptr && afterOpening && fromFlp)
+                safe->showImportReport();
+        });
 }
 
 void MainComponent::exportAudio()
@@ -2365,6 +2444,7 @@ juce::PopupMenu MainComponent::getMenuForIndex (int index, const juce::String&)
     else
     {
         menu.addItem (tr ("Shortcuts") + shortcutText ("help.shortcuts"), [this] { showHelp(); });
+        menu.addItem (tr ("Missing files..."), [this] { showMissingFiles (false); });
         menu.addItem (tr ("Last FL Studio import report"), [this] {
             const auto& r = engine.getImportReport();
             if (r.converted.empty() && r.approximated.empty() && r.unsupported.empty() && r.droppedEffects.empty() && r.missingSamples == 0

+ 4 - 0
src/ui/MainComponent.h

@@ -103,6 +103,9 @@ private:
     void showImportReport();
     void importFlp (const juce::File& file);
     void openLynxProject (const juce::File& file);
+    // The "Missing files" window (ui/MissingFilesDialog.h) for the current project; `afterOpening`: shown by opening a
+    // project (only when something is missing; the FL import report follows it), else from the menu (always).
+    void showMissingFiles (bool afterOpening);
     int scansSeen = 0; // background plugin scans already announced in the hint bar
     void showHelp();
 
@@ -281,6 +284,7 @@ private:
 
     std::unique_ptr<juce::FileChooser> fileChooser;
     juce::File currentFile;
+    juce::File importedFlpFile; // the .flp the current project was imported from (until another project is opened)
     juce::String importedSuffix; // " (imported from FL Studio)" in the title until saved as .lynx
     juce::String projectName; // suggested name for export (also from an imported .flp)
     std::map<int, std::vector<int>> heldKeys; // PC keyboard keys playing notes (keyCode -> channels)

+ 628 - 0
src/ui/MissingFilesDialog.cpp

@@ -0,0 +1,628 @@
+#include "ui/MissingFilesDialog.h"
+
+#include "engine/PluginHost.h"
+#include "ui/I18n.h"
+#include "ui/Theme.h"
+#include "ui/WindowOwner.h"
+
+namespace lynx
+{
+namespace
+{
+juce::String u8 (const std::string& s) { return juce::String::fromUTF8 (s.c_str()); }
+
+juce::File searchFoldersFile() { return PluginHost::settingsFolder().getChildFile ("search-folders.txt"); }
+
+// Recursive search of folders for the missing files' names, off the UI thread.
+class SearchThread final : public juce::Thread
+{
+public:
+    SearchThread (std::vector<MissingFile> m, juce::StringArray f, std::function<void (std::vector<std::string>, bool)> done)
+        : juce::Thread ("LYNX missing-files search"), missing (std::move (m)), folders (std::move (f)), onDone (std::move (done))
+    {
+    }
+
+    ~SearchThread() override { stopThread (4000); }
+
+    std::atomic<int> scanned { 0 };
+
+    void run() override
+    {
+        std::vector<std::string> hits;
+        auto list = [this] (const std::string& folder, const std::function<bool (const std::string&, bool)>& onEntry) {
+            for (const auto& entry : juce::RangedDirectoryIterator (juce::File (u8 (folder)), false, "*",
+                                                                    juce::File::findFilesAndDirectories | juce::File::ignoreHiddenFiles))
+            {
+                ++scanned;
+                if (! onEntry (entry.getFile().getFullPathName().toStdString(), entry.isDirectory()))
+                    return;
+            }
+        };
+        for (const auto& folder : folders)
+        {
+            auto found = searchFolderForMissing (missing, folder.toStdString(), list, 2000000, [this] { return threadShouldExit(); });
+            hits.insert (hits.end(), found.begin(), found.end());
+            if (threadShouldExit())
+                break;
+        }
+        const auto cancelled = threadShouldExit();
+        juce::MessageManager::callAsync ([done = onDone, hits = std::move (hits), cancelled]() mutable { done (std::move (hits), cancelled); });
+    }
+
+private:
+    std::vector<MissingFile> missing;
+    juce::StringArray folders;
+    std::function<void (std::vector<std::string>, bool)> onDone;
+};
+
+class MissingFilesPanel final : public juce::Component,
+                                private juce::ListBoxModel,
+                                private juce::Timer
+{
+public:
+    enum class Page { samples, plugins, found };
+
+    MissingFilesPanel (MissingFilesInfo i, bool live) : info (std::move (i)), persistent (live)
+    {
+        title.setText (tr ("Missing files"), juce::dontSendNotification);
+        title.setFont (theme::font (theme::type::display, true));
+        addAndMakeVisible (title);
+        summary.setFont (theme::font (theme::type::body));
+        summary.setColour (juce::Label::textColourId, theme::colour::textSecondary);
+        summary.setJustificationType (juce::Justification::topLeft);
+        addAndMakeVisible (summary);
+
+        for (auto* b : { &samplesTab, &pluginsTab, &foundTab })
+        {
+            b->setClickingTogglesState (true);
+            b->setRadioGroupId (81);
+            b->setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b->setColour (juce::TextButton::textColourOnId, theme::colour::textPrimary);
+            addAndMakeVisible (b);
+        }
+        samplesTab.onClick = [this] { showPage (Page::samples); };
+        pluginsTab.onClick = [this] { showPage (Page::plugins); };
+        foundTab.onClick = [this] { showPage (Page::found); };
+
+        list.setModel (this);
+        list.setRowHeight (46);
+        list.setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
+        list.setColour (juce::ListBox::outlineColourId, theme::colour::border);
+        list.setOutlineThickness (1);
+        list.setMultipleSelectionEnabled (true);
+        addAndMakeVisible (list);
+
+        searchButton.onClick = [this] { chooseSearchFolder(); };
+        locateButton.onClick = [this] { locateSelected(); };
+        skipButton.onClick = [this] { toggleSkipSelected(); };
+        stopButton.onClick = [this] { stopSearch(); };
+        for (auto* b : { &searchButton, &locateButton, &skipButton, &stopButton })
+            addAndMakeVisible (b);
+        stopButton.setVisible (false);
+
+        status.setFont (theme::font (theme::type::small));
+        status.setColour (juce::Label::textColourId, theme::colour::textSecondary);
+        addAndMakeVisible (status);
+
+        rememberToggle.setButtonText (tr ("Remember the folders I search"));
+        rememberToggle.setToggleState (true, juce::dontSendNotification);
+        addAndMakeVisible (rememberToggle);
+
+        applyButton.setColour (juce::TextButton::buttonColourId, theme::colour::accent);
+        applyButton.setColour (juce::TextButton::textColourOffId, theme::colour::onAccent);
+        applyButton.onClick = [this] { apply(); };
+        closeButton.onClick = [this] { close(); };
+        addAndMakeVisible (applyButton);
+        addAndMakeVisible (closeButton);
+
+        if (persistent)
+            folders = loadSearchFolders();
+
+        showPage (! info.files.empty() ? Page::samples : ! info.plugins.empty() ? Page::plugins : Page::found);
+        refresh();
+        setSize (760, 560);
+    }
+
+    ~MissingFilesPanel() override
+    {
+        stopTimer();
+        search.reset();
+    }
+
+    std::function<void (const std::map<std::string, std::string>&)> onApply;
+    std::function<void()> onCloseRequest; // the window's; none in snapshots
+
+    void showPageForSnapshot (int p, int row)
+    {
+        showPage (p == 1 ? Page::plugins : p == 2 ? Page::found : Page::samples);
+        if (row >= 0)
+            list.selectRow (row);
+        refresh();
+        if (p == 0)
+            status.setText (tr ("{0} still missing, {1} found", { "2", "2" }), juce::dontSendNotification);
+    }
+
+    // the remembered search folders and the Browser's folders, searched without asking
+    void searchRememberedFolders()
+    {
+        juce::StringArray all (info.searchFolders);
+        for (const auto& f : folders)
+            all.addIfNotAlreadyThere (u8 (f));
+        all.addArray (browserSearchFolders());
+        all.removeDuplicates (true);
+        for (int i = all.size(); --i >= 0;)
+            if (! juce::File (all[i]).isDirectory())
+                all.remove (i);
+        if (! all.isEmpty() && stillMissing() > 0)
+            startSearch (all, false);
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg2);
+        // header band with the accent mark
+        g.setColour (theme::colour::bg3);
+        g.fillRect (header);
+        g.setColour (theme::colour::accent);
+        g.fillRect (header.withWidth (4));
+        g.setColour (theme::colour::border);
+        g.drawHorizontalLine (header.getBottom(), 0.0f, (float) getWidth());
+        g.drawHorizontalLine (footer.getY() - 1, 0.0f, (float) getWidth());
+    }
+
+    void resized() override
+    {
+        auto area = getLocalBounds();
+        header = area.removeFromTop (56 + 18 * juce::jmax (1, summaryLines));
+        {
+            auto h = header.reduced (20, 12);
+            h.removeFromLeft (4);
+            title.setBounds (h.removeFromTop (28));
+            summary.setBounds (h);
+        }
+        footer = area.removeFromBottom (54);
+        {
+            auto f = footer.reduced (16, 12);
+            closeButton.setBounds (f.removeFromRight (150));
+            f.removeFromRight (8);
+            applyButton.setBounds (f.removeFromRight (150));
+            rememberToggle.setBounds (f.removeFromLeft (280));
+        }
+        area.reduce (16, 12);
+        {
+            auto tabs = area.removeFromTop (28);
+            for (auto* b : { &samplesTab, &pluginsTab, &foundTab })
+            {
+                b->setBounds (tabs.removeFromLeft (juce::jmax (120, juce::GlyphArrangement::getStringWidthInt (juce::Font (theme::font (theme::type::body)), b->getButtonText()) + 28)));
+                tabs.removeFromLeft (6);
+            }
+        }
+        area.removeFromTop (10);
+        auto actions = area.removeFromBottom (30);
+        area.removeFromBottom (10);
+        list.setBounds (area);
+        searchButton.setBounds (actions.removeFromLeft (150));
+        actions.removeFromLeft (8);
+        locateButton.setBounds (actions.removeFromLeft (110));
+        actions.removeFromLeft (8);
+        skipButton.setBounds (actions.removeFromLeft (110));
+        actions.removeFromLeft (12);
+        stopButton.setBounds (actions.removeFromRight (80));
+        status.setBounds (actions);
+    }
+
+private:
+    int stillMissing() const
+    {
+        return (int) std::count_if (info.files.begin(), info.files.end(), [] (const MissingFile& m) { return m.found.empty() && ! m.skipped; });
+    }
+    int foundCount() const
+    {
+        return (int) std::count_if (info.files.begin(), info.files.end(), [] (const MissingFile& m) { return ! m.found.empty() && ! m.skipped; });
+    }
+
+    void refresh()
+    {
+        const auto missing = stillMissing(), found = foundCount();
+        juce::StringArray lines;
+        if (! info.files.empty())
+            lines.add (tr ("{0} sample(s) used by {1} could not be found on this PC.",
+                           { juce::String ((int) info.files.size()), info.projectName.isNotEmpty() ? info.projectName : tr ("this project") }));
+        if (! info.plugins.empty())
+            lines.add (tr ("{0} plugin(s) are not installed (or not scanned): LYNX put something in their place.", { juce::String ((int) info.plugins.size()) }));
+        if (! info.autoRelocated.empty())
+            lines.add (tr ("{0} file(s) were found automatically in another folder.", { juce::String ((int) info.autoRelocated.size()) }));
+        if (lines.isEmpty())
+            lines.add (tr ("Nothing is missing: every sample and plugin this project uses was found."));
+        summaryLines = lines.size();
+        summary.setText (lines.joinIntoString ("\n"), juce::dontSendNotification);
+
+        samplesTab.setButtonText (tr ("Samples ({0})", { juce::String ((int) info.files.size()) }));
+        pluginsTab.setButtonText (tr ("Plugins ({0})", { juce::String ((int) info.plugins.size()) }));
+        foundTab.setButtonText (tr ("Found automatically ({0})", { juce::String ((int) info.autoRelocated.size()) }));
+
+        const auto searching = search != nullptr;
+        if (! searching && page == Page::samples)
+            status.setText (info.files.empty() ? juce::String()
+                            : missing == 0         ? tr ("Every sample has a place. Apply to use them.")
+                                                   : tr ("{0} still missing, {1} found", { juce::String (missing), juce::String (found) }),
+                            juce::dontSendNotification);
+        const auto samplesPage = page == Page::samples;
+        for (auto* b : { &searchButton, &locateButton, &skipButton })
+            b->setVisible (samplesPage);
+        searchButton.setEnabled (! searching && missing > 0);
+        locateButton.setEnabled (! searching && list.getNumSelectedRows() > 0);
+        skipButton.setEnabled (list.getNumSelectedRows() > 0);
+        stopButton.setVisible (searching && samplesPage);
+        status.setVisible (samplesPage);
+
+        applyButton.setButtonText (found > 0 ? tr ("Apply ({0})", { juce::String (found) }) : tr ("Apply"));
+        applyButton.setEnabled (found > 0 && ! searching);
+        closeButton.setButtonText (found > 0 ? tr ("Close without changes") : tr ("Close"));
+        rememberToggle.setVisible (! info.files.empty());
+        list.updateContent();
+        list.repaint();
+        resized();
+    }
+
+    void showPage (Page p)
+    {
+        page = p;
+        (p == Page::samples ? samplesTab : p == Page::plugins ? pluginsTab : foundTab).setToggleState (true, juce::dontSendNotification);
+        list.deselectAllRows();
+        list.setMultipleSelectionEnabled (p == Page::samples);
+        refresh();
+    }
+
+    // --- list ---------------------------------------------------------------------------------
+    int getNumRows() override
+    {
+        return page == Page::samples ? (int) info.files.size() : page == Page::plugins ? (int) info.plugins.size() : (int) info.autoRelocated.size();
+    }
+
+    void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
+    {
+        if (selected)
+        {
+            g.setColour (theme::colour::accentMuted);
+            g.fillRect (0, 0, width, height);
+            g.setColour (theme::colour::accent);
+            g.fillRect (0, 3, 3, height - 6);
+        }
+        else if (row % 2 == 1)
+        {
+            g.setColour (theme::colour::bg1);
+            g.fillRect (0, 0, width, height);
+        }
+
+        juce::Colour dot;
+        juce::String name, right, detail;
+        juce::Colour detailColour = theme::colour::textDisabled;
+
+        if (page == Page::samples)
+        {
+            const auto& m = info.files[(std::size_t) row];
+            name = u8 (pathFileName (m.path));
+            juce::StringArray users;
+            for (const auto& u : m.usedBy)
+                users.add (u8 (u));
+            right = users.joinIntoString (", ");
+            if (m.skipped)
+            {
+                dot = theme::colour::textDisabled;
+                detail = tr ("Skipped: stays silent") + "   " + u8 (m.path);
+            }
+            else if (! m.found.empty())
+            {
+                dot = theme::colour::ledOn;
+                detail = juce::String::fromUTF8 ("\xe2\x86\x92 ") + u8 (m.found);
+                detailColour = theme::colour::ledOn.withAlpha (0.85f);
+            }
+            else
+            {
+                dot = theme::colour::warning;
+                detail = u8 (m.path);
+            }
+        }
+        else if (page == Page::plugins)
+        {
+            const auto& p = info.plugins[(std::size_t) row];
+            dot = theme::colour::warning;
+            name = u8 (p.name);
+            juce::StringArray users;
+            for (const auto& u : p.usedBy)
+                users.add (u8 (u));
+            right = users.joinIntoString (", ");
+            detail = tr ("Replaced by: {0}", { tr (u8 (p.replacement)) });
+            detailColour = theme::colour::textSecondary;
+        }
+        else
+        {
+            const auto& [from, to] = info.autoRelocated[(std::size_t) row];
+            dot = theme::colour::info;
+            name = u8 (pathFileName (to));
+            detail = u8 (from) + juce::String::fromUTF8 ("  \xe2\x86\x92  ") + u8 (to);
+        }
+
+        g.setColour (dot);
+        g.fillEllipse (14.0f, 12.0f, 8.0f, 8.0f);
+
+        const auto rightWidth = juce::jmin (width / 3, juce::GlyphArrangement::getStringWidthInt (juce::Font (theme::font (theme::type::small)), right) + 8);
+        g.setFont (theme::font (theme::type::body, true));
+        g.setColour (theme::colour::textPrimary);
+        g.drawText (name, 32, 5, width - 44 - rightWidth, 18, juce::Justification::centredLeft, true);
+        g.setFont (theme::font (theme::type::small));
+        g.setColour (theme::colour::textSecondary);
+        g.drawText (right, width - 12 - rightWidth, 5, rightWidth, 18, juce::Justification::centredRight, true);
+        g.setColour (detailColour);
+        g.drawText (detail, 32, 24, width - 44, 16, juce::Justification::centredLeft, true);
+    }
+
+    void selectedRowsChanged (int) override { refresh(); }
+
+    void listBoxItemDoubleClicked (int row, const juce::MouseEvent&) override
+    {
+        if (page == Page::samples && search == nullptr)
+        {
+            list.selectRow (row);
+            locateSelected();
+        }
+    }
+
+    juce::String getTooltipForRow (int row) override
+    {
+        if (page == Page::samples && row < (int) info.files.size())
+            return u8 (info.files[(std::size_t) row].path);
+        return {};
+    }
+
+    // --- actions ------------------------------------------------------------------------------
+    void chooseSearchFolder()
+    {
+        chooser = std::make_unique<juce::FileChooser> (tr ("Search a folder (and its sub-folders) for the missing samples"),
+                                                       folders.empty() ? juce::File::getSpecialLocation (juce::File::userHomeDirectory) : juce::File (u8 (folders.front())));
+        chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
+                              [safe = juce::Component::SafePointer<MissingFilesPanel> (this)] (const juce::FileChooser& c) {
+                                  if (safe == nullptr || ! c.getResult().isDirectory())
+                                      return;
+                                  safe->remember (c.getResult());
+                                  safe->startSearch ({ c.getResult().getFullPathName() }, true);
+                              });
+    }
+
+    void locateSelected()
+    {
+        const auto row = list.getSelectedRow();
+        if (page != Page::samples || row < 0 || row >= (int) info.files.size())
+            return;
+        const auto wanted = u8 (pathFileName (info.files[(std::size_t) row].path));
+        const auto start = folders.empty() ? juce::File::getSpecialLocation (juce::File::userHomeDirectory) : juce::File (u8 (folders.front()));
+        chooser = std::make_unique<juce::FileChooser> (tr ("Where is {0}?", { wanted }), start.getChildFile (wanted),
+                                                       "*" + juce::File (wanted).getFileExtension());
+        chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
+                              [safe = juce::Component::SafePointer<MissingFilesPanel> (this), row] (const juce::FileChooser& c) {
+                                  if (safe == nullptr || ! c.getResult().existsAsFile())
+                                      return;
+                                  safe->located (row, c.getResult());
+                              });
+    }
+
+    // a file picked by hand: used for that row, and its folder is looked at for the others (as FL does)
+    void located (int row, const juce::File& file)
+    {
+        auto& m = info.files[(std::size_t) row];
+        m.found = file.getFullPathName().toStdString();
+        m.skipped = false;
+        std::vector<std::string> siblings;
+        for (const auto& entry : juce::RangedDirectoryIterator (file.getParentDirectory(), false, "*", juce::File::findFiles))
+            siblings.push_back (entry.getFile().getFullPathName().toStdString());
+        const auto more = relocateByName (info.files, siblings);
+        remember (file.getParentDirectory());
+        refresh();
+        if (more > 0)
+            status.setText (tr ("{0} more found in the same folder", { juce::String (more) }), juce::dontSendNotification);
+    }
+
+    void toggleSkipSelected()
+    {
+        const auto rows = list.getSelectedRows();
+        auto allSkipped = true;
+        for (int i = 0; i < rows.size(); ++i)
+            allSkipped = allSkipped && info.files[(std::size_t) rows[i]].skipped;
+        for (int i = 0; i < rows.size(); ++i)
+        {
+            auto& m = info.files[(std::size_t) rows[i]];
+            m.skipped = ! allSkipped;
+            if (m.skipped)
+                m.found.clear();
+        }
+        refresh();
+    }
+
+    void remember (const juce::File& folder)
+    {
+        if (! persistent || ! rememberToggle.getToggleState())
+            return;
+        rememberFolder (folders, folder.getFullPathName().toStdString());
+        saveSearchFolders (folders);
+    }
+
+    void startSearch (const juce::StringArray& where, bool userPicked)
+    {
+        if (search != nullptr)
+            return;
+        searchedBy = userPicked;
+        search = std::make_unique<SearchThread> (info.files, where,
+                                                 [safe = juce::Component::SafePointer<MissingFilesPanel> (this)] (std::vector<std::string> hits, bool cancelled) {
+                                                     if (safe != nullptr)
+                                                         safe->searchFinished (std::move (hits), cancelled);
+                                                 });
+        searchedFolders = where;
+        search->startThread();
+        startTimerHz (8);
+        refresh();
+        timerCallback();
+    }
+
+    void stopSearch()
+    {
+        if (search != nullptr)
+            search->signalThreadShouldExit();
+    }
+
+    void timerCallback() override
+    {
+        if (search != nullptr)
+            status.setText (tr ("Searching {0}... {1} files looked at",
+                                { searchedFolders.size() == 1 ? searchedFolders[0] : tr ("your search folders"), juce::String (search->scanned.load()) }),
+                            juce::dontSendNotification);
+    }
+
+    void searchFinished (std::vector<std::string> hits, bool cancelled)
+    {
+        stopTimer();
+        search.reset();
+        const auto found = relocateByName (info.files, hits);
+        refresh();
+        status.setText ((cancelled ? tr ("Search stopped.") + " " : juce::String())
+                            + tr ("{0} found, {1} still missing", { juce::String (found), juce::String (stillMissing()) }),
+                        juce::dontSendNotification);
+    }
+
+    void apply()
+    {
+        const auto map = relocationMap (info.files);
+        if (onApply && ! map.empty())
+            onApply (map);
+        close();
+    }
+
+    void close()
+    {
+        stopSearch();
+        if (onCloseRequest)
+            onCloseRequest();
+    }
+
+    MissingFilesInfo info;
+    bool persistent = false, searchedBy = false;
+    Page page = Page::samples;
+    std::vector<std::string> folders;
+    juce::StringArray searchedFolders;
+    std::unique_ptr<SearchThread> search;
+    std::unique_ptr<juce::FileChooser> chooser;
+    juce::Rectangle<int> header, footer;
+    int summaryLines = 1;
+
+    juce::Label title, summary, status;
+    juce::TextButton samplesTab, pluginsTab, foundTab;
+    juce::ListBox list;
+    juce::TextButton searchButton { tr ("Search folder...") }, locateButton { tr ("Locate...") }, skipButton { tr ("Skip") },
+        stopButton { tr ("Stop") };
+    juce::ToggleButton rememberToggle;
+    juce::TextButton applyButton, closeButton;
+};
+
+// closes like the panel's buttons and reports when it goes away
+class MissingFilesWindow final : public juce::DocumentWindow
+{
+public:
+    MissingFilesWindow (std::unique_ptr<MissingFilesPanel> panel, std::function<void()> closed)
+        : juce::DocumentWindow (tr ("Missing files"), theme::colour::bg2, juce::DocumentWindow::closeButton, true), onClosed (std::move (closed))
+    {
+        panel->onCloseRequest = [this] { closeWindow(); };
+        setUsingNativeTitleBar (true);
+        setContentOwned (panel.release(), true);
+        setResizable (true, false);
+        setResizeLimits (620, 420, 1600, 1200);
+        centreWithSize (getWidth(), getHeight());
+    }
+
+    void closeButtonPressed() override { closeWindow(); }
+
+    bool keyPressed (const juce::KeyPress& key) override
+    {
+        if (key == juce::KeyPress::escapeKey)
+        {
+            closeWindow();
+            return true;
+        }
+        return juce::DocumentWindow::keyPressed (key);
+    }
+
+    void closeWindow()
+    {
+        if (! isVisible())
+            return;
+        setVisible (false);
+        if (onClosed)
+            onClosed();
+        juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::Component> (this)] { delete safe.getComponent(); });
+    }
+
+private:
+    std::function<void()> onClosed;
+};
+} // namespace
+
+std::vector<std::string> loadSearchFolders()
+{
+    return parseFolderList (searchFoldersFile().loadFileAsString().toStdString());
+}
+
+void saveSearchFolders (const std::vector<std::string>& folders)
+{
+    searchFoldersFile().replaceWithText (u8 (folderListText (folders)));
+}
+
+juce::StringArray browserSearchFolders()
+{
+    juce::StringArray list;
+    list.addLines (PluginHost::settingsFolder().getChildFile ("browser-folders.txt").loadFileAsString());
+    list.trim();
+    list.removeEmptyStrings();
+    return list;
+}
+
+void showMissingFilesDialog (MissingFilesInfo info, std::function<void (const std::map<std::string, std::string>&)> onApply,
+                             std::function<void()> onClosed)
+{
+    auto panel = std::make_unique<MissingFilesPanel> (std::move (info), true);
+    panel->onApply = std::move (onApply);
+    auto* raw = panel.get();
+    auto* window = new MissingFilesWindow (std::move (panel), std::move (onClosed));
+    window->setVisible (true);
+    keepAboveMainWindow (*window);
+    raw->searchRememberedFolders();
+}
+
+std::unique_ptr<juce::Component> makeMissingFilesPanel (MissingFilesInfo info, int page, int selectedRow)
+{
+    auto panel = std::make_unique<MissingFilesPanel> (std::move (info), false);
+    panel->showPageForSnapshot (page, selectedRow);
+    return panel;
+}
+
+MissingFilesInfo missingFilesSnapshotInfo()
+{
+    MissingFilesInfo info;
+    info.projectName = "Night Drive";
+    info.files = {
+        { "C:\\Users\\Producer\\Samples\\Drums\\Kicks\\Kick Punchy 04.wav", { "Kick" }, "D:\\Library\\Drums\\Kicks\\Kick Punchy 04.wav", false },
+        { "C:\\Users\\Producer\\Samples\\Drums\\Snares\\Snare Tight 12.wav", { "Snare", "Snare 2" }, {}, false },
+        { "C:\\Users\\Producer\\Samples\\Vocals\\Hook take 3.wav", { "Audio clip: Hook take 3" }, {}, false },
+        { "C:\\Users\\Producer\\Samples\\FX\\Riser long.wav", { "Riser" }, {}, true },
+        { "E:\\Old drive\\Loops\\Pad texture 90bpm.wav", { "Pad", "Insert 4: Newtone" }, "D:\\Library\\Loops\\Pad texture 90bpm.wav", false },
+    };
+    info.plugins = {
+        { "Serum", { "Lead", "Pluck" }, "Built-in synth (a preset chosen by the channel name)" },
+        { "ValhallaRoom", { "Insert 3" }, "Nothing: the slot was left out of the mixer" },
+    };
+    info.autoRelocated = {
+        { "C:\\Users\\Studio PC\\Documents\\Image-Line\\FL Studio\\Audio\\Sliced audio\\Break 2.wav",
+          "C:\\Users\\me\\Documents\\Image-Line\\FL Studio\\Audio\\Sliced audio\\Break 2.wav" },
+        { "C:\\Projects\\Night Drive\\Samples\\Chord stab.wav", "D:\\Music\\Night Drive\\Samples\\Chord stab.wav" },
+    };
+    return info;
+}
+} // namespace lynx

+ 43 - 0
src/ui/MissingFilesDialog.h

@@ -0,0 +1,43 @@
+#pragma once
+
+#include <functional>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+#include "core/MissingFiles.h"
+
+namespace lynx
+{
+// What the "Missing files" window shows for an opened project (core/MissingFiles.h).
+struct MissingFilesInfo
+{
+    std::vector<MissingFile> files;     // samples not found
+    std::vector<MissingPlugin> plugins; // plugins not installed here, with what replaced them
+    std::vector<std::pair<std::string, std::string>> autoRelocated; // found elsewhere when opening: saved path → used path
+    juce::String projectName;
+    juce::StringArray searchFolders; // also searched when the window opens (the project's folder), not remembered
+};
+
+// Search folders the user picked in this window before (most recent first), kept in the settings folder; the
+// Browser's user folders are searched too. The window searches them by itself when it opens.
+std::vector<std::string> loadSearchFolders();
+void saveSearchFolders (const std::vector<std::string>& folders);
+juce::StringArray browserSearchFolders(); // the Browser's user folders (browser-folders.txt)
+
+// Opens the window (non-modal, above the main window). `onApply(saved path → new path)` runs when the user applies
+// the files found; `onClosed` runs when the window goes away (applied or not).
+void showMissingFilesDialog (MissingFilesInfo info, std::function<void (const std::map<std::string, std::string>&)> onApply,
+                             std::function<void()> onClosed = {});
+
+// The window's content, for --snapshot mode (no automatic search, nothing saved): `page` 0 samples, 1 plugins,
+// 2 found automatically; `selectedRow` ≥ 0 selects a row.
+std::unique_ptr<juce::Component> makeMissingFilesPanel (MissingFilesInfo info, int page = 0, int selectedRow = -1);
+
+// Sample content for the snapshots: a project with missing, located, skipped and relocated files and missing plugins.
+MissingFilesInfo missingFilesSnapshotInfo();
+} // namespace lynx

+ 138 - 0
tests/tests.cpp

@@ -34,6 +34,7 @@
 #include "core/WavPack.h"
 #include "core/FlWrapper.h"
 #include "core/FlPluginDb.h"
+#include "core/MissingFiles.h"
 #include "core/Gms.h"
 #include "core/PoiZone.h"
 #include "core/MiniSynth.h"
@@ -13890,3 +13891,140 @@ TEST (newtone_rack_follows_transport)
 }
 #include "HardcoreTests.inc"
 #include "DistructorTests.inc"
+
+// --- missing files (core/MissingFiles.h) ------------------------------------------------------------------------
+
+TEST (missing_files_names_and_scores)
+{
+    CHECK (lynx::pathFileName ("C:\\Samples\\Drums\\Kick 01.wav") == "Kick 01.wav");
+    CHECK (lynx::pathFileName ("/home/u/loops/beat.flac") == "beat.flac");
+    CHECK (lynx::pathFileName ("D:/mixed\\sep/x.wav/") == "x.wav");
+    CHECK (lynx::pathFileName ("plain.wav") == "plain.wav");
+    CHECK (lynx::relocationScore ("C:\\Old\\Drums\\Kicks\\kick.wav", "/new/Drums/Kicks/KICK.WAV") == 3);
+    CHECK (lynx::relocationScore ("C:\\Old\\Drums\\Kicks\\kick.wav", "/new/other/kick.wav") == 1);
+    CHECK (lynx::relocationScore ("C:\\Old\\kick.wav", "/new/kick2.wav") == 0);
+}
+
+TEST (missing_files_find_in_song)
+{
+    lynx::Song song;
+    lynx::ChannelDef a, b, c, d, e;
+    a.name = "Kick", a.instrument = lynx::InstrumentKind::sampler, a.samplePath = "C:\\gone\\kick.wav";
+    b.name = "Vox", b.instrument = lynx::InstrumentKind::audioClip, b.samplePath = "C:\\gone\\vox.wav";
+    c.name = "Here", c.instrument = lynx::InstrumentKind::sampler, c.samplePath = "C:\\here\\snare.wav";
+    d.name = "GMS", d.instrument = lynx::InstrumentKind::gms, d.samplePath = "C:\\FL\\gms waves"; // installation data: not listed
+    e.name = "Kick 2", e.instrument = lynx::InstrumentKind::sampler, e.samplePath = "c:/GONE/KICK.wav"; // same file, other spelling
+    lynx::SampleZone z;
+    z.path = "C:\\gone\\piano_c4.wav";
+    a.zones.push_back (z);
+    song.channels = { a, b, c, d, e };
+    song.mixer.resize (3);
+    lynx::EffectSlot fx;
+    fx.samplePath = "C:\\gone\\tune.wav";
+    lynx::EffectSlot parallel;
+    parallel.branches.push_back ({ { fx }, 1.0f });
+    song.mixer[2].effects.push_back (parallel);
+    song.mixer[2].name = "Lead";
+
+    const auto exists = [] (const std::string& p) { return p.find ("here") != std::string::npos || p.find ("FL") != std::string::npos; };
+    auto missing = lynx::findMissingSamples (song, exists);
+    CHECK (missing.size() == 4);
+    CHECK (missing.size() == 4 && missing[0].path == "C:\\gone\\kick.wav" && missing[0].usedBy.size() == 2 && missing[0].usedBy[1] == "Kick 2");
+    CHECK (missing.size() == 4 && missing[1].path == "C:\\gone\\piano_c4.wav" && missing[1].usedBy[0] == "Kick");
+    CHECK (missing.size() == 4 && missing[2].usedBy[0] == "Audio clip: Vox");
+    CHECK (missing.size() == 4 && missing[3].usedBy[0] == "Lead: effect");
+
+    // candidates from a search: the deeper path match wins; one stays missing
+    const std::vector<std::string> hits { "/lib/other/kick.wav", "/lib/gone/kick.wav", "/lib/x/vox.wav", "/lib/y/tune.wav" };
+    CHECK (lynx::relocateByName (missing, hits) == 3);
+    CHECK (missing[0].found == "/lib/gone/kick.wav");
+    CHECK (missing[1].found.empty());
+    missing[3].skipped = true; // skipped: not applied
+    const auto map = lynx::relocationMap (missing);
+    CHECK (map.size() == 2);
+    CHECK (lynx::applyRelocations (song, map) == 3); // both spellings of kick.wav + vox
+    CHECK (song.channels[0].samplePath == "/lib/gone/kick.wav" && song.channels[4].samplePath == "/lib/gone/kick.wav");
+    CHECK (song.channels[1].samplePath == "/lib/x/vox.wav");
+    CHECK (song.channels[2].samplePath == "C:\\here\\snare.wav");
+    CHECK (song.mixer[2].effects[0].branches[0].chain[0].samplePath == "C:\\gone\\tune.wav");
+    lynx::Song copy = song;
+    CHECK (lynx::applyRelocations (copy, { { "C:\\gone\\tune.wav", "/t.wav" } }) == 1 && copy.mixer[2].effects[0].branches[0].chain[0].samplePath == "/t.wav");
+}
+
+TEST (missing_files_folder_search)
+{
+    namespace fs = std::filesystem;
+    const auto root = fs::temp_directory_path() / "lynx-missing-test";
+    fs::remove_all (root);
+    fs::create_directories (root / "a" / "deep" / "Kicks");
+    fs::create_directories (root / "b");
+    for (const auto& f : { root / "a" / "deep" / "Kicks" / "Kick.WAV", root / "b" / "kick.wav", root / "b" / "hat.wav", root / "b" / "unrelated.wav" })
+        std::ofstream (f) << "x";
+
+    std::vector<lynx::MissingFile> missing { { "C:\\Old\\Kicks\\kick.wav", { "Kick" }, {}, false }, { "C:\\Old\\hat.wav", { "Hat" }, {}, false },
+                                             { "C:\\Old\\ride.wav", { "Ride" }, {}, false } };
+    int listed = 0;
+    auto list = [&] (const std::string& folder, const std::function<bool (const std::string&, bool)>& onEntry) {
+        for (const auto& entry : fs::directory_iterator (folder))
+        {
+            ++listed;
+            if (! onEntry (entry.path().string(), entry.is_directory()))
+                return;
+        }
+    };
+    const auto hits = lynx::searchFolderForMissing (missing, root.string(), list);
+    CHECK (hits.size() == 3);
+    CHECK (lynx::relocateByName (missing, hits) == 2);
+    CHECK (missing[0].found.find ("Kicks") != std::string::npos); // the copy in a "Kicks" folder matches better
+    CHECK (missing[1].found.find ("hat.wav") != std::string::npos);
+    CHECK (missing[2].found.empty());
+
+    // a bounded walk stops early; a cancelled one finds nothing
+    CHECK (lynx::searchFolderForMissing (missing, root.string(), list, 2).size() <= 1);
+    CHECK (lynx::searchFolderForMissing (missing, root.string(), list, 0, [] { return true; }).empty());
+    // nothing left to find: no walk at all
+    missing[2].skipped = true;
+    listed = 0;
+    CHECK (lynx::searchFolderForMissing (missing, root.string(), list).empty() && listed == 0);
+    fs::remove_all (root);
+}
+
+TEST (missing_files_folder_list)
+{
+    const auto folders = lynx::parseFolderList ("C:\\A\r\n  C:\\B  \n\nc:\\a\nD:/x\n");
+    CHECK (folders.size() == 3 && folders[0] == "C:\\A" && folders[1] == "C:\\B" && folders[2] == "D:/x");
+    auto list = folders;
+    lynx::rememberFolder (list, "D:\\x");
+    CHECK (list.size() == 3 && list[0] == "D:\\x" && list[1] == "C:\\A");
+    lynx::rememberFolder (list, "E:\\new", 2);
+    CHECK (list.size() == 2 && list[0] == "E:\\new" && list[1] == "D:\\x");
+    CHECK (lynx::parseFolderList (lynx::folderListText (list)) == list);
+}
+
+TEST (missing_files_flp_report_and_relocation)
+{
+    // an .flp sampler whose sample is gone: listed with its channel; a relocation map makes the import use the copy
+    flp::Project project;
+    flp::Channel ch;
+    ch.index = 0;
+    ch.type = flp::ChannelType::sampler;
+    ch.name = "Snare";
+    ch.samplePath = "C:\\Producer\\Packs\\snare 7.wav";
+    project.channels.push_back (ch);
+
+    lynx::FlpImportOptions options;
+    options.fileExists = [] (const std::string& p) { return p == "/found/snare 7.wav"; };
+    lynx::FlpImportReport report;
+    options.report = &report;
+    auto song = lynx::importFlp (project, options);
+    CHECK (report.missingFiles.size() == 1);
+    CHECK (report.missingFiles.size() == 1 && report.missingFiles[0].path == "C:\\Producer\\Packs\\snare 7.wav" && report.missingFiles[0].usedBy[0] == "Snare");
+    CHECK (song.channels.size() == 1 && song.channels[0].samplePath.empty());
+
+    lynx::FlpImportReport again;
+    options.report = &again;
+    options.relocations = { { "C:\\Producer\\Packs\\snare 7.wav", "/found/snare 7.wav" } };
+    song = lynx::importFlp (project, options);
+    CHECK (again.missingFiles.empty());
+    CHECK (song.channels.size() == 1 && song.channels[0].samplePath == "/found/snare 7.wav" && song.channels[0].instrument == lynx::InstrumentKind::sampler);
+}