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