Introduced parameter class ExporterInput

This commit is contained in:
Daniel Wolf 2017-08-15 21:52:08 +02:00
parent 4de8f3d18e
commit d705a0c0ee
8 changed files with 37 additions and 19 deletions

View File

@ -4,8 +4,23 @@
#include "ContinuousTimeline.h"
#include <boost/filesystem/path.hpp>
class ExporterInput {
public:
ExporterInput(
const boost::filesystem::path& inputFilePath,
const JoiningContinuousTimeline<Shape>& animation,
const ShapeSet& targetShapeSet) :
inputFilePath(inputFilePath),
animation(animation),
targetShapeSet(targetShapeSet) {}
boost::filesystem::path inputFilePath;
JoiningContinuousTimeline<Shape> animation;
ShapeSet targetShapeSet;
};
class Exporter {
public:
virtual ~Exporter() {}
virtual void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) = 0;
virtual void exportAnimation(const ExporterInput& input, std::ostream& outputStream) = 0;
};

View File

@ -34,17 +34,17 @@ string escapeJsonString(const string& s) {
return result;
}
void JsonExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) {
void JsonExporter::exportAnimation(const ExporterInput& input, std::ostream& outputStream) {
// Export as JSON.
// I'm not using a library because the code is short enough without one and it lets me control the formatting.
outputStream << "{\n";
outputStream << " \"metadata\": {\n";
outputStream << " \"soundFile\": \"" << escapeJsonString(inputFilePath.string()) << "\",\n";
outputStream << " \"duration\": " << formatDuration(animation.getRange().getDuration()) << "\n";
outputStream << " \"soundFile\": \"" << escapeJsonString(input.inputFilePath.string()) << "\",\n";
outputStream << " \"duration\": " << formatDuration(input.animation.getRange().getDuration()) << "\n";
outputStream << " },\n";
outputStream << " \"mouthCues\": [\n";
bool isFirst = true;
for (auto& timedShape : dummyShapeIfEmpty(animation, targetShapeSet)) {
for (auto& timedShape : dummyShapeIfEmpty(input.animation, input.targetShapeSet)) {
if (!isFirst) outputStream << ",\n";
isFirst = false;
outputStream << " { \"start\": " << formatDuration(timedShape.getStart())

View File

@ -4,5 +4,5 @@
class JsonExporter : public Exporter {
public:
void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override;
void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override;
};

View File

@ -1,14 +1,16 @@
#include "TsvExporter.h"
#include "targetShapeSet.h"
void TsvExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) {
UNUSED(inputFilePath);
void TsvExporter::exportAnimation(const ExporterInput& input, std::ostream& outputStream) {
// Output shapes with start times
for (auto& timedShape : animation) {
for (auto& timedShape : input.animation) {
outputStream << formatDuration(timedShape.getStart()) << "\t" << timedShape.getValue() << "\n";
}
// Output closed mouth with end time
outputStream << formatDuration(animation.getRange().getEnd()) << "\t" << convertToTargetShapeSet(Shape::X, targetShapeSet) << "\n";
outputStream
<< formatDuration(input.animation.getRange().getEnd())
<< "\t"
<< convertToTargetShapeSet(Shape::X, input.targetShapeSet)
<< "\n";
}

View File

@ -4,6 +4,6 @@
class TsvExporter : public Exporter {
public:
void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override;
void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override;
};

View File

@ -7,15 +7,15 @@
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) {
void XmlExporter::exportAnimation(const ExporterInput& input, std::ostream& outputStream) {
ptree tree;
// Add metadata
tree.put("rhubarbResult.metadata.soundFile", inputFilePath.string());
tree.put("rhubarbResult.metadata.duration", formatDuration(animation.getRange().getDuration()));
tree.put("rhubarbResult.metadata.soundFile", input.inputFilePath.string());
tree.put("rhubarbResult.metadata.duration", formatDuration(input.animation.getRange().getDuration()));
// Add mouth cues
for (auto& timedShape : dummyShapeIfEmpty(animation, targetShapeSet)) {
for (auto& timedShape : dummyShapeIfEmpty(input.animation, input.targetShapeSet)) {
ptree& mouthCueElement = tree.add("rhubarbResult.mouthCues.mouthCue", timedShape.getValue());
mouthCueElement.put("<xmlattr>.start", formatDuration(timedShape.getStart()));
mouthCueElement.put("<xmlattr>.end", formatDuration(timedShape.getEnd()));

View File

@ -4,5 +4,5 @@
class XmlExporter : public Exporter {
public:
void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline<Shape>& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override;
void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override;
};

View File

@ -184,7 +184,8 @@ int main(int platformArgc, char *platformArgv[]) {
outputFile = boost::in_place(outputFileName.getValue());
outputFile->exceptions(std::ifstream::failbit | std::ifstream::badbit);
}
exporter->exportAnimation(inputFilePath, animation, targetShapeSet, outputFile ? *outputFile : std::cout);
ExporterInput exporterInput = ExporterInput(inputFilePath, animation, targetShapeSet);
exporter->exportAnimation(exporterInput, outputFile ? *outputFile : std::cout);
logging::info("Exiting application normally.");
} catch (...) {