rhubarb-lip-sync/src/exporters/XmlExporter.cpp

35 lines
1.3 KiB
C++
Raw Normal View History

2016-11-16 10:35:27 +00:00
#include "XmlExporter.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/version.hpp>
2016-11-16 10:35:27 +00:00
#include "exporterTools.h"
using std::string;
using boost::property_tree::ptree;
void XmlExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) {
2016-11-16 10:35:27 +00:00
ptree tree;
// Add metadata
tree.put("rhubarbResult.metadata.soundFile", inputFilePath.string());
tree.put("rhubarbResult.metadata.duration", formatDuration(animation.getRange().getDuration()));
2016-11-16 10:35:27 +00:00
// Add mouth cues
for (auto& timedShape : dummyShapeIfEmpty(animation, targetShapeSet)) {
2016-11-16 10:35:27 +00:00
ptree& mouthCueElement = tree.add("rhubarbResult.mouthCues.mouthCue", timedShape.getValue());
mouthCueElement.put("<xmlattr>.start", formatDuration(timedShape.getStart()));
mouthCueElement.put("<xmlattr>.end", formatDuration(timedShape.getEnd()));
}
#ifndef BOOST_VERSION //present in version.hpp
#error "Could not detect Boost version."
#endif
2016-11-16 10:35:27 +00:00
#if BOOST_VERSION < 105600 // Support legacy syntax
using writer_setting = boost::property_tree::xml_writer_settings<char>;
#else
using writer_setting = boost::property_tree::xml_writer_settings<string>;
#endif
write_xml(outputStream, tree, writer_setting(' ', 2));
}