diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f6589b..69405b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,8 @@ set_target_properties(utf8proc PROPERTIES FOLDER lib) # Define Rhubarb libraries +include_directories("src") + # ... rhubarb-animation add_library(rhubarb-animation src/animation/animationRules.cpp @@ -261,7 +263,7 @@ add_library(rhubarb-animation src/animation/tweening.cpp src/animation/tweening.h ) -target_include_directories(rhubarb-animation PUBLIC "src/animation") +target_include_directories(rhubarb-animation PRIVATE "src/animation") target_link_libraries(rhubarb-animation rhubarb-core rhubarb-logging @@ -288,7 +290,7 @@ add_library(rhubarb-audio src/audio/waveFileWriting.cpp src/audio/waveFileWriting.h ) -target_include_directories(rhubarb-audio PUBLIC "src/audio") +target_include_directories(rhubarb-audio PRIVATE "src/audio") target_link_libraries(rhubarb-audio webRtc rhubarb-logging @@ -306,7 +308,7 @@ add_library(rhubarb-core src/core/Shape.cpp src/core/Shape.h ) -target_include_directories(rhubarb-core PUBLIC "src/core") +target_include_directories(rhubarb-core PRIVATE "src/core") target_link_libraries(rhubarb-core rhubarb-tools ) @@ -323,7 +325,7 @@ add_library(rhubarb-exporters src/exporters/XmlExporter.cpp src/exporters/XmlExporter.h ) -target_include_directories(rhubarb-exporters PUBLIC "src/exporters") +target_include_directories(rhubarb-exporters PRIVATE "src/exporters") target_link_libraries(rhubarb-exporters rhubarb-animation rhubarb-core @@ -335,7 +337,7 @@ add_library(rhubarb-lib src/lib/rhubarbLib.cpp src/lib/rhubarbLib.h ) -target_include_directories(rhubarb-lib PUBLIC "src/lib") +target_include_directories(rhubarb-lib PRIVATE "src/lib") target_link_libraries(rhubarb-lib rhubarb-animation rhubarb-audio @@ -347,10 +349,20 @@ target_link_libraries(rhubarb-lib # ... rhubarb-logging add_library(rhubarb-logging + src/logging/Entry.cpp + src/logging/Entry.h + src/logging/Formatter.h + src/logging/formatters.cpp + src/logging/formatters.h + src/logging/Level.cpp + src/logging/Level.h src/logging/logging.cpp src/logging/logging.h + src/logging/Sink.h + src/logging/sinks.cpp + src/logging/sinks.h ) -target_include_directories(rhubarb-logging PUBLIC "src/logging") +target_include_directories(rhubarb-logging PRIVATE "src/logging") target_link_libraries(rhubarb-logging rhubarb-tools ) @@ -366,7 +378,7 @@ add_library(rhubarb-recognition src/recognition/tokenization.cpp src/recognition/tokenization.h ) -target_include_directories(rhubarb-recognition PUBLIC "src/recognition") +target_include_directories(rhubarb-recognition PRIVATE "src/recognition") target_link_libraries(rhubarb-recognition flite pocketSphinx @@ -387,7 +399,7 @@ add_library(rhubarb-time src/time/TimeRange.cpp src/time/TimeRange.h ) -target_include_directories(rhubarb-time PUBLIC "src/time") +target_include_directories(rhubarb-time PRIVATE "src/time") target_link_libraries(rhubarb-time cppFormat rhubarb-logging @@ -420,7 +432,7 @@ add_library(rhubarb-tools src/tools/tools.h src/tools/tupleHash.h ) -target_include_directories(rhubarb-tools PUBLIC "src/tools") +target_include_directories(rhubarb-tools PRIVATE "src/tools") target_link_libraries(rhubarb-tools cppFormat whereami @@ -430,11 +442,11 @@ target_link_libraries(rhubarb-tools # Define Rhubarb executable add_executable(rhubarb - src/main.cpp - src/ExportFormat.cpp - src/ExportFormat.h + src/rhubarb/main.cpp + src/rhubarb/ExportFormat.cpp + src/rhubarb/ExportFormat.h ) -target_include_directories(rhubarb PUBLIC "src") +target_include_directories(rhubarb PUBLIC "src/rhubarb") target_link_libraries(rhubarb rhubarb-exporters rhubarb-lib diff --git a/resharper.DotSettings b/resharper.DotSettings new file mode 100644 index 0000000..6af058d --- /dev/null +++ b/resharper.DotSettings @@ -0,0 +1,87 @@ + + False + False + False + False + False + False + False + False + NONE + END_OF_LINE + NEXT_LINE + TOGETHER + True + END_OF_LINE + END_OF_LINE + END_OF_LINE + False + False + True + False + ON_SINGLE_LINE + True + False + END_OF_LINE + CHOP_ALWAYS + <NamingElement Priority="10"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="_" Style="aaBb" /></NamingElement> + <NamingElement Priority="9"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="11"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="PUBLIC"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="1"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <NamingElement Priority="13"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="enumerator" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <NamingElement Priority="2"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="enum" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <NamingElement Priority="15"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="8"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="7"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="6"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="local variable" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="16"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="namespace" /><type Name="namespace alias" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="14"><Descriptor Static="True" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="local variable" /><type Name="struct field" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="5"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="parameter" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="4"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="template parameter" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <NamingElement Priority="17"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="type alias" /><type Name="typedef" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <NamingElement Priority="12"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union member" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement> + <NamingElement Priority="3"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></NamingElement> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + \ No newline at end of file diff --git a/src/animation/ShapeRule.cpp b/src/animation/ShapeRule.cpp index eec8cf3..e9b98c0 100644 --- a/src/animation/ShapeRule.cpp +++ b/src/animation/ShapeRule.cpp @@ -1,6 +1,6 @@ #include "ShapeRule.h" #include -#include "ContinuousTimeline.h" +#include "time/ContinuousTimeline.h" using boost::optional; using boost::adaptors::transformed; diff --git a/src/animation/ShapeRule.h b/src/animation/ShapeRule.h index dc42fd3..acb0a08 100644 --- a/src/animation/ShapeRule.h +++ b/src/animation/ShapeRule.h @@ -1,9 +1,10 @@ #pragma once -#include "Phone.h" +#include "core/Phone.h" #include "animationRules.h" -#include "BoundedTimeline.h" -#include "ContinuousTimeline.h" +#include "time/BoundedTimeline.h" +#include "time/ContinuousTimeline.h" +#include "time/TimeRange.h" struct ShapeRule { ShapeSet shapeSet; diff --git a/src/animation/animationRules.cpp b/src/animation/animationRules.cpp index d9b77b5..4bef2e5 100644 --- a/src/animation/animationRules.cpp +++ b/src/animation/animationRules.cpp @@ -1,8 +1,8 @@ #include "animationRules.h" #include #include "shapeShorthands.h" -#include "array.h" -#include "ContinuousTimeline.h" +#include "tools/array.h" +#include "time/ContinuousTimeline.h" using std::chrono::duration_cast; using boost::algorithm::clamp; diff --git a/src/animation/animationRules.h b/src/animation/animationRules.h index c11ebab..e3a3b36 100644 --- a/src/animation/animationRules.h +++ b/src/animation/animationRules.h @@ -1,9 +1,9 @@ #pragma once #include -#include "Shape.h" -#include "Timeline.h" -#include "Phone.h" +#include "core/Shape.h" +#include "time/Timeline.h" +#include "core/Phone.h" // Returns the basic shape (A-F) that most closely resembles the specified shape. Shape getBasicShape(Shape shape); diff --git a/src/animation/mouthAnimation.cpp b/src/animation/mouthAnimation.cpp index 5ff7855..30add4c 100644 --- a/src/animation/mouthAnimation.cpp +++ b/src/animation/mouthAnimation.cpp @@ -1,5 +1,5 @@ #include "mouthAnimation.h" -#include "timedLogging.h" +#include "time/timedLogging.h" #include "ShapeRule.h" #include "roughAnimation.h" #include "pauseAnimation.h" diff --git a/src/animation/mouthAnimation.h b/src/animation/mouthAnimation.h index 07b0fce..f001d4a 100644 --- a/src/animation/mouthAnimation.h +++ b/src/animation/mouthAnimation.h @@ -1,8 +1,8 @@ #pragma once -#include "Phone.h" -#include "Shape.h" -#include "ContinuousTimeline.h" +#include "core/Phone.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" #include "targetShapeSet.h" JoiningContinuousTimeline animate(const BoundedTimeline& phones, const ShapeSet& targetShapeSet); diff --git a/src/animation/pauseAnimation.h b/src/animation/pauseAnimation.h index eb28bae..9fd6066 100644 --- a/src/animation/pauseAnimation.h +++ b/src/animation/pauseAnimation.h @@ -1,7 +1,7 @@ #pragma once -#include "Shape.h" -#include "ContinuousTimeline.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" // Takes an existing animation and modifies the pauses (X shapes) to look better. JoiningContinuousTimeline animatePauses(const JoiningContinuousTimeline& animation); diff --git a/src/animation/shapeShorthands.h b/src/animation/shapeShorthands.h index 2758cf9..3ebd08c 100644 --- a/src/animation/shapeShorthands.h +++ b/src/animation/shapeShorthands.h @@ -1,6 +1,6 @@ #pragma once -#include "Shape.h" +#include "core/Shape.h" constexpr Shape A = Shape::A; constexpr Shape B = Shape::B; diff --git a/src/animation/staticSegments.cpp b/src/animation/staticSegments.cpp index 2225612..33ca391 100644 --- a/src/animation/staticSegments.cpp +++ b/src/animation/staticSegments.cpp @@ -1,7 +1,7 @@ #include "staticSegments.h" #include #include -#include "nextCombination.h" +#include "tools/nextCombination.h" using std::vector; using boost::optional; diff --git a/src/animation/staticSegments.h b/src/animation/staticSegments.h index cd7f471..5b8ff68 100644 --- a/src/animation/staticSegments.h +++ b/src/animation/staticSegments.h @@ -1,7 +1,7 @@ #pragma once -#include "Shape.h" -#include "ContinuousTimeline.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" #include "ShapeRule.h" #include diff --git a/src/animation/targetShapeSet.h b/src/animation/targetShapeSet.h index 67bc65d..0725114 100644 --- a/src/animation/targetShapeSet.h +++ b/src/animation/targetShapeSet.h @@ -1,6 +1,6 @@ #pragma once -#include "Shape.h" +#include "core/Shape.h" #include "ShapeRule.h" // Returns the closest shape to the specified one that occurs in the target shape set. diff --git a/src/animation/timingOptimization.cpp b/src/animation/timingOptimization.cpp index 3df6ed5..b9ccd55 100644 --- a/src/animation/timingOptimization.cpp +++ b/src/animation/timingOptimization.cpp @@ -1,5 +1,5 @@ #include "timingOptimization.h" -#include "timedLogging.h" +#include "time/timedLogging.h" #include #include #include diff --git a/src/animation/timingOptimization.h b/src/animation/timingOptimization.h index d781c22..e8bb691 100644 --- a/src/animation/timingOptimization.h +++ b/src/animation/timingOptimization.h @@ -1,7 +1,7 @@ #pragma once -#include "Shape.h" -#include "ContinuousTimeline.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" // Changes the timing of an existing animation to reduce jitter and to make sure all shapes register visually. // In some cases, shapes may be omitted. diff --git a/src/animation/tweening.h b/src/animation/tweening.h index cb4073b..0e597f7 100644 --- a/src/animation/tweening.h +++ b/src/animation/tweening.h @@ -1,7 +1,7 @@ #pragma once -#include "Shape.h" -#include "ContinuousTimeline.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" // Takes an existing animation and inserts inbetween shapes for smoother results. JoiningContinuousTimeline insertTweens(const JoiningContinuousTimeline& animation); diff --git a/src/audio/AudioClip.h b/src/audio/AudioClip.h index c242215..4a188b3 100644 --- a/src/audio/AudioClip.h +++ b/src/audio/AudioClip.h @@ -1,9 +1,9 @@ #pragma once #include -#include "TimeRange.h" +#include "time/TimeRange.h" #include -#include "Lazy.h" +#include "tools/Lazy.h" class AudioClip; class SampleIterator; diff --git a/src/audio/WaveFileReader.cpp b/src/audio/WaveFileReader.cpp index 7b2be10..bb63393 100644 --- a/src/audio/WaveFileReader.cpp +++ b/src/audio/WaveFileReader.cpp @@ -2,7 +2,7 @@ #include #include "WaveFileReader.h" #include "ioTools.h" -#include "platformTools.h" +#include "tools/platformTools.h" using std::runtime_error; using fmt::format; diff --git a/src/audio/processing.h b/src/audio/processing.h index cd303b9..8ece651 100644 --- a/src/audio/processing.h +++ b/src/audio/processing.h @@ -3,7 +3,7 @@ #include #include #include "AudioClip.h" -#include "ProgressBar.h" +#include "tools/ProgressBar.h" void process16bitAudioClip(const AudioClip& audioClip, std::function&)> processBuffer, size_t bufferCapacity, ProgressSink& progressSink); void process16bitAudioClip(const AudioClip& audioClip, std::function&)> processBuffer, ProgressSink& progressSink); diff --git a/src/audio/voiceActivityDetection.cpp b/src/audio/voiceActivityDetection.cpp index c4dc62a..f801960 100644 --- a/src/audio/voiceActivityDetection.cpp +++ b/src/audio/voiceActivityDetection.cpp @@ -1,15 +1,15 @@ #include "voiceActivityDetection.h" #include "DcOffset.h" #include "SampleRateConverter.h" -#include "logging.h" -#include "pairs.h" +#include "logging/logging.h" +#include "tools/pairs.h" #include #include #include "processing.h" #include -#include "parallel.h" +#include "tools/parallel.h" #include "AudioSegment.h" -#include "stringTools.h" +#include "tools/stringTools.h" using std::vector; using boost::adaptors::transformed; diff --git a/src/audio/voiceActivityDetection.h b/src/audio/voiceActivityDetection.h index e1aa395..7820680 100644 --- a/src/audio/voiceActivityDetection.h +++ b/src/audio/voiceActivityDetection.h @@ -1,6 +1,6 @@ #pragma once #include "AudioClip.h" -#include -#include +#include "time/BoundedTimeline.h" +#include "tools/ProgressBar.h" JoiningBoundedTimeline detectVoiceActivity(const AudioClip& audioClip, int maxThreadCount, ProgressSink& progressSink); diff --git a/src/core/Phone.h b/src/core/Phone.h index 5c57f9d..63ecee3 100644 --- a/src/core/Phone.h +++ b/src/core/Phone.h @@ -1,6 +1,6 @@ #pragma once -#include "EnumConverter.h" +#include "tools/EnumConverter.h" // Defines a subset of the Arpabet enum class Phone { diff --git a/src/core/Shape.h b/src/core/Shape.h index f192f47..0ee34c5 100644 --- a/src/core/Shape.h +++ b/src/core/Shape.h @@ -1,6 +1,6 @@ #pragma once -#include "EnumConverter.h" +#include "tools/EnumConverter.h" #include // The classic Hanna-Barbera mouth shapes A-F plus the common supplements G-H diff --git a/src/exporters/Exporter.h b/src/exporters/Exporter.h index d09aa80..1be1092 100644 --- a/src/exporters/Exporter.h +++ b/src/exporters/Exporter.h @@ -1,11 +1,26 @@ #pragma once -#include -#include "ContinuousTimeline.h" +#include "core/Shape.h" +#include "time/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..ddd3149 100644 --- a/src/exporters/JsonExporter.cpp +++ b/src/exporters/JsonExporter.cpp @@ -1,50 +1,20 @@ #include "JsonExporter.h" #include "exporterTools.h" -#include +#include "tools/stringTools.h" using std::string; -string escapeJsonString(const string& s) { - // JavaScript uses UTF-16 internally. As a result, character escaping in JSON strings is UTF-16-based. - // Convert string to UTF-16 - std::u16string utf16String; - utf8::utf8to16(s.begin(), s.end(), std::back_inserter(utf16String)); - - string result; - for (char16_t c : utf16String) { - switch (c) { - case '"': result += "\\\""; break; - case '\\': result += "\\\\"; break; - case '\b': result += "\\b"; break; - case '\f': result += "\\f"; break; - case '\n': result += "\\n"; break; - case '\r': result += "\\r"; break; - case '\t': result += "\\t"; break; - default: - { - bool needsEscaping = c < '\x20' || c >= 0x80; - if (needsEscaping) { - result += fmt::format("\\u{0:04x}", c); - } else { - result += static_cast(c); - } - } - } - } - 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..6cdaaae 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); +#include "animation/targetShapeSet.h" +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/exporters/exporterTools.cpp b/src/exporters/exporterTools.cpp index 3b4eb79..51f09b4 100644 --- a/src/exporters/exporterTools.cpp +++ b/src/exporters/exporterTools.cpp @@ -1,5 +1,5 @@ #include "exporterTools.h" -#include "targetShapeSet.h" +#include "animation/targetShapeSet.h" // Makes sure there is at least one mouth shape std::vector> dummyShapeIfEmpty(const JoiningTimeline& animation, const ShapeSet& targetShapeSet) { diff --git a/src/exporters/exporterTools.h b/src/exporters/exporterTools.h index 70fccbb..c121f98 100644 --- a/src/exporters/exporterTools.h +++ b/src/exporters/exporterTools.h @@ -1,7 +1,7 @@ #pragma once -#include "Shape.h" -#include "Timeline.h" +#include "core/Shape.h" +#include "time/Timeline.h" // Makes sure there is at least one mouth shape std::vector> dummyShapeIfEmpty(const JoiningTimeline& animation, const ShapeSet& targetShapeSet); diff --git a/src/lib/rhubarbLib.cpp b/src/lib/rhubarbLib.cpp index 29c25bc..c85283f 100644 --- a/src/lib/rhubarbLib.cpp +++ b/src/lib/rhubarbLib.cpp @@ -1,9 +1,9 @@ #include "rhubarbLib.h" -#include "Phone.h" -#include "phoneRecognition.h" -#include "textFiles.h" -#include "mouthAnimation.h" -#include "WaveFileReader.h" +#include "core/Phone.h" +#include "recognition/phoneRecognition.h" +#include "tools/textFiles.h" +#include "animation/mouthAnimation.h" +#include "audio/WaveFileReader.h" using boost::optional; using std::string; diff --git a/src/lib/rhubarbLib.h b/src/lib/rhubarbLib.h index b4457c9..8663761 100644 --- a/src/lib/rhubarbLib.h +++ b/src/lib/rhubarbLib.h @@ -1,11 +1,11 @@ #pragma once -#include "Shape.h" -#include "ContinuousTimeline.h" -#include "AudioClip.h" -#include "ProgressBar.h" +#include "core/Shape.h" +#include "time/ContinuousTimeline.h" +#include "audio/AudioClip.h" +#include "tools/ProgressBar.h" #include -#include "targetShapeSet.h" +#include "animation/targetShapeSet.h" JoiningContinuousTimeline animateAudioClip( const AudioClip& audioClip, diff --git a/src/logging/Entry.cpp b/src/logging/Entry.cpp new file mode 100644 index 0000000..8772c7b --- /dev/null +++ b/src/logging/Entry.cpp @@ -0,0 +1,38 @@ +#include "Entry.h" + +#include +#include +#include + +using std::lock_guard; +using std::unordered_map; +using std::string; + +namespace logging { + + // Returns an int representing the current thread. + // This used to be a simple thread_local variable, but Xcode doesn't support that yet + int getThreadCounter() { + using thread_id = std::thread::id; + + static std::mutex counterMutex; + lock_guard lock(counterMutex); + + static unordered_map threadCounters; + static int lastThreadId = 0; + thread_id threadId = std::this_thread::get_id(); + if (threadCounters.find(threadId) == threadCounters.end()) { + threadCounters.insert({threadId, ++lastThreadId}); + } + return threadCounters.find(threadId)->second; + } + + Entry::Entry(Level level, const string& message) : + level(level), + message(message) + { + time(×tamp); + this->threadCounter = getThreadCounter(); + } + +} diff --git a/src/logging/Entry.h b/src/logging/Entry.h new file mode 100644 index 0000000..ff4961b --- /dev/null +++ b/src/logging/Entry.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Level.h" + +namespace logging { + + struct Entry { + Entry(Level level, const std::string& message); + + time_t timestamp; + int threadCounter; + Level level; + std::string message; + }; + +} diff --git a/src/logging/Formatter.h b/src/logging/Formatter.h new file mode 100644 index 0000000..9393b66 --- /dev/null +++ b/src/logging/Formatter.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include "Entry.h" + +namespace logging { + + class Formatter { + public: + virtual ~Formatter() = default; + virtual std::string format(const Entry& entry) = 0; + }; + +} diff --git a/src/logging/Level.cpp b/src/logging/Level.cpp new file mode 100644 index 0000000..ce4dfff --- /dev/null +++ b/src/logging/Level.cpp @@ -0,0 +1,35 @@ +#include "Level.h" + +using std::string; + +namespace logging { + + LevelConverter& LevelConverter::get() { + static LevelConverter converter; + return converter; + } + + string LevelConverter::getTypeName() { + return "Level"; + } + + EnumConverter::member_data LevelConverter::getMemberData() { + return member_data{ + {Level::Trace, "Trace"}, + {Level::Debug, "Debug"}, + {Level::Info, "Info"}, + {Level::Warn, "Warn"}, + {Level::Error, "Error"}, + {Level::Fatal, "Fatal"} + }; + } + + std::ostream& operator<<(std::ostream& stream, Level value) { + return LevelConverter::get().write(stream, value); + } + + std::istream& operator >> (std::istream& stream, Level& value) { + return LevelConverter::get().read(stream, value); + } + +} diff --git a/src/logging/Level.h b/src/logging/Level.h new file mode 100644 index 0000000..ebec696 --- /dev/null +++ b/src/logging/Level.h @@ -0,0 +1,29 @@ +#pragma once + +#include "tools/EnumConverter.h" + +namespace logging { + + enum class Level { + Trace, + Debug, + Info, + Warn, + Error, + Fatal, + EndSentinel + }; + + class LevelConverter : public EnumConverter { + public: + static LevelConverter& get(); + protected: + std::string getTypeName() override; + member_data getMemberData() override; + }; + + std::ostream& operator<<(std::ostream& stream, Level value); + + std::istream& operator >> (std::istream& stream, Level& value); + +} diff --git a/src/logging/Sink.h b/src/logging/Sink.h new file mode 100644 index 0000000..bfeafab --- /dev/null +++ b/src/logging/Sink.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Entry.h" + +namespace logging { + + class Sink { + public: + virtual ~Sink() = default; + virtual void receive(const Entry& entry) = 0; + }; + +} diff --git a/src/logging/formatters.cpp b/src/logging/formatters.cpp new file mode 100644 index 0000000..3ccfbcc --- /dev/null +++ b/src/logging/formatters.cpp @@ -0,0 +1,18 @@ +#include "formatters.h" +#include +#include "Entry.h" +#include "tools/tools.h" + +using std::string; + +namespace logging { + + string SimpleConsoleFormatter::format(const Entry& entry) { + return fmt::format("[{0}] {1}", entry.level, entry.message); + } + + string SimpleFileFormatter::format(const Entry& entry) { + return fmt::format("[{0}] {1} {2}", formatTime(entry.timestamp, "%F %H:%M:%S"), entry.threadCounter, consoleFormatter.format(entry)); + } + +} diff --git a/src/logging/formatters.h b/src/logging/formatters.h new file mode 100644 index 0000000..ca68fd2 --- /dev/null +++ b/src/logging/formatters.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Formatter.h" + +namespace logging { + + class SimpleConsoleFormatter : public Formatter { + public: + std::string format(const Entry& entry) override; + }; + + class SimpleFileFormatter : public Formatter { + public: + std::string format(const Entry& entry) override; + private: + SimpleConsoleFormatter consoleFormatter; + }; + +} diff --git a/src/logging/logging.cpp b/src/logging/logging.cpp index f5b95fd..067a3fe 100644 --- a/src/logging/logging.cpp +++ b/src/logging/logging.cpp @@ -1,130 +1,13 @@ #include "logging.h" -#include -#include -#include -#include -#include +#include "tools/tools.h" +#include +#include "Entry.h" using namespace logging; using std::string; using std::vector; using std::shared_ptr; using std::lock_guard; -using std::unordered_map; - -LevelConverter& LevelConverter::get() { - static LevelConverter converter; - return converter; -} - -string LevelConverter::getTypeName() { - return "Level"; -} - -EnumConverter::member_data LevelConverter::getMemberData() { - return member_data { - { Level::Trace, "Trace" }, - { Level::Debug, "Debug" }, - { Level::Info, "Info" }, - { Level::Warn, "Warn" }, - { Level::Error, "Error" }, - { Level::Fatal, "Fatal" } - }; -} - -std::ostream& logging::operator<<(std::ostream& stream, Level value) { - return LevelConverter::get().write(stream, value); -} - -std::istream& logging::operator>>(std::istream& stream, Level& value) { - return LevelConverter::get().read(stream, value); -} - -// Returns an int representing the current thread. -// This used to be a simple thread_local variable, but Xcode doesn't support that yet -int getThreadCounter() { - using thread_id = std::thread::id; - - static std::mutex counterMutex; - lock_guard lock(counterMutex); - - static unordered_map threadCounters; - static int lastThreadId = 0; - thread_id threadId = std::this_thread::get_id(); - if (threadCounters.find(threadId) == threadCounters.end()) { - threadCounters.insert({threadId, ++lastThreadId}); - } - return threadCounters.find(threadId)->second; -} - -Entry::Entry(Level level, const string& message) : - level(level), - message(message) -{ - time(×tamp); - this->threadCounter = getThreadCounter(); -} - -string SimpleConsoleFormatter::format(const Entry& entry) { - return fmt::format("[{0}] {1}", entry.level, entry.message); -} - -string SimpleFileFormatter::format(const Entry& entry) { - return fmt::format("[{0}] {1} {2}", formatTime(entry.timestamp, "%F %H:%M:%S"), entry.threadCounter, consoleFormatter.format(entry)); -} - -LevelFilter::LevelFilter(shared_ptr innerSink, Level minLevel) : - innerSink(innerSink), - minLevel(minLevel) -{} - -void LevelFilter::receive(const Entry& entry) { - if (entry.level >= minLevel) { - innerSink->receive(entry); - } -} - -StreamSink::StreamSink(shared_ptr stream, shared_ptr formatter) : - stream(stream), - formatter(formatter) -{} - -void StreamSink::receive(const Entry& entry) { - string line = formatter->format(entry); - *stream << line << std::endl; -} - -StdErrSink::StdErrSink(shared_ptr formatter) : - StreamSink(std::shared_ptr(&std::cerr, [](void*) {}), formatter) -{} - -PausableSink::PausableSink(shared_ptr innerSink) : - innerSink(innerSink) -{} - -void PausableSink::receive(const Entry& entry) { - lock_guard lock(mutex); - if (isPaused) { - buffer.push_back(entry); - } else { - innerSink->receive(entry); - } -} - -void PausableSink::pause() { - lock_guard lock(mutex); - isPaused = true; - -} - -void PausableSink::resume() { - lock_guard lock(mutex); - isPaused = false; - for (const Entry& entry : buffer) { - innerSink->receive(entry); - } - buffer.clear(); -} std::mutex& getLogMutex() { static std::mutex mutex; diff --git a/src/logging/logging.h b/src/logging/logging.h index 44d6240..1b65778 100644 --- a/src/logging/logging.h +++ b/src/logging/logging.h @@ -1,103 +1,11 @@ #pragma once -#include -#include -#include "tools.h" -#include "EnumConverter.h" +#include "tools/EnumConverter.h" +#include "Sink.h" +#include "Level.h" namespace logging { - enum class Level { - Trace, - Debug, - Info, - Warn, - Error, - Fatal, - EndSentinel - }; - - class LevelConverter : public EnumConverter { - public: - static LevelConverter& get(); - protected: - std::string getTypeName() override; - member_data getMemberData() override; - }; - - std::ostream& operator<<(std::ostream& stream, Level value); - - std::istream& operator>>(std::istream& stream, Level& value); - - struct Entry { - Entry(Level level, const std::string& message); - - time_t timestamp; - int threadCounter; - Level level; - std::string message; - }; - - class Formatter { - public: - virtual ~Formatter() = default; - virtual std::string format(const Entry& entry) = 0; - }; - - class SimpleConsoleFormatter : public Formatter { - public: - std::string format(const Entry& entry) override; - }; - - class SimpleFileFormatter : public Formatter { - public: - std::string format(const Entry& entry) override; - private: - SimpleConsoleFormatter consoleFormatter; - }; - - class Sink { - public: - virtual ~Sink() = default; - virtual void receive(const Entry& entry) = 0; - }; - - class LevelFilter : public Sink { - public: - LevelFilter(std::shared_ptr innerSink, Level minLevel); - void receive(const Entry& entry) override; - private: - std::shared_ptr innerSink; - Level minLevel; - }; - - class StreamSink : public Sink { - public: - StreamSink(std::shared_ptr stream, std::shared_ptr formatter); - void receive(const Entry& entry) override; - private: - std::shared_ptr stream; - std::shared_ptr formatter; - }; - - class StdErrSink : public StreamSink { - public: - explicit StdErrSink(std::shared_ptr formatter); - }; - - class PausableSink : public Sink { - public: - explicit PausableSink(std::shared_ptr innerSink); - void receive(const Entry& entry) override; - void pause(); - void resume(); - private: - std::shared_ptr innerSink; - std::vector buffer; - std::mutex mutex; - bool isPaused = false; - }; - void addSink(std::shared_ptr sink); void log(Level level, const std::string& message); diff --git a/src/logging/sinks.cpp b/src/logging/sinks.cpp new file mode 100644 index 0000000..a2be5cf --- /dev/null +++ b/src/logging/sinks.cpp @@ -0,0 +1,64 @@ +#include "sinks.h" +#include +#include "Entry.h" + +using std::string; +using std::lock_guard; +using std::shared_ptr; + +namespace logging { + + LevelFilter::LevelFilter(shared_ptr innerSink, Level minLevel) : + innerSink(innerSink), + minLevel(minLevel) + {} + + void LevelFilter::receive(const Entry& entry) { + if (entry.level >= minLevel) { + innerSink->receive(entry); + } + } + + StreamSink::StreamSink(shared_ptr stream, shared_ptr formatter) : + stream(stream), + formatter(formatter) + {} + + void StreamSink::receive(const Entry& entry) { + string line = formatter->format(entry); + *stream << line << std::endl; + } + + StdErrSink::StdErrSink(shared_ptr formatter) : + StreamSink(std::shared_ptr(&std::cerr, [](void*) {}), formatter) + {} + + PausableSink::PausableSink(shared_ptr innerSink) : + innerSink(innerSink) + {} + + void PausableSink::receive(const Entry& entry) { + lock_guard lock(mutex); + if (isPaused) { + buffer.push_back(entry); + } else { + innerSink->receive(entry); + } + } + + void PausableSink::pause() { + lock_guard lock(mutex); + isPaused = true; + + } + + void PausableSink::resume() { + lock_guard lock(mutex); + isPaused = false; + for (const Entry& entry : buffer) { + innerSink->receive(entry); + } + buffer.clear(); + } + +} diff --git a/src/logging/sinks.h b/src/logging/sinks.h new file mode 100644 index 0000000..460be40 --- /dev/null +++ b/src/logging/sinks.h @@ -0,0 +1,48 @@ +#pragma once + +#include "Sink.h" +#include +#include "Formatter.h" +#include +#include + +namespace logging { + enum class Level; + + class LevelFilter : public Sink { + public: + LevelFilter(std::shared_ptr innerSink, Level minLevel); + void receive(const Entry& entry) override; + private: + std::shared_ptr innerSink; + Level minLevel; + }; + + class StreamSink : public Sink { + public: + StreamSink(std::shared_ptr stream, std::shared_ptr formatter); + void receive(const Entry& entry) override; + private: + std::shared_ptr stream; + std::shared_ptr formatter; + }; + + class StdErrSink : public StreamSink { + public: + explicit StdErrSink(std::shared_ptr formatter); + }; + + class PausableSink : public Sink { + public: + explicit PausableSink(std::shared_ptr innerSink); + void receive(const Entry& entry) override; + void pause(); + void resume(); + private: + std::shared_ptr innerSink; + std::vector buffer; + std::mutex mutex; + bool isPaused = false; + }; + +} diff --git a/src/recognition/g2p.cpp b/src/recognition/g2p.cpp index eace1ec..6299061 100644 --- a/src/recognition/g2p.cpp +++ b/src/recognition/g2p.cpp @@ -1,7 +1,7 @@ #include #include -#include "stringTools.h" -#include "logging.h" +#include "tools/stringTools.h" +#include "logging/logging.h" using std::vector; using std::wstring; diff --git a/src/recognition/g2p.h b/src/recognition/g2p.h index 250358c..d2f5d17 100644 --- a/src/recognition/g2p.h +++ b/src/recognition/g2p.h @@ -1,6 +1,6 @@ #pragma once #include -#include "Phone.h" +#include "core/Phone.h" std::vector wordToPhones(const std::string& word); diff --git a/src/recognition/languageModels.cpp b/src/recognition/languageModels.cpp index c7b4a2c..6ccb303 100644 --- a/src/recognition/languageModels.cpp +++ b/src/recognition/languageModels.cpp @@ -4,9 +4,9 @@ #include #include #include -#include "platformTools.h" +#include "tools/platformTools.h" #include -#include "appInfo.h" +#include "core/appInfo.h" #include #include diff --git a/src/recognition/languageModels.h b/src/recognition/languageModels.h index a260c42..18df80c 100644 --- a/src/recognition/languageModels.h +++ b/src/recognition/languageModels.h @@ -1,7 +1,7 @@ #pragma once #include -#include "tools.h" +#include "tools/tools.h" extern "C" { #include diff --git a/src/recognition/phoneRecognition.cpp b/src/recognition/phoneRecognition.cpp index f56201f..5139596 100644 --- a/src/recognition/phoneRecognition.cpp +++ b/src/recognition/phoneRecognition.cpp @@ -1,26 +1,26 @@ #include #include "phoneRecognition.h" -#include "SampleRateConverter.h" -#include "platformTools.h" -#include "tools.h" +#include "audio/SampleRateConverter.h" +#include "tools/platformTools.h" +#include "tools/tools.h" #include #include #include #include -#include -#include "DcOffset.h" -#include "Timeline.h" -#include "voiceActivityDetection.h" -#include "AudioSegment.h" +#include "logging/logging.h" +#include "audio/DcOffset.h" +#include "time/Timeline.h" +#include "audio/voiceActivityDetection.h" +#include "audio/AudioSegment.h" #include "languageModels.h" #include "tokenization.h" #include "g2p.h" -#include "ContinuousTimeline.h" -#include "processing.h" -#include "parallel.h" +#include "time/ContinuousTimeline.h" +#include "audio/processing.h" +#include "tools/parallel.h" #include -#include "ObjectPool.h" -#include "timedLogging.h" +#include "tools/ObjectPool.h" +#include "time/timedLogging.h" extern "C" { #include diff --git a/src/recognition/phoneRecognition.h b/src/recognition/phoneRecognition.h index 61e94ee..2e66305 100644 --- a/src/recognition/phoneRecognition.h +++ b/src/recognition/phoneRecognition.h @@ -1,9 +1,9 @@ #pragma once -#include "AudioClip.h" -#include "Phone.h" -#include "ProgressBar.h" -#include "BoundedTimeline.h" +#include "audio/AudioClip.h" +#include "core/Phone.h" +#include "tools/ProgressBar.h" +#include "time/BoundedTimeline.h" BoundedTimeline recognizePhones( const AudioClip& audioClip, diff --git a/src/recognition/tokenization.cpp b/src/recognition/tokenization.cpp index 2fb7741..edef618 100644 --- a/src/recognition/tokenization.cpp +++ b/src/recognition/tokenization.cpp @@ -1,6 +1,6 @@ #include "tokenization.h" -#include "tools.h" -#include "stringTools.h" +#include "tools/tools.h" +#include "tools/stringTools.h" #include extern "C" { diff --git a/src/ExportFormat.cpp b/src/rhubarb/ExportFormat.cpp similarity index 100% rename from src/ExportFormat.cpp rename to src/rhubarb/ExportFormat.cpp diff --git a/src/ExportFormat.h b/src/rhubarb/ExportFormat.h similarity index 92% rename from src/ExportFormat.h rename to src/rhubarb/ExportFormat.h index d3801f1..1ff9392 100644 --- a/src/ExportFormat.h +++ b/src/rhubarb/ExportFormat.h @@ -1,6 +1,6 @@ #pragma once -#include "EnumConverter.h" +#include "tools/EnumConverter.h" enum class ExportFormat { Tsv, diff --git a/src/main.cpp b/src/rhubarb/main.cpp similarity index 90% rename from src/main.cpp rename to src/rhubarb/main.cpp index e709181..8d2e7e9 100644 --- a/src/main.cpp +++ b/src/rhubarb/main.cpp @@ -1,30 +1,32 @@ #include #include #include -#include "appInfo.h" -#include "NiceCmdLineOutput.h" -#include "ProgressBar.h" -#include "logging.h" +#include "core/appInfo.h" +#include "tools/NiceCmdLineOutput.h" +#include "tools/ProgressBar.h" +#include "logging/logging.h" +#include "logging/sinks.h" +#include "logging/formatters.h" #include -#include "Exporter.h" -#include "ContinuousTimeline.h" +#include "exporters/Exporter.h" +#include "time/ContinuousTimeline.h" #include -#include "stringTools.h" +#include "tools/stringTools.h" #include #include -#include "parallel.h" -#include "exceptions.h" -#include "textFiles.h" -#include "rhubarbLib.h" +#include "tools/parallel.h" +#include "tools/exceptions.h" +#include "tools/textFiles.h" +#include "lib/rhubarbLib.h" #include "ExportFormat.h" -#include "TsvExporter.h" -#include "XmlExporter.h" -#include "JsonExporter.h" +#include "exporters/TsvExporter.h" +#include "exporters/XmlExporter.h" +#include "exporters/JsonExporter.h" #include #include -#include "targetShapeSet.h" +#include "animation/targetShapeSet.h" #include -#include "platformTools.h" +#include "tools/platformTools.h" using std::exception; using std::string; @@ -184,7 +186,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 (...) { diff --git a/src/time/Timed.h b/src/time/Timed.h index f18bf05..04add08 100644 --- a/src/time/Timed.h +++ b/src/time/Timed.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "time/TimeRange.h" #include template diff --git a/src/time/Timeline.h b/src/time/Timeline.h index 6473c5d..88b9179 100644 --- a/src/time/Timeline.h +++ b/src/time/Timeline.h @@ -3,7 +3,7 @@ #include #include #include -#include "tools.h" +#include "tools/tools.h" enum class FindMode { SampleLeft, diff --git a/src/time/timedLogging.h b/src/time/timedLogging.h index 947f4fe..90407af 100644 --- a/src/time/timedLogging.h +++ b/src/time/timedLogging.h @@ -3,7 +3,7 @@ #include "centiseconds.h" #include "TimeRange.h" #include "Timed.h" -#include "logging.h" +#include "logging/logging.h" template void logTimedEvent(const std::string& eventName, const Timed timedValue) { diff --git a/src/tools/stringTools.cpp b/src/tools/stringTools.cpp index 5d27bbe..a223d4e 100644 --- a/src/tools/stringTools.cpp +++ b/src/tools/stringTools.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using std::string; using std::wstring; @@ -157,3 +158,33 @@ string normalizeUnicode(const string s, NormalizationOptions options) { free(result); return resultString; } + +string escapeJsonString(const string& s) { + // JavaScript uses UTF-16 internally. As a result, character escaping in JSON strings is UTF-16-based. + // Convert string to UTF-16 + std::u16string utf16String; + utf8::utf8to16(s.begin(), s.end(), std::back_inserter(utf16String)); + + string result; + for (char16_t c : utf16String) { + switch (c) { + case '"': result += "\\\""; break; + case '\\': result += "\\\\"; break; + case '\b': result += "\\b"; break; + case '\f': result += "\\f"; break; + case '\n': result += "\\n"; break; + case '\r': result += "\\r"; break; + case '\t': result += "\\t"; break; + default: + { + bool needsEscaping = c < '\x20' || c >= 0x80; + if (needsEscaping) { + result += fmt::format("\\u{0:04x}", c); + } else { + result += static_cast(c); + } + } + } + } + return result; +} diff --git a/src/tools/stringTools.h b/src/tools/stringTools.h index 2964de1..f1bd933 100644 --- a/src/tools/stringTools.h +++ b/src/tools/stringTools.h @@ -48,3 +48,5 @@ std::string join(T range, const std::string separator) { } return result; } + +std::string escapeJsonString(const std::string& s); \ No newline at end of file diff --git a/tests/BoundedTimelineTests.cpp b/tests/BoundedTimelineTests.cpp index a24f568..3a038de 100644 --- a/tests/BoundedTimelineTests.cpp +++ b/tests/BoundedTimelineTests.cpp @@ -1,5 +1,5 @@ #include -#include "BoundedTimeline.h" +#include "time/BoundedTimeline.h" using namespace testing; using std::vector; diff --git a/tests/ContinuousTimelineTests.cpp b/tests/ContinuousTimelineTests.cpp index e55cdcd..e1d4806 100644 --- a/tests/ContinuousTimelineTests.cpp +++ b/tests/ContinuousTimelineTests.cpp @@ -1,5 +1,5 @@ #include -#include "ContinuousTimeline.h" +#include "time/ContinuousTimeline.h" using namespace testing; using std::vector; diff --git a/tests/LazyTests.cpp b/tests/LazyTests.cpp index f3f1aac..dd17023 100644 --- a/tests/LazyTests.cpp +++ b/tests/LazyTests.cpp @@ -1,5 +1,5 @@ #include -#include "Lazy.h" +#include "tools/Lazy.h" using namespace testing; using std::make_unique; diff --git a/tests/TimelineTests.cpp b/tests/TimelineTests.cpp index 39724f9..ab6e807 100644 --- a/tests/TimelineTests.cpp +++ b/tests/TimelineTests.cpp @@ -1,5 +1,5 @@ #include -#include "Timeline.h" +#include "time/Timeline.h" #include #include diff --git a/tests/g2pTests.cpp b/tests/g2pTests.cpp index d992d4e..e246785 100644 --- a/tests/g2pTests.cpp +++ b/tests/g2pTests.cpp @@ -1,5 +1,5 @@ #include -#include "g2p.h" +#include "recognition/g2p.h" using namespace testing; using std::vector; diff --git a/tests/pairsTests.cpp b/tests/pairsTests.cpp index 1037225..b2eb27e 100644 --- a/tests/pairsTests.cpp +++ b/tests/pairsTests.cpp @@ -1,5 +1,5 @@ #include -#include "pairs.h" +#include "tools/pairs.h" using namespace testing; using std::vector; diff --git a/tests/stringToolsTests.cpp b/tests/stringToolsTests.cpp index 7f58971..722de8b 100644 --- a/tests/stringToolsTests.cpp +++ b/tests/stringToolsTests.cpp @@ -1,5 +1,5 @@ #include -#include "stringTools.h" +#include "tools/stringTools.h" using namespace testing; using std::string; diff --git a/tests/tokenizationTests.cpp b/tests/tokenizationTests.cpp index 577c6bb..5714706 100644 --- a/tests/tokenizationTests.cpp +++ b/tests/tokenizationTests.cpp @@ -1,5 +1,5 @@ #include -#include "tokenization.h" +#include "recognition/tokenization.h" #include #include #include