mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
LV2 Client: Use unicode consistently for filepaths on Windows
This commit is contained in:
parent
1fcaf709ca
commit
ba604f4ced
3 changed files with 97 additions and 8 deletions
|
|
@ -843,7 +843,7 @@ function(_juce_add_lv2_manifest_helper_target)
|
||||||
set(source "${module_path}/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp")
|
set(source "${module_path}/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp")
|
||||||
add_executable(juce_lv2_helper "${source}")
|
add_executable(juce_lv2_helper "${source}")
|
||||||
add_executable(juce::juce_lv2_helper ALIAS juce_lv2_helper)
|
add_executable(juce::juce_lv2_helper ALIAS juce_lv2_helper)
|
||||||
target_compile_features(juce_lv2_helper PRIVATE cxx_std_14)
|
target_compile_features(juce_lv2_helper PRIVATE cxx_std_17)
|
||||||
set_target_properties(juce_lv2_helper PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
|
set_target_properties(juce_lv2_helper PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
|
||||||
target_link_libraries(juce_lv2_helper PRIVATE ${CMAKE_DL_LIBS})
|
target_link_libraries(juce_lv2_helper PRIVATE ${CMAKE_DL_LIBS})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,19 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#undef UNICODE
|
||||||
|
#undef _UNICODE
|
||||||
|
|
||||||
|
#define UNICODE 1
|
||||||
|
#define _UNICODE 1
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
HMODULE dlopen (const char* filename, int) { return LoadLibrary (filename); }
|
HMODULE dlopen (const TCHAR* filename, int) { return LoadLibrary (filename); }
|
||||||
FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); }
|
FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); }
|
||||||
void printError()
|
void printError()
|
||||||
{
|
{
|
||||||
|
|
@ -44,12 +52,61 @@
|
||||||
numElements - 1,
|
numElements - 1,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
_tprintf ("%s", messageBuffer);
|
_tprintf (_T ("%s"), messageBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { RTLD_LAZY = 0 };
|
enum { RTLD_LAZY = 0 };
|
||||||
|
|
||||||
|
class ArgList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ArgList (int, const char**) {}
|
||||||
|
ArgList (const ArgList&) = delete;
|
||||||
|
ArgList (ArgList&&) = delete;
|
||||||
|
ArgList& operator= (const ArgList&) = delete;
|
||||||
|
ArgList& operator= (ArgList&&) = delete;
|
||||||
|
~ArgList() { LocalFree (argv); }
|
||||||
|
|
||||||
|
LPWSTR get (int i) const { return argv[i]; }
|
||||||
|
|
||||||
|
int size() const { return argc; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int argc = 0;
|
||||||
|
LPWSTR* argv = CommandLineToArgvW (GetCommandLineW(), &argc);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<char> toUTF8 (const TCHAR* str)
|
||||||
|
{
|
||||||
|
const auto numBytes = WideCharToMultiByte (CP_UTF8, 0, str, -1, nullptr, 0, nullptr, nullptr);
|
||||||
|
std::vector<char> result (numBytes);
|
||||||
|
WideCharToMultiByte (CP_UTF8, 0, str, -1, result.data(), static_cast<int> (result.size()), nullptr, nullptr);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
void printError() { printf ("%s\n", dlerror()); }
|
void printError() { printf ("%s\n", dlerror()); }
|
||||||
|
class ArgList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ArgList (int argcIn, const char** argvIn) : argc (argcIn), argv (argvIn) {}
|
||||||
|
ArgList (const ArgList&) = delete;
|
||||||
|
ArgList (ArgList&&) = delete;
|
||||||
|
ArgList& operator= (const ArgList&) = delete;
|
||||||
|
ArgList& operator= (ArgList&&) = delete;
|
||||||
|
~ArgList() = default;
|
||||||
|
|
||||||
|
const char* get (int i) const { return argv[i]; }
|
||||||
|
|
||||||
|
int size() const { return argc; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int argc = 0;
|
||||||
|
const char** argv = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<char> toUTF8 (const char* str) { return std::vector<char> (str, str + std::strlen (str) + 1); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Replicating part of the LV2 header here so that we don't have to set up any
|
// Replicating part of the LV2 header here so that we don't have to set up any
|
||||||
|
|
@ -74,10 +131,12 @@ extern "C"
|
||||||
|
|
||||||
int main (int argc, const char** argv)
|
int main (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
const ArgList argList { argc, argv };
|
||||||
|
|
||||||
|
if (argList.size() != 2)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
const auto* libraryPath = argv[1];
|
const auto* libraryPath = argList.get (1);
|
||||||
|
|
||||||
struct RecallFeature
|
struct RecallFeature
|
||||||
{
|
{
|
||||||
|
|
@ -87,11 +146,22 @@ int main (int argc, const char** argv)
|
||||||
if (auto* handle = dlopen (libraryPath, RTLD_LAZY))
|
if (auto* handle = dlopen (libraryPath, RTLD_LAZY))
|
||||||
{
|
{
|
||||||
if (auto* getDescriptor = reinterpret_cast<const LV2_Descriptor* (*) (uint32_t)> (dlsym (handle, "lv2_descriptor")))
|
if (auto* getDescriptor = reinterpret_cast<const LV2_Descriptor* (*) (uint32_t)> (dlsym (handle, "lv2_descriptor")))
|
||||||
|
{
|
||||||
if (auto* descriptor = getDescriptor (0))
|
if (auto* descriptor = getDescriptor (0))
|
||||||
|
{
|
||||||
if (auto* extensionData = descriptor->extension_data)
|
if (auto* extensionData = descriptor->extension_data)
|
||||||
|
{
|
||||||
if (auto* recallFeature = reinterpret_cast<const RecallFeature*> (extensionData ("https://lv2-extensions.juce.com/turtle_recall")))
|
if (auto* recallFeature = reinterpret_cast<const RecallFeature*> (extensionData ("https://lv2-extensions.juce.com/turtle_recall")))
|
||||||
|
{
|
||||||
if (auto* doRecall = recallFeature->doRecall)
|
if (auto* doRecall = recallFeature->doRecall)
|
||||||
return doRecall (libraryPath);
|
{
|
||||||
|
const auto converted = toUTF8 (libraryPath);
|
||||||
|
return doRecall (converted.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -840,15 +840,28 @@ private:
|
||||||
return JucePlugin_LV2URI + String (uriSeparator) + "preset" + String (index + 1);
|
return JucePlugin_LV2URI + String (uriSeparator) + "preset" + String (index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::ofstream openStream (const File& libraryPath, StringRef name)
|
static FileOutputStream openStream (const File& libraryPath, StringRef name)
|
||||||
{
|
{
|
||||||
return std::ofstream { libraryPath.getSiblingFile (name + ".ttl").getFullPathName().toRawUTF8() };
|
return FileOutputStream { libraryPath.getSiblingFile (name + ".ttl") };
|
||||||
|
}
|
||||||
|
|
||||||
|
static Result prepareStream (FileOutputStream& stream)
|
||||||
|
{
|
||||||
|
if (const auto result = stream.getStatus(); ! result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
stream.setPosition (0);
|
||||||
|
stream.truncate();
|
||||||
|
return Result::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result writeManifestTtl (AudioProcessor& proc, const File& libraryPath)
|
static Result writeManifestTtl (AudioProcessor& proc, const File& libraryPath)
|
||||||
{
|
{
|
||||||
auto os = openStream (libraryPath, "manifest");
|
auto os = openStream (libraryPath, "manifest");
|
||||||
|
|
||||||
|
if (const auto result = prepareStream (os); ! result)
|
||||||
|
return result;
|
||||||
|
|
||||||
os << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n"
|
os << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n"
|
||||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
|
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
|
||||||
"@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n"
|
"@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n"
|
||||||
|
|
@ -980,6 +993,9 @@ private:
|
||||||
{
|
{
|
||||||
auto os = openStream (libraryPath, "dsp");
|
auto os = openStream (libraryPath, "dsp");
|
||||||
|
|
||||||
|
if (const auto result = prepareStream (os); ! result)
|
||||||
|
return result;
|
||||||
|
|
||||||
os << "@prefix atom: <http://lv2plug.in/ns/ext/atom#> .\n"
|
os << "@prefix atom: <http://lv2plug.in/ns/ext/atom#> .\n"
|
||||||
"@prefix bufs: <http://lv2plug.in/ns/ext/buf-size#> .\n"
|
"@prefix bufs: <http://lv2plug.in/ns/ext/buf-size#> .\n"
|
||||||
"@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
|
"@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
|
||||||
|
|
@ -1317,6 +1333,9 @@ private:
|
||||||
|
|
||||||
auto os = openStream (libraryPath, "ui");
|
auto os = openStream (libraryPath, "ui");
|
||||||
|
|
||||||
|
if (const auto result = prepareStream (os); ! result)
|
||||||
|
return result;
|
||||||
|
|
||||||
const auto editorInstance = rawToUniquePtr (proc.createEditor());
|
const auto editorInstance = rawToUniquePtr (proc.createEditor());
|
||||||
const auto resizeFeatureString = editorInstance->isResizable() ? "ui:resize" : "ui:noUserResize";
|
const auto resizeFeatureString = editorInstance->isResizable() ? "ui:resize" : "ui:noUserResize";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue