1 #include "automation.inc"
5 #include "transportque.inc"
10 MaskAutos::MaskAutos(EDL *edl,
14 type = AUTOMATION_TYPE_MASK;
17 MaskAutos::~MaskAutos()
22 void MaskAutos::get_points(ArrayList<MaskPoint*> *points, int submask, int64_t position, int direction)
24 MaskAuto *begin = 0, *end = 0;
25 position = (direction == PLAY_FORWARD) ? position : (position - 1);
27 // Get auto before and after position
28 for(MaskAuto* current = (MaskAuto*)last;
30 current = (MaskAuto*)PREVIOUS)
32 if(current->position <= position)
35 end = NEXT ? (MaskAuto*)NEXT : current;
40 // Nothing before position found
43 begin = end = (MaskAuto*)first;
46 // Nothing after position found
49 begin = end = (MaskAuto*)default_auto;
53 SubMask *mask1 = begin->get_submask(submask);
54 SubMask *mask2 = end->get_submask(submask);
56 points->remove_all_objects();
57 int total_points = MIN(mask1->points.total, mask2->points.total);
58 for(int i = 0; i < total_points; i++)
60 MaskPoint *point = new MaskPoint;
62 mask1->points.values[i],
63 mask2->points.values[i],
67 points->append(point);
71 void MaskAutos::avg_points(MaskPoint *output,
74 int64_t output_position,
78 if(position2 == position1)
84 float fraction2 = (float)(output_position - position1) / (position2 - position1);
85 float fraction1 = 1 - fraction2;
86 output->x = input1->x * fraction1 + input2->x * fraction2;
87 output->y = input1->y * fraction1 + input2->y * fraction2;
88 output->control_x1 = input1->control_x1 * fraction1 + input2->control_x1 * fraction2;
89 output->control_y1 = input1->control_y1 * fraction1 + input2->control_y1 * fraction2;
90 output->control_x2 = input1->control_x2 * fraction1 + input2->control_x2 * fraction2;
91 output->control_y2 = input1->control_y2 * fraction1 + input2->control_y2 * fraction2;
97 Auto* MaskAutos::new_auto()
99 return new MaskAuto(edl, this);
102 void MaskAutos::dump()
104 printf(" MaskAutos::dump %p\n", this);
105 printf(" Default: position %ld submasks %d\n",
106 default_auto->position,
107 ((MaskAuto*)default_auto)->masks.total);
108 ((MaskAuto*)default_auto)->dump();
109 for(Auto* current = first; current; current = NEXT)
111 printf(" position %ld masks %d\n",
113 ((MaskAuto*)current)->masks.total);
114 ((MaskAuto*)current)->dump();
118 int MaskAutos::mask_exists(int64_t position, int direction)
121 position = (direction == PLAY_FORWARD) ? position : (position - 1);
123 MaskAuto* keyframe = (MaskAuto*)get_prev_auto(position, direction, current);
127 for(int i = 0; i < keyframe->masks.total; i++)
129 SubMask *mask = keyframe->get_submask(i);
130 if(mask->points.total > 1)
136 int MaskAutos::total_submasks(int64_t position, int direction)
138 position = (direction == PLAY_FORWARD) ? position : (position - 1);
139 for(MaskAuto* current = (MaskAuto*)last;
141 current = (MaskAuto*)PREVIOUS)
143 if(current->position <= position)
145 return current->masks.total;
149 return ((MaskAuto*)default_auto)->masks.total;
153 void MaskAutos::translate_masks(float translate_x, float translate_y)
155 ((MaskAuto *)default_auto)->translate_submasks(translate_x, translate_y);
156 for(MaskAuto* current = (MaskAuto*)first;
158 current = (MaskAuto*)NEXT)
160 current->translate_submasks(translate_x, translate_y);
161 for(int i = 0; i < current->masks.total; i++)
163 SubMask *mask = current->get_submask(i);
164 for (int j = 0; j < mask->points.total; j++)
166 mask->points.values[j]->x += translate_x;
167 mask->points.values[j]->y += translate_y;
168 printf("mpx: %f, mpy:%f\n",mask->points.values[j]->x,mask->points.values[j]->y);