diff --git a/source/plugin/carla-lv2.cpp b/source/plugin/carla-lv2.cpp index 5039da81b..53a77b548 100644 --- a/source/plugin/carla-lv2.cpp +++ b/source/plugin/carla-lv2.cpp @@ -74,7 +74,7 @@ public: #if defined(USING_JUCE) && (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)) fJuceInitialiser(), #endif - fLastProjectPath(nullptr), + fLastProjectPath(), fLoadedFile(), fWorkerUISignal(0) { @@ -107,12 +107,6 @@ public: fHost.ui_open_file = host_ui_open_file; fHost.ui_save_file = host_ui_save_file; fHost.dispatcher = host_dispatcher; - -#if 0 - // NOTE: a few hosts crash with this :( - if (fMakePath != nullptr && fMakePath->path != nullptr) - fLastProjectPath = fMakePath->path(fMakePath->handle, kPathForCarlaFiles); -#endif } ~NativePlugin() @@ -130,18 +124,6 @@ public: delete[] fHost.uiName; fHost.uiName = nullptr; } - - if (fLastProjectPath != nullptr) - { - if (fFreePath != nullptr && fFreePath->free_path != nullptr) - fFreePath->free_path(fFreePath->handle, fLastProjectPath); -#ifndef CARLA_OS_WIN - // this is not safe to call under windows - else - std::free(fLastProjectPath); -#endif - fLastProjectPath = nullptr; - } } // ---------------------------------------------------------------------------------------------------------------- @@ -431,43 +413,46 @@ public: // ---------------------------------------------------------------------------------------------------------------- + void cleanupLastProjectPath() + { + fLastProjectPath.clear(); + } + void saveLastProjectPathIfPossible(const LV2_Feature* const* const features) { - char* const last = fLastProjectPath; + if (features == nullptr) + return cleanupLastProjectPath(); + + const LV2_State_Free_Path* freePath = nullptr; + const LV2_State_Make_Path* makePath = nullptr; - if (fMakePath != nullptr && fMakePath->path != nullptr) + for (int i=0; features[i] != nullptr; ++i) { - fLastProjectPath = fMakePath->path(fMakePath->handle, kPathForCarlaFiles); + /**/ if (freePath == nullptr && std::strcmp(features[i]->URI, LV2_STATE__freePath) == 0) + freePath = (const LV2_State_Free_Path*)features[i]->data; + else if (makePath == nullptr && std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0) + makePath = (const LV2_State_Make_Path*)features[i]->data; } - else if (features != nullptr) - { - const LV2_State_Make_Path* makePath = nullptr; - for (int i=0; features[i] != nullptr; ++i) - { - if (std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0) - { - makePath = (const LV2_State_Make_Path*)features[i]->data; - break; - } - } + if (makePath == nullptr || makePath->path == nullptr) + return cleanupLastProjectPath(); - if (makePath != nullptr && makePath->path != nullptr) - fLastProjectPath = makePath->path(makePath->handle, kPathForCarlaFiles); - else - fLastProjectPath = nullptr; - } - else - { - fLastProjectPath = nullptr; - } + if (freePath == nullptr) + freePath = fFreePath; + + char* const newpath = makePath->path(makePath->handle, kPathForCarlaFiles); + + if (newpath == nullptr) + return cleanupLastProjectPath(); + + fLastProjectPath = CarlaString(water::File(newpath).getParentDirectory().getFullPathName().toRawUTF8()); - if (fFreePath != nullptr && fFreePath->free_path != nullptr) - fFreePath->free_path(fFreePath->handle, last); + if (freePath != nullptr && freePath->free_path != nullptr) + freePath->free_path(freePath->handle, newpath); #ifndef CARLA_OS_WIN // this is not safe to call under windows else - std::free(last); + std::free(newpath); #endif } @@ -875,8 +860,8 @@ protected: case NATIVE_HOST_OPCODE_GET_FILE_PATH: CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0); - if (fLastProjectPath != nullptr) - return static_cast((uintptr_t)fLastProjectPath); + if (std::strcmp((char*)ptr, "carla") == 0 && fLastProjectPath != nullptr) + return static_cast((uintptr_t)fLastProjectPath.buffer()); break; case NATIVE_HOST_OPCODE_UI_UNAVAILABLE: @@ -939,7 +924,7 @@ private: juce::SharedResourcePointer fJuceInitialiser; #endif - char* fLastProjectPath; + CarlaString fLastProjectPath; CarlaString fLoadedFile; int fWorkerUISignal; diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index c39d88a2f..0e9604461 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -571,7 +571,6 @@ public: fBufferSize(0), fSampleRate(sampleRate), fFreePath(nullptr), - fMakePath(nullptr), fUridMap(nullptr), fUridUnmap(nullptr), fWorker(nullptr), @@ -592,7 +591,6 @@ public: } const LV2_State_Free_Path* freePath = nullptr; - const LV2_State_Make_Path* makePath = nullptr; const LV2_Options_Option* options = nullptr; const LV2_URID_Map* uridMap = nullptr; const LV2_URID_Unmap* uridUnmap = nullptr; @@ -602,8 +600,6 @@ public: { /**/ if (std::strcmp(features[i]->URI, LV2_STATE__freePath) == 0) freePath = (const LV2_State_Free_Path*)features[i]->data; - else if (std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0) - makePath = (const LV2_State_Make_Path*)features[i]->data; else if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0) options = (const LV2_Options_Option*)features[i]->data; else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0) @@ -672,7 +668,6 @@ public: fURIs.map(uridMap); fFreePath = freePath; - fMakePath = makePath; fUridUnmap = uridUnmap; fWorker = worker; @@ -1189,7 +1184,6 @@ protected: // LV2 host features const LV2_State_Free_Path* fFreePath; - const LV2_State_Make_Path* fMakePath; const LV2_URID_Map* fUridMap; const LV2_URID_Unmap* fUridUnmap; const LV2_Worker_Schedule* fWorker;