From e4b5b395048a403b6d416df6f131212996d377b8 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Tue, 1 Dec 2015 22:28:29 +0100 Subject: [PATCH] Fixed corner cases Handling silences and last mouth shape --- src/Phone.cpp | 1 + src/mouth_animation.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Phone.cpp b/src/Phone.cpp index 82d7792..a348764 100644 --- a/src/Phone.cpp +++ b/src/Phone.cpp @@ -25,6 +25,7 @@ boost::bimap phonesByName = makeBimap({ }); Phone stringToPhone(const string& s) { + if (s == "SIL") return Phone::None; auto it = phonesByName.left.find(s); return (it != phonesByName.left.end()) ? it->second : Phone::Unknown; } diff --git a/src/mouth_animation.cpp b/src/mouth_animation.cpp index 81e998c..87b73d6 100644 --- a/src/mouth_animation.cpp +++ b/src/mouth_animation.cpp @@ -1,4 +1,5 @@ #include "mouth_animation.h" +#include using std::map; @@ -69,10 +70,10 @@ Shape getShape(Phone phone) { map animate(const map &phones) { map shapes; Shape lastShape = Shape::Invalid; - for (auto& pair : phones) { - Shape shape = getShape(pair.second); - if (shape != lastShape) { - shapes[pair.first] = shape; + for (auto it = phones.cbegin(); it != phones.cend(); it++) { + Shape shape = getShape(it->second); + if (shape != lastShape || next(it) == phones.cend()) { + shapes[it->first] = shape; lastShape = shape; } }