Browse Source

Implement export of LV2 presets; Put UI in a separate ttl

pull/6/head
falkTX 8 years ago
parent
commit
2f3950d633
1 changed files with 184 additions and 24 deletions
  1. +184
    -24
      distrho/src/DistrhoPluginLV2export.cpp

+ 184
- 24
distrho/src/DistrhoPluginLV2export.cpp View File

@@ -23,6 +23,7 @@
#include "lv2/midi.h"
#include "lv2/options.h"
#include "lv2/port-props.h"
#include "lv2/presets.h"
#include "lv2/resize-port.h"
#include "lv2/state.h"
#include "lv2/time.h"
@@ -49,6 +50,18 @@
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#if DISTRHO_PLUGIN_HAS_UI
# if DISTRHO_OS_HAIKU
# define DISTRHO_LV2_UI_TYPE "BeUI"
# elif DISTRHO_OS_MAC
# define DISTRHO_LV2_UI_TYPE "CocoaUI"
# elif DISTRHO_OS_WINDOWS
# define DISTRHO_LV2_UI_TYPE "WindowsUI"
# else
# define DISTRHO_LV2_UI_TYPE "X11UI"
# endif
#endif

#define DISTRHO_LV2_USE_EVENTS_IN (DISTRHO_PLUGIN_WANT_MIDI_INPUT || DISTRHO_PLUGIN_WANT_TIMEPOS || (DISTRHO_PLUGIN_WANT_STATE && DISTRHO_PLUGIN_HAS_UI))
#define DISTRHO_LV2_USE_EVENTS_OUT (DISTRHO_PLUGIN_WANT_MIDI_OUTPUT || (DISTRHO_PLUGIN_WANT_STATE && DISTRHO_PLUGIN_HAS_UI))

@@ -69,6 +82,15 @@ void lv2_generate_ttl(const char* const basename)
String pluginDLL(basename);
String pluginTTL(pluginDLL + ".ttl");

#if DISTRHO_PLUGIN_HAS_UI
String pluginUI(pluginDLL);
# if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
pluginUI.truncate(pluginDLL.rfind("_dsp"));
pluginUI += "_ui";
const String uiTTL(pluginUI + ".ttl");
# endif
#endif

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

{
@@ -78,6 +100,9 @@ void lv2_generate_ttl(const char* const basename)
String manifestString;
manifestString += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
manifestString += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
#if DISTRHO_PLUGIN_WANT_PROGRAMS
manifestString += "@prefix pset: <" LV2_PRESETS_PREFIX "> .\n";
#endif
#if DISTRHO_PLUGIN_HAS_UI
manifestString += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
#endif
@@ -91,45 +116,49 @@ void lv2_generate_ttl(const char* const basename)

#if DISTRHO_PLUGIN_HAS_UI
manifestString += "<" DISTRHO_UI_URI ">\n";
# if DISTRHO_OS_HAIKU
manifestString += " a ui:BeUI ;\n";
# elif DISTRHO_OS_MAC
manifestString += " a ui:CocoaUI ;\n";
# elif DISTRHO_OS_WINDOWS
manifestString += " a ui:WindowsUI ;\n";
# else
manifestString += " a ui:X11UI ;\n";
# endif
# if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
String pluginUI(pluginDLL);
pluginUI.truncate(pluginDLL.rfind("_dsp"));
pluginUI += "_ui";

manifestString += " a ui:" DISTRHO_LV2_UI_TYPE " ;\n";
manifestString += " ui:binary <" + pluginUI + "." DISTRHO_DLL_EXTENSION "> ;\n";
# else
manifestString += " ui:binary <" + pluginDLL + "." DISTRHO_DLL_EXTENSION "> ;\n";
#endif
# if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
manifestString += "\n";
manifestString += " lv2:extensionData ui:idleInterface ,\n";
# if DISTRHO_PLUGIN_WANT_PROGRAMS
# if DISTRHO_PLUGIN_WANT_PROGRAMS
manifestString += " ui:showInterface ,\n";
manifestString += " <" LV2_PROGRAMS__Interface "> ;\n";
# else
# else
manifestString += " ui:showInterface ;\n";
# endif
# endif
manifestString += "\n";
manifestString += " lv2:optionalFeature ui:noUserResize ,\n";
manifestString += " ui:resize ,\n";
manifestString += " ui:touch ;\n";
manifestString += "\n";
# if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
manifestString += " lv2:requiredFeature <" LV2_DATA_ACCESS_URI "> ,\n";
manifestString += " <" LV2_INSTANCE_ACCESS_URI "> ,\n";
manifestString += " <" LV2_OPTIONS__options "> ,\n";
manifestString += " <" LV2_URID__map "> .\n";
# else
manifestString += " lv2:requiredFeature <" LV2_OPTIONS__options "> ,\n";
manifestString += " rdfs:seeAlso <" + uiTTL + "> .\n";
# endif
manifestString += " <" LV2_URID__map "> .\n";
manifestString += "\n";
#endif

#if DISTRHO_PLUGIN_WANT_PROGRAMS
const String presetSeparator(std::strstr(DISTRHO_PLUGIN_URI, "#") != nullptr ? ":" : "#");

char strBuf[0xff+1];
strBuf[0xff] = '\0';

// Presets
for (uint32_t i = 0; i < plugin.getProgramCount(); ++i)
{
std::snprintf(strBuf, 0xff, "%03i", i+1);

manifestString += "<" DISTRHO_PLUGIN_URI + presetSeparator + "preset" + strBuf + ">\n";
manifestString += " a pset:Preset ;\n";
manifestString += " lv2:appliesTo <" DISTRHO_PLUGIN_URI "> ;\n";
manifestString += " rdfs:seeAlso <presets.ttl> .\n";
manifestString += "\n";
}
#endif

manifestFile << manifestString << std::endl;
@@ -161,7 +190,9 @@ void lv2_generate_ttl(const char* const basename)

// plugin
pluginString += "<" DISTRHO_PLUGIN_URI ">\n";
#if DISTRHO_PLUGIN_IS_SYNTH
#ifdef DISTRHO_PLUGIN_LV2_CATEGORY
pluginString += " a " DISTRHO_PLUGIN_LV2_CATEGORY ", lv2:Plugin ;\n";
#elif DISTRHO_PLUGIN_IS_SYNTH
pluginString += " a lv2:InstrumentPlugin, lv2:Plugin ;\n";
#else
pluginString += " a lv2:Plugin ;\n";
@@ -428,4 +459,133 @@ void lv2_generate_ttl(const char* const basename)
pluginFile.close();
std::cout << " done!" << std::endl;
}

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

