diff --git a/currentGitHash.txt b/currentGitHash.txt index 62b2c6bf5d..0f16438e00 100644 --- a/currentGitHash.txt +++ b/currentGitHash.txt @@ -1 +1 @@ -bab0acff62b8f04252bb4d4cffb7999f51a537cc +056ee73fdda33d666989491af04ab1694247287f diff --git a/hi_backend/backend/currentGit.h b/hi_backend/backend/currentGit.h index 3db7f41ee9..e32e2fc3cf 100644 --- a/hi_backend/backend/currentGit.h +++ b/hi_backend/backend/currentGit.h @@ -1 +1 @@ -#define PREVIOUS_HISE_COMMIT "bab0acff62b8f04252bb4d4cffb7999f51a537cc" +#define PREVIOUS_HISE_COMMIT "056ee73fdda33d666989491af04ab1694247287f" diff --git a/hi_core/hi_core/MainController.cpp b/hi_core/hi_core/MainController.cpp index d38e6d7e4e..9cc1dcf5fc 100644 --- a/hi_core/hi_core/MainController.cpp +++ b/hi_core/hi_core/MainController.cpp @@ -728,18 +728,13 @@ bool MainController::shouldUseSoftBypassRamps() const noexcept ONNXLoader::Ptr MainController::getONNXLoader() { - if(onnxLoader == nullptr) - { -#if USE_BACKEND || 1 - File libraryPath(GET_HISE_SETTING(getMainSynthChain(), HiseSettings::Compiler::HisePath).toString()); - libraryPath = libraryPath.getChildFile("tools/onnx_lib"); +#if USE_BACKEND + File libraryPath(GET_HISE_SETTING(getMainSynthChain(), HiseSettings::Compiler::HisePath).toString()); + libraryPath = libraryPath.getChildFile("tools/onnx_lib"); #else - auto libraryPath = FrontendHandler::getAppDataDirectory(this); + auto libraryPath = FrontendHandler::getAppDataDirectory(this); #endif - onnxLoader = new ONNXLoader(libraryPath.getFullPathName()); - } - - return onnxLoader; + return new ONNXLoader(libraryPath.getFullPathName()); } MarkdownContentProcessor* MainController::getCurrentMarkdownPreview() diff --git a/hi_tools/hi_neural/onnx_loader.cpp b/hi_tools/hi_neural/onnx_loader.cpp index 2c48bdd648..ff075c1506 100644 --- a/hi_tools/hi_neural/onnx_loader.cpp +++ b/hi_tools/hi_neural/onnx_loader.cpp @@ -36,55 +36,12 @@ using namespace juce; ONNXLoader::ONNXLoader(const String& rootDir): ok(Result::fail("dll could not open")) { - if(File::isAbsolutePath(rootDir) && File(rootDir).isDirectory()) - { - auto dllFile = File(rootDir); - -#if JUCE_DEBUG -#if JUCE_WINDOWS - dllFile = dllFile.getChildFile("Builds/VisualStudio2022/x64/Debug/Dynamic Library"); -#else - dllFile = dllFile.getChildFile("Builds/MacOSX/build/Debug"); -#endif -#endif - -#if JUCE_WINDOWS - dllFile = dllFile.getChildFile("onnx_hise_library.dll"); -#elif JUCE_MAC - dllFile = dllFile.getChildFile("onnx_hise_library.dylib"); -#elif JUCE_LINUX - // DAVID!!!! - jassertfalse; -#endif - - if(!dllFile.existsAsFile()) - { - ok = Result::fail("Missing dynamic library " + dllFile.getFullPathName()); - } - else - { - dll = new DynamicLibrary(); - - if(dll->open(dllFile.getFullPathName())) - ok = Result::ok(); - else - dll = nullptr; - } - } + ok = data->initialise(rootDir); } ONNXLoader::~ONNXLoader() { - if(currentModel != nullptr) - { - jassert(dll != nullptr); - - if(auto f = getFunction("destroyModel")) - f(currentModel); - - currentModel = nullptr; - dll = nullptr; - } + unloadModel(); } bool ONNXLoader::run(const Image& img, std::vector& outputValues, bool isGreyscale) @@ -127,7 +84,9 @@ bool ONNXLoader::run(const Image& img, std::vector& outputValues, bool is Result ONNXLoader::loadModel(const MemoryBlock& mb) { - if(dll != nullptr) + unloadModel(); + + if(data->dll != nullptr) { if(auto f = getFunction("loadModel")) { @@ -149,6 +108,20 @@ Result ONNXLoader::getLastError() const return ok; } +void ONNXLoader::unloadModel() +{ + if(currentModel != nullptr) + { + jassert(data->dll != nullptr); + + if(auto f = getFunction("destroyModel")) + f(currentModel); + + currentModel = nullptr; + + } +} + void ONNXLoader::setLastError() { if(auto f = getFunction("getError")) @@ -165,4 +138,56 @@ void ONNXLoader::setLastError() } } +ONNXLoader::SharedData::SharedData(): + ok(Result::ok()) +{} + +ONNXLoader::SharedData::~SharedData() +{ + dll = nullptr; +} + +Result ONNXLoader::SharedData::initialise(const String& rootDir) +{ + if(dll != nullptr) + return ok; + + if(File::isAbsolutePath(rootDir) && File(rootDir).isDirectory()) + { + auto dllFile = File(rootDir); + +#if JUCE_DEBUG +#if JUCE_WINDOWS + dllFile = dllFile.getChildFile("Builds/VisualStudio2022/x64/Debug/Dynamic Library"); +#else + dllFile = dllFile.getChildFile("Builds/MacOSX/build/Debug"); +#endif +#endif + +#if JUCE_WINDOWS + dllFile = dllFile.getChildFile("onnx_hise_library.dll"); +#elif JUCE_MAC + dllFile = dllFile.getChildFile("onnx_hise_library.dylib"); +#elif JUCE_LINUX + // DAVID!!!! + jassertfalse; +#endif + + if(!dllFile.existsAsFile()) + { + ok = Result::fail("Missing dynamic library " + dllFile.getFullPathName()); + } + else + { + dll = new DynamicLibrary(); + + if(dll->open(dllFile.getFullPathName())) + ok = Result::ok(); + else + dll = nullptr; + } + } + + return ok; +} } // namespace hise \ No newline at end of file diff --git a/hi_tools/hi_neural/onnx_loader.h b/hi_tools/hi_neural/onnx_loader.h index 2db12718bd..60c8865fd0 100644 --- a/hi_tools/hi_neural/onnx_loader.h +++ b/hi_tools/hi_neural/onnx_loader.h @@ -60,12 +60,14 @@ class ONNXLoader: public ReferenceCountedObject private: + void unloadModel(); + void setLastError(); template Func getFunction(const String& name) { - if(auto f = reinterpret_cast(dll->getFunction(name))) + if(auto f = reinterpret_cast(data->dll->getFunction(name))) return f; else { @@ -74,7 +76,20 @@ class ONNXLoader: public ReferenceCountedObject } } - ScopedPointer dll{}; + struct SharedData + { + SharedData(); + + ~SharedData(); + + Result initialise(const String& rootDir); + + Result ok; + ScopedPointer dll; + }; + + SharedResourcePointer data; + Result ok; void* currentModel = nullptr;