void Rig::loadJSON(JSONNode root) { //JSONNode::const_iterator i = root.begin(); JSONNode::iterator i = root.begin(); auto version = root.find("version"); if (version == root.end()) { Logger::log(ERR, "No version specified for input file. Aborting load."); return; } else { stringstream ss; stringstream ss2(version->as_string()); ss << LumiverseCore_VERSION_MAJOR << "." << LumiverseCore_VERSION_MINOR; float libVer; float fileVer; ss >> libVer; ss2 >> fileVer; if (fileVer < libVer) { // Friendly warning if you're loading an old file. Logger::log(WARN, "File created against earlier version of Lumiverse. Check logs for any load problems."); } else if (fileVer > libVer) { // Loading newer file with older library. Logger::log(WARN, "File created against newer version of Lumiverse. Check logs for any load problems."); } } while (i != root.end()){ // get the node name and value as a string std::string nodeName = i->name(); if (nodeName == "devices") { loadDevices(*i); Logger::log(INFO, "Device load complete"); } else if (nodeName == "patches") { i->push_back(*root.find("jsonPath")); loadPatches(*i); Logger::log(INFO, "Patch load complete"); } else if (nodeName == "refreshRate") { setRefreshRate(i->as_int()); } //increment the iterator ++i; } }
void Rig::loadPatches(JSONNode root) { JSONNode::iterator i = root.begin(); // for this we want to iterate through all children and have the device class // parse the sub-element. while (i != root.end()){ if (i->name() == "jsonPath") { i++; continue; } // get the node name and value as a string std::string nodeName = i->name(); stringstream ss; ss << "Loading patch " << nodeName; Logger::log(INFO, ss.str()); Patch* patch; auto type = i->find("type"); if (type == i->end()) { stringstream ss; ss << "Unable to determine Patch type for " << nodeName << ". Patch not loaded."; Logger::log(WARN, ss.str()); } string patchType = type->as_string(); // New patch types will need new seralization definitions. if (patchType == "DMXPatch") { patch = (Patch*) new DMXPatch(*i); addPatch(nodeName, patch); } #ifdef USE_ARNOLD else if (patchType == "PhotoPatch") { patch = (Patch*) new PhotoPatch(*i); addPatch(nodeName, patch); Device::DeviceCallbackFunction callback = std::bind(&PhotoPatch::onDeviceChanged, (PhotoPatch*)patch, std::placeholders::_1); for (Device *d : getDeviceRaw()) { d->addParameterChangedCallback(callback); d->addMetadataChangedCallback(callback); } } else if (patchType == "PhotoAnimationPatch") { patch = (Patch*) new PhotoAnimationPatch(*i); addPatch(nodeName, patch); Device::DeviceCallbackFunction callback = std::bind(&PhotoAnimationPatch::onDeviceChanged, (PhotoAnimationPatch*)patch, std::placeholders::_1); for (Device *d : getDeviceRaw()) { d->addParameterChangedCallback(callback); d->addMetadataChangedCallback(callback); } } else if (patchType == "ArnoldAnimationPatch") { i->push_back(*root.find("jsonPath")); patch = (Patch*) new ArnoldAnimationPatch(*i); addPatch(nodeName, patch); Device::DeviceCallbackFunction callback = std::bind(&ArnoldAnimationPatch::onDeviceChanged, (ArnoldAnimationPatch*)patch, std::placeholders::_1); for (Device *d : getDeviceRaw()) { d->addParameterChangedCallback(callback); d->addMetadataChangedCallback(callback); } } else if (patchType == "ArnoldPatch") { i->push_back(*i->find("jsonPath")); patch = (Patch*) new ArnoldPatch(*i); addPatch(nodeName, patch); Device::DeviceCallbackFunction callback = std::bind(&ArnoldPatch::onDeviceChanged, (ArnoldPatch*)patch, std::placeholders::_1); for (Device *d : getDeviceRaw()) { d->addParameterChangedCallback(callback); d->addMetadataChangedCallback(callback); } } #endif else { stringstream ss; ss << "Unknown Patch type " << patchType << " in Patch ID " << nodeName << "Patch not loaded."; Logger::log(WARN, ss.str()); } //increment the iterator ++i; } }