void ParametersState::readJson(const ofJson &obj) { JsonUtil::assertIsObject(obj); const ofJson *paramVals; if (obj.count("params") == 0 || obj["params"].is_null()) { // parsing it as old format that only contains raw params paramVals = &obj; } else { paramVals = &(obj["params"]); if (obj.count("presets") != 0) { const auto& presetsArr = obj["presets"]; if (presetsArr.is_array()) { _params.clear(); for (const auto& presetObj : presetsArr) { auto preset = std::make_shared<ParamPreset>(); preset->readJson(presetObj); if (preset->name().empty()) { preset->setName("preset " + ofToString(_presets.size())); } preset->stripUnsupportedParams(_params); _presets.push_back(preset); } } } } if (!paramVals->is_null()) { JsonUtil::assertIsObject(*paramVals); _params.readJson(*paramVals); } else { AppSystem::get().log().app().logWarning("Unable to find param values in settings json"); } }
void Loader::setupPropertyKeysJson(Property<ofFloatColor>& prop, const ofJson& json, const ofFloatColor& scale, const ofFloatColor& offset) { for(auto key = json.begin(); key != json.end(); ++key) { const string& name = key.key(); int key_frame = ofToInt(name); ofFloatColor value = ofFloatColor(json[name][0], json[name][1], json[name][2])*scale+offset; prop.addKey(key_frame, value); } }
void Loader::setupPropertyKeysJson(Property<bool>& prop, const ofJson& json) { for(auto key = json.begin(); key != json.end(); ++key) { const string& name = key.key(); int key_frame = ofToInt(name); bool value = json[name]; prop.addKey(key_frame, value); } }
void Loader::setupPropertyKeysJson(Property<float>& prop, const ofJson& json, float scale, float offset) { for(auto key = json.begin(); key != json.end(); ++key) { const string& name = key.key(); int key_frame = ofToInt(name); float value = json.value(name, 0)*scale+offset; prop.addKey(key_frame, value); } }
void Loader::setupMovieJson(MovieCap &cap, const ofJson& json) { const ofJson& source_dir = json["sourceDirectory"]; const ofJson& source = json["source"]; if(!source.is_null()) { cap.loadMovie(base_path_+(source_dir.is_null()?"":source_dir.get<string>())+source.get<string>()); } bool use_audio = json.value("hasAudio", true) && json.value("audioActive", true); cap.setUseAudio(use_audio); }
void Loader::setupMaskJson(Mask& mask, const ofJson& json, const ofVec2f &size) { mask.name_ = json.value("name", "noname"); const string& blend_mode = json.value("mode", "none"); if(blend_mode == "none") { mask.blend_mode_ = OF_BLENDMODE_ALPHA; } if(blend_mode == "add") { mask.blend_mode_ = OF_BLENDMODE_ADD; } if(blend_mode == "subtract") { mask.blend_mode_ = OF_BLENDMODE_SUBTRACT; } { auto prop = mask.getPathProperty(); setupPropertyKeysJson(*prop, json); prop->setSize(size); prop->setInverted(json.value("inverted", false)); } setupPropertyKeysJson(*mask.getOpacityProperty(), json["opacity"], 0.01f); }
void Scene::readJson(const ofJson &obj) { _name = JsonUtil::fromJsonField<std::string>(obj, "name", "scene"); _nodes.clear(); auto iter = obj.find("nodes"); if (iter != obj.end() && !iter.value().is_null()) { const auto& nodesArray = iter.value(); JsonUtil::assertIsArray(nodesArray); for (const auto& nodeObj : nodesArray) { JsonUtil::assertIsObject(nodeObj); std::string typeName = nodeObj["type"]; auto node = createNode(typeName); if (!node) { continue; } _nodes.insert(std::make_pair(node->id(), node)); } } }
void Loader::setupPropertyKeysJson(TransformProperty& prop, const ofJson& json) { setupPropertyKeysJson(*prop.getTranslation(), json["Position"], ofVec3f(1,1,-1)); setupPropertyKeysJson(*prop.getScale(), json["Scale"], ofVec3f(0.01f,0.01f,0.01f)); setupPropertyKeysJson(*prop.getRotation(), json["Rotation"], ofVec3f(-1,-1,1)); if(json.find("AnchorPoint") != end(json)) { setupPropertyKeysJson(*prop.getAnchorPoint(), json["AnchorPoint"], ofVec3f(1,1,-1)); } setupPropertyKeysJson(*prop.getOrientation(), json["Orientation"], ofVec3f(-1,-1,1)); }
void Loader::setupAVLayerJson(AVLayer& layer, const ofJson& json) { const ofJson& properties = json["property"]; layer.allocate(json.value("width", 1), json.value("height", 1)); layer.is_3d_ = json.value("is3d", false); layer.is_collapse_ = json.value("isCollapse", false); const string& blend_mode = json.value("blendingMode", "none"); if(blend_mode == "none") { layer.blend_mode_ = OF_BLENDMODE_ALPHA; } if(blend_mode == "add") { layer.blend_mode_ = OF_BLENDMODE_ADD; } if(blend_mode == "subtract") { layer.blend_mode_ = OF_BLENDMODE_SUBTRACT; } setupLayerJson(layer, json); auto masks = properties.find("mask"); if(masks != end(properties) && masks->is_array()) { int mask_count = masks->size(); for(int i = 0; i < mask_count; ++i) { setupMaskJson(*layer.addNewMask("mask"+ofToString(i,2,'0')), (*masks)[i], ofVec2f(layer.getWidth(),layer.getHeight())); } } }
OAuth10Credentials OAuth10Credentials::fromJSON(const ofJson& json) { OAuth10Credentials credentials; auto iter = json.cbegin(); while (iter != json.cend()) { const auto& key = iter.key(); const auto& value = iter.value(); if (key == "consumerKey") credentials._consumerKey = value; else if (key == "consumerSecret") credentials._consumerSecret = value; else if (key == "accessToken") credentials._accessToken = value; else if (key == "accessTokenSecret") credentials._accessTokenSecret = value; else ofLogWarning("Credentials::fromJSON") << "Unknown key: " << key << std::endl << value.dump(4); ++iter; } return credentials; }
void Loader::setupLayerJson(Layer& layer, const ofJson& json) { layer.name_ = json.value("name", "noname"); layer.frame_offset_ = json.value("frameOffset", 0); layer.frame_in_ = json.value("inFrame", 0); layer.frame_out_ = json.value("outFrame", 0); layer.setParamByComment(json.value("comment", "")); const ofJson& properties = json["property"]; setupPropertyKeysJson(*layer.getActiveProperty(), properties["active"]); setupPropertyKeysJson(*layer.getOpacityProperty(), properties["Opacity"], 0.01f); setupPropertyKeysJson(*layer.getTransformProperty(), properties); // Markers auto markers = json.find("marker"); if(markers != end(json) && markers->is_array()) { int marker_count = markers->size(); for(int i = 0; i < marker_count; ++i) { setupMarkerJson(*layer.addNewMarker(), (*markers)[i]); } } }
void Loader::setupCompositionJson(Composition& comp, const ofJson& json) { // Basics comp.name_ = json.value("name", "noname"); comp.allocate(json.value("width", 1), json.value("height", 1)); comp.setLength(json.value("length", 0)); comp.setFrameRate(json.value("frameRate", 0)); // Layers const ofJson& layers = json["layer"]; if(layers.is_array()) { map<shared_ptr<Layer>, int> all; map<shared_ptr<Layer>, int> children; int layer_count = layers.size(); for(int i = layer_count; i--;) { // reverse iterate for draw priority const ofJson& layer = layers[i]; const string& type_name = layer.value("layerType", "unknown"); shared_ptr<Layer> l = nullptr; shared_ptr<LayerCap> c = nullptr; if(type_name == "composition") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<CompositionCap>(); setupCompositionJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "solid") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<PlaneCap>(); setupPlaneJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "sequence") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<SequenceCap>(); setupSequenceJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "image") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<ImageCap>(); setupImageJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "movie") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<MovieCap>(); setupMovieJson(*cap, layer); cap->setComposition(&comp); comp.av_.push_back(ll); l = ll; c = cap; } else if(type_name == "camera") { auto ll = make_shared<CameraLayer>(); setupCameraLayerJson(*ll, layer, comp); comp.camera_.push_back(ll); l = ll; } else if(type_name == "shape") { auto ll = make_shared<AVLayer>(); setupAVLayerJson(*ll, layer); auto cap = make_shared<ShapeCap>(); setupShapeJson(*cap, layer); comp.av_.push_back(ll); l = ll; c = cap; } if(!l) { continue; } if(c) { l->setCap(c); } all.insert(pair<shared_ptr<Layer>,int>(l, layer.value("index", 0))); auto parent = layer.find("parent"); if(parent != end(layer)) { children.insert(pair<shared_ptr<Layer>,int>(l, *parent)); } } // search parent for(auto &child : children) { for(auto &parent : all) { if(child.second == parent.second) { child.first->setParent(parent.first); } } } } // Markers auto markers = json.find("marker"); if(markers != end(json) && markers->is_array()) { int marker_count = markers->size(); for(int i = 0; i < marker_count; ++i) { setupMarkerJson(*comp.addNewMarker(), (*markers)[i]); } } comp.setFrame(0); }
void Loader::setupMarkerJson(Marker& marker, const ofJson& json) { marker.setupByComment(json.value("comment", "")); marker.from_ = json.value("from", 0); marker.length_ = json.value("length", 0); }
void Loader::setupShapeContentsJson(ShapeCap &cap, const ofJson& contents, shared_ptr<ShapeContentGroup> parent) { int content_count = contents.size(); for(int i = 0; i < content_count; ++i) { const ofJson& content = contents[i]; const string& type = content.value("type", ""); if(type == "group") { auto target = make_shared<ShapeContentGroup>(); auto content = contents.find("contents"); if(content != end(contents)) { setupShapeContentsJson(cap, *content, target); } if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "ellipse") { auto target = make_shared<ShapeContentEllipse>(); setupPropertyKeysJson(*target->getPositionProperty(), content["Position"]); setupPropertyKeysJson(*target->getSizeProperty(), content["Size"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "rect") { auto target = make_shared<ShapeContentRect>(); setupPropertyKeysJson(*target->getPositionProperty(), content["Position"]); setupPropertyKeysJson(*target->getSizeProperty(), content["Size"]); setupPropertyKeysJson(*target->getRoundnessProperty(), content["Roundness"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "path") { auto target = make_shared<ShapeContentPath>(); { auto prop = target->getPathProperty(); prop->setSize(cap.getSize()); setupPropertyKeysJson(*prop, content["path"]); } if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "stroke") { auto target = make_shared<ShapeContentStroke>(); setupPropertyKeysJson(*target->getColorProperty(), content["Color"]); setupPropertyKeysJson(*target->getOpacityProperty(), content["Opacity"], 0.01f); setupPropertyKeysJson(*target->getStrokeWidthProperty(), content["StrokeWidth"]); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "fill") { auto target = make_shared<ShapeContentFill>(); setupPropertyKeysJson(*target->getColorProperty(), content["Color"]); setupPropertyKeysJson(*target->getOpacityProperty(), content["Opacity"], 0.01f); if(parent) { parent->addContent(target); } else { cap.addContent(target); } } else if(type == "transform") { { auto prop = parent->getTransformProperty(); setupPropertyKeysJson(*prop->getTranslation(), content["Position"]); setupPropertyKeysJson(*prop->getAnchorPoint(), content["AnchorPoint"]); setupPropertyKeysJson(*prop->getScale(), content["Scale"], ofVec3f(0.01f,0.01f,0), ofVec3f(0,0,1)); } setupPropertyKeysJson(*parent->getRotationZProperty(), content["Rotation"]); setupPropertyKeysJson(*parent->getOpacityProperty(), content["Opacity"], 0.01f); setupPropertyKeysJson(*parent->getSkewProperty(), content["Skew"]); setupPropertyKeysJson(*parent->getSkewAxisProperty(), content["SkewAxis"]); } } }