]> git.sesse.net Git - casparcg/blobdiff - common/tweener.h
[scene_producer] Added possibility to CALL/CG PLAY/CG STOP/CG NEXT/CG INVOKE layers...
[casparcg] / common / tweener.h
index 158f56593f5d414142065594a71be06684df7898..b5231f816375646711c21b6a66760ade521f61d9 100644 (file)
@@ -1,38 +1,83 @@
-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-\r
-#pragma once\r
-\r
-#include <functional>\r
-\r
-namespace caspar { namespace core {\r
-\r
-class tweener\r
-{\r
-public:\r
-       tweener(const std::wstring& name = L"linear");\r
-       tweener(const wchar_t* name);\r
-       double operator()(double t, double b , double c, double d) const;\r
-private:\r
-       std::function<double(double, double, double, double)> func_;\r
-};\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include <functional>
+#include <vector>
+
+namespace caspar {
+
+/**
+ * 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");
+
+       /**
+        * @return The possible tween function names. Some of them may also support
+        *                 additional parameters appended to the name.
+        */
+       static const std::vector<std::wstring>& 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;
+
+       bool operator==(const tweener& other) const;
+       bool operator!=(const tweener& other) const;
+private:
+       std::function<double(double, double, double, double)>   func_;
+       std::wstring                                                                                    name_;
+};
+
+}