Browse Source

carla-lv2: First attempt at getting project dir from host

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 5 years ago
parent
commit
b088240281
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 72 additions and 5 deletions
  1. +65
    -4
      source/plugin/carla-lv2.cpp
  2. +7
    -1
      source/utils/CarlaLv2Utils.hpp

+ 65
- 4
source/plugin/carla-lv2.cpp View File

@@ -41,6 +41,8 @@


#include "water/files/File.h" #include "water/files/File.h"


static const char* const kPathForCarlaFiles = "carlafiles";

template<> template<>
void Lv2PluginBaseClass<NativeTimeInfo>::clearTimeData() noexcept void Lv2PluginBaseClass<NativeTimeInfo>::clearTimeData() noexcept
{ {
@@ -72,6 +74,7 @@ public:
#if defined(USING_JUCE) && (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)) #if defined(USING_JUCE) && (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
fJuceInitialiser(), fJuceInitialiser(),
#endif #endif
fLastProjectPath(nullptr),
fLoadedFile(), fLoadedFile(),
fWorkerUISignal(0) fWorkerUISignal(0)
{ {
@@ -104,6 +107,12 @@ public:
fHost.ui_open_file = host_ui_open_file; fHost.ui_open_file = host_ui_open_file;
fHost.ui_save_file = host_ui_save_file; fHost.ui_save_file = host_ui_save_file;
fHost.dispatcher = host_dispatcher; 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() ~NativePlugin()
@@ -121,6 +130,12 @@ public:
delete[] fHost.uiName; delete[] fHost.uiName;
fHost.uiName = nullptr; fHost.uiName = nullptr;
} }

if (fLastProjectPath != nullptr)
{
std::free(fLastProjectPath);
fLastProjectPath = nullptr;
}
} }


// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------
@@ -410,9 +425,45 @@ public:


// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------


void saveLastProjectPathIfPossible(const LV2_Feature* const* const features)
{
char* const last = fLastProjectPath;

if (fMakePath != nullptr && fMakePath->path != nullptr)
{
fLastProjectPath = fMakePath->path(fMakePath->handle, kPathForCarlaFiles);
}
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)
fLastProjectPath = makePath->path(makePath->handle, kPathForCarlaFiles);
else
fLastProjectPath = nullptr;
}
else
{
fLastProjectPath = nullptr;
}

std::free(last);
}

LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle, LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle,
const uint32_t /*flags*/, const LV2_Feature* const* const /*features*/) const
const uint32_t /*flags*/, const LV2_Feature* const* const features)
{ {
saveLastProjectPathIfPossible(features);

if (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE) if (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
{ {
store(handle, store(handle,
@@ -429,7 +480,8 @@ public:


if (char* const state = fDescriptor->get_state(fHandle)) if (char* const state = fDescriptor->get_state(fHandle))
{ {
store(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"), state, std::strlen(state)+1, fURIs.atomString, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE);
store(handle, fUridMap->map(fUridMap->handle, "http://kxstudio.sf.net/ns/carla/chunk"),
state, std::strlen(state)+1, fURIs.atomString, LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE);
std::free(state); std::free(state);
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;
} }
@@ -438,8 +490,10 @@ public:
} }


LV2_State_Status lv2_restore(const LV2_State_Retrieve_Function retrieve, const LV2_State_Handle handle, LV2_State_Status lv2_restore(const LV2_State_Retrieve_Function retrieve, const LV2_State_Handle handle,
uint32_t flags, const LV2_Feature* const* const /*features*/)
uint32_t flags, const LV2_Feature* const* const features)
{ {
saveLastProjectPathIfPossible(features);

size_t size = 0; size_t size = 0;
uint32_t type = 0; uint32_t type = 0;


@@ -804,10 +858,15 @@ protected:
case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN: case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN:
case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY: case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY:
case NATIVE_HOST_OPCODE_REQUEST_IDLE: case NATIVE_HOST_OPCODE_REQUEST_IDLE:
case NATIVE_HOST_OPCODE_GET_FILE_PATH:
// nothing // nothing
break; break;


case NATIVE_HOST_OPCODE_GET_FILE_PATH:
CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
if (fLastProjectPath != nullptr)
return static_cast<intptr_t>((uintptr_t)fLastProjectPath);
break;

case NATIVE_HOST_OPCODE_UI_UNAVAILABLE: case NATIVE_HOST_OPCODE_UI_UNAVAILABLE:
handleUiClosed(); handleUiClosed();
break; break;
@@ -868,7 +927,9 @@ private:
juce::SharedResourcePointer<juce::ScopedJuceInitialiser_GUI> fJuceInitialiser; juce::SharedResourcePointer<juce::ScopedJuceInitialiser_GUI> fJuceInitialiser;
#endif #endif


char* fLastProjectPath;
CarlaString fLoadedFile; CarlaString fLoadedFile;

int fWorkerUISignal; int fWorkerUISignal;


// ------------------------------------------------------------------- // -------------------------------------------------------------------


+ 7
- 1
source/utils/CarlaLv2Utils.hpp View File

@@ -570,6 +570,7 @@ public:
fUsingNominal(false), fUsingNominal(false),
fBufferSize(0), fBufferSize(0),
fSampleRate(sampleRate), fSampleRate(sampleRate),
fMakePath(nullptr),
fUridMap(nullptr), fUridMap(nullptr),
fUridUnmap(nullptr), fUridUnmap(nullptr),
fWorker(nullptr), fWorker(nullptr),
@@ -589,6 +590,7 @@ public:
return; return;
} }


const LV2_State_Make_Path* makePath = nullptr;
const LV2_Options_Option* options = nullptr; const LV2_Options_Option* options = nullptr;
const LV2_URID_Map* uridMap = nullptr; const LV2_URID_Map* uridMap = nullptr;
const LV2_URID_Unmap* uridUnmap = nullptr; const LV2_URID_Unmap* uridUnmap = nullptr;
@@ -596,7 +598,9 @@ public:


for (int i=0; features[i] != nullptr; ++i) for (int i=0; features[i] != nullptr; ++i)
{ {
/**/ if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0)
/**/ 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; options = (const LV2_Options_Option*)features[i]->data;
else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0) else if (std::strcmp(features[i]->URI, LV2_URID__map) == 0)
uridMap = (const LV2_URID_Map*)features[i]->data; uridMap = (const LV2_URID_Map*)features[i]->data;
@@ -663,6 +667,7 @@ public:
fUridMap = uridMap; fUridMap = uridMap;
fURIs.map(uridMap); fURIs.map(uridMap);


fMakePath = makePath;
fUridUnmap = uridUnmap; fUridUnmap = uridUnmap;
fWorker = worker; fWorker = worker;


@@ -1178,6 +1183,7 @@ protected:
double fSampleRate; double fSampleRate;


// LV2 host features // LV2 host features
const LV2_State_Make_Path* fMakePath;
const LV2_URID_Map* fUridMap; const LV2_URID_Map* fUridMap;
const LV2_URID_Unmap* fUridUnmap; const LV2_URID_Unmap* fUridUnmap;
const LV2_Worker_Schedule* fWorker; const LV2_Worker_Schedule* fWorker;


Loading…
Cancel
Save