00001 #include "asset.h"
00002 #include "assets.h"
00003 #include "clipedit.h"
00004 #include "defaults.h"
00005 #include "edl.h"
00006 #include "edlsession.h"
00007 #include "filesystem.h"
00008 #include "filexml.h"
00009 #include "language.h"
00010 #include "localsession.h"
00011 #include "mainclock.h"
00012 #include "mwindow.h"
00013 #include "mwindowgui.h"
00014 #include "playbackengine.h"
00015 #include "tracks.h"
00016 #include "transportque.h"
00017 #include "vplayback.h"
00018 #include "vtimebar.h"
00019 #include "vtracking.h"
00020 #include "vwindow.h"
00021 #include "vwindowgui.h"
00022
00023
00024 VWindow::VWindow(MWindow *mwindow) : Thread()
00025 {
00026 this->mwindow = mwindow;
00027 asset = 0;
00028 }
00029
00030
00031 VWindow::~VWindow()
00032 {
00033
00034 delete playback_engine;
00035
00036 delete playback_cursor;
00037 delete_edl();
00038 delete clip_edit;
00039
00040 }
00041
00042 void VWindow::delete_edl()
00043 {
00044
00045 if(mwindow->edl->vwindow_edl)
00046 {
00047 if (!edl_shared)
00048 delete mwindow->edl->vwindow_edl;
00049 mwindow->edl->vwindow_edl = 0;
00050 }
00051
00052 if(asset) delete asset;
00053 asset = 0;
00054 edl_shared = 0;
00055 }
00056
00057
00058 void VWindow::load_defaults()
00059 {
00060 }
00061
00062 int VWindow::create_objects()
00063 {
00064
00065 gui = new VWindowGUI(mwindow, this);
00066
00067 gui->create_objects();
00068
00069
00070 playback_engine = new VPlayback(mwindow, this, gui->canvas);
00071
00072
00073
00074 playback_engine->create_objects();
00075
00076 gui->transport->set_engine(playback_engine);
00077
00078 playback_cursor = new VTracking(mwindow, this);
00079
00080 playback_cursor->create_objects();
00081
00082
00083 clip_edit = new ClipEdit(mwindow, 0, this);
00084 return 0;
00085 }
00086
00087 void VWindow::run()
00088 {
00089 gui->run_window();
00090 }
00091
00092 EDL* VWindow::get_edl()
00093 {
00094
00095 return mwindow->edl->vwindow_edl;
00096 }
00097
00098 Asset* VWindow::get_asset()
00099 {
00100 return this->asset;
00101 }
00102
00103 void VWindow::change_source()
00104 {
00105
00106 if(mwindow->edl->vwindow_edl)
00107 {
00108 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
00109 update_position(CHANGE_ALL, 1, 1);
00110 }
00111 else
00112 {
00113 if(asset) delete asset;
00114 asset = 0;
00115 edl_shared = 0;
00116 }
00117 }
00118
00119 void VWindow::change_source(Asset *asset)
00120 {
00121
00122
00123
00124
00125
00126
00127
00128 char title[BCTEXTLEN];
00129 FileSystem fs;
00130 fs.extract_name(title, asset->path);
00131
00132
00133 delete_edl();
00134
00135
00136
00137 this->asset = new Asset;
00138 *this->asset = *asset;
00139 mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
00140 edl_shared = 0;
00141 mwindow->edl->vwindow_edl->create_objects();
00142 mwindow->asset_to_edl(mwindow->edl->vwindow_edl, asset);
00143
00144
00145
00146
00147 gui->change_source(mwindow->edl->vwindow_edl, title);
00148 update_position(CHANGE_ALL, 1, 1);
00149
00150
00151
00152 strcpy(mwindow->edl->session->vwindow_folder, MEDIA_FOLDER);
00153 mwindow->edl->session->vwindow_source = 0;
00154 int i = 0;
00155 for(Asset *current = mwindow->edl->assets->first;
00156 current;
00157 current = NEXT)
00158 {
00159 if(this->asset->equivalent(*current, 0, 0))
00160 {
00161 mwindow->edl->session->vwindow_source = i;
00162 break;
00163 }
00164 i++;
00165 }
00166
00167
00168 }
00169
00170 void VWindow::change_source(EDL *edl)
00171 {
00172
00173
00174
00175 if(edl && mwindow->edl->vwindow_edl &&
00176 edl->id == mwindow->edl->vwindow_edl->id) return;
00177
00178 delete_edl();
00179
00180 if(edl)
00181 {
00182 this->asset = 0;
00183 mwindow->edl->vwindow_edl = edl;
00184
00185 edl_shared = 1;
00186
00187
00188 gui->change_source(edl, edl->local_session->clip_title);
00189 update_position(CHANGE_ALL, 1, 1);
00190
00191
00192 strcpy(mwindow->edl->session->vwindow_folder, CLIP_FOLDER);
00193 mwindow->edl->session->vwindow_source =
00194 mwindow->edl->clips.number_of(edl);
00195 }
00196 else
00197 gui->change_source(edl, _("Viewer"));
00198 }
00199
00200
00201 void VWindow::remove_source()
00202 {
00203 delete_edl();
00204 gui->change_source(0, _("Viewer"));
00205 }
00206
00207 void VWindow::change_source(char *folder, int item)
00208 {
00209
00210 int result = 0;
00211
00212 if(!strcasecmp(folder, CLIP_FOLDER))
00213 {
00214 if(item < mwindow->edl->clips.total)
00215 {
00216 change_source(mwindow->edl->clips.values[item]);
00217 result = 1;
00218 }
00219 }
00220 else
00221
00222 if(!strcasecmp(folder, MEDIA_FOLDER))
00223 {
00224 if(item < mwindow->edl->assets->total())
00225 {
00226 change_source(mwindow->edl->assets->get_item_number(item));
00227 result = 1;
00228 }
00229 }
00230 else
00231
00232 {
00233 }
00234
00235 if(!result)
00236 {
00237 remove_source();
00238 }
00239 }
00240
00241
00242
00243
00244 void VWindow::goto_start()
00245 {
00246 if(get_edl())
00247 {
00248 get_edl()->local_session->set_selectionstart(0);
00249 get_edl()->local_session->set_selectionend(0);
00250 update_position(CHANGE_NONE,
00251 0,
00252 1);
00253 }
00254 }
00255
00256 void VWindow::goto_end()
00257 {
00258 if(get_edl())
00259 {
00260 double position = get_edl()->tracks->total_length();
00261 get_edl()->local_session->set_selectionstart(position);
00262 get_edl()->local_session->set_selectionend(position);
00263 update_position(CHANGE_NONE,
00264 0,
00265 1);
00266 }
00267 }
00268
00269 void VWindow::update(int do_timebar)
00270 {
00271 if(do_timebar)
00272 gui->timebar->update();
00273 }
00274
00275 void VWindow::update_position(int change_type,
00276 int use_slider,
00277 int update_slider)
00278 {
00279 EDL *edl = get_edl();
00280 if(edl)
00281 {
00282 Asset *asset = edl->assets->first;
00283 if(use_slider)
00284 {
00285 edl->local_session->set_selectionstart(gui->slider->get_value());
00286 edl->local_session->set_selectionend(gui->slider->get_value());
00287 }
00288
00289 if(update_slider)
00290 {
00291 gui->slider->set_position();
00292 }
00293
00294 playback_engine->que->send_command(CURRENT_FRAME,
00295 change_type,
00296 edl,
00297 1);
00298
00299 gui->clock->update(edl->local_session->get_selectionstart(1) +
00300 asset->tcstart /
00301 (asset->video_data ? asset->frame_rate : asset->sample_rate));
00302 }
00303 }
00304
00305 void VWindow::set_inpoint()
00306 {
00307 EDL *edl = get_edl();
00308 if(edl)
00309 {
00310 edl->set_inpoint(edl->local_session->get_selectionstart(1));
00311 gui->timebar->update();
00312 }
00313 }
00314
00315 void VWindow::set_outpoint()
00316 {
00317 EDL *edl = get_edl();
00318 if(edl)
00319 {
00320 edl->set_outpoint(edl->local_session->get_selectionstart(1));
00321 gui->timebar->update();
00322 }
00323 }
00324
00325 void VWindow::clear_inpoint()
00326 {
00327 EDL *edl = get_edl();
00328 if(edl)
00329 {
00330 edl->local_session->unset_inpoint();
00331 gui->timebar->update();
00332 }
00333 }
00334
00335 void VWindow::clear_outpoint()
00336 {
00337 EDL *edl = get_edl();
00338 if(edl)
00339 {
00340 edl->local_session->unset_outpoint();
00341 gui->timebar->update();
00342 }
00343 }
00344
00345 void VWindow::copy()
00346 {
00347 EDL *edl = get_edl();
00348 if(edl)
00349 {
00350 double start = edl->local_session->get_selectionstart();
00351 double end = edl->local_session->get_selectionend();
00352 FileXML file;
00353 edl->copy(start,
00354 end,
00355 0,
00356 0,
00357 0,
00358 &file,
00359 mwindow->plugindb,
00360 "",
00361 1);
00362 mwindow->gui->lock_window();
00363 mwindow->gui->get_clipboard()->to_clipboard(file.string,
00364 strlen(file.string),
00365 SECONDARY_SELECTION);
00366 mwindow->gui->unlock_window();
00367 }
00368 }
00369
00370 void VWindow::splice_selection()
00371 {
00372 }
00373
00374 void VWindow::overwrite_selection()
00375 {
00376 }
00377
00378
00379