Browse Source

merge moduleFromJson() from Rack 0.6.2

pull/1639/head
bsp2 6 years ago
parent
commit
c8a87a685c
2 changed files with 30 additions and 61 deletions
  1. +4
    -0
      include/app.hpp
  2. +26
    -61
      src/app/RackWidget.cpp

+ 4
- 0
include/app.hpp View File

@@ -46,6 +46,8 @@ struct SVGPanel;
static const float RACK_GRID_WIDTH = 15;
static const float RACK_GRID_HEIGHT = 380;
static const Vec RACK_GRID_SIZE = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
static const std::string PRESET_FILTERS = "VCV Rack module preset (.vcvm):vcvm";
static const std::string PATCH_FILTERS = "VCV Rack patch (.vcv):vcv";


struct ModuleWidget : OpaqueWidget {
@@ -172,6 +174,8 @@ struct RackWidget : OpaqueWidget {
#endif // USE_VST2
json_t *toJson();
void fromJson(json_t *rootJ);
/** Creates a module and adds it to the rack */
ModuleWidget *moduleFromJson(json_t *moduleJ);

void addModule(ModuleWidget *m);
/** Removes the module and transfers ownership to the caller */


+ 26
- 61
src/app/RackWidget.cpp View File

@@ -398,10 +398,9 @@ json_t *RackWidget::toJson() {
void RackWidget::fromJson(json_t *rootJ) {
std::string message;

// Dprintf("fromJson: 1\n");
vst2_set_shared_plugin_tls_globals(); // update JSON hashtable seed
// Dprintf("fromJson: ENTER\n");

// Dprintf("fromJson: 2\n");
vst2_set_shared_plugin_tls_globals(); // update JSON hashtable seed

// version
std::string version;
@@ -410,8 +409,6 @@ void RackWidget::fromJson(json_t *rootJ) {
version = json_string_value(versionJ);
}

// Dprintf("fromJson: 3\n");

// Detect old patches with ModuleWidget::params/inputs/outputs indices.
// (We now use Module::params/inputs/outputs indices.)
int legacy = 0;
@@ -422,8 +419,6 @@ void RackWidget::fromJson(json_t *rootJ) {
info("Loading patch using legacy mode %d", legacy);
}

// Dprintf("fromJson: 4\n");

#ifdef RACK_HOST
float oversampleFactor = -1.0f;
int oversampleQuality = -1;
@@ -436,8 +431,6 @@ void RackWidget::fromJson(json_t *rootJ) {
}
}

// Dprintf("fromJson: 5\n");

// Oversample quality (0..10)
{
json_t *oversampleJ = json_object_get(rootJ, "oversampleQuality");
@@ -446,12 +439,8 @@ void RackWidget::fromJson(json_t *rootJ) {
}
}

// Dprintf("fromJson: 6\n");

vst2_oversample_realtime_set(oversampleFactor, oversampleQuality);

// Dprintf("fromJson: 7\n");

// Oversample channel limit
int oversampleNumIn = -1;
int oversampleNumOut = -1;
@@ -464,8 +453,6 @@ void RackWidget::fromJson(json_t *rootJ) {
}
}

// Dprintf("fromJson: 8\n");

// Oversample output channel limit
{
json_t *oversampleJ = json_object_get(rootJ, "oversampleNumOut");
@@ -474,12 +461,8 @@ void RackWidget::fromJson(json_t *rootJ) {
}
}

// Dprintf("fromJson: 9\n");

vst2_oversample_channels_set(oversampleNumIn, oversampleNumOut);

// Dprintf("fromJson: 10\n");

// Idle detection mode
{
json_t *idleJ = json_object_get(rootJ, "idleDetect");
@@ -511,8 +494,6 @@ void RackWidget::fromJson(json_t *rootJ) {
}
#endif // RACK_HOST

// Dprintf("fromJson: 11\n");

// modules
std::map<int, ModuleWidget*> moduleWidgets;
json_t *modulesJ = json_object_get(rootJ, "modules");
@@ -521,78 +502,47 @@ void RackWidget::fromJson(json_t *rootJ) {
json_t *moduleJ;
json_array_foreach(modulesJ, moduleId, moduleJ) {
// Add "legacy" property if in legacy mode
// Dprintf("fromJson: 12.1\n");
if (legacy) {
json_object_set(moduleJ, "legacy", json_integer(legacy));
}
// Dprintf("fromJson: 12.2\n");

json_t *pluginSlugJ = json_object_get(moduleJ, "plugin");
if (!pluginSlugJ) continue;
// Dprintf("fromJson: 12.3\n");
json_t *modelSlugJ = json_object_get(moduleJ, "model");
if (!modelSlugJ) continue;
// Dprintf("fromJson: 12.4\n");
std::string pluginSlug = json_string_value(pluginSlugJ);
// Dprintf("fromJson: 12.5\n");
std::string modelSlug = json_string_value(modelSlugJ);
// Dprintf("fromJson: 12.6\n");

Model *model = pluginGetModel(pluginSlug, modelSlug);
// Dprintf("fromJson: 12.7\n");
if (!model) {
message += stringf("Could not find module \"%s\" of plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str());
continue;
}
// Dprintf("fromJson: 12.8\n");

// Create ModuleWidget
// // #ifdef USE_VST2
// // if(NULL != model->plugin->set_tls_globals_fxn) {
// // model->plugin->set_tls_globals_fxn(model->plugin);
// // }
// // #endif // USE_VST2
// Dprintf("fromJson: 12.9\n");
ModuleWidget *moduleWidget = model->createModuleWidget();
// Dprintf("fromJson: 12.10\n");
assert(moduleWidget);
// Dprintf("fromJson: 12.11\n");
moduleWidget->fromJson(moduleJ);
// Dprintf("fromJson: 12.12\n");
moduleContainer->addChild(moduleWidget);
// Dprintf("fromJson: 12.13\n");
moduleWidgets[moduleId] = moduleWidget;
// Dprintf("fromJson: 12.14\n");
}

// Dprintf("fromJson: 13\n");

// wires
json_t *wiresJ = json_object_get(rootJ, "wires");
if (!wiresJ) return;
// Dprintf("fromJson: 14\n");
size_t wireId;
json_t *wireJ;
json_array_foreach(wiresJ, wireId, wireJ) {
// Dprintf("fromJson: 14.1\n");
int outputModuleId = json_integer_value(json_object_get(wireJ, "outputModuleId"));
// Dprintf("fromJson: 14.2\n");
int outputId = json_integer_value(json_object_get(wireJ, "outputId"));
// Dprintf("fromJson: 14.3\n");
int inputModuleId = json_integer_value(json_object_get(wireJ, "inputModuleId"));
// Dprintf("fromJson: 14.4\n");
int inputId = json_integer_value(json_object_get(wireJ, "inputId"));
// Dprintf("fromJson: 14.5\n");

// Get module widgets
ModuleWidget *outputModuleWidget = moduleWidgets[outputModuleId];
// Dprintf("fromJson: 14.6\n");
if (!outputModuleWidget) continue;
// Dprintf("fromJson: 14.7\n");
ModuleWidget *inputModuleWidget = moduleWidgets[inputModuleId];
// Dprintf("fromJson: 14.8\n");
if (!inputModuleWidget) continue;
// Dprintf("fromJson: 14.9\n");

// Get port widgets
Port *outputPort = NULL;
@@ -619,31 +569,22 @@ void RackWidget::fromJson(json_t *rootJ) {
}
if (!outputPort || !inputPort)
continue;
// Dprintf("fromJson: 14.10\n");

// Create WireWidget
WireWidget *wireWidget = new WireWidget();
// Dprintf("fromJson: 14.11\n");
wireWidget->fromJson(wireJ);
// Dprintf("fromJson: 14.12\n");
wireWidget->outputPort = outputPort;
wireWidget->inputPort = inputPort;
wireWidget->updateWire();
// Dprintf("fromJson: 14.13\n");
// Add wire to rack
wireContainer->addChild(wireWidget);
// Dprintf("fromJson: 14.14\n");
}

// Dprintf("fromJson: 15\n");

// Display a message if we have something to say
if (!message.empty()) {
osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK, message.c_str());
}

// Dprintf("fromJson: 16\n");

#ifdef USE_VST2
global_ui->param_info.placeholder_framecount = (30*30)-10;
global_ui->param_info.last_param_widget = NULL;
@@ -652,6 +593,30 @@ void RackWidget::fromJson(json_t *rootJ) {
// Dprintf("fromJson: LEAVE\n");
}

ModuleWidget *RackWidget::moduleFromJson(json_t *moduleJ) {
// Get slugs
json_t *pluginSlugJ = json_object_get(moduleJ, "plugin");
if (!pluginSlugJ)
return NULL;
json_t *modelSlugJ = json_object_get(moduleJ, "model");
if (!modelSlugJ)
return NULL;
std::string pluginSlug = json_string_value(pluginSlugJ);
std::string modelSlug = json_string_value(modelSlugJ);

// Get Model
Model *model = pluginGetModel(pluginSlug, modelSlug);
if (!model)
return NULL;

// Create ModuleWidget
ModuleWidget *moduleWidget = model->createModuleWidget();
assert(moduleWidget);
moduleWidget->fromJson(moduleJ);
moduleContainer->addChild(moduleWidget);
return moduleWidget;
}

void RackWidget::addModule(ModuleWidget *m) {
rack::global_ui->app.mtx_param.lock();
moduleContainer->addChild(m);


Loading…
Cancel
Save