]> git.sesse.net Git - casparcg/blob - common/tweener.h
25833b5030a6e0631b4e40fe941edc1383a51a17
[casparcg] / common / tweener.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include <functional>\r
25 #include <vector>\r
26 \r
27 namespace caspar { namespace core {\r
28 \r
29 /**\r
30  * A tweener can be used for creating any kind of (image position, image fade\r
31  * in/out, audio volume etc) transition, by invoking it for each temporal\r
32  * timepoint when a tweened value is needed.\r
33  *\r
34  * For video the temporal resolution will usually be each frame or field (for\r
35  * interlaced material).\r
36  *\r
37  * For audio the smoothest transitions will be generated by using the samplerate\r
38  * as temporal resolution, but using the video frame/field rate is probably fine\r
39  * most of the times and much less time consuming.\r
40  */\r
41 class tweener\r
42 {\r
43 public:\r
44         /**\r
45          * Constructor.\r
46          *\r
47          * @param name The name of the tween function to use.\r
48          */\r
49         tweener(const std::wstring& name = L"linear");\r
50         tweener(const wchar_t* name);\r
51 \r
52         /**\r
53          * @return The possible tween function names. Some of them may also support\r
54          *                 additional parameters appended to the name.\r
55          */\r
56         static const std::vector<std::wstring>& names();\r
57 \r
58         /**\r
59          * Calculate a tweened value given a timepoint within the total duration\r
60          * and the starting value and the destination delta value.\r
61          *\r
62          * Usually b, c and d remains constant during a transition, while t changes\r
63          * for each temporal tweened value.\r
64          * \r
65          * @param t     The timepoint within the total duration (0 <= n <= d).\r
66          * @param b     The starting value.\r
67          * @param c     The destination value delta from the starting value\r
68          *              (absolute destination value - b).\r
69          * @param d The total duration (when t = d, the destination value should\r
70          *              have been reached).\r
71          *\r
72          * @return The tweened value for the given timepoint. Can sometimes be less\r
73          *             than b or greater than b + c for some tweener functions.\r
74          */\r
75         double operator()(double t, double b , double c, double d) const;\r
76 private:\r
77         std::function<double(double, double, double, double)> func_;\r
78 };\r
79 \r
80 }}