From d705a0c0eeb39a74c4dbc07b3a8f4cf2bdf45cc7 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Tue, 15 Aug 2017 21:52:08 +0200 Subject: [PATCH] Introduced parameter class ExporterInput --- src/exporters/Exporter.h | 17 ++++++++++++++++- src/exporters/JsonExporter.cpp | 8 ++++---- src/exporters/JsonExporter.h | 2 +- src/exporters/TsvExporter.cpp | 12 +++++++----- src/exporters/TsvExporter.h | 2 +- src/exporters/XmlExporter.cpp | 10 +++++----- src/exporters/XmlExporter.h | 2 +- src/main.cpp | 3 ++- 8 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/exporters/Exporter.h b/src/exporters/Exporter.h index d09aa80..e0ce699 100644 --- a/src/exporters/Exporter.h +++ b/src/exporters/Exporter.h @@ -4,8 +4,23 @@ #include "ContinuousTimeline.h" #include +class ExporterInput { +public: + ExporterInput( + const boost::filesystem::path& inputFilePath, + const JoiningContinuousTimeline& animation, + const ShapeSet& targetShapeSet) : + inputFilePath(inputFilePath), + animation(animation), + targetShapeSet(targetShapeSet) {} + + boost::filesystem::path inputFilePath; + JoiningContinuousTimeline animation; + ShapeSet targetShapeSet; +}; + class Exporter { public: virtual ~Exporter() {} - virtual void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) = 0; + virtual void exportAnimation(const ExporterInput& input, std::ostream& outputStream) = 0; }; diff --git a/src/exporters/JsonExporter.cpp b/src/exporters/JsonExporter.cpp index b228d31..5977643 100644 --- a/src/exporters/JsonExporter.cpp +++ b/src/exporters/JsonExporter.cpp @@ -34,17 +34,17 @@ string escapeJsonString(const string& s) { return result; } -void JsonExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& 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()) diff --git a/src/exporters/JsonExporter.h b/src/exporters/JsonExporter.h index 2782129..5847526 100644 --- a/src/exporters/JsonExporter.h +++ b/src/exporters/JsonExporter.h @@ -4,5 +4,5 @@ class JsonExporter : public Exporter { public: - void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override; + void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override; }; diff --git a/src/exporters/TsvExporter.cpp b/src/exporters/TsvExporter.cpp index 543d8fa..754d000 100644 --- a/src/exporters/TsvExporter.cpp +++ b/src/exporters/TsvExporter.cpp @@ -1,14 +1,16 @@ #include "TsvExporter.h" #include "targetShapeSet.h" -void TsvExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& 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"; } diff --git a/src/exporters/TsvExporter.h b/src/exporters/TsvExporter.h index fd226b9..c42c3fa 100644 --- a/src/exporters/TsvExporter.h +++ b/src/exporters/TsvExporter.h @@ -4,6 +4,6 @@ class TsvExporter : public Exporter { public: - void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override; + void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override; }; diff --git a/src/exporters/XmlExporter.cpp b/src/exporters/XmlExporter.cpp index 270716f..73b172c 100644 --- a/src/exporters/XmlExporter.cpp +++ b/src/exporters/XmlExporter.cpp @@ -7,22 +7,22 @@ using std::string; using boost::property_tree::ptree; -void XmlExporter::exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& 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(".start", formatDuration(timedShape.getStart())); mouthCueElement.put(".end", formatDuration(timedShape.getEnd())); } #ifndef BOOST_VERSION //present in version.hpp - #error "Could not detect Boost version." + #error "Could not detect Boost version." #endif #if BOOST_VERSION < 105600 // Support legacy syntax diff --git a/src/exporters/XmlExporter.h b/src/exporters/XmlExporter.h index 81aa939..0ecc96a 100644 --- a/src/exporters/XmlExporter.h +++ b/src/exporters/XmlExporter.h @@ -4,5 +4,5 @@ class XmlExporter : public Exporter { public: - void exportAnimation(const boost::filesystem::path& inputFilePath, const JoiningContinuousTimeline& animation, const ShapeSet& targetShapeSet, std::ostream& outputStream) override; + void exportAnimation(const ExporterInput& input, std::ostream& outputStream) override; }; diff --git a/src/main.cpp b/src/main.cpp index e709181..6bf0d6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 (...) {