Browse Source

Move asset::autosavePath to Patch. Add Module::createPatchStorageDir() and remove asset::module().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
2966cd57f7
6 changed files with 33 additions and 29 deletions
  1. +0
    -10
      include/asset.hpp
  2. +5
    -0
      include/engine/Module.hpp
  3. +3
    -0
      include/patch.hpp
  4. +0
    -8
      src/asset.cpp
  5. +8
    -0
      src/engine/Module.cpp
  6. +17
    -11
      src/patch.cpp

+ 0
- 10
include/asset.hpp View File

@@ -33,15 +33,6 @@ Examples:
*/
std::string plugin(plugin::Plugin* plugin, std::string filename = "");

/** Returns the path to an asset in the module patch folder.
The module patch folder is *not* created automatically. Before creating files at these paths, call
system::createDirectories(asset::module(module))

Examples:
asset::module(module, "recordings/00.wav") // "/path/to/Rack/user/folder/autosave/modules/1234/recordings/00.wav"
*/
std::string module(engine::Module* module, const std::string& filename = "");


// Set these before calling init() to override the default paths
extern std::string systemDir;
@@ -50,7 +41,6 @@ extern std::string userDir;
extern std::string logPath;
extern std::string pluginsPath;
extern std::string settingsPath;
extern std::string autosavePath;
extern std::string templatePath;
// Only defined on Mac
extern std::string bundlePath;


+ 5
- 0
include/engine/Module.hpp View File

@@ -218,6 +218,11 @@ struct Module {
bypassRoutes.push_back(br);
}

/** Creates and returns the module's patch storage folder path.
Since the folder is created when this is called, do not call it frequently or in an audio/engine thread such as process().
*/
std::string createPatchStorageDir();

