Created
May 15, 2017 17:06
-
-
Save arturoc/b949f4bac6f1d993b07835f3c0dc920f to your computer and use it in GitHub Desktop.
custom save gui/timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listeners.push_back(gui.savePressedE.newListener([this]{ | |
auto saveTo = ofSystemSaveDialog(ofGetTimestampString() + ".json", "save settings"); | |
if(saveTo.bSuccess){ | |
auto path = std::filesystem::path(saveTo.getPath()); | |
auto folder = path.parent_path(); | |
auto basename = path.stem().filename().string(); | |
auto extension = ofToLower(path.extension().string()); | |
auto timelineDir = (folder / (basename + "_timeline")).string(); | |
if(extension == ".xml"){ | |
ofXml xml; | |
if(std::filesystem::exists(path)){ | |
xml.load(path); | |
} | |
ofSerialize(xml, gui.getParameter()); | |
timeline.saveTracksToFolder(timelineDir); | |
timeline.saveStructure(timelineDir); | |
xml.save(path); | |
}else if(extension == ".json"){ | |
ofJson json = ofLoadJson(path); | |
ofSerialize(json, gui.getParameter()); | |
timeline.saveTracksToFolder(timelineDir); | |
timeline.saveStructure(timelineDir); | |
ofSavePrettyJson(path, json); | |
}else{ | |
ofLogError("ofxGui") << extension << " not recognized, only .xml and .json supported by now"; | |
} | |
} | |
return true; | |
})); | |
listeners.push_back(gui.loadPressedE.newListener([this]{ | |
auto loadFrom = ofSystemLoadDialog("load settings"); | |
if(loadFrom.bSuccess){ | |
auto path = std::filesystem::path(loadFrom.getPath()); | |
auto folder = path.parent_path(); | |
auto basename = path.stem().filename().string(); | |
auto extension = ofToLower(path.extension().string()); | |
auto timelineDir = (folder / (basename + "_timeline")).string(); | |
if(extension == ".xml"){ | |
ofXml xml; | |
xml.load(path); | |
ofDeserialize(xml, gui.getParameter()); | |
timeline.loadStructure(timelineDir); | |
timeline.loadTracksFromFolder(timelineDir); | |
timeline.setOffset(glm::vec2(0, ofGetHeight() - timeline.getHeight())); | |
gui.refreshTimelined(&timeline); | |
}else | |
if(extension == ".json"){ | |
ofJson json; | |
ofFile jsonFile(path); | |
jsonFile >> json; | |
ofDeserialize(json, gui.getParameter()); | |
timeline.loadStructure(timelineDir); | |
timeline.loadTracksFromFolder(timelineDir); | |
timeline.setOffset(glm::vec2(0, ofGetHeight() - timeline.getHeight())); | |
gui.refreshTimelined(&timeline); | |
}else{ | |
ofLogError("ofxGui") << extension << " not recognized, only .xml and .json supported by now"; | |
} | |
resetWavelengths(); | |
} | |
return true; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment