4 * Copyright (C) 1997-2011 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 "awindowgui.h"
30 #include "edlsession.h"
31 #include "filesystem.h"
37 #include "localsession.h"
38 #include "mainclock.h"
40 #include "mainsession.h"
42 #include "meterpanel.h"
43 #include "mwindowgui.h"
45 #include "playtransport.h"
46 #include "preferences.h"
51 #include "vplayback.h"
53 #include "vwindowgui.h"
59 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
60 : BC_Window(_(PROGRAM_NAME ": Viewer"),
61 mwindow->session->vwindow_x,
62 mwindow->session->vwindow_y,
63 mwindow->session->vwindow_w,
64 mwindow->session->vwindow_h,
71 this->mwindow = mwindow;
72 this->vwindow = vwindow;
78 strcpy(loaded_title, "");
82 VWindowGUI::~VWindowGUI()
84 vwindow->playback_engine->interrupt_playback(1);
85 sources.remove_all_objects();
86 labels.remove_all_objects();
94 void VWindowGUI::change_source(EDL *edl, const char *title)
96 //printf("VWindowGUI::change_source %d\n", __LINE__);
98 update_sources(title);
99 strcpy(loaded_title, title);
100 char string[BCTEXTLEN];
102 sprintf(string, _(PROGRAM_NAME ": %s"), title);
104 sprintf(string, _(PROGRAM_NAME ": Viewer"));
106 lock_window("VWindowGUI::change_source");
114 // Get source list from master EDL
115 void VWindowGUI::update_sources(const char *title)
117 lock_window("VWindowGUI::update_sources");
119 //printf("VWindowGUI::update_sources 1\n");
120 sources.remove_all_objects();
121 //printf("VWindowGUI::update_sources 2\n");
126 i < mwindow->edl->clips.total;
129 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
132 for(int j = 0; j < sources.total; j++)
134 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
142 sources.append(new BC_ListBoxItem(clip_title));
145 //printf("VWindowGUI::update_sources 3\n");
148 for(Asset *current = mwindow->edl->assets->first;
152 char clip_title[BCTEXTLEN];
153 fs.extract_name(clip_title, current->path);
156 for(int j = 0; j < sources.total; j++)
158 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
166 sources.append(new BC_ListBoxItem(clip_title));
170 //printf("VWindowGUI::update_sources 4\n");
172 // source->update_list(&sources);
173 // source->update(title);
177 void VWindowGUI::create_objects()
181 lock_window("VWindowGUI::create_objects");
182 set_icon(mwindow->theme->get_image("vwindow_icon"));
184 //printf("VWindowGUI::create_objects 1\n");
185 mwindow->theme->get_vwindow_sizes(this);
186 mwindow->theme->draw_vwindow_bg(this);
189 meters = new VWindowMeters(mwindow,
191 mwindow->theme->vmeter_x,
192 mwindow->theme->vmeter_y,
193 mwindow->theme->vmeter_h);
194 meters->create_objects();
196 //printf("VWindowGUI::create_objects 1\n");
197 // Requires meters to build
198 edit_panel = new VWindowEditing(mwindow, vwindow);
199 edit_panel->set_meters(meters);
200 edit_panel->create_objects();
202 //printf("VWindowGUI::create_objects 1\n");
203 transport = new VWindowTransport(mwindow,
205 mwindow->theme->vtransport_x,
206 mwindow->theme->vtransport_y);
207 transport->create_objects();
209 //printf("VWindowGUI::create_objects 1\n");
210 // add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
211 add_subwindow(clock = new MainClock(mwindow,
212 mwindow->theme->vtime_x,
213 mwindow->theme->vtime_y,
214 mwindow->theme->vtime_w));
216 canvas = new VWindowCanvas(mwindow, this);
217 canvas->create_objects(mwindow->edl);
218 canvas->use_vwindow();
221 //printf("VWindowGUI::create_objects 1\n");
222 add_subwindow(timebar = new VTimeBar(mwindow,
224 mwindow->theme->vtimebar_x,
225 mwindow->theme->vtimebar_y,
226 mwindow->theme->vtimebar_w,
227 mwindow->theme->vtimebar_h));
228 timebar->create_objects();
229 //printf("VWindowGUI::create_objects 2\n");
232 //printf("VWindowGUI::create_objects 1\n");
233 // source = new VWindowSource(mwindow,
235 // mwindow->theme->vsource_x,
236 // mwindow->theme->vsource_y);
237 // source->create_objects();
238 update_sources(_("None"));
240 //printf("VWindowGUI::create_objects 2\n");
247 int VWindowGUI::resize_event(int w, int h)
249 mwindow->session->vwindow_x = get_x();
250 mwindow->session->vwindow_y = get_y();
251 mwindow->session->vwindow_w = w;
252 mwindow->session->vwindow_h = h;
254 mwindow->theme->get_vwindow_sizes(this);
255 mwindow->theme->draw_vwindow_bg(this);
258 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vedit_y);
259 edit_panel->reposition_buttons(mwindow->theme->vedit_x,
260 mwindow->theme->vedit_y);
262 timebar->resize_event();
263 transport->reposition_buttons(mwindow->theme->vtransport_x,
264 mwindow->theme->vtransport_y);
265 clock->reposition_window(mwindow->theme->vtime_x,
266 mwindow->theme->vtime_y,
267 mwindow->theme->vtime_w,
269 canvas->reposition_window(0,
270 mwindow->theme->vcanvas_x,
271 mwindow->theme->vcanvas_y,
272 mwindow->theme->vcanvas_w,
273 mwindow->theme->vcanvas_h);
274 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
275 // source->reposition_window(mwindow->theme->vsource_x,
276 // mwindow->theme->vsource_y);
277 meters->reposition_window(mwindow->theme->vmeter_x,
278 mwindow->theme->vmeter_y,
280 mwindow->theme->vmeter_h);
282 BC_WindowBase::resize_event(w, h);
290 int VWindowGUI::translation_event()
292 mwindow->session->vwindow_x = get_x();
293 mwindow->session->vwindow_y = get_y();
297 int VWindowGUI::close_event()
300 int i = mwindow->vwindows.size();
301 while( --i >= 0 && mwindow->vwindows.get(i)->gui != this );
307 mwindow->session->show_vwindow = 0;
310 mwindow->gui->lock_window("VWindowGUI::close_event");
311 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
312 mwindow->gui->unlock_window();
314 lock_window("VWindowGUI::close_event");
315 mwindow->save_defaults();
319 int VWindowGUI::keypress_event()
322 switch(get_keypress())
330 mwindow->undo_entry(this);
333 mwindow->redo_entry(this);
337 if(mwindow->session->vwindow_fullscreen)
338 canvas->stop_fullscreen();
340 canvas->start_fullscreen();
341 lock_window("VWindowGUI::keypress_event 1");
345 if(mwindow->session->vwindow_fullscreen)
346 canvas->stop_fullscreen();
347 lock_window("VWindowGUI::keypress_event 2");
350 if(!result) result = transport->keypress_event();
355 int VWindowGUI::button_press_event()
357 if( get_buttonpress() == LEFT_BUTTON && canvas->get_canvas() &&
358 canvas->get_canvas()->get_cursor_over_window() ) {
360 PlaybackEngine *playback_engine = vwindow->playback_engine;
361 if( !playback_engine->is_playing_back && vwindow->get_edl() != 0 ) {
362 double length = vwindow->get_edl()->tracks->total_playable_length();
363 double position = playback_engine->get_tracking_position();
364 if( position >= length ) transport->goto_start();
365 command = NORMAL_FWD;
368 transport->handle_transport(command, 1);
369 lock_window("VWindowGUI::button_press_event");
372 if(canvas->get_canvas())
373 return canvas->button_press_event_base(canvas->get_canvas());
377 int VWindowGUI::cursor_leave_event()
379 if(canvas->get_canvas())
380 return canvas->cursor_leave_event_base(canvas->get_canvas());
384 int VWindowGUI::cursor_enter_event()
386 if(canvas->get_canvas())
387 return canvas->cursor_enter_event_base(canvas->get_canvas());
391 int VWindowGUI::button_release_event()
393 if(canvas->get_canvas())
394 return canvas->button_release_event();
398 int VWindowGUI::cursor_motion_event()
400 if(canvas->get_canvas())
402 canvas->get_canvas()->unhide_cursor();
403 return canvas->cursor_motion_event();
409 void VWindowGUI::drag_motion()
412 if(get_hidden()) return;
413 if(mwindow->session->current_operation != DRAG_ASSET) return;
414 int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0;
415 if( highlighted == need_highlight ) return;
416 highlighted = need_highlight;
417 canvas->draw_refresh();
420 int VWindowGUI::drag_stop()
422 if(get_hidden()) return 0;
425 mwindow->session->current_operation == DRAG_ASSET)
428 canvas->draw_refresh();
431 Indexable *indexable = mwindow->session->drag_assets->size() ?
432 mwindow->session->drag_assets->get(0) :
434 EDL *edl = mwindow->session->drag_clips->size() ?
435 mwindow->session->drag_clips->get(0) :
438 vwindow->change_source(indexable);
441 vwindow->change_source(edl);
442 lock_window("VWindowGUI::drag_stop");
450 void VWindowGUI::update_meters()
452 if(mwindow->edl->session->vwindow_meter != meters->visible)
454 meters->set_meters(meters->meter_count,
455 mwindow->edl->session->vwindow_meter);
456 mwindow->theme->get_vwindow_sizes(this);
457 resize_event(get_w(), get_h());
463 VWindowMeters::VWindowMeters(MWindow *mwindow,
468 : MeterPanel(mwindow,
474 mwindow->edl->session->audio_channels,
475 mwindow->edl->session->vwindow_meter,
479 this->mwindow = mwindow;
483 VWindowMeters::~VWindowMeters()
487 int VWindowMeters::change_status_event(int new_status)
489 mwindow->edl->session->vwindow_meter = new_status;
490 gui->update_meters();
500 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
503 mwindow->theme->vedit_x,
504 mwindow->theme->vedit_y,
524 this->mwindow = mwindow;
525 this->vwindow = vwindow;
528 VWindowEditing::~VWindowEditing()
532 void VWindowEditing::copy_selection()
537 void VWindowEditing::splice_selection()
539 if(vwindow->get_edl())
541 mwindow->gui->lock_window("VWindowEditing::splice_selection");
542 mwindow->splice(vwindow->get_edl());
543 mwindow->gui->unlock_window();
547 void VWindowEditing::overwrite_selection()
549 if(vwindow->get_edl())
551 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
552 mwindow->overwrite(vwindow->get_edl());
553 mwindow->gui->unlock_window();
557 void VWindowEditing::toggle_label()
559 if(vwindow->get_edl())
561 EDL *edl = vwindow->get_edl();
562 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
563 edl->local_session->get_selectionend(1));
564 vwindow->gui->timebar->update(1);
568 void VWindowEditing::prev_label()
570 if(vwindow->get_edl())
572 EDL *edl = vwindow->get_edl();
573 vwindow->gui->unlock_window();
574 vwindow->playback_engine->interrupt_playback(1);
575 vwindow->gui->lock_window("VWindowEditing::prev_label");
577 Label *current = edl->labels->prev_label(
578 edl->local_session->get_selectionstart(1));
583 edl->local_session->set_selectionstart(0);
584 edl->local_session->set_selectionend(0);
585 vwindow->update_position(CHANGE_NONE, 0, 1, 0);
586 vwindow->gui->timebar->update(1);
590 edl->local_session->set_selectionstart(current->position);
591 edl->local_session->set_selectionend(current->position);
592 vwindow->update_position(CHANGE_NONE, 0, 1, 0);
593 vwindow->gui->timebar->update(1);
598 void VWindowEditing::next_label()
600 if(vwindow->get_edl())
602 EDL *edl = vwindow->get_edl();
603 Label *current = edl->labels->next_label(
604 edl->local_session->get_selectionstart(1));
607 vwindow->gui->unlock_window();
608 vwindow->playback_engine->interrupt_playback(1);
609 vwindow->gui->lock_window("VWindowEditing::next_label 1");
611 double position = edl->tracks->total_length();
612 edl->local_session->set_selectionstart(position);
613 edl->local_session->set_selectionend(position);
614 vwindow->update_position(CHANGE_NONE, 0, 1, 0);
615 vwindow->gui->timebar->update(1);
619 vwindow->gui->unlock_window();
620 vwindow->playback_engine->interrupt_playback(1);
621 vwindow->gui->lock_window("VWindowEditing::next_label 2");
623 edl->local_session->set_selectionstart(current->position);
624 edl->local_session->set_selectionend(current->position);
625 vwindow->update_position(CHANGE_NONE, 0, 1, 0);
626 vwindow->gui->timebar->update(1);
631 double VWindowEditing::get_position()
633 EDL *edl = vwindow->get_edl();
634 double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
638 void VWindowEditing::set_position(double position)
640 EDL *edl = vwindow->get_edl();
642 if( get_position() != position ) {
643 if( position < 0 ) position = 0;
644 edl->local_session->set_selectionstart(position);
645 edl->local_session->set_selectionend(position);
646 vwindow->update_position(CHANGE_NONE, 0, 1);
650 void VWindowEditing::set_inpoint()
652 vwindow->set_inpoint();
655 void VWindowEditing::set_outpoint()
657 vwindow->set_outpoint();
660 void VWindowEditing::unset_inoutpoint()
662 vwindow->unset_inoutpoint();
666 void VWindowEditing::to_clip()
668 EDL *edl = vwindow->get_edl();
670 mwindow->to_clip(edl, _("viewer window: "));
673 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
674 : BC_PopupTextBox(vwindow,
682 this->mwindow = mwindow;
683 this->vwindow = vwindow;
686 VWindowSource::~VWindowSource()
690 int VWindowSource::handle_event()
696 VWindowTransport::VWindowTransport(MWindow *mwindow,
700 : PlayTransport(mwindow,
708 EDL* VWindowTransport::get_edl()
710 return gui->vwindow->get_edl();
714 void VWindowTransport::goto_start()
716 gui->unlock_window();
717 handle_transport(REWIND, 1);
718 gui->lock_window("VWindowTransport::goto_start");
719 gui->vwindow->goto_start();
722 void VWindowTransport::goto_end()
724 gui->unlock_window();
725 handle_transport(GOTO_END, 1);
726 gui->lock_window("VWindowTransport::goto_end");
727 gui->vwindow->goto_end();
733 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
736 mwindow->theme->vcanvas_x,
737 mwindow->theme->vcanvas_y,
738 mwindow->theme->vcanvas_w,
739 mwindow->theme->vcanvas_h,
742 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
743 this->mwindow = mwindow;
747 void VWindowCanvas::zoom_resize_window(float percentage)
749 EDL *edl = gui->vwindow->get_edl();
750 if(!edl) edl = mwindow->edl;
752 int canvas_w, canvas_h;
755 // Get required canvas size
756 calculate_sizes(edl->get_aspect_ratio(),
757 edl->session->output_w,
758 edl->session->output_h,
763 // Estimate window size from current borders
764 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
765 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
767 mwindow->session->vwindow_w = new_w;
768 mwindow->session->vwindow_h = new_h;
770 mwindow->theme->get_vwindow_sizes(gui);
772 // Estimate again from new borders
773 new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
774 new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
777 gui->resize_window(new_w, new_h);
778 gui->resize_event(new_w, new_h);
781 void VWindowCanvas::close_source()
783 gui->unlock_window();
784 gui->vwindow->playback_engine->interrupt_playback(1);
785 gui->lock_window("VWindowCanvas::close_source");
786 gui->vwindow->delete_source(1, 1);
790 void VWindowCanvas::draw_refresh(int flush)
792 EDL *edl = gui->vwindow->get_edl();
794 if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
795 if(!get_canvas()->get_video_on() && refresh_frame && edl)
797 float in_x1, in_y1, in_x2, in_y2;
798 float out_x1, out_y1, out_x2, out_y2;
808 get_canvas()->draw_vframe(refresh_frame,
811 (int)(out_x2 - out_x1),
812 (int)(out_y2 - out_y1),
815 (int)(in_x2 - in_x1),
816 (int)(in_y2 - in_y1),
820 if(!get_canvas()->get_video_on())
823 get_canvas()->flash(flush);
827 void VWindowCanvas::draw_overlays()
829 if( gui->highlighted )
831 get_canvas()->set_color(WHITE);
832 get_canvas()->set_inverse();
833 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
834 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
835 get_canvas()->set_opaque();
839 int VWindowCanvas::get_fullscreen()
841 return mwindow->session->vwindow_fullscreen;
844 void VWindowCanvas::set_fullscreen(int value)
846 mwindow->session->vwindow_fullscreen = value;
886 void VWindowGUI::update_points()
888 EDL *edl = vwindow->get_edl();
890 //printf("VWindowGUI::update_points 1\n");
893 //printf("VWindowGUI::update_points 2\n");
894 long pixel = (long)((double)edl->local_session->in_point /
895 edl->tracks->total_length() *
896 (mwindow->theme->vtimebar_w -
898 mwindow->theme->in_point[0]->get_w())) +
899 mwindow->theme->in_point[0]->get_w();
901 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
904 //printf("VWindowGUI::update_points 3.1\n");
905 if(edl->local_session->in_point >= 0)
907 //printf("VWindowGUI::update_points 4\n");
908 if(edl->local_session->in_point != in_point->position ||
909 in_point->pixel != pixel)
911 in_point->pixel = pixel;
912 in_point->reposition();
915 //printf("VWindowGUI::update_points 5\n");
916 in_point->position = edl->local_session->in_point;
918 //printf("VWindowGUI::update_points 6\n");
919 if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
920 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
924 //printf("VWindowGUI::update_points 7\n");
933 if(edl->local_session->in_point >= 0)
935 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
936 add_subwindow(in_point =
937 new VWindowInPoint(mwindow,
941 edl->local_session->in_point));
942 //printf("VWindowGUI::update_points 9\n");
944 //printf("VWindowGUI::update_points 10\n");
946 pixel = (long)((double)edl->local_session->out_point /
947 (edl->tracks->total_length() + 0.5) *
948 (mwindow->theme->vtimebar_w -
950 mwindow->theme->in_point[0]->get_w())) +
951 mwindow->theme->in_point[0]->get_w() *
956 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
958 if(edl->local_session->out_point != out_point->position ||
959 out_point->pixel != pixel)
961 out_point->pixel = pixel;
962 out_point->reposition();
964 out_point->position = edl->local_session->out_point;
966 if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
967 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
968 out_point->update(1);
970 out_point->update(0);
979 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
981 add_subwindow(out_point =
982 new VWindowOutPoint(mwindow,
986 edl->local_session->out_point));
991 void VWindowGUI::update_labels()
993 EDL *edl = vwindow->get_edl();
996 for(Label *current = edl->labels->first;
1000 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1002 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1005 if(output >= labels.total)
1007 LabelGUI *new_label;
1008 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1009 labels.append(new_label);
1012 // Reposition old label
1013 if(labels.values[output]->pixel != pixel)
1015 labels.values[output]->pixel = pixel;
1016 labels.values[output]->position = current->position;
1017 labels.values[output]->reposition();
1020 if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1021 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1022 labels.values[output]->update(1);
1024 if(labels.values[output]->get_value())
1025 labels.values[output]->update(0);
1030 // Delete excess labels
1031 while(labels.total > output)
1033 labels.remove_object();
1039 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1044 : InPointGUI(mwindow,
1052 int VWindowInPoint::handle_event()
1054 EDL *edl = gui->vwindow->get_edl();
1058 double position = edl->align_to_frame(this->position, 0);
1060 edl->local_session->set_selectionstart(position);
1061 edl->local_session->set_selectionend(position);
1062 gui->timebar->update(1);
1065 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1072 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1077 : OutPointGUI(mwindow,
1085 int VWindowOutPoint::handle_event()
1087 EDL *edl = gui->vwindow->get_edl();
1091 double position = edl->align_to_frame(this->position, 0);
1093 edl->local_session->set_selectionstart(position);
1094 edl->local_session->set_selectionend(position);
1095 gui->timebar->update(1);
1098 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);