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();
142 BC_Window* VWindow::new_gui()
144 //printf("VWindow::create_objects 1\n");
145 gui = new VWindowGUI(mwindow, this);
146 //printf("VWindow::create_objects 1\n");
147 gui->create_objects();
148 //printf("VWindow::create_objects 1\n");
150 playback_engine = new VPlayback(mwindow, this, gui->canvas);
151 //printf("VWindow::create_objects 1\n");
153 // Start command loop
154 playback_engine->create_objects();
155 //printf("VWindow::create_objects 1\n");
156 gui->transport->set_engine(playback_engine);
157 //printf("VWindow::create_objects 1\n");
158 playback_cursor = new VTracking(mwindow, this);
159 //printf("VWindow::create_objects 1\n");
160 playback_cursor->create_objects();
161 //printf("VWindow::create_objects 2\n");
163 clip_edit = new ClipEdit(mwindow, 0, this);
168 EDL* VWindow::get_edl()
170 // return mwindow->edl->vwindow_edl;
174 Indexable* VWindow::get_source()
176 return this->indexable;
179 void VWindow::change_source(int edl_number)
181 if(!is_running()) return;
183 //printf("VWindow::change_source %d %p\n", __LINE__, mwindow->edl->get_vwindow_edl(edl_number));
184 if( edl_number >= 0 && edl_number < mwindow->edl->total_vwindow_edls() &&
185 mwindow->edl->get_vwindow_edl(edl_number) )
187 this->edl = mwindow->edl->get_vwindow_edl(edl_number);
188 this->edl->Garbage::add_user();
189 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
190 update_position(CHANGE_ALL, 1, 1, 1);
195 // if(indexable) indexable->Garbage::remove_user();
197 // mwindow->edl->vwindow_edl_shared = 0;
201 void VWindow::change_source(Indexable *indexable)
203 if(!running()) return;
204 //printf("VWindow::change_source %d\n", __LINE__);
205 // if(asset && this->asset &&
206 // asset->id == this->asset->id &&
207 // asset == this->asset) return;
209 //printf("VWindow::change_source %d\n", __LINE__);
211 char title[BCTEXTLEN];
213 fs.extract_name(title, indexable->path);
214 //printf("VWindow::change_source 1\n");
217 //printf("VWindow::change_source 1\n");
219 // Generate EDL off of main EDL for cutting
222 if(indexable->is_asset)
224 this->indexable = asset = new Asset;
225 asset->copy_from((Asset*)indexable, 0);
229 this->indexable = nested_edl = new EDL;
230 nested_edl->create_objects();
231 nested_edl->copy_all((EDL*)indexable);
235 this->edl = new EDL(mwindow->edl);
236 this->edl->create_objects();
237 mwindow->edl->append_vwindow_edl(this->edl, 1);
239 // mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
240 // mwindow->edl->vwindow_edl_shared = 0;
241 // mwindow->edl->vwindow_edl->create_objects();
243 //printf("VWindow::change_source 1 %d %p %p\n", __LINE__, asset, nested_edl);
245 mwindow->asset_to_edl(this->edl, asset);
247 mwindow->edl_to_nested(this->edl, nested_edl);
250 gui->change_source(this->edl, title);
251 update_position(CHANGE_ALL, 1, 1, 1);
255 //printf("VWindow::change_source 2\n");
258 void VWindow::change_source(EDL *edl)
260 if(!running()) return;
261 //printf("VWindow::change_source %d %p\n", __LINE__, edl);
262 // EDLs are identical
263 // if(edl && mwindow->edl->vwindow_edl &&
264 // edl->id == mwindow->edl->vwindow_edl->id) return;
265 if(edl && get_edl() && edl->id == get_edl()->id) return;
271 mwindow->edl->append_vwindow_edl(edl, 1);
273 this->edl->Garbage::add_user();
275 // mwindow->edl->vwindow_edl = edl;
276 // in order not to later delete edl if it is shared
277 // edl->Garbage::add_user();
278 // mwindow->edl->vwindow_edl_shared = 1;
281 gui->change_source(edl, edl->local_session->clip_title);
282 update_position(CHANGE_ALL, 1, 1, 1);
285 gui->change_source(edl, _("Viewer"));
288 void VWindow::change_source(char *folder, int item)
290 //printf("VWindow::change_source %d\n", __LINE__);
292 if(!running()) return;
294 if(!strcasecmp(folder, CLIP_FOLDER))
296 if(item < mwindow->edl->clips.total)
298 change_source(mwindow->edl->clips.values[item]);
304 if(!strcasecmp(folder, MEDIA_FOLDER))
306 if(item < mwindow->edl->assets->total())
308 change_source(mwindow->edl->assets->get_item_number(item));
313 // Search extra clip folders
326 void VWindow::goto_start()
330 get_edl()->local_session->set_selectionstart(0);
331 get_edl()->local_session->set_selectionend(0);
332 update_position(CHANGE_NONE,
339 void VWindow::goto_end()
343 double position = get_edl()->tracks->total_length();
344 get_edl()->local_session->set_selectionstart(position);
345 get_edl()->local_session->set_selectionend(position);
346 update_position(CHANGE_NONE,
353 void VWindow::update(int do_timebar)
356 gui->timebar->update(1);
359 void VWindow::update_position(int change_type,
364 EDL *edl = get_edl();
367 //printf("VWindow::update_position %d\n", __LINE__);
369 playback_engine->que->send_command(CURRENT_FRAME,
374 if(lock_window) gui->lock_window("VWindow::update_position");
375 gui->clock->update(edl->local_session->get_selectionstart(1));
376 if(lock_window) gui->unlock_window();
384 int VWindow::update_position(double position)
386 EDL *edl = get_edl();
389 gui->unlock_window();
391 playback_engine->interrupt_playback(1);
393 position = mwindow->edl->align_to_frame(position, 0);
394 position = MAX(0, position);
396 edl->local_session->set_selectionstart(position);
397 edl->local_session->set_selectionend(position);
399 gui->lock_window("VWindow::update_position 1");
400 update_position(CHANGE_NONE, 0, 1, 0);
407 void VWindow::set_inpoint()
409 EDL *edl = get_edl();
412 edl->set_inpoint(edl->local_session->get_selectionstart(1));
413 gui->timebar->update(1);
417 void VWindow::set_outpoint()
419 EDL *edl = get_edl();
422 edl->set_outpoint(edl->local_session->get_selectionstart(1));
423 gui->timebar->update(1);
427 void VWindow::clear_inpoint()
429 EDL *edl = get_edl();
432 edl->local_session->unset_inpoint();
433 gui->timebar->update(1);
437 void VWindow::clear_outpoint()
439 EDL *edl = get_edl();
442 edl->local_session->unset_outpoint();
443 gui->timebar->update(1);
449 EDL *edl = get_edl();
452 double start = edl->local_session->get_selectionstart();
453 double end = edl->local_session->get_selectionend();
463 const char *file_string = file.string();
464 long file_length = strlen(file_string);
465 mwindow->gui->lock_window();
466 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
467 SECONDARY_SELECTION);
468 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
469 BC_PRIMARY_SELECTION);
470 mwindow->gui->unlock_window();
474 void VWindow::splice_selection()
478 void VWindow::overwrite_selection()