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)
52 this->mwindow = mwindow;
65 //printf("VWindow::~VWindow 1\n");
66 delete playback_engine;
67 //printf("VWindow::~VWindow 1\n");
68 delete playback_cursor;
71 //printf("VWindow::~VWindow 2\n");
74 void VWindow::delete_source(int do_main_edl, int update_gui)
76 if(do_main_edl) mwindow->edl->remove_vwindow_edl(get_edl());
81 //printf("VWindow::delete_source %d %p\n", __LINE__, 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();
96 //printf("VWindow::delete_source %d\n", __LINE__);
99 if(update_gui) gui->change_source(0, _("Viewer"));
103 void VWindow::load_defaults()
107 void VWindow::create_objects()
112 void VWindow::handle_close_event(int result)
115 delete playback_engine;
116 delete playback_cursor;
121 if( mwindow->in_destructor ) return;
124 for(int i = 0; i < mwindow->vwindows.size(); i++)
127 //printf("VWindow::handle_close_event %d %d\n", __LINE__, mwindow->vwindows.get(i)->is_running());
128 if(mwindow->vwindows.get(i)->is_running()) total++;
130 // subtract ourselves
133 // Update the menu if no viewers visible
136 mwindow->gui->lock_window("VWindowGUI::close_event");
137 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
138 mwindow->gui->unlock_window();
140 mwindow->session->show_vwindow = 0;
141 mwindow->save_defaults();
147 BC_Window* VWindow::new_gui()
149 //printf("VWindow::create_objects 1\n");
150 gui = new VWindowGUI(mwindow, this);
151 //printf("VWindow::create_objects 1\n");
152 gui->create_objects();
153 //printf("VWindow::create_objects 1\n");
155 playback_engine = new VPlayback(mwindow, this, gui->canvas);
156 //printf("VWindow::create_objects 1\n");
158 // Start command loop
159 playback_engine->create_objects();
160 //printf("VWindow::create_objects 1\n");
161 gui->transport->set_engine(playback_engine);
162 //printf("VWindow::create_objects 1\n");
163 playback_cursor = new VTracking(mwindow, this);
164 //printf("VWindow::create_objects 1\n");
165 playback_cursor->create_objects();
166 //printf("VWindow::create_objects 2\n");
168 clip_edit = new ClipEdit(mwindow, 0, this);
173 EDL* VWindow::get_edl()
175 // return mwindow->edl->vwindow_edl;
179 Indexable* VWindow::get_source()
181 return this->indexable;
184 void VWindow::change_source(int edl_number)
186 if(!is_running()) return;
188 //printf("VWindow::change_source %d %p\n", __LINE__, mwindow->edl->get_vwindow_edl(edl_number));
189 if( edl_number >= 0 && edl_number < mwindow->edl->total_vwindow_edls() &&
190 mwindow->edl->get_vwindow_edl(edl_number) )
192 this->edl = mwindow->edl->get_vwindow_edl(edl_number);
193 this->edl->Garbage::add_user();
194 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
195 update_position(CHANGE_ALL, 1, 1, 1);
200 // if(indexable) indexable->Garbage::remove_user();
202 // mwindow->edl->vwindow_edl_shared = 0;
206 void VWindow::change_source(Indexable *indexable)
208 if(!running()) return;
209 //printf("VWindow::change_source %d\n", __LINE__);
210 // if(asset && this->asset &&
211 // asset->id == this->asset->id &&
212 // asset == this->asset) return;
214 //printf("VWindow::change_source %d\n", __LINE__);
216 char title[BCTEXTLEN];
218 fs.extract_name(title, indexable->path);
219 //printf("VWindow::change_source 1\n");
222 //printf("VWindow::change_source 1\n");
224 // Generate EDL off of main EDL for cutting
227 if(indexable->is_asset)
229 this->indexable = asset = new Asset;
230 asset->copy_from((Asset*)indexable, 0);
234 this->indexable = nested_edl = new EDL;
235 nested_edl->create_objects();
236 nested_edl->copy_all((EDL*)indexable);
240 this->edl = new EDL(mwindow->edl);
241 this->edl->create_objects();
242 mwindow->edl->append_vwindow_edl(this->edl, 1);
244 // mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
245 // mwindow->edl->vwindow_edl_shared = 0;
246 // mwindow->edl->vwindow_edl->create_objects();
248 //printf("VWindow::change_source 1 %d %p %p\n", __LINE__, asset, nested_edl);
250 mwindow->asset_to_edl(this->edl, asset);
252 mwindow->edl_to_nested(this->edl, nested_edl);
255 gui->change_source(this->edl, title);
256 update_position(CHANGE_ALL, 1, 1, 1);
260 //printf("VWindow::change_source 2\n");
263 void VWindow::change_source(EDL *edl)
265 if(!running()) return;
266 //printf("VWindow::change_source %d %p\n", __LINE__, edl);
267 // EDLs are identical
268 // if(edl && mwindow->edl->vwindow_edl &&
269 // edl->id == mwindow->edl->vwindow_edl->id) return;
270 if(edl && get_edl() && edl->id == get_edl()->id) return;
276 mwindow->edl->append_vwindow_edl(edl, 1);
278 this->edl->Garbage::add_user();
280 // mwindow->edl->vwindow_edl = edl;
281 // in order not to later delete edl if it is shared
282 // edl->Garbage::add_user();
283 // mwindow->edl->vwindow_edl_shared = 1;
286 gui->change_source(edl, edl->local_session->clip_title);
287 update_position(CHANGE_ALL, 1, 1, 1);
290 gui->change_source(edl, _("Viewer"));
293 void VWindow::change_source(char *folder, int item)
295 //printf("VWindow::change_source %d\n", __LINE__);
297 if(!running()) return;
299 if(!strcasecmp(folder, CLIP_FOLDER))
301 if(item < mwindow->edl->clips.total)
303 change_source(mwindow->edl->clips.values[item]);
309 if(!strcasecmp(folder, MEDIA_FOLDER))
311 if(item < mwindow->edl->assets->total())
313 change_source(mwindow->edl->assets->get_item_number(item));
318 // Search extra clip folders
331 void VWindow::goto_start()
335 get_edl()->local_session->set_selectionstart(0);
336 get_edl()->local_session->set_selectionend(0);
337 update_position(CHANGE_NONE,
344 void VWindow::goto_end()
348 double position = get_edl()->tracks->total_length();
349 get_edl()->local_session->set_selectionstart(position);
350 get_edl()->local_session->set_selectionend(position);
351 update_position(CHANGE_NONE,
358 void VWindow::update(int do_timebar)
361 gui->timebar->update(1);
364 void VWindow::update_position(int change_type,
369 EDL *edl = get_edl();
372 //printf("VWindow::update_position %d\n", __LINE__);
374 playback_engine->que->send_command(CURRENT_FRAME,
379 if(lock_window) gui->lock_window("VWindow::update_position");
380 gui->clock->update(edl->local_session->get_selectionstart(1));
381 if(lock_window) gui->unlock_window();
389 int VWindow::update_position(double position)
391 EDL *edl = get_edl();
394 gui->unlock_window();
396 playback_engine->interrupt_playback(1);
398 position = mwindow->edl->align_to_frame(position, 0);
399 position = MAX(0, position);
401 edl->local_session->set_selectionstart(position);
402 edl->local_session->set_selectionend(position);
404 gui->lock_window("VWindow::update_position 1");
405 update_position(CHANGE_NONE, 0, 1, 0);
412 void VWindow::set_inpoint()
414 EDL *edl = get_edl();
417 edl->set_inpoint(edl->local_session->get_selectionstart(1));
418 gui->timebar->update(1);
422 void VWindow::set_outpoint()
424 EDL *edl = get_edl();
427 edl->set_outpoint(edl->local_session->get_selectionstart(1));
428 gui->timebar->update(1);
432 void VWindow::clear_inpoint()
434 EDL *edl = get_edl();
437 edl->local_session->unset_inpoint();
438 gui->timebar->update(1);
442 void VWindow::clear_outpoint()
444 EDL *edl = get_edl();
447 edl->local_session->unset_outpoint();
448 gui->timebar->update(1);
454 EDL *edl = get_edl();
457 double start = edl->local_session->get_selectionstart();
458 double end = edl->local_session->get_selectionend();
468 const char *file_string = file.string();
469 long file_length = strlen(file_string);
470 mwindow->gui->lock_window();
471 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
472 SECONDARY_SELECTION);
473 mwindow->gui->get_clipboard()->to_clipboard(file_string, file_length,
474 BC_PRIMARY_SELECTION);
475 mwindow->gui->unlock_window();
479 void VWindow::splice_selection()
483 void VWindow::overwrite_selection()