struct ProcessArgs {
/** The current sample rate in Hz. */
float sampleRate;


+ 3
- 0
include/patch.hpp View File

@@ -10,6 +10,9 @@ namespace rack {
struct PatchManager {
/** The currently loaded patch file path */
std::string path;
/** Path to autosave folder */
std::string autosavePath;
/** Append to this while loading/saving a patch to display messages to the user after success. */
std::string warningLog;

PatchManager();


+ 0
- 8
src/asset.cpp View File

@@ -120,14 +120,12 @@ void init() {
if (settings::devMode) {
pluginsPath = system::join(userDir, "plugins");
settingsPath = system::join(userDir, "settings.json");
autosavePath = system::join(userDir, "autosave");
templatePath = system::join(userDir, "template.vcv");
}
else {
logPath = system::join(userDir, "log.txt");
pluginsPath = system::join(userDir, "plugins-v" + ABI_VERSION);
settingsPath = system::join(userDir, "settings-v" + ABI_VERSION + ".json");
autosavePath = system::join(userDir, "autosave-v" + ABI_VERSION);
templatePath = system::join(userDir, "template-v" + ABI_VERSION + ".vcv");
}
}
@@ -149,12 +147,6 @@ std::string plugin(plugin::Plugin* plugin, std::string filename) {
}


std::string module(engine::Module* module, const std::string& filename) {
assert(module);
return system::join(autosavePath, "modules", std::to_string(module->id), filename);
}


std::string systemDir;
std::string userDir;



+ 8
- 0
src/engine/Module.cpp View File

@@ -5,6 +5,7 @@
#include <settings.hpp>
#include <asset.hpp>
#include <context.hpp>
#include <patch.hpp>


namespace rack {
@@ -81,6 +82,13 @@ void Module::config(int numParams, int numInputs, int numOutputs, int numLights)
}


std::string Module::createPatchStorageDir() {
std::string path = system::join(APP->patch->autosavePath, "modules", std::to_string(id));
system::createDirectories(path);
return path;
}


void Module::processBypass(const ProcessArgs& args) {
for (BypassRoute& bypassRoute : bypassRoutes) {
// Route input voltages to output


+ 17
- 11
src/patch.cpp View File

@@ -23,6 +23,12 @@ static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv";


PatchManager::PatchManager() {
if (settings::devMode) {
autosavePath = asset::user("autosave");
}
else {
autosavePath = asset::user("autosave-v" + ABI_VERSION);
}
}


@@ -85,11 +91,11 @@ void PatchManager::save(std::string path) {
cleanAutosave();

// Take screenshot (disabled because there is currently no way to quickly view them on any OS or website.)
// APP->window->screenshot(system::join(asset::autosavePath, "screenshot.png"));
// APP->window->screenshot(system::join(autosavePath, "screenshot.png"));

double startTime = system::getTime();
// Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked
system::archiveFolder(path, asset::autosavePath, 1);
system::archiveFolder(path, autosavePath, 1);
double endTime = system::getTime();
INFO("Archived patch in %lf seconds", (endTime - startTime));
}
@@ -177,7 +183,7 @@ void PatchManager::saveTemplateDialog() {


void PatchManager::saveAutosave() {
std::string patchPath = system::join(asset::autosavePath, "patch.json");
std::string patchPath = system::join(autosavePath, "patch.json");
INFO("Saving autosave %s", patchPath.c_str());
json_t* rootJ = toJson();
if (!rootJ)
@@ -185,7 +191,7 @@ void PatchManager::saveAutosave() {
DEFER({json_decref(rootJ);});

// Write to temporary path and then rename it to the correct path
system::createDirectories(asset::autosavePath);
system::createDirectories(autosavePath);
std::string tmpPath = patchPath + ".tmp";
FILE* file = std::fopen(tmpPath.c_str(), "w");
if (!file) {
@@ -202,7 +208,7 @@ void PatchManager::saveAutosave() {

void PatchManager::cleanAutosave() {
// Remove files and folders in the `autosave/modules` folder that doesn't match a module in the rack.
std::string modulesDir = system::join(asset::autosavePath, "modules");
std::string modulesDir = system::join(autosavePath, "modules");
if (system::isDirectory(modulesDir)) {
for (const std::string& entry : system::getEntries(modulesDir)) {
try {
@@ -237,17 +243,17 @@ static bool isPatchLegacyV1(std::string path) {
void PatchManager::load(std::string path) {
INFO("Loading patch %s", path.c_str());

system::removeRecursively(asset::autosavePath);
system::createDirectories(asset::autosavePath);
system::removeRecursively(autosavePath);
system::createDirectories(autosavePath);

if (isPatchLegacyV1(path)) {
// Copy the .vcv file directly to "patch.json".
system::copy(path, system::join(asset::autosavePath, "patch.json"));
system::copy(path, system::join(autosavePath, "patch.json"));
}
else {
// Extract the .vcv file as a .tar.zst archive.
double startTime = system::getTime();
system::unarchiveToFolder(path, asset::autosavePath);
system::unarchiveToFolder(path, autosavePath);
double endTime = system::getTime();
INFO("Unarchived patch in %lf seconds", (endTime - startTime));
}
@@ -287,7 +293,7 @@ void PatchManager::loadTemplateDialog() {


bool PatchManager::hasAutosave() {
std::string patchPath = system::join(asset::autosavePath, "patch.json");
std::string patchPath = system::join(autosavePath, "patch.json");
INFO("Loading autosave %s", patchPath.c_str());
FILE* file = std::fopen(patchPath.c_str(), "r");
if (!file)
@@ -298,7 +304,7 @@ bool PatchManager::hasAutosave() {


void PatchManager::loadAutosave() {
std::string patchPath = system::join(asset::autosavePath, "patch.json");
std::string patchPath = system::join(autosavePath, "patch.json");
INFO("Loading autosave %s", patchPath.c_str());
FILE* file = std::fopen(patchPath.c_str(), "r");
if (!file)


Loading…
Cancel
Save