#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
{
std::cout << "Writing " << uiTTL << "..."; std::cout.flush();
std::fstream uiFile(uiTTL, std::ios::out);

String uiString;
uiString += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
uiString += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
uiString += "\n";

uiString += "<" DISTRHO_UI_URI ">\n";
uiString += " lv2:extensionData ui:idleInterface ,\n";
# if DISTRHO_PLUGIN_WANT_PROGRAMS
uiString += " ui:showInterface ,\n";
uiString += " <" LV2_PROGRAMS__Interface "> ;\n";
# else
uiString += " ui:showInterface ;\n";
# endif
uiString += "\n";
uiString += " lv2:optionalFeature ui:noUserResize ,\n";
uiString += " ui:resize ,\n";
uiString += " ui:touch ;\n";
uiString += "\n";
uiString += " lv2:requiredFeature <" LV2_OPTIONS__options "> ,\n";
uiString += " <" LV2_URID__map "> .\n";

uiFile << uiString << std::endl;
uiFile.close();
std::cout << " done!" << std::endl;
}
#endif

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

#if DISTRHO_PLUGIN_WANT_PROGRAMS
{
std::cout << "Writing presets.ttl..."; std::cout.flush();
std::fstream presetsFile("presets.ttl", std::ios::out);

String presetsString;
presetsString += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
presetsString += "@prefix pset: <" LV2_PRESETS_PREFIX "> .\n";
presetsString += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
# if DISTRHO_PLUGIN_WANT_STATE
presetsString += "@prefix state: <" LV2_STATE_PREFIX "> .\n";
# endif
presetsString += "\n";

const uint32_t numParameters = plugin.getParameterCount();
const uint32_t numPrograms = plugin.getProgramCount();
# if DISTRHO_PLUGIN_WANT_STATE
const uint32_t numStates = plugin.getStateCount();
# endif

const String presetSeparator(std::strstr(DISTRHO_PLUGIN_URI, "#") != nullptr ? ":" : "#");

char strBuf[0xff+1];
strBuf[0xff] = '\0';

String presetString;

for (uint32_t i=0; i<numPrograms; ++i)
{
std::snprintf(strBuf, 0xff, "%03i", i+1);

plugin.loadProgram(i);

presetString = "<" DISTRHO_PLUGIN_URI + presetSeparator + "preset" + strBuf + ">\n";
presetString += " rdfs:label \"" + plugin.getProgramName(i) + "\" ;\n\n";

// TODO
# if 0 // DISTRHO_PLUGIN_WANT_STATE
for (uint32_t j=0; j<numStates; ++j)
{
if (j == 0)
presetString += " state:state [\n";
else
presetString += " [\n";

presetString += " <urn:distrho:" + plugin.getStateKey(j) + ">\n";
presetString += "\"\"\"\n";
presetString += plugin.getState(j);
presetString += "\"\"\"\n";

if (j+1 == numStates)
{
if (numParameters > 0)
presetString += " ] ;\n\n";
else
presetString += " ] .\n\n";
}
else
{
presetString += " ] ,\n";
}
}
# endif

for (uint32_t j=0; j <numParameters; ++j)
{
if (j == 0)
presetString += " lv2:port [\n";
else
presetString += " [\n";

presetString += " lv2:symbol \"" + plugin.getParameterSymbol(j) + "\" ;\n";

if (plugin.getParameterHints(j) & kParameterIsInteger)
presetString += " pset:value " + String(int(plugin.getParameterValue(j))) + " ;\n";
else
presetString += " pset:value " + String(plugin.getParameterValue(j)) + " ;\n";

if (j+1 == numParameters)
presetString += " ] .\n\n";
else
presetString += " ] ,\n";
}

presetsString += presetString;
}

presetsFile << presetsString << std::endl;
presetsFile.close();
std::cout << " done!" << std::endl;
}
#endif
}

Loading…
Cancel
Save