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 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::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())); } } }
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); }