void JsonTestApp::setup() { JsonTree value( "key", "value" ); console() << value << endl; JsonTree doc( loadResource( RES_JSON ) ); JsonTree musicLibrary( doc.getChild( "library" ) ); JsonTree owner = doc.getChild( "library.owner" ); for( JsonTree::ConstIter item = owner.begin(); item != owner.end(); ++item ) { console() << "Node: " << item->getKey() << " Value: " << item->getValue<string>() << endl; } JsonTree tracks = doc.getChild( "library.albums[0].tracks" ); for( JsonTree::ConstIter track = tracks.begin(); track != tracks.end(); ++track ) { console() << track->getChild( "id" ).getValue<int>() << endl; } for( JsonTree::ConstIter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) { JsonTree track = * trackIt; console() << track["id"].getValue<int>() << endl; } JsonTree firstAlbum = doc.getChild( "library.albums[0]" ); for( JsonTree::Iter child = firstAlbum.begin(); child != firstAlbum.end(); ++child ) { if ( !child->hasChildren() ) { console() << "Key: " << child->getKey() << " Value: " << child->getValue<string>() << endl; } } console() << doc.getChild( "library.owner" ); JsonTree &ownerCity = doc.getChild( "library.owner.city" ); string s = ownerCity.getPath(); console() << "Path: " << ownerCity.getPath() << "\n Value: " << ownerCity.getValue<string>() << std::endl; console() << doc; JsonTree firstTrackCopy = doc.getChild( "library.albums[0].tracks[0].title" ); firstTrackCopy = JsonTree( firstTrackCopy.getKey(), string( "Replacement name" ) ); console() << doc.getChild( "library.albums[0].tracks[0]['title']" ) << std::endl; JsonTree &firstTrackRef = doc.getChild( "library.albums[0].tracks[2].title" ); console() << firstTrackRef.getPath() << std::endl; firstTrackRef = JsonTree( firstTrackRef.getKey(), string( "Replacement name" ) ); console() << doc.getChild( "library.albums[0].tracks[0].title" ) << std::endl; try { JsonTree invalid( "%%%%%%%%" ); } catch ( JsonTree::ExcJsonParserError ex ) { console() << ex.what() << std::endl; } }
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 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 + "/"); } }