From cc78d0d7915135ff010d95a381a728aec97a0632 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Tue, 6 May 2025 11:52:11 -0700 Subject: [PATCH] Fixes for OpenFX plugin search paths Signed-off-by: Darby Johnston --- bin/toucan-filmstrip/App.cpp | 9 +------ bin/toucan-render/App.cpp | 9 +------ lib/toucanRender/Plugin.cpp | 3 +-- lib/toucanRender/Util.cpp | 48 ++++++++++++++++++++++++++++++++++++ lib/toucanRender/Util.h | 6 +++++ lib/toucanView/App.cpp | 12 +++------ tests/toucan-test/main.cpp | 12 +++------ 7 files changed, 63 insertions(+), 36 deletions(-) diff --git a/bin/toucan-filmstrip/App.cpp b/bin/toucan-filmstrip/App.cpp index db52a51..4778700 100644 --- a/bin/toucan-filmstrip/App.cpp +++ b/bin/toucan-filmstrip/App.cpp @@ -86,14 +86,7 @@ namespace toucan const IMATH_NAMESPACE::V2d imageSize = _graph->getImageSize(); // Create the image host. - std::vector searchPath; - searchPath.push_back(parentPath); -#if defined(_WINDOWS) - searchPath.push_back(parentPath / ".." / ".." / ".."); -#else // _WINDOWS - searchPath.push_back(parentPath / ".." / ".."); -#endif // _WINDOWS - _host = std::make_shared(_context, searchPath); + _host = std::make_shared(_context, getOpenFXPluginPaths(getExeName())); // Initialize the filmstrip. OIIO::ImageBuf filmstripBuf; diff --git a/bin/toucan-render/App.cpp b/bin/toucan-render/App.cpp index e51c7dd..49558c1 100644 --- a/bin/toucan-render/App.cpp +++ b/bin/toucan-render/App.cpp @@ -199,14 +199,7 @@ namespace toucan } // Create the image host. - std::vector searchPath; - searchPath.push_back(parentPath); -#if defined(_WINDOWS) - searchPath.push_back(parentPath / ".." / ".." / ".."); -#else // _WINDOWS - searchPath.push_back(parentPath / ".." / ".."); -#endif // _WINDOWS - _host = std::make_shared(_context, searchPath); + _host = std::make_shared(_context, getOpenFXPluginPaths(getExeName())); // Open the movie file. std::shared_ptr ffWrite; diff --git a/lib/toucanRender/Plugin.cpp b/lib/toucanRender/Plugin.cpp index 86bde8f..0c39b64 100644 --- a/lib/toucanRender/Plugin.cpp +++ b/lib/toucanRender/Plugin.cpp @@ -49,7 +49,6 @@ namespace toucan const std::filesystem::path& path, std::vector& out) { - _findPlugins(path, out, 0, 2); + _findPlugins(path, out, 0, 10); } - } diff --git a/lib/toucanRender/Util.cpp b/lib/toucanRender/Util.cpp index 6aca87e..f3c4df0 100644 --- a/lib/toucanRender/Util.cpp +++ b/lib/toucanRender/Util.cpp @@ -185,4 +185,52 @@ namespace toucan out.w = std::any_cast(any[3]); } } + + std::vector getOpenFXPluginPaths( + const std::filesystem::path& executablePath) + { + const std::filesystem::path parentPath = executablePath.parent_path(); + std::vector searchPath; + + // Add executable directory and relative paths + searchPath.push_back(parentPath); +#if defined(_WINDOWS) + searchPath.push_back(parentPath / ".." / ".." / ".."); + // Add standard Windows OpenFX plugin path + searchPath.push_back("C:\\Program Files\\Common Files\\OFX\\Plugins"); +#else // _WINDOWS + searchPath.push_back(parentPath / ".." / ".."); +#if defined(__APPLE__) + // Add standard macOS OpenFX plugin path + searchPath.push_back("/Library/OFX/Plugins"); +#else + // Add standard Linux/Unix OpenFX plugin path + searchPath.push_back("/usr/OFX/Plugins"); +#endif // __APPLE__ +#endif // _WINDOWS + + // Add paths from environment variable OFX_PLUGIN_PATH if it exists + if (const char* envPath = std::getenv("OFX_PLUGIN_PATH")) { +#if defined(_WINDOWS) + const char delimiter = ';'; +#else + const char delimiter = ':'; +#endif + std::string envPathStr(envPath); + size_t pos = 0; + std::string token; + while ((pos = envPathStr.find(delimiter)) != std::string::npos) { + token = envPathStr.substr(0, pos); + if (!token.empty()) { + searchPath.push_back(token); + } + envPathStr.erase(0, pos + 1); + } + if (!envPathStr.empty()) { + searchPath.push_back(envPathStr); + } + } + + return searchPath; + } } diff --git a/lib/toucanRender/Util.h b/lib/toucanRender/Util.h index a7aae46..e32c160 100644 --- a/lib/toucanRender/Util.h +++ b/lib/toucanRender/Util.h @@ -48,4 +48,10 @@ namespace toucan //! Conversion from any vector. void anyToVec(const OTIO_NS::AnyVector&, IMATH_NAMESPACE::V2i&); void anyToVec(const OTIO_NS::AnyVector&, IMATH_NAMESPACE::V4f&); + + //! Get standard OpenFX plugin search paths. + //! Includes executable directory, standard OS-specific plugin directories, + //! and paths from the OFX_PLUGIN_PATH environment variable. + std::vector getOpenFXPluginPaths( + const std::filesystem::path& executablePath); } diff --git a/lib/toucanView/App.cpp b/lib/toucanView/App.cpp index 03223f4..6ed73f4 100644 --- a/lib/toucanView/App.cpp +++ b/lib/toucanView/App.cpp @@ -9,6 +9,8 @@ #include "ViewModel.h" #include "WindowModel.h" +#include + #include #include #include @@ -41,15 +43,7 @@ namespace toucan _timeUnitsModel = std::make_shared(context); - std::vector searchPath; - const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path(); - searchPath.push_back(parentPath); -#if defined(_WINDOWS) - searchPath.push_back(parentPath / ".." / ".." / ".."); -#else // _WINDOWS - searchPath.push_back(parentPath / ".." / ".."); -#endif // _WINDOWS - _host = std::make_shared(context, searchPath); + _host = std::make_shared(context, getOpenFXPluginPaths(getExeName())); auto fileBrowserSystem = context->getSystem(); fileBrowserSystem->setNativeFileDialog(false); diff --git a/tests/toucan-test/main.cpp b/tests/toucan-test/main.cpp index 4516575..93b73e9 100644 --- a/tests/toucan-test/main.cpp +++ b/tests/toucan-test/main.cpp @@ -14,6 +14,8 @@ #include #include +#include + #if defined(toucan_VIEW) #include #endif // toucan_VIEW @@ -31,7 +33,6 @@ int main(int argc, char** argv) std::cout << "Usage: toucan-test (path to test data)" << std::endl; return 1; } - const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path(); const std::filesystem::path path(argv[1]); auto context = dtk::Context::create(); @@ -40,14 +41,7 @@ int main(int argc, char** argv) dtk::uiInit(context); #endif // toucan_VIEW - std::vector searchPath; - searchPath.push_back(parentPath); -#if defined(_WINDOWS) - searchPath.push_back(parentPath / ".." / ".." / ".."); -#else // _WINDOWS - searchPath.push_back(parentPath / ".." / ".."); -#endif // _WINDOWS - auto host = std::make_shared(context, searchPath); + auto host = std::make_shared(context, getOpenFXPluginPaths(argv[0])); compTest(path); propertySetTest();