From: hellgore Date: Mon, 18 Jun 2012 12:41:17 +0000 (+0000) Subject: Added some documentation to tweener.h and to memory.h X-Git-Tag: 2.1.0_Beta1~510 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a947e8fcde25dcb0fd46958149ce17af56ab8760;p=casparcg Added some documentation to tweener.h and to memory.h git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@3118 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/common/memory.h b/common/memory.h index 5e2e4731e..c3235240b 100644 --- a/common/memory.h +++ b/common/memory.h @@ -30,6 +30,16 @@ namespace caspar { namespace spl { // unique_ptr +/** + * A wrapper around std::unique_ptr ensuring that the pointer is never null + * except in the case of a moved from instance. + * + * The default constructor will point the wrapped pointer to a default + * contructed instance of T. + * + * Use the make_unique overloads for perfectly forwarding the contructor + * arguments of T and creating a unique_ptr to the created T instance. + */ template> class unique_ptr { @@ -315,6 +325,15 @@ unique_ptr make_unique(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5) // shared_ptr +/** + * A wrapper around std::shared_ptr ensuring that it never points to a null + * pointer except in the case of a moved from instance. + * + * A default constructed shared_ptr will point to a default constructed T. + * + * Use the make_shared overloads for perfect forwarding of the constructor + * arguments of T which will return a shared_ptr pointing to the constructed T. + */ template class shared_ptr { diff --git a/common/tweener.cpp b/common/tweener.cpp index f5420063f..8b8c12dbe 100644 --- a/common/tweener.cpp +++ b/common/tweener.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -379,27 +380,10 @@ double ease_out_in_bounce (double t, double b, double c, double d, const std::ve return ease_in_bounce((t*2)-d, b+c/2, c/2, d, params); } -tweener_t get_tweener(std::wstring name) -{ - std::transform(name.begin(), name.end(), name.begin(), std::tolower); +typedef std::function&)> tween_t; - if(name == L"linear") - return [](double t, double b, double c, double d){return ease_none(t, b, c, d, std::vector());}; - - std::vector params; - - static const boost::wregex expr(L"(?\\w*)(:(?\\d+\\.?\\d?))?(:(?\\d+\\.?\\d?))?"); // boost::regex has no repeated captures? - boost::wsmatch what; - if(boost::regex_match(name, what, expr)) - { - name = what["NAME"].str(); - if(what["V0"].matched) - params.push_back(boost::lexical_cast(what["V0"].str())); - if(what["V1"].matched) - params.push_back(boost::lexical_cast(what["V1"].str())); - } - - typedef std::function&)> tween_t; +const std::unordered_map& get_tweens() +{ static const std::unordered_map tweens = boost::assign::map_list_of (L"", ease_none ) (L"linear", ease_none ) @@ -445,6 +429,31 @@ tweener_t get_tweener(std::wstring name) (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); + + if(name == L"linear") + return [](double t, double b, double c, double d){return ease_none(t, b, c, d, std::vector());}; + + std::vector params; + + static const boost::wregex expr(L"(?\\w*)(:(?\\d+\\.?\\d?))?(:(?\\d+\\.?\\d?))?"); // boost::regex has no repeated captures? + boost::wsmatch what; + if(boost::regex_match(name, what, expr)) + { + name = what["NAME"].str(); + if(what["V0"].matched) + params.push_back(boost::lexical_cast(what["V0"].str())); + if(what["V1"].matched) + params.push_back(boost::lexical_cast(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)); @@ -471,4 +480,15 @@ double tweener::operator()(double t, double b , double c, double d) const return func_(t, b, c, d); } -}} \ No newline at end of file +const std::vector& tweener::names() +{ + using namespace boost::adaptors; + + static const std::vector names( + (get_tweens() | map_keys).begin(), + (get_tweens() | map_keys).end()); + + return names; +} + +}} diff --git a/common/tweener.h b/common/tweener.h index 158f56593..25833b503 100644 --- a/common/tweener.h +++ b/common/tweener.h @@ -22,14 +22,56 @@ #pragma once #include +#include namespace caspar { namespace core { +/** + * A tweener can be used for creating any kind of (image position, image fade + * in/out, audio volume etc) transition, by invoking it for each temporal + * timepoint when a tweened value is needed. + * + * For video the temporal resolution will usually be each frame or field (for + * interlaced material). + * + * For audio the smoothest transitions will be generated by using the samplerate + * as temporal resolution, but using the video frame/field rate is probably fine + * most of the times and much less time consuming. + */ class tweener { public: + /** + * Constructor. + * + * @param name The name of the tween function to use. + */ tweener(const std::wstring& name = L"linear"); tweener(const wchar_t* name); + + /** + * @return The possible tween function names. Some of them may also support + * additional parameters appended to the name. + */ + static const std::vector& names(); + + /** + * Calculate a tweened value given a timepoint within the total duration + * and the starting value and the destination delta value. + * + * Usually b, c and d remains constant during a transition, while t changes + * for each temporal tweened value. + * + * @param t The timepoint within the total duration (0 <= n <= d). + * @param b The starting value. + * @param c The destination value delta from the starting value + * (absolute destination value - b). + * @param d The total duration (when t = d, the destination value should + * have been reached). + * + * @return The tweened value for the given timepoint. Can sometimes be less + * than b or greater than b + c for some tweener functions. + */ double operator()(double t, double b , double c, double d) const; private: std::function func_;