4 #include "transportque.inc"
9 MaskAutos::MaskAutos(EDL *edl,
15 MaskAutos::~MaskAutos()
20 void MaskAutos::get_points(ArrayList<MaskPoint*> *points, int submask, int64_t position, int direction)
22 MaskAuto *begin = 0, *end = 0;
23 position = (direction == PLAY_FORWARD) ? position : (position - 1);
25 // Get auto before and after position
26 for(MaskAuto* current = (MaskAuto*)last;
28 current = (MaskAuto*)PREVIOUS)
30 if(current->position <= position)
33 end = NEXT ? (MaskAuto*)NEXT : current;
38 // Nothing before position found
41 begin = end = (MaskAuto*)first;
44 // Nothing after position found
47 begin = end = (MaskAuto*)default_auto;
51 SubMask *mask1 = begin->get_submask(submask);
52 SubMask *mask2 = end->get_submask(submask);
54 points->remove_all_objects();
55 int total_points = MIN(mask1->points.total, mask2->points.total);
56 for(int i = 0; i < total_points; i++)
58 MaskPoint *point = new MaskPoint;
60 mask1->points.values[i],
61 mask2->points.values[i],
65 points->append(point);
69 void MaskAutos::avg_points(MaskPoint *output,
72 int64_t output_position,
76 if(position2 == position1)
82 float fraction2 = (float)(output_position - position1) / (position2 - position1);
83 float fraction1 = 1 - fraction2;
84 output->x = input1->x * fraction1 + input2->x * fraction2;
85 output->y = input1->y * fraction1 + input2->y * fraction2;
86 output->control_x1 = input1->control_x1 * fraction1 + input2->control_x1 * fraction2;
87 output->control_y1 = input1->control_y1 * fraction1 + input2->control_y1 * fraction2;
88 output->control_x2 = input1->control_x2 * fraction1 + input2->control_x2 * fraction2;
89 output->control_y2 = input1->control_y2 * fraction1 + input2->control_y2 * fraction2;
95 Auto* MaskAutos::new_auto()
97 return new MaskAuto(edl, this);
100 int MaskAutos::dump()
102 printf(" MaskAutos::dump %p\n", this);
103 printf(" Default: position %ld submasks %d\n",
104 default_auto->position,
105 ((MaskAuto*)default_auto)->masks.total);
106 ((MaskAuto*)default_auto)->dump();
107 for(Auto* current = first; current; current = NEXT)
109 printf(" position %ld masks %d\n",
111 ((MaskAuto*)current)->masks.total);
112 ((MaskAuto*)current)->dump();
117 int MaskAutos::mask_exists(int64_t position, int direction)
120 position = (direction == PLAY_FORWARD) ? position : (position - 1);
122 MaskAuto* keyframe = (MaskAuto*)get_prev_auto(position, direction, current);
126 for(int i = 0; i < keyframe->masks.total; i++)
128 SubMask *mask = keyframe->get_submask(i);
129 if(mask->points.total > 1)
135 int MaskAutos::total_submasks(int64_t position, int direction)
137 position = (direction == PLAY_FORWARD) ? position : (position - 1);
138 for(MaskAuto* current = (MaskAuto*)last;
140 current = (MaskAuto*)PREVIOUS)
142 if(current->position <= position)
144 return current->masks.total;
148 return ((MaskAuto*)default_auto)->masks.total;