00001 #include "assets.h"
00002 #include "autoconf.h"
00003 #include "bezierautos.h"
00004 #include "cache.h"
00005 #include "edit.h"
00006 #include "edits.h"
00007 #include "filexml.h"
00008 #include "floatautos.h"
00009 #include "mwindow.h"
00010 #include "patch.h"
00011 #include "trackcanvas.h"
00012 #include "tracks.h"
00013 #include "vedit.h"
00014 #include "vedits.h"
00015 #include "vframe.h"
00016 #include "vtrack.h"
00017 #include "datatype.h"
00018
00019 VTrack::VTrack(MWindow *mwindow, Tracks *tracks) : Track(mwindow, tracks)
00020 {
00021 data_type = TRACK_VIDEO;
00022 }
00023
00024 VTrack::~VTrack()
00025 {
00026 delete edits;
00027 delete camera_autos;
00028 delete projector_autos;
00029 }
00030
00031 int VTrack::create_derived_objs(int flash)
00032 {
00033 int i;
00034 edits = new VEdits(mwindow, this);
00035 camera_autos = new BezierAutos(this,
00036 WHITE,
00037 0,
00038 0,
00039 1,
00040 mwindow->track_w,
00041 mwindow->track_h);
00042
00043 projector_autos = new BezierAutos(this,
00044 WHITE,
00045 0,
00046 0,
00047 1,
00048 mwindow->output_w,
00049 mwindow->output_h);
00050
00051 fade_autos = new FloatAutos(this, LTGREY, -100, 100);
00052 fade_autos->create_objects();
00053
00054 if(mwindow->gui)
00055 {
00056 if(mwindow->session->tracks_vertical)
00057 draw(pixel, mwindow->zoom_track, 0, tracks->canvas->h, flash);
00058 else
00059 draw(0, tracks->canvas->w, pixel, mwindow->zoom_track, flash);
00060 }
00061 }
00062
00063
00064 int VTrack::save_derived(FileXML *xml)
00065 {
00066 edits->save(xml);
00067
00068 if(camera_autos->total())
00069 {
00070 xml->tag.set_title("CAMERAAUTOS");
00071 xml->append_tag();
00072 xml->append_newline();
00073 camera_autos->save(xml);
00074 xml->tag.set_title("/CAMERAAUTOS");
00075 xml->append_tag();
00076 xml->append_newline();
00077 }
00078
00079 if(projector_autos->total())
00080 {
00081 xml->tag.set_title("PROJECTORAUTOS");
00082 xml->append_tag();
00083 xml->append_newline();
00084 projector_autos->save(xml);
00085 xml->tag.set_title("/PROJECTORAUTOS");
00086 xml->append_tag();
00087 xml->append_newline();
00088 }
00089 }
00090
00091 int VTrack::load_derived(FileXML *xml, int automation_only, int edits_only, int load_all, int &output_channel)
00092 {
00093 if(xml->tag.title_is("CAMERAAUTOS"))
00094 {
00095 camera_autos->load(xml, "/CAMERAAUTOS");
00096 }
00097 else
00098 if(xml->tag.title_is("PROJECTORAUTOS"))
00099 {
00100 projector_autos->load(xml, "/PROJECTORAUTOS");
00101 }
00102 }
00103
00104 long VTrack::length()
00105 {
00106 return tosamples(edits->end(), mwindow->sample_rate, mwindow->frame_rate);
00107 }
00108
00109 int VTrack::get_dimensions(float &view_start, float &view_units, float &zoom_units)
00110 {
00111 view_start = toframes(mwindow->view_start, mwindow->sample_rate, mwindow->frame_rate);
00112 view_units = toframes(tracks->view_samples(), mwindow->sample_rate, mwindow->frame_rate);
00113 zoom_units = toframes(mwindow->zoom_sample, mwindow->sample_rate, mwindow->frame_rate);
00114 }
00115
00116 long VTrack::samples_to_units(long &samples)
00117 {
00118 samples = toframes_round(samples, mwindow->sample_rate, mwindow->frame_rate);
00119 }
00120
00121 int VTrack::copy_derived(long start, long end, FileXML *xml)
00122 {
00123
00124 }
00125
00126 int VTrack::copy_automation_derived(AutoConf *auto_conf, long start, long end, FileXML *xml)
00127 {
00128
00129 if(auto_conf->camera)
00130 {
00131 xml->tag.set_title("CAMERAAUTOS");
00132 xml->append_tag();
00133
00134 camera_autos->copy(start, end, xml, 1);
00135
00136 xml->tag.set_title("/CAMERAAUTOS");
00137 xml->append_tag();
00138 xml->append_newline();
00139 }
00140
00141 if(auto_conf->projector)
00142 {
00143 xml->tag.set_title("PROJECTORAUTOS");
00144 xml->append_tag();
00145
00146 projector_autos->copy(start, end, xml, 1);
00147
00148 xml->tag.set_title("/PROJECTORAUTOS");
00149 xml->append_tag();
00150 xml->append_newline();
00151 }
00152 }
00153
00154 int VTrack::paste_derived(long start, long end, long total_length, FileXML *xml, int ¤t_channel)
00155 {
00156 if(xml->tag.title_is("CAMERAAUTOS"))
00157 {
00158 camera_autos->paste(start, end, total_length, xml, "/CAMERAAUTOS", 1);
00159 }
00160 else
00161 if(xml->tag.title_is("PROJECTORAUTOS"))
00162 {
00163 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1);
00164 }
00165 }
00166
00167 int VTrack::paste_output(long startproject, long endproject, long startsource, long endsource, int layer, Asset *asset)
00168 {
00169 int result = 0;
00170
00171
00172
00173
00174 result = ((VEdits*)edits)->paste_edit(startproject,
00175 endproject,
00176 startsource,
00177 endsource - startsource,
00178 layer,
00179 0,
00180 0,
00181 1,
00182 asset);
00183
00184
00185
00186
00187
00188 return result;
00189 }
00190
00191 int VTrack::clear_derived(long start, long end)
00192 {
00193 if(mwindow->autos_follow_edits)
00194 {
00195 camera_autos->clear(start, end, mwindow->autos_follow_edits, 1);
00196 projector_autos->clear(start, end, mwindow->autos_follow_edits, 1);
00197 }
00198 }
00199
00200 int VTrack::paste_automation_derived(long start, long end, long total_length, FileXML *xml, int shift_autos, int ¤t_pan)
00201 {
00202
00203 camera_autos->paste(start, end, total_length, xml, "/CAMERAUTOS", 1, shift_autos);
00204 projector_autos->paste(start, end, total_length, xml, "/PROJECTORAUTOS", 1, shift_autos);
00205 }
00206
00207 int VTrack::clear_automation_derived(AutoConf *auto_conf, long start, long end, int shift_autos)
00208 {
00209 if(auto_conf->camera)
00210 camera_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
00211
00212 if(auto_conf->projector)
00213 projector_autos->clear(start, end, mwindow->autos_follow_edits, shift_autos);
00214 }
00215
00216 int VTrack::paste_auto_silence_derived(long start, long end)
00217 {
00218 camera_autos->paste_silence(start, end);
00219 projector_autos->paste_silence(start, end);
00220 }
00221
00222 int VTrack::draw_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf)
00223 {
00224 if(auto_conf->camera)
00225 camera_autos->draw(tracks->canvas,
00226 pixel,
00227 mwindow->zoom_track,
00228 zoom_units,
00229 view_start,
00230 mwindow->session->tracks_vertical);
00231
00232 if(auto_conf->projector)
00233 projector_autos->draw(tracks->canvas,
00234 pixel,
00235 mwindow->zoom_track,
00236 zoom_units,
00237 view_start,
00238 mwindow->session->tracks_vertical);
00239 }
00240
00241 int VTrack::select_translation(int cursor_x, int cursor_y)
00242 {
00243
00244 int result = 0;
00245 float view_start, view_units, zoom_units;
00246 get_dimensions(view_start, view_units, zoom_units);
00247
00248 if(cursor_y > pixel && cursor_y < pixel + mwindow->zoom_track)
00249 {
00250 for(Edit* current = edits->first; current && !result; current = NEXT)
00251 {
00252 result = ((VEdit*)current)->select_translation(cursor_x, cursor_y, view_start, zoom_units);
00253 }
00254 }
00255 return result;
00256 }
00257
00258 int VTrack::update_translation(int cursor_x, int cursor_y, int shift_down)
00259 {
00260 int result = 0;
00261 float view_start, view_units, zoom_units;
00262 get_dimensions(view_start, view_units, zoom_units);
00263
00264 for(Edit* current = edits->first; current && !result; current = NEXT)
00265 {
00266 result = ((VEdit*)current)->update_translation(cursor_x, cursor_y, shift_down, view_start, zoom_units);
00267 }
00268 return result;
00269 }
00270
00271 int VTrack::end_translation()
00272 {
00273 int result = 0;
00274 for(Edit* current = edits->first; current && !result; current = NEXT)
00275 {
00276 result = ((VEdit*)current)->end_translation();
00277 }
00278 return result;
00279 }
00280
00281 int VTrack::reset_translation(long start, long end)
00282 {
00283 int result = 0;
00284 Track::samples_to_units(start, end);
00285 for(Edit* current = edits->first; current && !result; current = NEXT)
00286 {
00287 result = ((VEdit*)current)->reset_translation(start, end);
00288 }
00289 return result;
00290 }
00291
00292
00293 int VTrack::select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y)
00294 {
00295 int result = 0;
00296
00297 if(auto_conf->camera)
00298 result = camera_autos->select_auto(tracks->canvas,
00299 pixel,
00300 mwindow->zoom_track,
00301 zoom_units,
00302 view_start,
00303 cursor_x,
00304 cursor_y,
00305 tracks->canvas->shift_down(),
00306 tracks->canvas->ctrl_down(),
00307 tracks->canvas->get_buttonpress(),
00308 mwindow->session->tracks_vertical);
00309
00310 if(auto_conf->projector && !result)
00311 result = projector_autos->select_auto(tracks->canvas,
00312 pixel,
00313 mwindow->zoom_track,
00314 zoom_units,
00315 view_start,
00316 cursor_x,
00317 cursor_y,
00318 tracks->canvas->shift_down(),
00319 tracks->canvas->ctrl_down(),
00320 tracks->canvas->get_buttonpress(),
00321 mwindow->session->tracks_vertical);
00322
00323 return result;
00324 }
00325
00326
00327 int VTrack::move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
00328 {
00329 int result;
00330 result = 0;
00331
00332 if(auto_conf->camera)
00333 result = camera_autos->move_auto(tracks->canvas,
00334 pixel,
00335 mwindow->zoom_track,
00336 zoom_units,
00337 view_start,
00338 cursor_x,
00339 cursor_y,
00340 shift_down,
00341 mwindow->session->tracks_vertical);
00342
00343 if(auto_conf->projector && !result)
00344 result = projector_autos->move_auto(tracks->canvas,
00345 pixel,
00346 mwindow->zoom_track,
00347 zoom_units,
00348 view_start,
00349 cursor_x,
00350 cursor_y,
00351 shift_down,
00352 mwindow->session->tracks_vertical);
00353
00354 if(result)
00355 {
00356 mwindow->tracks->hide_overlays(0);
00357 draw_clear(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
00358 draw(0, tracks->canvas->w, 0, tracks->canvas->h, 0);
00359 mwindow->tracks->show_overlays(0);
00360 }
00361
00362 return result;
00363 }
00364
00365 int VTrack::draw_floating_autos_derived(float view_start, float zoom_units, AutoConf *auto_conf, int flash)
00366 {
00367 if(auto_conf->camera)
00368 camera_autos->draw_floating_autos(tracks->canvas,
00369 pixel,
00370 mwindow->zoom_track,
00371 zoom_units,
00372 view_start,
00373 mwindow->session->tracks_vertical, flash);
00374
00375 if(auto_conf->projector)
00376 projector_autos->draw_floating_autos(tracks->canvas,
00377 pixel,
00378 mwindow->zoom_track,
00379 zoom_units,
00380 view_start,
00381 mwindow->session->tracks_vertical, flash);
00382 }
00383
00384 int VTrack::release_auto_derived()
00385 {
00386 int result;
00387 result = 0;
00388
00389 result = camera_autos->release_auto();
00390 if(!result) result = projector_autos->release_auto();
00391
00392 return result;
00393 }
00394
00395 int VTrack::scale_video(float camera_scale, float projector_scale, int *offsets)
00396 {
00397
00398 for(VEdit *current = (VEdit*)edits->first; current; current = (VEdit*)NEXT)
00399 {
00400 current->center_z *= camera_scale;
00401 current->center_x = -offsets[0];
00402 current->center_y = -offsets[1];
00403 }
00404
00405
00406 projector_autos->scale_video(projector_scale, &offsets[2]);
00407 }
00408
00409 int VTrack::render(VFrame **output, long input_len, long input_position, float step)
00410 {
00411 BezierAuto *before[4], *after[4];
00412 int i;
00413 for(i = 0; i < 4; i++) { before[i] = 0; after[i] = 0; }
00414
00415
00416
00417
00418
00419
00420 output[0]->clear_frame();
00421
00422
00423 for(VEdit *current = (VEdit*)edits->last; current; current = (VEdit*)PREVIOUS)
00424 {
00425
00426
00427 if(input_position < current->startproject + current->length + current->feather_right &&
00428 input_position >= current->startproject)
00429 current->render(output,
00430 input_len,
00431 input_position,
00432 step,
00433 before,
00434 after,
00435 get_patch_of()->automate);
00436 }
00437 }
00438
00439 int VTrack::get_projection(float &in_x1, float &in_y1, float &in_x2, float &in_y2,
00440 float &out_x1, float &out_y1, float &out_x2, float &out_y2,
00441 int frame_w, int frame_h, long real_position,
00442 BezierAuto **before, BezierAuto **after)
00443 {
00444 static float center_x, center_y, center_z;
00445 static float x[4], y[4];
00446
00447 projector_autos->get_center(center_x, center_y, center_z, (float)real_position, 0, before, after);
00448 x[0] = y[0] = 0;
00449 x[1] = frame_w;
00450 y[1] = frame_h;
00451
00452 center_x += mwindow->output_w / 2;
00453 center_y += mwindow->output_h / 2;
00454
00455 x[2] = center_x - (frame_w / 2) * center_z;
00456 y[2] = center_y - (frame_h / 2) * center_z;
00457 x[3] = x[2] + frame_w * center_z;
00458 y[3] = y[2] + frame_h * center_z;
00459
00460 if(x[2] < 0)
00461 {
00462 x[0] -= x[2] / center_z;
00463 x[2] = 0;
00464 }
00465 if(y[2] < 0)
00466 {
00467 y[0] -= y[2] / center_z;
00468 y[2] = 0;
00469 }
00470 if(x[3] > mwindow->output_w)
00471 {
00472 x[1] -= (x[3] - mwindow->output_w) / center_z;
00473 x[3] = mwindow->output_w;
00474 }
00475 if(y[3] > mwindow->output_h)
00476 {
00477 y[1] -= (y[3] - mwindow->output_h) / center_z;
00478 y[3] = mwindow->output_h;
00479 }
00480
00481 in_x1 = x[0];
00482 in_y1 = y[0];
00483 in_x2 = x[1];
00484 in_y2 = y[1];
00485 out_x1 = x[2];
00486 out_y1 = y[2];
00487 out_x2 = x[3];
00488 out_y2 = y[3];
00489 }
00490
00491 int VTrack::scale_time_derived(float rate_scale, int scale_edits, int scale_autos, long start, long end)
00492 {
00493 camera_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);
00494 projector_autos->scale_time(rate_scale, scale_edits, scale_autos, start, end);
00495 }
00496