Create unique temporary path per instance for auto-save function
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
4a5e71eb7f
commit
0ecf6954e1
2 changed files with 41 additions and 4 deletions
|
|
@ -130,6 +130,7 @@ static const Initializer& getInitializerInstance()
|
|||
class CardinalPlugin : public Plugin
|
||||
{
|
||||
rack::Context* const fContext;
|
||||
std::string fAutosavePath;
|
||||
|
||||
struct ScopedContext {
|
||||
ScopedContext(CardinalPlugin* const plugin)
|
||||
|
|
@ -148,20 +149,44 @@ public:
|
|||
: Plugin(0, 0, 0),
|
||||
fContext(new rack::Context)
|
||||
{
|
||||
// create unique temporary path for this instance
|
||||
try {
|
||||
char uidBuf[24];
|
||||
const std::string tmp = rack::system::getTempDirectory();
|
||||
|
||||
for (int i=1;; ++i)
|
||||
{
|
||||
std::snprintf(uidBuf, sizeof(uidBuf), "Cardinal.%04d", i);
|
||||
const std::string trypath = rack::system::join(tmp, uidBuf);
|
||||
|
||||
if (! rack::system::exists(trypath))
|
||||
{
|
||||
if (rack::system::createDirectories(trypath))
|
||||
fAutosavePath = trypath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} DISTRHO_SAFE_EXCEPTION("create unique temporary path");
|
||||
|
||||
// create temporary path
|
||||
const ScopedContext sc(this);
|
||||
|
||||
fContext->engine = new rack::engine::Engine;
|
||||
fContext->history = new rack::history::State;
|
||||
fContext->patch = new rack::patch::Manager;
|
||||
fContext->patch->autosavePath = "/OBVIOUSLY-NOT-VALID-PATH/";
|
||||
fContext->patch->autosavePath = fAutosavePath;
|
||||
fContext->engine->startFallbackThread();
|
||||
}
|
||||
|
||||
~CardinalPlugin() override
|
||||
{
|
||||
const ScopedContext sc(this);
|
||||
{
|
||||
const ScopedContext sc(this);
|
||||
delete fContext;
|
||||
}
|
||||
|
||||
delete fContext;
|
||||
if (! fAutosavePath.empty())
|
||||
rack::system::removeRecursively(fAutosavePath);
|
||||
}
|
||||
|
||||
rack::Context* getRackContext() const noexcept
|
||||
|
|
@ -246,6 +271,11 @@ protected:
|
|||
*/
|
||||
void run(const float** inputs, float** outputs, uint32_t frames) override
|
||||
{
|
||||
/*
|
||||
fContext->engine->setFrame(getTimePosition().frame);
|
||||
fContext->engine->stepBlock(frames);
|
||||
*/
|
||||
|
||||
// copy inputs over outputs if needed
|
||||
if (outputs[0] != inputs[0])
|
||||
std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
|
||||
|
|
@ -254,6 +284,13 @@ protected:
|
|||
std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
|
||||
}
|
||||
|
||||
/*
|
||||
void sampleRateChanged(const double newSampleRate) override
|
||||
{
|
||||
fContext->engine->setSampleRate(newSampleRate);
|
||||
}
|
||||
*/
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@
|
|||
#define DISTRHO_PLUGIN_HAS_UI 1
|
||||
#define DISTRHO_PLUGIN_NUM_INPUTS 2
|
||||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
|
||||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 1
|
||||
#define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 1
|
||||
// #define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:AnalyserPlugin"
|
||||
// #define DISTRHO_PLUGIN_VST3_CATEGORIES "Fx|Analyzer"
|
||||
#define DISTRHO_UI_USE_NANOVG 1
|
||||
#define DISTRHO_UI_USER_RESIZABLE 0
|
||||
#define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 1
|
||||
|
||||
enum Parameters {
|
||||
kParameterCount
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue