Просмотр исходного кода

macOS/Linux: open FL-spelled paths through platform::localFile ('/' separators, case match); quiet sse2neon

Ka1-S 1 месяц назад
Родитель
Сommit
7db9636322
6 измененных файлов с 34 добавлено и 5 удалено
  1. 2 2
      src/Main.cpp
  2. 1 0
      src/core/Simd.h
  3. 3 2
      src/engine/AudioEngine.cpp
  4. 2 1
      src/engine/SampleLibrary.cpp
  5. 20 0
      src/platform/Paths.cpp
  6. 6 0
      src/platform/Paths.h

+ 2 - 2
src/Main.cpp

@@ -1855,10 +1855,10 @@ private:
                     project.channels.front().type = flp::ChannelType::native;
                     lynx::FlpImportOptions options;
                     options.roots = roots;
-                    options.fileExists = [] (const std::string& path) { return juce::File (juce::String::fromUTF8 (path.c_str())).existsAsFile(); };
+                    options.fileExists = [] (const std::string& path) { return lynx::platform::localFile (path).existsAsFile(); };
                     options.readFile = [] (const std::string& path) {
                         juce::MemoryBlock block;
-                        juce::File (juce::String::fromUTF8 (path.c_str())).loadFileAsData (block);
+                        lynx::platform::localFile (path).loadFileAsData (block);
                         const auto* b = static_cast<const std::uint8_t*> (block.getData());
                         return std::vector<std::uint8_t> (b, b + block.getSize());
                     };

+ 1 - 0
src/core/Simd.h

@@ -9,6 +9,7 @@
  #include <immintrin.h>
  #define LYNX_X86 1
 #elif defined(__aarch64__) || defined(_M_ARM64)
+ #define SSE2NEON_SUPPRESS_WARNINGS 1
  #define SSE2NEON_PRECISE_MINMAX 1
  #define SSE2NEON_PRECISE_DIV 1
  #define SSE2NEON_PRECISE_SQRT 1

+ 3 - 2
src/engine/AudioEngine.cpp

@@ -1,4 +1,5 @@
 #include "engine/AudioEngine.h"
+#include "platform/Paths.h"
 #include "engine/FlStudio.h"
 
 #include <map>
@@ -1183,10 +1184,10 @@ bool AudioEngine::importFlpFile (const juce::File& file, juce::String& error, co
         FlpImportOptions options;
         options.roots = findFlStudioRoots();
         options.projectFolder = file.getParentDirectory().getFullPathName().toStdString();
-        options.fileExists = [] (const std::string& path) { return juce::File (juce::String::fromUTF8 (path.c_str())).existsAsFile(); };
+        options.fileExists = [] (const std::string& path) { return platform::localFile (path).existsAsFile(); };
         options.readFile = [] (const std::string& path) {
             juce::MemoryBlock data;
-            juce::File (juce::String::fromUTF8 (path.c_str())).loadFileAsData (data);
+            platform::localFile (path).loadFileAsData (data);
             const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
             return std::vector<std::uint8_t> (bytes, bytes + data.getSize());
         };

+ 2 - 1
src/engine/SampleLibrary.cpp

@@ -1,4 +1,5 @@
 #include "engine/SampleLibrary.h"
+#include "platform/Paths.h"
 
 #include "core/OggVorbis.h"
 #include "core/TimeStretch.h"
@@ -326,7 +327,7 @@ std::shared_ptr<const SampleData> SampleLibrary::load (const juce::String& path)
     if (auto cached = cache[path].lock())
         return cached;
 
-    const juce::File file (path);
+    const auto file = platform::localFile (path); // FL's Windows spelling on macOS/Linux (platform/Paths.h)
 
     if (! file.existsAsFile())
         return nullptr;

+ 20 - 0
src/platform/Paths.cpp

@@ -1,5 +1,7 @@
 #include "platform/Paths.h"
 
+#include "core/FlpImport.h"
+
 namespace lynx::platform
 {
 namespace
@@ -82,4 +84,22 @@ juce::FileSearchPath standardPluginFolders()
     return paths;
 }
 
+juce::File localFile (const juce::String& path)
+{
+   #if JUCE_WINDOWS
+    return juce::File (path);
+   #else
+    if (! path.containsChar ('\\') && juce::File::isAbsolutePath (path) && juce::File (path).exists())
+        return juce::File (path);
+    const auto posix = path.replaceCharacter ('\\', '/');
+    if (! juce::File::isAbsolutePath (posix))
+        return {};
+    return juce::File (juce::String::fromUTF8 (existingPathIgnoringCase (posix.toStdString()).c_str()));
+   #endif
+}
+
+juce::File localFile (const std::string& utf8Path)
+{
+    return localFile (juce::String::fromUTF8 (utf8Path.c_str()));
+}
 } // namespace lynx::platform

+ 6 - 0
src/platform/Paths.h

@@ -25,4 +25,10 @@ juce::File cacheFolder (const juce::String& name);
 // The standard plugin folders of this OS, in scan order (they need not exist yet: plugins installed later land
 // there): VST3, VST2, CLAP (+ AU components on macOS, LV2 on Linux) and LYNX's own Plugins folder.
 juce::FileSearchPath standardPluginFolders();
+
+// A file named by a path stored in a project or written by the FL import: on Windows as it is; on macOS/Linux FL's
+// backslashes become '/' and, when the exact spelling does not exist, the letter case is matched against the disk
+// (FL Studio's data was written for a case-insensitive file system).
+juce::File localFile (const juce::String& path);
+juce::File localFile (const std::string& utf8Path);
 } // namespace lynx::platform