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());
81 edl->Garbage::remove_user();
86 indexable->Garbage::remove_user();
91 gui->change_source(0, _("Viewer"));
97 void VWindow::load_defaults()
101 void VWindow::create_objects()
106 void VWindow::handle_done_event(int result)
108 playback_engine->interrupt_playback(1);
110 if( mwindow->in_destructor ) return;
113 for(int i = 0; i < mwindow->vwindows.size(); i++)
116 //printf("VWindow::handle_done_event %d %d\n", __LINE__, mwindow->vwindows.get(i)->is_running());
117 if(mwindow->vwindows.get(i)->is_running()) total++;
119 // subtract ourselves
122 // Update the menu if no viewers visible
125 mwindow->gui->lock_window("VWindowGUI::close_event");
126 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
127 mwindow->gui->unlock_window();
129 mwindow->session->show_vwindow = 0;
130 mwindow->save_defaults();
134 BC_Window* VWindow::new_gui()
136 //printf("VWindow::create_objects 1\n");
137 gui = new VWindowGUI(mwindow, this);
138 //printf("VWindow::create_objects 1\n");
139 gui->create_objects();
140 //printf("VWindow::create_objects 1\n");
142 playback_engine = new VPlayback(mwindow, this, gui->canvas);
143 //printf("VWindow::create_objects 1\n");
145 // Start command loop
146 playback_engine->create_objects();
147 //printf("VWindow::create_objects 1\n");
148 gui->transport->set_engine(playback_engine);
149 //printf("VWindow::create_objects 1\n");
150 playback_cursor = new VTracking(mwindow, this);
151 //printf("VWindow::create_objects 1\n");
152 playback_cursor->create_objects();
153 //printf("VWindow::create_objects 2\n");
155 clip_edit = new ClipEdit(mwindow, 0, this);
159 void VWindow::handle_close_event(int result)
161 delete playback_engine;
166 EDL* VWindow::get_edl()
168 // return mwindow->edl->vwindow_edl;
172 Indexable* VWindow::get_source()
174 return this->indexable;
177 void VWindow::change_source(int edl_number)
179 if(!is_running()) return;
180 if( playback_engine->is_playing_back )
183 gui->lock_window("VWindow::change_source 1");
184 //printf("VWindow::change_source %d %p\n", __LINE__, mwindow->edl->get_vwindow_edl(edl_number));
185 if( edl_number >= 0 && edl_number < mwindow->edl->total_vwindow_edls() &&
186 mwindow->edl->get_vwindow_edl(edl_number) )
188 this->edl = mwindow->edl->get_vwindow_edl(edl_number);
189 this->edl->Garbage::add_user();
190 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
191 update_position(CHANGE_ALL);
196 // if(indexable) indexable->Garbage::remove_user();
198 // mwindow->edl->vwindow_edl_shared = 0;
200 gui->unlock_window();
203 void VWindow::change_source(Indexable *indexable)
205 if( !indexable->is_asset ) {
206 change_source((EDL*)indexable);
209 if(!running()) return;
210 if( playback_engine->is_playing_back )
213 gui->lock_window("VWindow::change_source 2");
215 char title[BCTEXTLEN];
217 fs.extract_name(title, indexable->path);
221 this->edl = new EDL(mwindow->edl);
222 this->edl->create_objects();
223 mwindow->edl->append_vwindow_edl(this->edl, 1);
225 // Generate EDL off of main EDL for cutting
226 Asset *asset = new Asset;
227 asset->copy_from((Asset*)indexable, 0);
228 this->indexable = asset;
229 mwindow->asset_to_edl(this->edl, asset);
232 gui->change_source(this->edl, title);
233 update_position(CHANGE_ALL);
234 gui->unlock_window();
237 void VWindow::change_source(EDL *edl)
239 if(!running()) return;
240 if( playback_engine->is_playing_back )
243 //printf("VWindow::change_source %d %p\n", __LINE__, edl);
244 // EDLs are identical
245 // if(edl && mwindow->edl->vwindow_edl &&
246 // edl->id == mwindow->edl->vwindow_edl->id) return;
247 if(edl && get_edl() && edl->id == get_edl()->id) return;
249 gui->lock_window("VWindow::change_source 3");
255 mwindow->edl->append_vwindow_edl(edl, 1);
257 this->edl->Garbage::add_user();
258 edl->local_session->preview_start = 0;
259 edl->local_session->preview_end = -1;
260 // mwindow->edl->vwindow_edl = edl;
261 // in order not to later delete edl if it is shared
262 // edl->Garbage::add_user();
263 // mwindow->edl->vwindow_edl_shared = 1;
266 gui->change_source(edl, edl->local_session->clip_title);
267 update_position(CHANGE_ALL);
270 gui->change_source(edl, _("Viewer"));
271 gui->unlock_window();
275 void VWindow::goto_start()
278 get_edl()->local_session->set_selectionstart(0);
279 get_edl()->local_session->set_selectionend(0);
284 void VWindow::goto_end()
287 double position = get_edl()->tracks->total_length();
288 get_edl()->local_session->set_selectionstart(position);
289 get_edl()->local_session->set_selectionend(position);
294 void VWindow::update(int do_timebar)
297 gui->timebar->update(1);
298 gui->edit_panel->update();
301 void VWindow::update_position(int change_type)
303 EDL *edl = get_edl();
305 gui->unlock_window();
306 playback_engine->refresh_frame(change_type, edl);
307 gui->lock_window("VWindow::update_position");
308 double position = edl->local_session->get_selectionstart(1);
309 gui->clock->update(position);
310 gui->timebar->update(1);
314 void VWindow::stop_playback(int wait)
316 playback_engine->stop_playback(wait);
319 void VWindow::interrupt_playback(int wait)
321 gui->unlock_window();
322 playback_engine->interrupt_playback(wait);
323 gui->lock_window("VWindow::interrupt_playback");
326 int VWindow::update_position(double position)
328 EDL *edl = get_edl();
330 interrupt_playback(1);
331 position = mwindow->edl->align_to_frame(position, 0);
332 position = MAX(0, position);
333 edl->local_session->set_selectionstart(position);
334 edl->local_session->set_selectionend(position);
341 void VWindow::set_inpoint()
343 EDL *edl = get_edl();
345 edl->set_inpoint(edl->local_session->get_selectionstart(1));
346 gui->timebar->update(1);
350 void VWindow::set_outpoint()
352 EDL *edl = get_edl();
355 edl->set_outpoint(edl->local_session->get_selectionstart(1));
356 gui->timebar->update(1);
360 void VWindow::unset_inoutpoint()
362 EDL *edl = get_edl();
365 edl->unset_inoutpoint();
366 gui->timebar->update(1);
370 void VWindow::copy(int all)
372 EDL *edl = get_edl();
375 double start = all ? 0 :
376 edl->local_session->get_selectionstart();
377 double end = all ? edl->tracks->total_length() :
378 edl->local_session->get_selectionend();
379 EDL *copy_edl = new EDL; // no parent or assets wont be copied
380 copy_edl->create_objects();
381 copy_edl->copy_all(edl);
383 copy_edl->copy(COPY_CLIPBOARD, start, end, &file, "", 1);
384 copy_edl->remove_user();
385 const char *file_string = file.string();
386 long file_length = strlen(file_string);
387 mwindow->gui->lock_window();
388 mwindow->gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
389 mwindow->gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
390 mwindow->gui->unlock_window();
394 void VWindow::splice_selection()
398 void VWindow::overwrite_selection()