3 #include "awindowgui.h"
9 #include "edlsession.h"
10 #include "filesystem.h"
16 #include "localsession.h"
17 #include "mainclock.h"
19 #include "mainsession.h"
21 #include "meterpanel.h"
22 #include "mwindowgui.h"
24 #include "playtransport.h"
25 #include "preferences.h"
30 #include "vplayback.h"
32 #include "vwindowgui.h"
38 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
39 : BC_Window(PROGRAM_NAME ": Viewer",
40 mwindow->session->vwindow_x,
41 mwindow->session->vwindow_y,
42 mwindow->session->vwindow_w,
43 mwindow->session->vwindow_h,
50 this->mwindow = mwindow;
51 this->vwindow = vwindow;
52 strcpy(loaded_title, "");
55 VWindowGUI::~VWindowGUI()
61 void VWindowGUI::change_source(EDL *edl, char *title)
63 update_sources(title);
64 char string[BCTEXTLEN];
66 sprintf(string, PROGRAM_NAME ": %s", title);
68 sprintf(string, PROGRAM_NAME);
69 strcpy(loaded_title, title);
70 lock_window("VWindowGUI::change_source");
71 slider->set_position();
78 // Get source list from master EDL
79 void VWindowGUI::update_sources(char *title)
81 lock_window("VWindowGUI::update_sources");
83 //printf("VWindowGUI::update_sources 1\n");
84 sources.remove_all_objects();
85 //printf("VWindowGUI::update_sources 2\n");
90 i < mwindow->edl->clips.total;
93 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
96 for(int j = 0; j < sources.total; j++)
98 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
106 sources.append(new BC_ListBoxItem(clip_title));
109 //printf("VWindowGUI::update_sources 3\n");
112 for(Asset *current = mwindow->edl->assets->first;
116 char clip_title[BCTEXTLEN];
117 fs.extract_name(clip_title, current->path);
120 for(int j = 0; j < sources.total; j++)
122 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
130 sources.append(new BC_ListBoxItem(clip_title));
134 //printf("VWindowGUI::update_sources 4\n");
136 // source->update_list(&sources);
137 // source->update(title);
141 int VWindowGUI::create_objects()
145 set_icon(mwindow->theme->get_image("vwindow_icon"));
147 //printf("VWindowGUI::create_objects 1\n");
148 mwindow->theme->get_vwindow_sizes(this);
149 mwindow->theme->draw_vwindow_bg(this);
152 meters = new VWindowMeters(mwindow,
154 mwindow->theme->vmeter_x,
155 mwindow->theme->vmeter_y,
156 mwindow->theme->vmeter_h);
157 meters->create_objects();
159 //printf("VWindowGUI::create_objects 1\n");
160 // Requires meters to build
161 edit_panel = new VWindowEditing(mwindow, vwindow);
162 edit_panel->set_meters(meters);
163 edit_panel->create_objects();
165 //printf("VWindowGUI::create_objects 1\n");
166 add_subwindow(slider = new VWindowSlider(mwindow,
169 mwindow->theme->vslider_x,
170 mwindow->theme->vslider_y,
171 mwindow->theme->vslider_w));
173 //printf("VWindowGUI::create_objects 1\n");
174 transport = new VWindowTransport(mwindow,
176 mwindow->theme->vtransport_x,
177 mwindow->theme->vtransport_y);
178 transport->create_objects();
179 transport->set_slider(slider);
181 //printf("VWindowGUI::create_objects 1\n");
182 // add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
183 add_subwindow(clock = new MainClock(mwindow,
184 mwindow->theme->vtime_x,
185 mwindow->theme->vtime_y,
186 mwindow->theme->vtime_w));
188 canvas = new VWindowCanvas(mwindow, this);
189 canvas->create_objects(mwindow->edl);
193 //printf("VWindowGUI::create_objects 1\n");
194 add_subwindow(timebar = new VTimeBar(mwindow,
196 mwindow->theme->vtimebar_x,
197 mwindow->theme->vtimebar_y,
198 mwindow->theme->vtimebar_w,
199 mwindow->theme->vtimebar_h));
200 timebar->create_objects();
201 //printf("VWindowGUI::create_objects 2\n");
204 //printf("VWindowGUI::create_objects 1\n");
205 // source = new VWindowSource(mwindow,
207 // mwindow->theme->vsource_x,
208 // mwindow->theme->vsource_y);
209 // source->create_objects();
210 update_sources(_("None"));
212 //printf("VWindowGUI::create_objects 2\n");
218 int VWindowGUI::resize_event(int w, int h)
220 mwindow->session->vwindow_x = get_x();
221 mwindow->session->vwindow_y = get_y();
222 mwindow->session->vwindow_w = w;
223 mwindow->session->vwindow_h = h;
225 mwindow->theme->get_vwindow_sizes(this);
226 mwindow->theme->draw_vwindow_bg(this);
229 edit_panel->reposition_buttons(mwindow->theme->vedit_x,
230 mwindow->theme->vedit_y);
231 slider->reposition_window(mwindow->theme->vslider_x,
232 mwindow->theme->vslider_y,
233 mwindow->theme->vslider_w);
234 // Recalibrate pointer motion range
235 slider->set_position();
236 timebar->resize_event();
237 transport->reposition_buttons(mwindow->theme->vtransport_x,
238 mwindow->theme->vtransport_y);
239 clock->reposition_window(mwindow->theme->vtime_x,
240 mwindow->theme->vtime_y,
241 mwindow->theme->vtime_w);
242 canvas->reposition_window(0,
243 mwindow->theme->vcanvas_x,
244 mwindow->theme->vcanvas_y,
245 mwindow->theme->vcanvas_w,
246 mwindow->theme->vcanvas_h);
247 // source->reposition_window(mwindow->theme->vsource_x,
248 // mwindow->theme->vsource_y);
249 meters->reposition_window(mwindow->theme->vmeter_x,
250 mwindow->theme->vmeter_y,
251 mwindow->theme->vmeter_h);
253 BC_WindowBase::resize_event(w, h);
261 int VWindowGUI::translation_event()
263 mwindow->session->vwindow_x = get_x();
264 mwindow->session->vwindow_y = get_y();
268 int VWindowGUI::close_event()
271 mwindow->session->show_vwindow = 0;
275 mwindow->gui->lock_window("VWindowGUI::close_event");
276 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
277 mwindow->gui->unlock_window();
279 lock_window("VWindowGUI::close_event");
280 mwindow->save_defaults();
284 int VWindowGUI::keypress_event()
287 switch(get_keypress())
295 mwindow->undo_entry(this);
298 mwindow->redo_entry(this);
302 if(mwindow->session->vwindow_fullscreen)
303 canvas->stop_fullscreen();
305 canvas->start_fullscreen();
306 lock_window("VWindowGUI::keypress_event 1");
310 if(mwindow->session->vwindow_fullscreen)
311 canvas->stop_fullscreen();
312 lock_window("VWindowGUI::keypress_event 2");
315 if(!result) result = transport->keypress_event();
320 int VWindowGUI::button_press_event()
322 if(canvas->get_canvas())
323 return canvas->button_press_event_base(canvas->get_canvas());
327 int VWindowGUI::cursor_leave_event()
329 if(canvas->get_canvas())
330 return canvas->cursor_leave_event_base(canvas->get_canvas());
334 int VWindowGUI::cursor_enter_event()
336 if(canvas->get_canvas())
337 return canvas->cursor_enter_event_base(canvas->get_canvas());
341 int VWindowGUI::button_release_event()
343 if(canvas->get_canvas())
344 return canvas->button_release_event();
348 int VWindowGUI::cursor_motion_event()
350 if(canvas->get_canvas())
352 canvas->get_canvas()->unhide_cursor();
353 return canvas->cursor_motion_event();
359 void VWindowGUI::drag_motion()
361 if(get_hidden()) return;
362 if(mwindow->session->current_operation != DRAG_ASSET) return;
364 int old_status = mwindow->session->vcanvas_highlighted;
366 int cursor_x = get_relative_cursor_x();
367 int cursor_y = get_relative_cursor_y();
369 mwindow->session->vcanvas_highlighted = (get_cursor_over_window() &&
370 cursor_x >= canvas->x &&
371 cursor_x < canvas->x + canvas->w &&
372 cursor_y >= canvas->y &&
373 cursor_y < canvas->y + canvas->h);
374 //printf("VWindowGUI::drag_motion 1 %d\n", mwindow->session->vcanvas_highlighted);
377 if(old_status != mwindow->session->vcanvas_highlighted)
378 canvas->draw_refresh();
381 int VWindowGUI::drag_stop()
383 if(get_hidden()) return 0;
385 if(mwindow->session->vcanvas_highlighted &&
386 mwindow->session->current_operation == DRAG_ASSET)
388 mwindow->session->vcanvas_highlighted = 0;
389 canvas->draw_refresh();
391 Asset *asset = mwindow->session->drag_assets->total ?
392 mwindow->session->drag_assets->values[0] :
394 EDL *edl = mwindow->session->drag_clips->total ?
395 mwindow->session->drag_clips->values[0] :
399 vwindow->change_source(asset);
402 vwindow->change_source(edl);
413 VWindowMeters::VWindowMeters(MWindow *mwindow,
418 : MeterPanel(mwindow,
423 mwindow->edl->session->audio_channels,
424 mwindow->edl->session->vwindow_meter)
426 this->mwindow = mwindow;
430 VWindowMeters::~VWindowMeters()
434 int VWindowMeters::change_status_event()
436 mwindow->edl->session->vwindow_meter = use_meters;
437 //printf("VWindowMeters::change_status_event 1 %d\n", mwindow->edl->session->vwindow_meter);
438 mwindow->theme->get_vwindow_sizes(gui);
439 gui->resize_event(gui->get_w(), gui->get_h());
449 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
452 mwindow->theme->vedit_x,
453 mwindow->theme->vedit_y,
472 this->mwindow = mwindow;
473 this->vwindow = vwindow;
476 VWindowEditing::~VWindowEditing()
480 void VWindowEditing::copy_selection()
485 void VWindowEditing::splice_selection()
487 if(vwindow->get_edl())
489 mwindow->gui->lock_window("VWindowEditing::splice_selection");
490 mwindow->splice(vwindow->get_edl());
491 mwindow->gui->unlock_window();
495 void VWindowEditing::overwrite_selection()
497 if(vwindow->get_edl())
499 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
500 mwindow->overwrite(vwindow->get_edl());
501 mwindow->gui->unlock_window();
505 void VWindowEditing::toggle_label()
507 if(vwindow->get_edl())
509 EDL *edl = vwindow->get_edl();
510 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
511 edl->local_session->get_selectionend(1));
512 vwindow->gui->timebar->update();
516 void VWindowEditing::prev_label()
518 if(vwindow->get_edl())
520 EDL *edl = vwindow->get_edl();
521 vwindow->gui->unlock_window();
522 vwindow->playback_engine->interrupt_playback(1);
523 vwindow->gui->lock_window("VWindowEditing::prev_label");
525 Label *current = edl->labels->prev_label(
526 edl->local_session->get_selectionstart(1));
531 edl->local_session->set_selectionstart(0);
532 edl->local_session->set_selectionend(0);
533 vwindow->update_position(CHANGE_NONE, 0, 1);
534 vwindow->gui->timebar->update();
538 edl->local_session->set_selectionstart(current->position);
539 edl->local_session->set_selectionend(current->position);
540 vwindow->update_position(CHANGE_NONE, 0, 1);
541 vwindow->gui->timebar->update();
546 void VWindowEditing::next_label()
548 if(vwindow->get_edl())
550 EDL *edl = vwindow->get_edl();
551 Label *current = edl->labels->next_label(
552 edl->local_session->get_selectionstart(1));
555 vwindow->gui->unlock_window();
556 vwindow->playback_engine->interrupt_playback(1);
557 vwindow->gui->lock_window("VWindowEditing::next_label 1");
559 double position = edl->tracks->total_length();
560 edl->local_session->set_selectionstart(position);
561 edl->local_session->set_selectionend(position);
562 vwindow->update_position(CHANGE_NONE, 0, 1);
563 vwindow->gui->timebar->update();
567 vwindow->gui->unlock_window();
568 vwindow->playback_engine->interrupt_playback(1);
569 vwindow->gui->lock_window("VWindowEditing::next_label 2");
571 edl->local_session->set_selectionstart(current->position);
572 edl->local_session->set_selectionend(current->position);
573 vwindow->update_position(CHANGE_NONE, 0, 1);
574 vwindow->gui->timebar->update();
579 void VWindowEditing::set_inpoint()
581 vwindow->set_inpoint();
584 void VWindowEditing::set_outpoint()
586 vwindow->set_outpoint();
589 void VWindowEditing::clear_inpoint()
591 vwindow->clear_inpoint();
594 void VWindowEditing::clear_outpoint()
596 vwindow->clear_outpoint();
599 void VWindowEditing::to_clip()
601 if(vwindow->get_edl())
604 EDL *edl = vwindow->get_edl();
605 double start = edl->local_session->get_selectionstart();
606 double end = edl->local_session->get_selectionend();
608 if(EQUIV(start, end))
610 end = edl->tracks->total_length();
629 EDL *new_edl = new EDL(mwindow->edl);
630 new_edl->create_objects();
631 new_edl->load_xml(mwindow->plugindb, &file, LOAD_ALL);
632 sprintf(new_edl->local_session->clip_title, _("Clip %d"), mwindow->session->clip_number++);
633 char string[BCTEXTLEN];
634 Units::totext(string,
636 edl->session->time_format,
637 edl->session->sample_rate,
638 edl->session->frame_rate,
639 edl->session->frames_per_foot);
641 sprintf(new_edl->local_session->clip_notes, _("%s\n Created from:\n%s"), string, vwindow->gui->loaded_title);
643 new_edl->local_session->set_selectionstart(0);
644 new_edl->local_session->set_selectionend(0);
647 //printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title);
648 new_edl->local_session->set_selectionstart(0.0);
649 new_edl->local_session->set_selectionend(0.0);
650 vwindow->clip_edit->create_clip(new_edl);
659 VWindowSlider::VWindowSlider(MWindow *mwindow,
665 : BC_PercentageSlider(x,
674 this->mwindow = mwindow;
675 this->vwindow = vwindow;
677 set_precision(0.00001);
678 set_pagination(1.0, 10.0);
681 VWindowSlider::~VWindowSlider()
685 int VWindowSlider::handle_event()
688 vwindow->playback_engine->interrupt_playback(1);
689 lock_window("VWindowSlider::handle_event");
691 vwindow->update_position(CHANGE_NONE, 1, 0);
692 gui->timebar->update();
696 void VWindowSlider::set_position()
698 EDL *edl = vwindow->get_edl();
701 double new_length = edl->tracks->total_playable_length();
702 if(EQUIV(edl->local_session->preview_end, 0))
703 edl->local_session->preview_end = new_length;
704 if(edl->local_session->preview_end > new_length)
705 edl->local_session->preview_end = new_length;
706 if(edl->local_session->preview_start > new_length)
707 edl->local_session->preview_start = 0;
709 update(mwindow->theme->vslider_w,
710 edl->local_session->get_selectionstart(1),
711 edl->local_session->preview_start,
712 edl->local_session->preview_end);
724 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
725 : BC_PopupTextBox(vwindow,
733 this->mwindow = mwindow;
734 this->vwindow = vwindow;
737 VWindowSource::~VWindowSource()
741 int VWindowSource::handle_event()
752 VWindowTransport::VWindowTransport(MWindow *mwindow,
756 : PlayTransport(mwindow,
764 EDL* VWindowTransport::get_edl()
766 return gui->vwindow->get_edl();
770 void VWindowTransport::goto_start()
772 gui->unlock_window();
773 handle_transport(REWIND, 1);
774 gui->lock_window("VWindowTransport::goto_start");
775 gui->vwindow->goto_start();
778 void VWindowTransport::goto_end()
780 gui->unlock_window();
781 handle_transport(GOTO_END, 1);
782 gui->lock_window("VWindowTransport::goto_end");
783 gui->vwindow->goto_end();
789 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
792 mwindow->theme->vcanvas_x,
793 mwindow->theme->vcanvas_y,
794 mwindow->theme->vcanvas_w,
795 mwindow->theme->vcanvas_h,
803 this->mwindow = mwindow;
807 void VWindowCanvas::zoom_resize_window(float percentage)
809 EDL *edl = mwindow->vwindow->get_edl();
810 if(!edl) edl = mwindow->edl;
812 int canvas_w, canvas_h;
813 calculate_sizes(edl->get_aspect_ratio(),
814 edl->session->output_w,
815 edl->session->output_h,
820 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
821 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
822 gui->resize_window(new_w, new_h);
823 gui->resize_event(new_w, new_h);
826 void VWindowCanvas::close_source()
828 mwindow->vwindow->remove_source();
832 void VWindowCanvas::draw_refresh()
834 EDL *edl = gui->vwindow->get_edl();
836 if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
837 if(!get_canvas()->get_video_on() && refresh_frame && edl)
839 float in_x1, in_y1, in_x2, in_y2;
840 float out_x1, out_y1, out_x2, out_y2;
850 get_canvas()->draw_vframe(refresh_frame,
853 (int)(out_x2 - out_x1),
854 (int)(out_y2 - out_y1),
857 (int)(in_x2 - in_x1),
858 (int)(in_y2 - in_y1),
862 if(!get_canvas()->get_video_on())
865 get_canvas()->flash();
869 void VWindowCanvas::draw_overlays()
871 if(mwindow->session->vcanvas_highlighted)
873 get_canvas()->set_color(WHITE);
874 get_canvas()->set_inverse();
875 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
876 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
877 get_canvas()->set_opaque();
881 int VWindowCanvas::get_fullscreen()
883 return mwindow->session->vwindow_fullscreen;
886 void VWindowCanvas::set_fullscreen(int value)
888 mwindow->session->vwindow_fullscreen = value;
928 void VWindowGUI::update_points()
930 EDL *edl = vwindow->get_edl();
932 //printf("VWindowGUI::update_points 1\n");
935 //printf("VWindowGUI::update_points 2\n");
936 long pixel = (long)((double)edl->local_session->in_point /
937 edl->tracks->total_playable_length() *
938 (mwindow->theme->vtimebar_w -
940 mwindow->theme->in_point[0]->get_w())) +
941 mwindow->theme->in_point[0]->get_w();
943 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
946 //printf("VWindowGUI::update_points 3.1\n");
947 if(edl->local_session->in_point >= 0)
949 //printf("VWindowGUI::update_points 4\n");
950 if(edl->local_session->in_point != in_point->position ||
951 in_point->pixel != pixel)
953 in_point->pixel = pixel;
954 in_point->reposition();
957 //printf("VWindowGUI::update_points 5\n");
958 in_point->position = edl->local_session->in_point;
960 //printf("VWindowGUI::update_points 6\n");
961 if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
962 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
966 //printf("VWindowGUI::update_points 7\n");
975 if(edl->local_session->in_point >= 0)
977 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
978 add_subwindow(in_point =
979 new VWindowInPoint(mwindow,
983 edl->local_session->in_point));
984 //printf("VWindowGUI::update_points 9\n");
986 //printf("VWindowGUI::update_points 10\n");
988 pixel = (long)((double)edl->local_session->out_point /
989 (edl->tracks->total_playable_length() + 0.5) *
990 (mwindow->theme->vtimebar_w -
992 mwindow->theme->in_point[0]->get_w())) +
993 mwindow->theme->in_point[0]->get_w() *
998 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1000 if(edl->local_session->out_point != out_point->position ||
1001 out_point->pixel != pixel)
1003 out_point->pixel = pixel;
1004 out_point->reposition();
1006 out_point->position = edl->local_session->out_point;
1008 if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
1009 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
1010 out_point->update(1);
1012 out_point->update(0);
1021 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1023 add_subwindow(out_point =
1024 new VWindowOutPoint(mwindow,
1028 edl->local_session->out_point));
1033 void VWindowGUI::update_labels()
1035 EDL *edl = vwindow->get_edl();
1038 for(Label *current = edl->labels->first;
1042 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1044 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1047 if(output >= labels.total)
1049 LabelGUI *new_label;
1050 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1051 labels.append(new_label);
1054 // Reposition old label
1055 if(labels.values[output]->pixel != pixel)
1057 labels.values[output]->pixel = pixel;
1058 labels.values[output]->position = current->position;
1059 labels.values[output]->reposition();
1062 if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1063 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1064 labels.values[output]->update(1);
1066 if(labels.values[output]->get_value())
1067 labels.values[output]->update(0);
1072 // Delete excess labels
1073 while(labels.total > output)
1075 labels.remove_object();
1081 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1086 : InPointGUI(mwindow,
1094 int VWindowInPoint::handle_event()
1096 EDL *edl = gui->vwindow->get_edl();
1100 double position = edl->align_to_frame(this->position, 0);
1102 edl->local_session->set_selectionstart(position);
1103 edl->local_session->set_selectionend(position);
1104 gui->timebar->update();
1107 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1114 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1119 : OutPointGUI(mwindow,
1127 int VWindowOutPoint::handle_event()
1129 EDL *edl = gui->vwindow->get_edl();
1133 double position = edl->align_to_frame(this->position, 0);
1135 edl->local_session->set_selectionstart(position);
1136 edl->local_session->set_selectionend(position);
1137 gui->timebar->update();
1140 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);