]> git.sesse.net Git - casparcg/blobdiff - common/tweener.cpp
[streaming_consumer] Default to pcm_s24le for containers supporting it instead of...
[casparcg] / common / tweener.cpp
index 872ebfd772292acaf037d1adbbc523c1fec5f299..e92cec8dbd3cf293437372707bbc5193a55b31e5 100644 (file)
@@ -28,7 +28,7 @@
 //
 //Open source under the BSD License.
 //
-//Copyright © 2001 Robert Penner
+//Copyright  2001 Robert Penner
 //All rights reserved.
 //
 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 #include "tweener.h"
 
 #include "except.h"
+#include "linq.h"
 
-#include <boost/assign/list_of.hpp>
 #include <boost/regex.hpp>
 #include <boost/lexical_cast.hpp>
-#include <boost/range/adaptor/map.hpp>
 
 #include <unordered_map>
 #include <string>
@@ -56,7 +55,7 @@
 #include <algorithm>
 #include <vector>
 
-namespace caspar { namespace core {
+namespace caspar {
 
 typedef std::function<double(double, double, double, double)> tweener_t;
                        
@@ -385,57 +384,58 @@ typedef std::function<double(double, double, double, double, const std::vector<d
 
 const std::unordered_map<std::wstring, tween_t>& get_tweens()
 {
-       static const std::unordered_map<std::wstring, tween_t> tweens = boost::assign::map_list_of      
-               (L"",                                   ease_none                  )    
-               (L"linear",                             ease_none                  )    
-               (L"easenone",                   ease_none                  )
-               (L"easeinquad",                 ease_in_quad       )
-               (L"easeoutquad",                ease_out_quad      )
-               (L"easeinoutquad",              ease_in_out_quad   )
-               (L"easeoutinquad",              ease_out_in_quad   )
-               (L"easeincubic",                ease_in_cubic      )
-               (L"easeoutcubic",               ease_out_cubic     )
-               (L"easeinoutcubic",             ease_in_out_cubic  )
-               (L"easeoutincubic",             ease_out_in_cubic  )
-               (L"easeinquart",                ease_in_quart      )
-               (L"easeoutquart",               ease_out_quart     )
-               (L"easeinoutquart",             ease_in_out_quart  )
-               (L"easeoutinquart",             ease_out_in_quart  )
-               (L"easeinquint",                ease_in_quint      )
-               (L"easeoutquint",               ease_out_quint     )
-               (L"easeinoutquint",             ease_in_out_quint  )
-               (L"easeoutinquint",             ease_out_in_quint  )
-               (L"easeinsine",                 ease_in_sine       )
-               (L"easeoutsine",                ease_out_sine      )
-               (L"easeinoutsine",              ease_in_out_sine   )
-               (L"easeoutinsine",              ease_out_in_sine   )
-               (L"easeinexpo",                 ease_in_expo       )
-               (L"easeoutexpo",                ease_out_expo      )
-               (L"easeinoutexpo",              ease_in_out_expo   )
-               (L"easeoutinexpo",              ease_out_in_expo   )
-               (L"easeincirc",                 ease_in_circ       )
-               (L"easeoutcirc",                ease_out_circ      )
-               (L"easeinoutcirc",              ease_in_out_circ   )
-               (L"easeoutincirc",              ease_out_in_circ   )
-               (L"easeinelastic",              ease_in_elastic    )
-               (L"easeoutelastic",             ease_out_elastic   )
-               (L"easeinoutelastic",   ease_in_out_elastic)
-               (L"easeoutinelastic",   ease_out_in_elastic)
-               (L"easeinback",                 ease_in_back       )
-               (L"easeoutback",                ease_out_back      )
-               (L"easeinoutback",              ease_in_out_back   )
-               (L"easeoutintback",             ease_out_int_back  )
-               (L"easeoutbounce",              ease_out_bounce    )
-               (L"easeinbounce",               ease_in_bounce     )
-               (L"easeinoutbounce",    ease_in_out_bounce )
-               (L"easeoutinbounce",    ease_out_in_bounce );
+       static const std::unordered_map<std::wstring, tween_t> tweens = {
+               {L"",                 ease_none },
+               {L"linear",           ease_none },
+               {L"easenone",         ease_none },
+               {L"easeinquad",       ease_in_quad },
+               {L"easeoutquad",      ease_out_quad },
+               {L"easeinoutquad",    ease_in_out_quad },
+               {L"easeoutinquad",    ease_out_in_quad },
+               {L"easeincubic",      ease_in_cubic },
+               {L"easeoutcubic",     ease_out_cubic },
+               {L"easeinoutcubic",   ease_in_out_cubic },
+               {L"easeoutincubic",   ease_out_in_cubic },
+               {L"easeinquart",      ease_in_quart },
+               {L"easeoutquart",     ease_out_quart },
+               {L"easeinoutquart",   ease_in_out_quart },
+               {L"easeoutinquart",   ease_out_in_quart },
+               {L"easeinquint",      ease_in_quint },
+               {L"easeoutquint",     ease_out_quint },
+               {L"easeinoutquint",   ease_in_out_quint },
+               {L"easeoutinquint",   ease_out_in_quint },
+               {L"easeinsine",       ease_in_sine },
+               {L"easeoutsine",      ease_out_sine },
+               {L"easeinoutsine",    ease_in_out_sine },
+               {L"easeoutinsine",    ease_out_in_sine },
+               {L"easeinexpo",       ease_in_expo },
+               {L"easeoutexpo",      ease_out_expo },
+               {L"easeinoutexpo",    ease_in_out_expo },
+               {L"easeoutinexpo",    ease_out_in_expo },
+               {L"easeincirc",       ease_in_circ },
+               {L"easeoutcirc",      ease_out_circ },
+               {L"easeinoutcirc",    ease_in_out_circ },
+               {L"easeoutincirc",    ease_out_in_circ },
+               {L"easeinelastic",    ease_in_elastic },
+               {L"easeoutelastic",   ease_out_elastic },
+               {L"easeinoutelastic", ease_in_out_elastic },
+               {L"easeoutinelastic", ease_out_in_elastic },
+               {L"easeinback",       ease_in_back },
+               {L"easeoutback",      ease_out_back },
+               {L"easeinoutback",    ease_in_out_back },
+               {L"easeoutintback",   ease_out_int_back },
+               {L"easeoutbounce",    ease_out_bounce },
+               {L"easeinbounce",     ease_in_bounce },
+               {L"easeinoutbounce",  ease_in_out_bounce },
+               {L"easeoutinbounce",  ease_out_in_bounce }
+       };
 
        return tweens;
 }
 
 tweener_t get_tweener(std::wstring name)
 {
-       std::transform(name.begin(), name.end(), name.begin(), std::tolower);
+       std::transform(name.begin(), name.end(), name.begin(), std::towlower);
 
        if(name == L"linear")
                return [](double t, double b, double c, double d){return ease_none(t, b, c, d, std::vector<double>());};
@@ -453,11 +453,9 @@ tweener_t get_tweener(std::wstring name)
                        params.push_back(boost::lexical_cast<double>(what["V1"].str()));
        }
                
-       auto tweens = get_tweens();
-
-       auto it = tweens.find(name);
-       if(it == tweens.end())
-               CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Could not find tween.") << arg_value_info(name));
+       auto it = get_tweens().find(name);
+       if(it == get_tweens().end())
+               CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Could not find tween " + name));
        
        auto tween = it->second;
        return [=](double t, double b, double c, double d)
@@ -468,28 +466,43 @@ tweener_t get_tweener(std::wstring name)
 
 tweener::tweener(const std::wstring& name)
        : func_(get_tweener(name))
+       , name_(name)
 {
 }
 
-tweener::tweener(const wchar_t* name)
-       : func_(get_tweener(name))
+double tweener::operator()(double t, double b , double c, double d) const
 {
+       return func_(t, b, c, d);
 }
 
-double tweener::operator()(double t, double b , double c, double d) const
+bool tweener::operator==(const tweener& other) const
 {
-       return func_(t, b, c, d);
+       return name_ == other.name_;
+}
+
+bool tweener::operator!=(const tweener& other) const
+{
+       return !(*this == other);
 }
 
 const std::vector<std::wstring>& tweener::names()
 {
-       using namespace boost::adaptors;
+       /*static const auto names = cpplinq::from(get_tweens())
+               .select(keys())
+               .to_vector();*/
 
-       static const std::vector<std::wstring> names(
-               (get_tweens() | map_keys).begin(),
-               (get_tweens() | map_keys).end());
+       static const auto result = []
+       {
+               std::vector<std::wstring> tweens;
 
-       return names;
+               for (auto& tween : get_tweens())
+                       tweens.push_back(tween.first);
+
+               return tweens;
+       }();
+       //static const std::vector<std::wstring> result;
+
+       return result;
 }
 
-}}
+}