MCPcopy Create free account
hub / github.com/VCVRack/Rack / fromJson

Method fromJson

src/patch.cpp:512–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510
511
512void Manager::fromJson(json_t* rootJ) {
513 clear();
514
515 // version
516 std::string version;
517 json_t* versionJ = json_object_get(rootJ, "version");
518 if (versionJ)
519 version = json_string_value(versionJ);
520 if (version != APP_VERSION) {
521 INFO("Patch was made with Rack %s, current Rack version is %s", version.c_str(), APP_VERSION.c_str());
522 }
523
524 // path
525 json_t* pathJ = json_object_get(rootJ, "path");
526 if (pathJ)
527 path = json_string_value(pathJ);
528
529 // unsaved
530 json_t* unsavedJ = json_object_get(rootJ, "unsaved");
531 if (!unsavedJ)
532 APP->history->setSaved();
533
534 if (APP->scene) {
535 // zoom
536 json_t* zoomJ = json_object_get(rootJ, "zoom");
537 if (zoomJ)
538 APP->scene->rackScroll->setZoom(json_number_value(zoomJ));
539
540 // gridOffset
541 json_t* gridOffsetJ = json_object_get(rootJ, "gridOffset");
542 if (gridOffsetJ) {
543 double x, y;
544 json_unpack(gridOffsetJ, "[F, F]", &x, &y);
545 APP->scene->rackScroll->setGridOffset(math::Vec(x, y));
546 }
547 }
548
549 // Pass JSON to Engine and RackWidget
550 try {
551 APP->engine->fromJson(rootJ);
552 if (APP->scene) {
553 APP->scene->rack->fromJson(rootJ);
554 }
555 }
556 catch (Exception& e) {
557 WARN("Cannot load patch: %s", e.what());
558 }
559 // At this point, ModuleWidgets and CableWidgets should own all Modules and Cables.
560 // TODO Assert this
561}
562
563
564bool Manager::checkUnavailableModulesJson(json_t* rootJ) {

Callers

nothing calls this directly

Calls 5

VecClass · 0.85
setSavedMethod · 0.80
setGridOffsetMethod · 0.80
whatMethod · 0.80
setZoomMethod · 0.45

Tested by

no test coverage detected