void PretzelGlobal::saveSettings(fs::path settingsPath){ fs::path appPath = settingsPath; if (appPath.string() == ""){ appPath = getAppPath() / "guiSettings"; if (!fs::exists(appPath)){ console() << appPath << " does not exist" << endl; fs::create_directory(appPath); } appPath /= "settings.json"; } JsonTree pSettings = JsonTree::makeObject( "pretzelSettings" ); std::string tmp; for (int i = 0; i < mParamList.size(); i++){ switch (mParamList[i].type){ case _FLOAT: pSettings.pushBack( JsonTree(mParamList[i].name, to_string(*(float*)mParamList[i].value)) ); break; case _INT: pSettings.pushBack(JsonTree(mParamList[i].name, to_string(*(int*)mParamList[i].value))); break; case _BOOL: tmp = ((*(bool*)mParamList[i].value) == true) ? "1" : "0"; pSettings.pushBack(JsonTree(mParamList[i].name, tmp)); break; default: break; } } JsonTree root; root.pushBack(pSettings); root.write(appPath, JsonTree::WriteOptions()); }
void FaceController::saveFace() {/* for (size_t i = 0, ilen= facesStoreVector.size(); i<ilen; i++) { JsonTree oneFaceJson; oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[i].getTexName() ) ); JsonTree facesDataJson = JsonTree::makeArray( "data" ); auto points = facesStoreVector[i].getPoints(); for (size_t j = 0, ilen = points.size() ; j < ilen; j++) { JsonTree point; point.addChild(JsonTree( "x",points[j].x) ); point.addChild(JsonTree( "y",points[j].y) ); facesDataJson.pushBack(point); } oneFaceJson.addChild(facesDataJson ); facesJson.pushBack(oneFaceJson); } doc.pushBack( facesJson ); writeImage( getAppPath() /FACE_STORAGE_FOLDER/genericName, surf ); doc.write( writeFile( getAppPath() / DATA_BASE_NAME ), JsonTree::WriteOptions() ); */ // SAVE LAST ONLY!!!! JsonTree doc; JsonTree facesJson = JsonTree::makeArray( "faces" ); int id = facesStoreVector.size() - 1; JsonTree oneFaceJson; oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[id].getTexName() ) ); JsonTree facesDataJson = JsonTree::makeArray( "data" ); auto points = facesStoreVector[id].getPoints(); for (size_t j = 0, ilen = points.size() ; j < ilen; j++) { JsonTree point; point.addChild(JsonTree( "x",points[j].x) ); point.addChild(JsonTree( "y",points[j].y) ); facesDataJson.pushBack(point); } oneFaceJson.addChild(facesDataJson ); facesJson.pushBack(oneFaceJson); doc.pushBack( facesJson ); string jsonName = "base_"+to_string(id) + ".json"; doc.write( writeFile( getAppPath() / JSON_STORAGE_FOLDER / jsonName ), JsonTree::WriteOptions() ); }
void JsonTree::init( const string &key, const Json::Value &value, bool setType, NodeType nodeType, ValueType valueType ) { mKey = key; mNodeType = nodeType; mParent = 0; mValue = ""; mValueType = valueType; if( ! value.isNull() && ( value.isArray() || value.isObject() ) ) { if( value.isArray() ) { mNodeType = NODE_ARRAY; for ( uint32_t i = 0; i < value.size(); i++ ) { pushBack( JsonTree( "", value[ i ] ) ); } } else if( value.isObject() ) { mNodeType = NODE_OBJECT; Json::Value::Members members = value.getMemberNames(); for( Json::Value::Members::const_iterator memberIt = members.begin(); memberIt != members.end(); ++memberIt ) { string key = *memberIt; pushBack( JsonTree( key, value[ key ] ) ); } } } else { if( value.isBool() ) { mValue = toString( value.asBool() ); if( setType ) { mValueType = VALUE_BOOL; } } else if ( value.isDouble() ) { mValue = toString( value.asDouble() ); if ( setType ) { mValueType = VALUE_DOUBLE; } } else if ( value.isInt() ) { mValue = toString( value.asInt() ); if ( setType ) { mValueType = VALUE_INT; } } else if ( value.isString() ) { mValue = toString( value.asString() ); if ( setType ) { mValueType = VALUE_STRING; } } else if ( value.isUInt() ) { mValue = toString( value.asUInt() ); if ( setType ) { mValueType = VALUE_UINT; } } } }
void TextureSequenceOptimizer::saveMax( fs::path path ) { if ( path == fs::path() ) { path = app::App::get()->getFolderPath(); app::console() << "SAVE MAX: " << path << std::endl; } if( ! path.empty() ){ fs::path jsonPath = path; jsonPath.append("sequence.json"); JsonTree doc = JsonTree::makeObject(); JsonTree size = JsonTree::makeObject("size"); size.pushBack(JsonTree("width", mOriOutline.getWidth() )); size.pushBack(JsonTree("height", mOriOutline.getHeight() )); doc.pushBack(size); JsonTree sequence = JsonTree::makeArray("sequence"); //go thru each surface for (int i = 0; i < mSurfaceRefs.size(); i++) { fs::path tempPath = path; //only clone the non-transparent area based on the offsets Surface tempSurf; JsonTree curImage = JsonTree::makeObject(); if( mTrimMaxAreas[i].calcArea() == 0 ){ app::console() << " Image is completely transparent: " << mFileNames[i] << std::endl; tempPath.append("transparent.png"); // check if transparent pixel exists if( !fs::exists(tempPath) ){ // create transparent png if it doesn't exist tempSurf = mSurfaceRefs[i]->clone( Area(0,0,10,10) ); writeImage( tempPath, tempSurf ); } // point to transparent image curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1)); curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1)); curImage.pushBack(JsonTree("fileName", "transparent.png" )); }else{ tempSurf = mSurfaceRefs[i]->clone(mTrimMaxAreas[i]); tempPath.append(toString(mFileNames[i])); writeImage( tempPath, tempSurf ); curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1)); curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1)); curImage.pushBack(JsonTree("fileName", mFileNames[i] )); } sequence.pushBack(curImage); //app::console() << "saving: " << tempPath << " "<< mTrimMaxAreas[i] << std::endl; tempPath.clear(); } doc.pushBack(sequence); doc.write( jsonPath, JsonTree::WriteOptions()); //saveJson(path); } }
JsonTree queryWinChattyv2Server(const std::string &query) { UrlOptions options = UrlOptions(); options.setTimeout(2.0f * 60.0f);// 2 minutes Url url("https://winchatty.com/v2/" + query, true); return JsonTree(loadUrl(url, options)); }
std::vector<Joint *> SkeletonData::LoadSkeleton(std::string filePath) { //Not sure about this error catching setup std::vector<Joint*> joints; if( PathFileExistsA(filePath.c_str()) == TRUE) { try{ JsonTree doc = JsonTree(loadFile(filePath)); JsonTree jointsJson = doc.getChild( "joints" ); Joint * parent = nullptr; unsigned int i = 0; for( JsonTree::ConstIter joint = jointsJson.begin(); joint != jointsJson.end(); ++joint ) { // Apparently, getKey DOESN't return an index if there is no key? (Even though it says it will in the json.h header...) //JsonTree jJson = jointsJson.getChild(joint->getKey()); JsonTree jJson = jointsJson.getChild(i); Joint * j = readJoint(jJson); joints.push_back(j); i++; } }catch (std::exception ex) { //throw ex; throw std::exception("Invalid File Format. File may be out of date."); } }else{ throw std::exception("File does not exist!"); } return joints; }
void TextureSequenceOptimizer::saveJson( const fs::path& path ) { fs::path jsonPath = path; jsonPath.append("sequence.json"); //save the offsets for each image into a json file JsonTree doc = JsonTree::makeObject(); JsonTree size = JsonTree::makeObject(); size.pushBack(JsonTree("width", mOriOutline.getWidth() )); size.pushBack(JsonTree("height", mOriOutline.getHeight() )); doc.pushBack(size); JsonTree sequence = JsonTree::makeArray("sequence"); for (int i = 0; i < mTrimMaxAreas.size(); i ++) { JsonTree curImage = JsonTree::makeObject(); curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1)); curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1)); curImage.pushBack(JsonTree("fileName", mFileNames[i] )); sequence.pushBack(curImage); } doc.pushBack(sequence); doc.write( jsonPath, JsonTree::WriteOptions()); }
void FaceController::loadFaces() { /* JsonTree faces( doc.getChild( "faces" ) ); facesStoreVector.clear(); for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face ) { FaceObject newFace; vector<Vec2f> points; string name = face->getChild( "texname" ).getValue<string>(); gl::Texture tex; try{ tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name); } catch(...) { continue; } JsonTree datas =JsonTree( face->getChild( "data" )); for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data ) { float x = data->getChild( "x" ).getValue<float>(); float y = data->getChild( "y" ).getValue<float>(); points.push_back(Vec2f(x,y)); } newFace.setPoints(points); newFace.setTexName(name); newFace.setTexture(tex); facesStoreVector.push_back(newFace); } */ facesStoreVector.clear(); string path = getAppPath().string() + JSON_STORAGE_FOLDER; fs::path p(path); for (fs::directory_iterator it(p); it != fs::directory_iterator(); ++it) { if (fs::is_regular_file(*it)) { JsonTree doc; try{ doc = JsonTree(loadFile(getAppPath() / JSON_STORAGE_FOLDER / it->path().filename().string())); } catch(...) { return; } JsonTree faces( doc.getChild( "faces" ) ); for( JsonTree::ConstIter face = faces.begin(); face != faces.end(); ++face ) { FaceObject newFace; vector<Vec2f> points; string name = face->getChild( "texname" ).getValue<string>(); gl::Texture tex; try{ tex = loadImage(getAppPath() /FACE_STORAGE_FOLDER/name); } catch(...) { continue; } JsonTree datas =JsonTree( face->getChild( "data" )); for( JsonTree::ConstIter data = datas.begin(); data != datas.end(); ++data ) { float x = data->getChild( "x" ).getValue<float>(); float y = data->getChild( "y" ).getValue<float>(); points.push_back(Vec2f(x,y)); } newFace.setPoints(points); newFace.setTexName(name); newFace.setTexture(tex); facesStoreVector.push_back(newFace); } } } }
void timeManage::save_shutdown(){ extern ci::fs::path getDocumentPath(); Path = getDocumentPath(); JsonTree ex_json; if(ci::fs::is_regular_file(Path / "Save.json")){ JsonTree ex_json = JsonTree(loadFile(Path / "Save.json")); ex_json = ci::JsonTree::makeObject(("Time")); ex_json.addChild(JsonTree("year",time_object->tm_year)); ex_json.addChild(JsonTree("month",time_object->tm_mon)); ex_json.addChild(JsonTree("day",time_object->tm_mday)); ex_json.addChild(JsonTree("hour",time_object->tm_hour)); ex_json.addChild(JsonTree("minute",time_object->tm_min)); ex_json.addChild(JsonTree("second",time_object->tm_sec)); ex_json.write(Path / "Save.json",JsonTree::WriteOptions().createDocument(true)); } else{ ex_json = ci::JsonTree::makeObject(("Time")); ex_json.addChild(JsonTree("year",time_object->tm_year)); ex_json.addChild(JsonTree("month",time_object->tm_mon)); ex_json.addChild(JsonTree("day",time_object->tm_mday)); ex_json.addChild(JsonTree("hour",time_object->tm_hour)); ex_json.addChild(JsonTree("minute",time_object->tm_min)); ex_json.addChild(JsonTree("second",time_object->tm_sec)); ex_json.write(Path / "Save.json",JsonTree::WriteOptions().createDocument(true)); } }
void ReymentaServerApp::fileDrop(FileDropEvent event) { int index; string ext = ""; // use the last of the dropped files const fs::path &mPath = event.getFile(event.getNumFiles() - 1); string mFile = mPath.string(); int dotIndex = mFile.find_last_of("."); int slashIndex = mFile.find_last_of("\\"); if (dotIndex != std::string::npos && dotIndex > slashIndex) ext = mFile.substr(mFile.find_last_of(".") + 1); index = (int)(event.getX() / (margin + mParameterBag->mPreviewFboWidth + inBetween));// +1; //mBatchass->log(mFile + " dropped, currentSelectedIndex:" + toString(mParameterBag->currentSelectedIndex) + " x: " + toString(event.getX()) + " PreviewFboWidth: " + toString(mParameterBag->mPreviewFboWidth)); if (ext == "wav" || ext == "mp3") { //mAudio->loadWaveFile(mFile); } else if (ext == "png" || ext == "jpg") { if (index < 1) index = 1; if (index > 3) index = 3; //mTextures->loadImageFile(mParameterBag->currentSelectedIndex, mFile); mBatchass->getTexturesRef()->loadImageFile(index, mFile); } else if (ext == "glsl") { if (index < 4) index = 4; int rtn = mBatchass->getShadersRef()->loadPixelFragmentShaderAtIndex(mFile, index); if (rtn > -1 && rtn < mBatchass->getShadersRef()->getCount()) { mParameterBag->controlValues[22] = 1.0f; // TODO send content via websockets /*fs::path fr = mFile; string name = "unknown"; if (mFile.find_last_of("\\") != std::string::npos) name = mFile.substr(mFile.find_last_of("\\") + 1); if (fs::exists(fr)) { std::string fs = loadString(loadFile(mFile)); if (mParameterBag->mOSCEnabled) mOSC->sendOSCStringMessage("/fs", 0, fs, name); }*/ // save thumb //timeline().apply(&mTimer, 1.0f, 1.0f).finishFn([&]{ saveThumb(); }); } } else if (ext == "mov" || ext == "mp4") { /* if (index < 1) index = 1; if (index > 3) index = 3; mBatchass->getTexturesRef()->loadMovieFile(index, mFile);*/ } else if (ext == "fs") { //mShaders->incrementPreviewIndex(); mBatchass->getShadersRef()->loadFragmentShader(mPath); } else if (ext == "xml") { mBatchass->getWarpsRef()->loadWarps(mFile); } else if (ext == "patchjson") { // try loading patch try { JsonTree patchjson; try { patchjson = JsonTree(loadFile(mFile)); mParameterBag->mCurrentFilePath = mFile; } catch (cinder::JsonTree::Exception exception) { CI_LOG_V("patchjsonparser exception " + mFile + ": " + exception.what()); } //Assets int i = 1; // 0 is audio JsonTree jsons = patchjson.getChild("assets"); for (JsonTree::ConstIter jsonElement = jsons.begin(); jsonElement != jsons.end(); ++jsonElement) { string jsonFileName = jsonElement->getChild("filename").getValue<string>(); int channel = jsonElement->getChild("channel").getValue<int>(); if (channel < mBatchass->getTexturesRef()->getTextureCount()) { CI_LOG_V("asset filename: " + jsonFileName); mBatchass->getTexturesRef()->setTexture(channel, jsonFileName); } i++; } } catch (...) { CI_LOG_V("patchjson parsing error: " + mFile); } } else if (ext == "txt") { // try loading shader parts if (mBatchass->getShadersRef()->loadTextFile(mFile)) { } } else if (ext == "") { // try loading image sequence from dir if (index < 1) index = 1; if (index > 3) index = 3; mBatchass->getTexturesRef()->createFromDir(mFile + "/", index); // or create thumbs from shaders mBatchass->getShadersRef()->createThumbsFromDir(mFile + "/"); } }