]> git.sesse.net Git - casparcg/blob - core/producer/scene/scene_producer.cpp
* Changed so that a paused scene still produces new frames, but just does not advance...
[casparcg] / core / producer / scene / scene_producer.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "../../StdAfx.h"
23
24 #include <common/future.h>
25 #include <common/prec_timer.h>
26
27 #include <boost/algorithm/string/split.hpp>
28 #include <boost/algorithm/string.hpp>
29
30 #include "scene_producer.h"
31
32 #include "../../frame/draw_frame.h"
33 #include "../../interaction/interaction_aggregator.h"
34 #include "../text/text_producer.h"
35
36 namespace caspar { namespace core { namespace scene {
37
38 layer::layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer)
39         : name(name), producer(producer)
40 {
41         crop.lower_right.x.bind(producer.get()->pixel_constraints().width);
42         crop.lower_right.y.bind(producer.get()->pixel_constraints().height);
43         perspective.upper_right.x.bind(producer.get()->pixel_constraints().width);
44         perspective.lower_right.x.bind(producer.get()->pixel_constraints().width);
45         perspective.lower_right.y.bind(producer.get()->pixel_constraints().height);
46         perspective.lower_left.y.bind(producer.get()->pixel_constraints().height);
47 }
48
49 adjustments::adjustments()
50         : opacity(1.0)
51 {
52 }
53
54 struct timeline
55 {
56         std::map<int64_t, keyframe> keyframes;
57
58         void on_frame(int64_t frame)
59         {
60                 auto before = --keyframes.upper_bound(frame);
61                 bool found_before = before != keyframes.end() && before->first < frame;
62                 auto after = keyframes.upper_bound(frame);
63                 bool found_after = after != keyframes.end() && after->first > frame;
64                 auto exact_frame = keyframes.find(frame);
65                 bool found_exact_frame = exact_frame != keyframes.end();
66
67                 if (found_exact_frame)
68                 {
69                         exact_frame->second.on_destination_frame();
70
71                         auto next_frame = ++exact_frame;
72
73                         if (next_frame != keyframes.end() && next_frame->second.on_start_animate)
74                                 next_frame->second.on_start_animate();
75                 }
76                 else if (found_after)
77                 {
78                         int64_t start_frame = 0;
79
80                         if (found_before)
81                         {
82                                 start_frame = before->first;
83                         }
84
85                         if (after->second.on_start_animate && frame == 0)
86                                 after->second.on_start_animate();
87                         else if (after->second.on_animate_to)
88                                 after->second.on_animate_to(start_frame, frame);
89                 }
90         }
91 };
92
93 mark_action get_mark_action(const std::wstring& name)
94 {
95         if (name == L"start")
96                 return mark_action::start;
97         else if (name == L"stop")
98                 return mark_action::stop;
99         else if (name == L"jump_to")
100                 return mark_action::jump_to;
101         else if (name == L"remove")
102                 return mark_action::remove;
103         else
104                 CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info(L"Invalid mark_action " + name));
105 }
106
107 struct marker
108 {
109         mark_action             action;
110         std::wstring    label_argument;
111
112         marker(mark_action action, const std::wstring& label_argument)
113                 : action(action)
114                 , label_argument(label_argument)
115         {
116         }
117 };
118
119 struct scene_producer::impl
120 {
121         constraints                                                                                             pixel_constraints_;
122         video_format_desc                                                                               format_desc_;
123         std::list<layer>                                                                                layers_;
124         interaction_aggregator                                                                  aggregator_;
125         binding<int64_t>                                                                                frame_number_;
126         binding<double>                                                                                 speed_;
127         double                                                                                                  frame_fraction_         = 0.0;
128         std::map<void*, timeline>                                                               timelines_;
129         std::map<std::wstring, std::shared_ptr<core::variable>> variables_;
130         std::vector<std::wstring>                                                               variable_names_;
131         std::multimap<int64_t, marker>                                                  markers_by_frame_;
132         monitor::subject                                                                                monitor_subject_;
133         bool                                                                                                    paused_                         = true;
134         bool                                                                                                    removed_                        = false;
135         bool                                                                                                    going_to_mark_          = false;
136
137         impl(int width, int height, const video_format_desc& format_desc)
138                 : pixel_constraints_(width, height)
139                 , format_desc_(format_desc)
140                 , aggregator_([=] (double x, double y) { return collission_detect(x, y); })
141         {
142                 auto speed_variable = std::make_shared<core::variable_impl<double>>(L"1.0", true, 1.0);
143                 store_variable(L"scene_speed", speed_variable);
144                 speed_ = speed_variable->value();
145                 auto frame_variable = std::make_shared<core::variable_impl<int64_t>>(L"-1", true, -1);
146                 store_variable(L"frame", frame_variable);
147                 frame_number_ = frame_variable->value();
148         }
149
150         layer& create_layer(
151                         const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
152         {
153                 layer layer(name, producer);
154
155                 layer.position.x.set(x);
156                 layer.position.y.set(y);
157
158                 layers_.push_back(layer);
159
160                 return layers_.back();
161         }
162
163         void store_keyframe(void* timeline_identity, const keyframe& k)
164         {
165                 timelines_[timeline_identity].keyframes.insert(std::make_pair(k.destination_frame, k));
166         }
167
168         void store_variable(
169                         const std::wstring& name, const std::shared_ptr<core::variable>& var)
170         {
171                 variables_.insert(std::make_pair(name, var));
172                 variable_names_.push_back(name);
173         }
174
175         void add_mark(int64_t frame, mark_action action, const std::wstring& label)
176         {
177                 markers_by_frame_.insert(std::make_pair(frame, marker(action, label)));
178         }
179
180         core::variable& get_variable(const std::wstring& name)
181         {
182                 auto found = variables_.find(name);
183
184                 if (found == variables_.end())
185                         CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(name + L" not found in scene"));
186
187                 return *found->second;
188         }
189
190         const std::vector<std::wstring>& get_variables() const
191         {
192                 return variable_names_;
193         }
194
195         binding<int64_t> frame()
196         {
197                 return frame_number_;
198         }
199
200         frame_transform get_transform(const layer& layer) const
201         {
202                 frame_transform transform;
203
204                 auto& anchor            = transform.image_transform.anchor;
205                 auto& pos                       = transform.image_transform.fill_translation;
206                 auto& scale                     = transform.image_transform.fill_scale;
207                 auto& angle                     = transform.image_transform.angle;
208                 auto& crop                      = transform.image_transform.crop;
209                 auto& pers                      = transform.image_transform.perspective;
210
211                 anchor[0]       = layer.anchor.x.get()                                                                          / layer.producer.get()->pixel_constraints().width.get();
212                 anchor[1]       = layer.anchor.y.get()                                                                          / layer.producer.get()->pixel_constraints().height.get();
213                 pos[0]          = layer.position.x.get()                                                                        / pixel_constraints_.width.get();
214                 pos[1]          = layer.position.y.get()                                                                        / pixel_constraints_.height.get();
215                 scale[0]        = layer.producer.get()->pixel_constraints().width.get()         / pixel_constraints_.width.get();
216                 scale[1]        = layer.producer.get()->pixel_constraints().height.get()        / pixel_constraints_.height.get();
217                 crop.ul[0]      = layer.crop.upper_left.x.get()                                                         / layer.producer.get()->pixel_constraints().width.get();
218                 crop.ul[1]      = layer.crop.upper_left.y.get()                                                         / layer.producer.get()->pixel_constraints().height.get();
219                 crop.lr[0]      = layer.crop.lower_right.x.get()                                                        / layer.producer.get()->pixel_constraints().width.get();
220                 crop.lr[1]      = layer.crop.lower_right.y.get()                                                        / layer.producer.get()->pixel_constraints().height.get();
221                 pers.ul[0]      = layer.perspective.upper_left.x.get()                                          / layer.producer.get()->pixel_constraints().width.get();
222                 pers.ul[1]      = layer.perspective.upper_left.y.get()                                          / layer.producer.get()->pixel_constraints().height.get();
223                 pers.ur[0]      = layer.perspective.upper_right.x.get()                                         / layer.producer.get()->pixel_constraints().width.get();
224                 pers.ur[1]      = layer.perspective.upper_right.y.get()                                         / layer.producer.get()->pixel_constraints().height.get();
225                 pers.lr[0]      = layer.perspective.lower_right.x.get()                                         / layer.producer.get()->pixel_constraints().width.get();
226                 pers.lr[1]      = layer.perspective.lower_right.y.get()                                         / layer.producer.get()->pixel_constraints().height.get();
227                 pers.ll[0]      = layer.perspective.lower_left.x.get()                                          / layer.producer.get()->pixel_constraints().width.get();
228                 pers.ll[1]      = layer.perspective.lower_left.y.get()                                          / layer.producer.get()->pixel_constraints().height.get();
229
230                 static const double PI = 3.141592653589793;
231
232                 angle           = layer.rotation.get() * PI / 180.0;
233
234                 transform.image_transform.opacity                       = layer.adjustments.opacity.get();
235                 transform.image_transform.is_key                        = layer.is_key.get();
236                 transform.image_transform.use_mipmap            = layer.use_mipmap.get();
237                 transform.image_transform.blend_mode            = layer.blend_mode.get();
238                 transform.image_transform.chroma.key            = layer.chroma_key.key.get();
239                 transform.image_transform.chroma.threshold      = layer.chroma_key.threshold.get();
240                 transform.image_transform.chroma.softness       = layer.chroma_key.softness.get();
241                 transform.image_transform.chroma.spill          = layer.chroma_key.spill.get();
242
243                 // Mark as sublayer, so it will be composited separately by the mixer.
244                 transform.image_transform.layer_depth = 1;
245
246                 return transform;
247         }
248
249         boost::optional<std::pair<int64_t, marker>> find_first_stop_or_jump_or_remove(int64_t start_frame, int64_t end_frame)
250         {
251                 auto lower = markers_by_frame_.lower_bound(start_frame);
252                 auto upper = markers_by_frame_.upper_bound(end_frame);
253
254                 if (lower == markers_by_frame_.end())
255                         return boost::none;
256
257                 for (auto iter = lower; iter != upper; ++iter)
258                 {
259                         auto action = iter->second.action;
260
261                         if (action == mark_action::stop || action == mark_action::jump_to || action == mark_action::remove)
262                                 return *iter;
263                 }
264
265                 return boost::none;
266         }
267
268         boost::optional<std::pair<int64_t, marker>> find_first_start(int64_t start_frame)
269         {
270                 auto lower = markers_by_frame_.lower_bound(start_frame);
271
272                 if (lower == markers_by_frame_.end())
273                         return boost::none;
274
275                 for (auto iter = lower; iter != markers_by_frame_.end(); ++iter)
276                 {
277                         auto action = iter->second.action;
278
279                         if (action == mark_action::start)
280                                 return *iter;
281                 }
282
283                 return boost::none;
284         }
285
286         draw_frame render_frame()
287         {
288                 if (format_desc_.field_count == 1)
289                         return render_progressive_frame();
290                 else
291                 {
292                         prec_timer timer;
293                         timer.tick_millis(0);
294                         
295                         auto field1 = render_progressive_frame();
296                         
297                         timer.tick(0.5 / format_desc_.fps);
298
299                         auto field2 = render_progressive_frame();
300
301                         return draw_frame::interlace(field1, field2, format_desc_.field_mode);
302                 }
303         }
304
305         void advance()
306         {
307                 frame_fraction_ += speed_.get();
308
309                 if (std::abs(frame_fraction_) >= 1.0)
310                 {
311                         int64_t delta = static_cast<int64_t>(frame_fraction_);
312                         auto previous_frame = frame_number_.get();
313                         auto next_frame = frame_number_.get() + delta;
314                         auto marker = find_first_stop_or_jump_or_remove(previous_frame + 1, next_frame);
315
316                         if (marker && marker->second.action == mark_action::remove)
317                         {
318                                 remove();
319                         }
320                         if (marker && !going_to_mark_)
321                         {
322                                 if (marker->second.action == mark_action::stop)
323                                 {
324                                         frame_number_.set(marker->first);
325                                         frame_fraction_ = 0.0;
326                                         paused_ = true;
327                                 }
328                                 else if (marker->second.action == mark_action::jump_to)
329                                 {
330                                         go_to_marker(marker->second.label_argument, 0);
331                                 }
332                         }
333                         else
334                         {
335                                 frame_number_.set(next_frame);
336                                 frame_fraction_ -= delta;
337                         }
338
339                         going_to_mark_ = false;
340                 }
341         }
342
343         draw_frame render_progressive_frame()
344         {
345                 if (removed_)
346                         return draw_frame::empty();
347
348                 if (!paused_)
349                         advance();
350
351                 for (auto& timeline : timelines_)
352                         timeline.second.on_frame(frame_number_.get());
353
354                 std::vector<draw_frame> frames;
355
356                 for (auto& layer : layers_)
357                 {
358                         if (layer.hidden.get())
359                                 continue;
360
361                         draw_frame frame(layer.producer.get()->receive());
362                         frame.transform() = get_transform(layer);
363                         frames.push_back(frame);
364                 }
365
366                 return draw_frame(frames);
367         }
368
369         void on_interaction(const interaction_event::ptr& event)
370         {
371                 aggregator_.translate_and_send(event);
372         }
373
374         bool collides(double x, double y) const
375         {
376                 return static_cast<bool>((collission_detect(x, y)));
377         }
378
379         boost::optional<interaction_target> collission_detect(double x, double y) const
380         {
381                 for (auto& layer : layers_ | boost::adaptors::reversed)
382                 {
383                         if (layer.hidden.get())
384                                 continue;
385
386                         auto transform = get_transform(layer);
387                         auto translated = translate(x, y, transform);
388
389                         if (translated.first >= 0.0
390                                 && translated.first <= 1.0
391                                 && translated.second >= 0.0
392                                 && translated.second <= 1.0
393                                 && layer.producer.get()->collides(translated.first, translated.second))
394                         {
395                                 return std::make_pair(transform, static_cast<interaction_sink*>(layer.producer.get().get()));
396                         }
397                 }
398
399                 return boost::optional<interaction_target>();
400         }
401
402         std::future<std::wstring> call(const std::vector<std::wstring>& params) 
403         {
404                 if (!params.empty() && boost::ends_with(params.at(0), L"()"))
405                         return make_ready_future(handle_call(params));
406                 else
407                         return make_ready_future(handle_variable_set(params));
408         }
409
410         std::wstring handle_variable_set(const std::vector<std::wstring>& params)
411         {
412                 for (int i = 0; i + 1 < params.size(); i += 2)
413                 {
414                         auto found = variables_.find(boost::to_lower_copy(params[i]));
415
416                         if (found != variables_.end() && found->second->is_public())
417                                 found->second->from_string(params[i + 1]);
418                 }
419
420                 return L"";
421         }
422
423         std::wstring handle_call(const std::vector<std::wstring>& params)
424         {
425                 auto call = params.at(0);
426
427                 if (call == L"play()")
428                         go_to_marker(params.at(1), -1);
429                 else if (call == L"remove()")
430                         remove();
431                 else if (call == L"next()")
432                         next();
433                 else
434                         CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(L"Unknown call " + call));
435
436                 return L"";
437         }
438
439         void remove()
440         {
441                 removed_ = true;
442                 layers_.clear();
443         }
444
445         void next()
446         {
447                 auto marker = find_first_start(frame_number_.get() + 1);
448
449                 if (marker)
450                 {
451                         frame_number_.set(marker->first - 1);
452                         frame_fraction_ = 0.0;
453                         paused_ = false;
454                         going_to_mark_ = true;
455                 }
456                 else
457                 {
458                         remove();
459                 }
460         }
461
462         void go_to_marker(const std::wstring& marker_name, int64_t offset)
463         {
464                 for (auto& marker : markers_by_frame_)
465                 {
466                         if (marker.second.label_argument == marker_name && marker.second.action == mark_action::start)
467                         {
468                                 frame_number_.set(marker.first + offset);
469                                 frame_fraction_ = 0.0;
470                                 paused_ = false;
471                                 going_to_mark_ = true;
472
473                                 return;
474                         }
475                 }
476
477                 if (marker_name == L"intro")
478                 {
479                         frame_number_.set(offset);
480                         frame_fraction_ = 0.0;
481                         paused_ = false;
482                         going_to_mark_ = true;
483                 }
484                 else if (marker_name == L"outro")
485                 {
486                         remove();
487                 }
488                 else
489                         CASPAR_LOG(info) << print() << L" no marker called " << marker_name << " found";
490         }
491
492         std::wstring print() const
493         {
494                 return L"scene[]";
495         }
496
497         std::wstring name() const
498         {
499                 return L"scene";
500         }
501         
502         boost::property_tree::wptree info() const
503         {
504                 boost::property_tree::wptree info;
505                 info.add(L"type", L"scene");
506                 return info;
507         }
508
509         monitor::subject& monitor_output()
510         {
511                 return monitor_subject_;
512         }
513 };
514
515 scene_producer::scene_producer(int width, int height, const video_format_desc& format_desc)
516         : impl_(new impl(width, height, format_desc))
517 {
518 }
519
520 scene_producer::~scene_producer()
521 {
522 }
523
524 layer& scene_producer::create_layer(
525                 const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
526 {
527         return impl_->create_layer(producer, x, y, name);
528 }
529
530 layer& scene_producer::create_layer(
531                 const spl::shared_ptr<frame_producer>& producer, const std::wstring& name)
532 {
533         return impl_->create_layer(producer, 0, 0, name);
534 }
535
536 binding<int64_t> scene_producer::frame()
537 {
538         return impl_->frame();
539 }
540
541 draw_frame scene_producer::receive_impl()
542 {
543         return impl_->render_frame();
544 }
545
546 constraints& scene_producer::pixel_constraints() { return impl_->pixel_constraints_; }
547
548 void scene_producer::on_interaction(const interaction_event::ptr& event)
549 {
550         impl_->on_interaction(event);
551 }
552
553 bool scene_producer::collides(double x, double y) const
554 {
555         return impl_->collides(x, y);
556 }
557
558 std::wstring scene_producer::print() const
559 {
560         return impl_->print();
561 }
562
563 std::wstring scene_producer::name() const
564 {
565         return impl_->name();
566 }
567
568 boost::property_tree::wptree scene_producer::info() const
569 {
570         return impl_->info();
571 }
572
573 std::future<std::wstring> scene_producer::call(const std::vector<std::wstring>& params) 
574 {
575         return impl_->call(params);
576 }
577
578 monitor::subject& scene_producer::monitor_output()
579 {
580         return impl_->monitor_output();
581 }
582
583 void scene_producer::store_keyframe(void* timeline_identity, const keyframe& k)
584 {
585         impl_->store_keyframe(timeline_identity, k);
586 }
587
588 void scene_producer::store_variable(
589                 const std::wstring& name, const std::shared_ptr<core::variable>& var)
590 {
591         impl_->store_variable(name, var);
592 }
593
594 void scene_producer::add_mark(int64_t frame, mark_action action, const std::wstring& label)
595 {
596         impl_->add_mark(frame, action, label);
597 }
598
599 core::variable& scene_producer::get_variable(const std::wstring& name)
600 {
601         return impl_->get_variable(name);
602 }
603
604 const std::vector<std::wstring>& scene_producer::get_variables() const
605 {
606         return impl_->get_variables();
607 }
608
609 spl::shared_ptr<core::frame_producer> create_dummy_scene_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params)
610 {
611         if (params.size() < 1 || !boost::iequals(params.at(0), L"[SCENE]"))
612                 return core::frame_producer::empty();
613
614         auto scene = spl::make_shared<scene_producer>(format_desc.width, format_desc.height, format_desc);
615
616         text::text_info text_info;
617         text_info.font = L"ArialMT";
618         text_info.size = 62;
619         text_info.color.r = 1;
620         text_info.color.g = 1;
621         text_info.color.b = 1;
622         text_info.color.a = 0.5;
623         auto text_area = text_producer::create(frame_factory, 0, 0, L"a", text_info, 1280, 720, false);
624
625         auto text_width = text_area->pixel_constraints().width;
626         binding<double> padding(1.0);
627         binding<double> panel_width = padding + text_width + padding;
628         binding<double> panel_height = padding + text_area->pixel_constraints().height + padding;
629
630         auto subscription = panel_width.on_change([&]
631         {
632                 CASPAR_LOG(info) << "Panel width: " << panel_width.get();
633         });
634
635         padding.set(2);
636
637         auto create_param = [](std::wstring elem) -> std::vector<std::wstring>
638         {
639                 std::vector<std::wstring> result;
640                 result.push_back(elem);
641                 return result;
642         };
643
644         auto& car_layer = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"car")), L"car");
645         car_layer.adjustments.opacity.set(0.5);
646         //car_layer.hidden = scene->frame() % 50 > 25 || !(scene->frame() < 1000);
647         std::vector<std::wstring> sub_params;
648         sub_params.push_back(L"[FREEHAND]");
649         sub_params.push_back(L"640");
650         sub_params.push_back(L"360");
651         scene->create_layer(create_producer(frame_factory, format_desc, sub_params), 10, 10, L"freehand");
652         sub_params.clear();
653
654         auto& color_layer = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"RED")), 110, 10, L"color");
655         color_layer.producer.get()->pixel_constraints().width.set(1000);
656         color_layer.producer.get()->pixel_constraints().height.set(550);
657
658         //scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"SP")), 50, 50);
659
660         auto& upper_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_left")), L"upper_left");
661         auto& upper_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_right")), L"upper_right");
662         auto& lower_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_left")), L"lower_left");
663         auto& lower_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_right")), L"lower_right");
664         auto& text_layer = scene->create_layer(text_area, L"text_area");
665         upper_left.adjustments.opacity.bind(text_layer.adjustments.opacity);
666         upper_right.adjustments.opacity.bind(text_layer.adjustments.opacity);
667         lower_left.adjustments.opacity.bind(text_layer.adjustments.opacity);
668         lower_right.adjustments.opacity.bind(text_layer.adjustments.opacity);
669
670         /*
671         binding<double> panel_x = (scene->frame()
672                         .as<double>()
673                         .transformed([](double v) { return std::sin(v / 20.0); })
674                         * 20.0
675                         + 40.0)
676                         .transformed([](double v) { return std::floor(v); }); // snap to pixels instead of subpixels
677                         */
678         tweener tween(L"easeoutbounce");
679         binding<double> panel_x(0.0);
680
681         scene->add_keyframe(panel_x, -panel_width, 0);
682         scene->add_keyframe(panel_x, 300.0, 50, L"easeinoutsine");
683         scene->add_keyframe(panel_x, 300.0, 50 * 4);
684         scene->add_keyframe(panel_x, 1000.0, 50 * 5, L"easeinoutsine");
685         //panel_x = delay(panel_x, add_tween(panel_x, scene->frame(), 200.0, int64_t(50), L"linear"), scene->frame(), int64_t(100));
686         /*binding<double> panel_x = when(scene->frame() < 50)
687                 .then(scene->frame().as<double>().transformed([tween](double t) { return tween(t, 0.0, 200, 50); }))
688                 .otherwise(200.0);*/
689         //binding<double> panel_y = when(car_layer.hidden).then(500.0).otherwise(-panel_x + 300);
690         binding<double> panel_y(500.0);
691         scene->add_keyframe(panel_y, panel_y.get(), 50 * 4);
692         scene->add_keyframe(panel_y, 720.0, 50 * 5, L"easeinexpo");
693
694         scene->add_keyframe(text_layer.adjustments.opacity, 1.0, 100);
695         scene->add_keyframe(text_layer.adjustments.opacity, 0.0, 125, L"linear");
696         scene->add_keyframe(text_layer.adjustments.opacity, 1.0, 150, L"linear");
697
698         upper_left.position.x = panel_x;
699         upper_left.position.y = panel_y;
700         upper_right.position.x = upper_left.position.x + upper_left.producer.get()->pixel_constraints().width + panel_width;
701         upper_right.position.y = upper_left.position.y;
702         lower_left.position.x = upper_left.position.x;
703         lower_left.position.y = upper_left.position.y + upper_left.producer.get()->pixel_constraints().height + panel_height;
704         lower_right.position.x = upper_right.position.x;
705         lower_right.position.y = lower_left.position.y;
706         text_layer.position.x = upper_left.position.x + upper_left.producer.get()->pixel_constraints().width + padding;
707         text_layer.position.y = upper_left.position.y + upper_left.producer.get()->pixel_constraints().height + padding + text_area->current_bearing_y().as<double>();
708
709         text_area->text().bind(scene->create_variable<std::wstring>(L"text", true));
710
711         auto params2 = params;
712         params2.erase(params2.begin());
713
714         scene->call(params2);
715
716         return scene;
717 }
718
719 }}}