4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "edlsession.h"
29 #include "filesystem.h"
31 #include "indexable.h"
33 #include "localsession.h"
34 #include "mainclock.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
39 #include "playbackengine.h"
41 #include "transportque.h"
42 #include "vplayback.h"
44 #include "vtracking.h"
46 #include "vwindowgui.h"
49 VWindow::VWindow(MWindow *mwindow) : BC_DialogThread()
51 this->mwindow = mwindow;
67 //printf("VWindow::~VWindow 1\n");
68 delete playback_engine;
69 //printf("VWindow::~VWindow 1\n");
70 delete playback_cursor;
73 //printf("VWindow::~VWindow 2\n");
76 void VWindow::delete_source(int do_main_edl, int update_gui)
78 if(do_main_edl) mwindow->edl->remove_vwindow_edl(get_edl());
83 //printf("VWindow::delete_source %d %p\n", __LINE__, edl);
84 edl->Garbage::remove_user();
85 //printf("VWindow::delete_source %d\n", __LINE__);
89 // if(mwindow->edl->vwindow_edl && !mwindow->edl->vwindow_edl_shared)
91 // mwindow->edl->vwindow_edl->Garbage::remove_user();
92 // mwindow->edl->vwindow_edl = 0;
93 // mwindow->edl->vwindow_edl_shared = 0;
96 //printf("VWindow::delete_source %d\n", __LINE__);
97 if(indexable) indexable->Garbage::remove_user();
98 //printf("VWindow::delete_source %d\n", __LINE__);
101 if(update_gui) gui->change_source(0, _("Viewer"));
105 void VWindow::load_defaults()
109 void VWindow::create_objects()
114 void VWindow::handle_close_event(int result)
117 delete playback_engine;
118 delete playback_cursor;
123 if( mwindow->in_destructor ) return;
126 for(int i = 0; i < mwindow->vwindows.size(); i++)
129 //printf("VWindow::handle_close_event %d %d\n", __LINE__, mwindow->vwindows.get(i)->is_running());
130 if(mwindow->vwindows.get(i)->is_running()) total++;
132 // subtract ourselves
135 // Update the menu if no viewers visible
138 mwindow->gui->lock_window("VWindowGUI::close_event");
139 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
140 mwindow->gui->unlock_window();
142 mwindow->session->show_vwindow = 0;
143 mwindow->save_defaults();
149 BC_Window* VWindow::new_gui()
151 //printf("VWindow::create_objects 1\n");
152 gui = new VWindowGUI(mwindow, this);
153 //printf("VWindow::create_objects 1\n");
154 gui->create_objects();
155 //printf("VWindow::create_objects 1\n");
157 playback_engine = new VPlayback(mwindow, this, gui->canvas);
158 //printf("VWindow::create_objects 1\n");
160 // Start command loop
161 playback_engine->create_objects();
162 //printf("VWindow::create_objects 1\n");
163 gui->transport->set_engine(playback_engine);
164 //printf("VWindow::create_objects 1\n");
165 playback_cursor = new VTracking(mwindow, this);
166 //printf("VWindow::create_objects 1\n");
167 playback_cursor->create_objects();
168 //printf("VWindow::create_objects 2\n");
170 clip_edit = new ClipEdit(mwindow, 0, this);
175 EDL* VWindow::get_edl()
177 // return mwindow->edl->vwindow_edl;
181 Indexable* VWindow::get_source()
183 return this->indexable;
186 void VWindow::change_source(int edl_number)
188 if(!is_running()) return;
190 //printf("VWindow::change_source %d %p\n", __LINE__, mwindow->edl->get_vwindow_edl(edl_number));
191 if( edl_number >= 0 && edl_number < mwindow->edl->total_vwindow_edls() &&
192 mwindow->edl->get_vwindow_edl(edl_number) )
194 this->edl = mwindow->edl->get_vwindow_edl(edl_number);
195 this->edl->Garbage::add_user();
196 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
197 update_position(CHANGE_ALL, 1, 1, 1);
202 // if(indexable) indexable->Garbage::remove_user();
204 // mwindow->edl->vwindow_edl_shared = 0;
208 void VWindow::change_source(Indexable *indexable)
210 if(!running()) return;
211 //printf("VWindow::change_source %d\n", __LINE__);
212 // if(asset && this->asset &&
213 // asset->id == this->asset->id &&
214 // asset == this->asset) return;
216 //printf("VWindow::change_source %d\n", __LINE__);
218 char title[BCTEXTLEN];
220 fs.extract_name(title, indexable->path);
221 //printf("VWindow::change_source 1\n");
224 //printf("VWindow::change_source 1\n");
226 // Generate EDL off of main EDL for cutting
229 if(indexable->is_asset)
231 this->indexable = asset = new Asset;
232 asset->copy_from((Asset*)indexable, 0);
236 this->indexable = nested_edl = new EDL;
237 nested_edl->create_objects();
238 nested_edl->copy_all((EDL*)indexable);
242 this->edl = new EDL(mwindow->edl);
243 this->edl->create_objects();
244 mwindow->edl->append_vwindow_edl(this->edl, 1);
246 // mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
247 // mwindow->edl->vwindow_edl_shared = 0;
248 // mwindow->edl->vwindow_edl->create_objects();
250 //printf("VWindow::change_source 1 %d %p %p\n", __LINE__, asset, nested_edl);
252 mwindow->asset_to_edl(this->edl, asset);
254 mwindow->edl_to_nested(this->edl, nested_edl);
257 gui->change_source(this->edl, title);
258 update_position(CHANGE_ALL, 1, 1, 1);
262 //printf("VWindow::change_source 2\n");
265 void VWindow::change_source(EDL *edl)
267 if(!running()) return;
268 //printf("VWindow::change_source %d %p\n", __LINE__, edl);
269 // EDLs are identical
270 // if(edl && mwindow->edl->vwindow_edl &&
271 // edl->id == mwindow->edl->vwindow_edl->id) return;
272 if(edl && get_edl() && edl->id == get_edl()->id) return;
278 mwindow->edl->append_vwindow_edl(edl, 1);
280 this->edl->Garbage::add_user();
282 // mwindow->edl->vwindow_edl = edl;
283 // in order not to later delete edl if it is shared
284 // edl->Garbage::add_user();
285 // mwindow->edl->vwindow_edl_shared = 1;
288 gui->change_source(edl, edl->local_session->clip_title);
289 update_position(CHANGE_ALL, 1, 1, 1);
292 gui->change_source(edl, _("Viewer"));
295 void VWindow::change_source(char *folder, int item)
297 //printf("VWindow::change_source %d\n", __LINE__);
299 if(!running()) return;
301 if(!strcasecmp(folder, CLIP_FOLDER))
303 if(item < mwindow->edl->clips.total)
305 change_source(mwindow->edl->clips.values[item]);
311 if(!strcasecmp(folder, MEDIA_FOLDER))
313 if(item < mwindow->edl->assets->total())
315 change_source(mwindow->edl->assets->get_item_number(item));
320 // Search extra clip folders
333 void VWindow::goto_start()
337 get_edl()->local_session->set_selectionstart(0);
338 get_edl()->local_session->set_selectionend(0);
339 update_position(CHANGE_NONE,
346 void VWindow::goto_end()
350 double position = get_edl()->tracks->total_length();
351 get_edl()->local_session->set_selectionstart(position);
352 get_edl()->local_session->set_selectionend(position);
353 update_position(CHANGE_NONE,
360 void VWindow::update(int do_timebar)
363 gui->timebar->update(1);
366 void VWindow::update_position(int change_type,
371 EDL *edl = get_edl();
374 //printf("VWindow::update_position %d\n", __LINE__);
376 playback_engine->que->send_command(CURRENT_FRAME,
381 if(lock_window) gui->lock_window("VWindow::update_position");
382 gui->clock->update(edl->local_session->get_selectionstart(1));
383 if(lock_window) gui->unlock_window();
391 int VWindow::update_position(double position)
393 EDL *edl = get_edl();
396 gui->unlock_window();
398 playback_engine->interrupt_playback(1);
400 position = mwindow->edl->align_to_frame(position, 0);
401 position = MAX(0, position);
403 edl->local_session->set_selectionstart(position);
404 edl->local_session->set_selectionend(position);
406 gui->lock_window("VWindow::update_position 1");
407 update_position(CHANGE_NONE, 0, 1, 0);
414 void VWindow::set_inpoint()
416 EDL *edl = get_edl();
419 edl->set_inpoint(edl->local_session->get_selectionstart(1));
420 gui->timebar->update(1);
424 void VWindow::set_outpoint()
426 EDL *edl = get_edl();
429 edl->set_outpoint(edl->local_session->get_selectionstart(1));
430 gui->timebar->update(1);
434 void VWindow::clear_inpoint()
436 EDL *edl = get_edl();
439 edl->local_session->unset_inpoint();
440 gui->timebar->update(1);
444 void VWindow::clear_outpoint()
446 EDL *edl = get_edl();
449 edl->local_session->unset_outpoint();
450 gui->timebar->update(1);
456 EDL *edl = get_edl();
459 double start = edl->local_session->get_selectionstart();
460 double end = edl->local_session->get_selectionend();
470 const char *file_string = file.string();
471 long file_length = strlen(file_string);
472 mwindow->gui->lock_window();
473 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
474 SECONDARY_SELECTION);
475 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
476 BC_PRIMARY_SELECTION);
477 mwindow->gui->unlock_window();
481 void VWindow::splice_selection()
485 void VWindow::overwrite_selection()