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
24 #include "bcsignals.h"
29 #include "edlsession.h"
30 #include "filesystem.h"
32 #include "indexable.h"
34 #include "localsession.h"
35 #include "mainclock.h"
37 #include "mainsession.h"
39 #include "mwindowgui.h"
40 #include "playbackengine.h"
42 #include "transportque.h"
43 #include "vplayback.h"
45 #include "vtracking.h"
47 #include "vwindowgui.h"
50 VWindow::VWindow(MWindow *mwindow)
53 this->mwindow = mwindow;
66 //printf("VWindow::~VWindow 1\n");
67 delete playback_engine;
68 //printf("VWindow::~VWindow 1\n");
69 delete playback_cursor;
72 //printf("VWindow::~VWindow 2\n");
75 void VWindow::delete_source(int do_main_edl, int update_gui)
77 //printf("VWindow::delete_source %d %d %p %p\n", __LINE__, gui->get_window_lock(), edl, indexable);
78 if(do_main_edl) mwindow->edl->remove_vwindow_edl(get_edl());
82 edl->Garbage::remove_user();
83 //printf("VWindow::delete_source %d\n", __LINE__);
87 // if(mwindow->edl->vwindow_edl && !mwindow->edl->vwindow_edl_shared)
89 // mwindow->edl->vwindow_edl->Garbage::remove_user();
90 // mwindow->edl->vwindow_edl = 0;
91 // mwindow->edl->vwindow_edl_shared = 0;
94 //printf("VWindow::delete_source %d\n", __LINE__);
95 if(indexable) indexable->Garbage::remove_user();
98 if(update_gui) gui->change_source(0, _("Viewer"));
99 //printf("VWindow::delete_source %d\n", __LINE__);
103 void VWindow::load_defaults()
107 void VWindow::create_objects()
112 void VWindow::handle_done_event(int result)
114 playback_engine->interrupt_playback(1);
116 if( mwindow->in_destructor ) return;
119 for(int i = 0; i < mwindow->vwindows.size(); i++)
122 //printf("VWindow::handle_done_event %d %d\n", __LINE__, mwindow->vwindows.get(i)->is_running());
123 if(mwindow->vwindows.get(i)->is_running()) total++;
125 // subtract ourselves
128 // Update the menu if no viewers visible
131 mwindow->gui->lock_window("VWindowGUI::close_event");
132 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
133 mwindow->gui->unlock_window();
135 mwindow->session->show_vwindow = 0;
136 mwindow->save_defaults();
140 BC_Window* VWindow::new_gui()
142 //printf("VWindow::create_objects 1\n");
143 gui = new VWindowGUI(mwindow, this);
144 //printf("VWindow::create_objects 1\n");
145 gui->create_objects();
146 //printf("VWindow::create_objects 1\n");
148 playback_engine = new VPlayback(mwindow, this, gui->canvas);
149 //printf("VWindow::create_objects 1\n");
151 // Start command loop
152 playback_engine->create_objects();
153 //printf("VWindow::create_objects 1\n");
154 gui->transport->set_engine(playback_engine);
155 //printf("VWindow::create_objects 1\n");
156 playback_cursor = new VTracking(mwindow, this);
157 //printf("VWindow::create_objects 1\n");
158 playback_cursor->create_objects();
159 //printf("VWindow::create_objects 2\n");
161 clip_edit = new ClipEdit(mwindow, 0, this);
165 void VWindow::handle_close_event(int result)
167 delete playback_engine;
172 EDL* VWindow::get_edl()
174 // return mwindow->edl->vwindow_edl;
178 Indexable* VWindow::get_source()
180 return this->indexable;
183 void VWindow::change_source(int edl_number)
185 if(!is_running()) return;
187 //printf("VWindow::change_source %d %p\n", __LINE__, mwindow->edl->get_vwindow_edl(edl_number));
188 if( edl_number >= 0 && edl_number < mwindow->edl->total_vwindow_edls() &&
189 mwindow->edl->get_vwindow_edl(edl_number) )
191 this->edl = mwindow->edl->get_vwindow_edl(edl_number);
192 this->edl->Garbage::add_user();
193 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
194 update_position(CHANGE_ALL, 1, 1, 1);
199 // if(indexable) indexable->Garbage::remove_user();
201 // mwindow->edl->vwindow_edl_shared = 0;
205 void VWindow::change_source(Indexable *indexable)
207 if(!running()) return;
208 // if(asset && this->asset &&
209 // asset->id == this->asset->id &&
210 // asset == this->asset) return;
212 //printf("VWindow::change_source %d\n", __LINE__);
214 char title[BCTEXTLEN];
216 fs.extract_name(title, indexable->path);
217 //printf("VWindow::change_source 1\n");
220 //printf("VWindow::change_source 1\n");
222 // Generate EDL off of main EDL for cutting
225 if(indexable->is_asset)
227 this->indexable = asset = new Asset;
228 asset->copy_from((Asset*)indexable, 0);
232 this->indexable = nested_edl = new EDL;
233 nested_edl->create_objects();
234 nested_edl->copy_all((EDL*)indexable);
238 this->edl = new EDL(mwindow->edl);
239 this->edl->create_objects();
240 mwindow->edl->append_vwindow_edl(this->edl, 1);
242 // mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
243 // mwindow->edl->vwindow_edl_shared = 0;
244 // mwindow->edl->vwindow_edl->create_objects();
246 //printf("VWindow::change_source 1 %d %p %p\n", __LINE__, asset, nested_edl);
248 mwindow->asset_to_edl(this->edl, asset);
250 mwindow->edl_to_nested(this->edl, nested_edl);
253 gui->change_source(this->edl, title);
254 update_position(CHANGE_ALL, 1, 1, 1);
258 //printf("VWindow::change_source 2\n");
261 void VWindow::change_source(EDL *edl)
263 if(!running()) return;
264 //printf("VWindow::change_source %d %p\n", __LINE__, edl);
265 // EDLs are identical
266 // if(edl && mwindow->edl->vwindow_edl &&
267 // edl->id == mwindow->edl->vwindow_edl->id) return;
268 if(edl && get_edl() && edl->id == get_edl()->id) return;
274 mwindow->edl->append_vwindow_edl(edl, 1);
276 this->edl->Garbage::add_user();
278 // mwindow->edl->vwindow_edl = edl;
279 // in order not to later delete edl if it is shared
280 // edl->Garbage::add_user();
281 // mwindow->edl->vwindow_edl_shared = 1;
284 gui->change_source(edl, edl->local_session->clip_title);
285 update_position(CHANGE_ALL, 1, 1, 1);
288 gui->change_source(edl, _("Viewer"));
292 void VWindow::goto_start()
296 get_edl()->local_session->set_selectionstart(0);
297 get_edl()->local_session->set_selectionend(0);
298 update_position(CHANGE_NONE,
305 void VWindow::goto_end()
309 double position = get_edl()->tracks->total_length();
310 get_edl()->local_session->set_selectionstart(position);
311 get_edl()->local_session->set_selectionend(position);
312 update_position(CHANGE_NONE,
319 void VWindow::update(int do_timebar)
322 gui->timebar->update(1);
325 void VWindow::update_position(int change_type,
330 EDL *edl = get_edl();
333 //printf("VWindow::update_position %d\n", __LINE__);
335 playback_engine->refresh_frame(change_type, edl);
337 double position = edl->local_session->get_selectionstart(1);
338 if(lock_window) gui->lock_window("VWindow::update_position");
339 gui->clock->update(position);
340 if(lock_window) gui->unlock_window();
344 void VWindow::stop_playback(int wait)
346 playback_engine->stop_playback(wait);
349 int VWindow::update_position(double position)
351 EDL *edl = get_edl();
354 gui->unlock_window();
356 playback_engine->interrupt_playback(1);
358 position = mwindow->edl->align_to_frame(position, 0);
359 position = MAX(0, position);
361 edl->local_session->set_selectionstart(position);
362 edl->local_session->set_selectionend(position);
364 gui->lock_window("VWindow::update_position 1");
365 update_position(CHANGE_NONE, 0, 1, 0);
371 void VWindow::set_inpoint()
373 EDL *edl = get_edl();
376 edl->set_inpoint(edl->local_session->get_selectionstart(1));
377 gui->timebar->update(1);
381 void VWindow::set_outpoint()
383 EDL *edl = get_edl();
386 edl->set_outpoint(edl->local_session->get_selectionstart(1));
387 gui->timebar->update(1);
391 void VWindow::unset_inoutpoint()
393 EDL *edl = get_edl();
396 edl->unset_inoutpoint();
397 gui->timebar->update(1);
403 EDL *edl = get_edl();
406 double start = edl->local_session->get_selectionstart();
407 double end = edl->local_session->get_selectionend();
417 const char *file_string = file.string();
418 long file_length = strlen(file_string);
419 mwindow->gui->lock_window();
420 mwindow->gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
421 mwindow->gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
422 mwindow->gui->unlock_window();
426 void VWindow::splice_selection()
430 void VWindow::overwrite_selection()