00001 #include "automation.inc"
00002 #include "clip.h"
00003 #include "maskauto.h"
00004 #include "maskautos.h"
00005 #include "transportque.inc"
00006
00007
00008
00009
00010 MaskAutos::MaskAutos(EDL *edl,
00011 Track *track)
00012 : Autos(edl, track)
00013 {
00014 type = AUTOMATION_TYPE_MASK;
00015 }
00016
00017 MaskAutos::~MaskAutos()
00018 {
00019 }
00020
00021
00022 void MaskAutos::get_points(ArrayList<MaskPoint*> *points, int submask, int64_t position, int direction)
00023 {
00024 MaskAuto *begin = 0, *end = 0;
00025 position = (direction == PLAY_FORWARD) ? position : (position - 1);
00026
00027
00028 for(MaskAuto* current = (MaskAuto*)last;
00029 current;
00030 current = (MaskAuto*)PREVIOUS)
00031 {
00032 if(current->position <= position)
00033 {
00034 begin = current;
00035 end = NEXT ? (MaskAuto*)NEXT : current;
00036 break;
00037 }
00038 }
00039
00040
00041 if(!begin)
00042 {
00043 begin = end = (MaskAuto*)first;
00044 }
00045
00046
00047 if(!begin)
00048 {
00049 begin = end = (MaskAuto*)default_auto;
00050 }
00051
00052
00053 SubMask *mask1 = begin->get_submask(submask);
00054 SubMask *mask2 = end->get_submask(submask);
00055
00056 points->remove_all_objects();
00057 int total_points = MIN(mask1->points.total, mask2->points.total);
00058 for(int i = 0; i < total_points; i++)
00059 {
00060 MaskPoint *point = new MaskPoint;
00061 avg_points(point,
00062 mask1->points.values[i],
00063 mask2->points.values[i],
00064 position,
00065 begin->position,
00066 end->position);
00067 points->append(point);
00068 }
00069 }
00070
00071 void MaskAutos::avg_points(MaskPoint *output,
00072 MaskPoint *input1,
00073 MaskPoint *input2,
00074 int64_t output_position,
00075 int64_t position1,
00076 int64_t position2)
00077 {
00078 if(position2 == position1)
00079 {
00080 *output = *input1;
00081 }
00082 else
00083 {
00084 float fraction2 = (float)(output_position - position1) / (position2 - position1);
00085 float fraction1 = 1 - fraction2;
00086 output->x = input1->x * fraction1 + input2->x * fraction2;
00087 output->y = input1->y * fraction1 + input2->y * fraction2;
00088 output->control_x1 = input1->control_x1 * fraction1 + input2->control_x1 * fraction2;
00089 output->control_y1 = input1->control_y1 * fraction1 + input2->control_y1 * fraction2;
00090 output->control_x2 = input1->control_x2 * fraction1 + input2->control_x2 * fraction2;
00091 output->control_y2 = input1->control_y2 * fraction1 + input2->control_y2 * fraction2;
00092 }
00093
00094 }
00095
00096
00097 Auto* MaskAutos::new_auto()
00098 {
00099 return new MaskAuto(edl, this);
00100 }
00101
00102 void MaskAutos::dump()
00103 {
00104 printf(" MaskAutos::dump %p\n", this);
00105 printf(" Default: position %ld submasks %d\n",
00106 default_auto->position,
00107 ((MaskAuto*)default_auto)->masks.total);
00108 ((MaskAuto*)default_auto)->dump();
00109 for(Auto* current = first; current; current = NEXT)
00110 {
00111 printf(" position %ld masks %d\n",
00112 current->position,
00113 ((MaskAuto*)current)->masks.total);
00114 ((MaskAuto*)current)->dump();
00115 }
00116 }
00117
00118 int MaskAutos::mask_exists(int64_t position, int direction)
00119 {
00120 Auto *current = 0;
00121 position = (direction == PLAY_FORWARD) ? position : (position - 1);
00122
00123 MaskAuto* keyframe = (MaskAuto*)get_prev_auto(position, direction, current);
00124
00125
00126
00127 for(int i = 0; i < keyframe->masks.total; i++)
00128 {
00129 SubMask *mask = keyframe->get_submask(i);
00130 if(mask->points.total > 1)
00131 return 1;
00132 }
00133 return 0;
00134 }
00135
00136 int MaskAutos::total_submasks(int64_t position, int direction)
00137 {
00138 position = (direction == PLAY_FORWARD) ? position : (position - 1);
00139 for(MaskAuto* current = (MaskAuto*)last;
00140 current;
00141 current = (MaskAuto*)PREVIOUS)
00142 {
00143 if(current->position <= position)
00144 {
00145 return current->masks.total;
00146 }
00147 }
00148
00149 return ((MaskAuto*)default_auto)->masks.total;
00150 }
00151
00152
00153 void MaskAutos::translate_masks(float translate_x, float translate_y)
00154 {
00155 ((MaskAuto *)default_auto)->translate_submasks(translate_x, translate_y);
00156 for(MaskAuto* current = (MaskAuto*)first;
00157 current;
00158 current = (MaskAuto*)NEXT)
00159 {
00160 current->translate_submasks(translate_x, translate_y);
00161 for(int i = 0; i < current->masks.total; i++)
00162 {
00163 SubMask *mask = current->get_submask(i);
00164 for (int j = 0; j < mask->points.total; j++)
00165 {
00166 mask->points.values[j]->x += translate_x;
00167 mask->points.values[j]->y += translate_y;
00168 printf("mpx: %f, mpy:%f\n",mask->points.values[j]->x,mask->points.values[j]->y);
00169 }
00170 }
00171
00172 }
00173 }
00174