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;
54 VWindowGUI::~VWindowGUI()
60 void VWindowGUI::change_source(EDL *edl, char *title)
62 update_sources(title);
63 char string[BCTEXTLEN];
65 sprintf(string, PROGRAM_NAME ": %s", title);
67 sprintf(string, PROGRAM_NAME);
69 lock_window("VWindowGUI::change_source");
70 slider->set_position();
77 // Get source list from master EDL
78 void VWindowGUI::update_sources(char *title)
80 lock_window("VWindowGUI::update_sources");
82 //printf("VWindowGUI::update_sources 1\n");
83 sources.remove_all_objects();
84 //printf("VWindowGUI::update_sources 2\n");
89 i < mwindow->edl->clips.total;
92 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
95 for(int j = 0; j < sources.total; j++)
97 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
105 sources.append(new BC_ListBoxItem(clip_title));
108 //printf("VWindowGUI::update_sources 3\n");
111 for(Asset *current = mwindow->edl->assets->first;
115 char clip_title[BCTEXTLEN];
116 fs.extract_name(clip_title, current->path);
119 for(int j = 0; j < sources.total; j++)
121 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
129 sources.append(new BC_ListBoxItem(clip_title));
133 //printf("VWindowGUI::update_sources 4\n");
135 // source->update_list(&sources);
136 // source->update(title);
140 int VWindowGUI::create_objects()
144 set_icon(mwindow->theme->get_image("vwindow_icon"));
146 //printf("VWindowGUI::create_objects 1\n");
147 mwindow->theme->get_vwindow_sizes(this);
148 mwindow->theme->draw_vwindow_bg(this);
151 meters = new VWindowMeters(mwindow,
153 mwindow->theme->vmeter_x,
154 mwindow->theme->vmeter_y,
155 mwindow->theme->vmeter_h);
156 meters->create_objects();
158 //printf("VWindowGUI::create_objects 1\n");
159 // Requires meters to build
160 edit_panel = new VWindowEditing(mwindow, vwindow);
161 edit_panel->set_meters(meters);
162 edit_panel->create_objects();
164 //printf("VWindowGUI::create_objects 1\n");
165 add_subwindow(slider = new VWindowSlider(mwindow,
168 mwindow->theme->vslider_x,
169 mwindow->theme->vslider_y,
170 mwindow->theme->vslider_w));
172 //printf("VWindowGUI::create_objects 1\n");
173 transport = new VWindowTransport(mwindow,
175 mwindow->theme->vtransport_x,
176 mwindow->theme->vtransport_y);
177 transport->create_objects();
178 transport->set_slider(slider);
180 //printf("VWindowGUI::create_objects 1\n");
181 // add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
182 add_subwindow(clock = new MainClock(mwindow,
183 mwindow->theme->vtime_x,
184 mwindow->theme->vtime_y,
185 mwindow->theme->vtime_w));
187 canvas = new VWindowCanvas(mwindow, this);
188 canvas->create_objects(mwindow->edl);
192 //printf("VWindowGUI::create_objects 1\n");
193 add_subwindow(timebar = new VTimeBar(mwindow,
195 mwindow->theme->vtimebar_x,
196 mwindow->theme->vtimebar_y,
197 mwindow->theme->vtimebar_w,
198 mwindow->theme->vtimebar_h));
199 timebar->create_objects();
200 //printf("VWindowGUI::create_objects 2\n");
203 //printf("VWindowGUI::create_objects 1\n");
204 // source = new VWindowSource(mwindow,
206 // mwindow->theme->vsource_x,
207 // mwindow->theme->vsource_y);
208 // source->create_objects();
209 update_sources(_("None"));
211 //printf("VWindowGUI::create_objects 2\n");
217 int VWindowGUI::resize_event(int w, int h)
219 mwindow->session->vwindow_x = get_x();
220 mwindow->session->vwindow_y = get_y();
221 mwindow->session->vwindow_w = w;
222 mwindow->session->vwindow_h = h;
224 mwindow->theme->get_vwindow_sizes(this);
225 mwindow->theme->draw_vwindow_bg(this);
228 edit_panel->reposition_buttons(mwindow->theme->vedit_x,
229 mwindow->theme->vedit_y);
230 slider->reposition_window(mwindow->theme->vslider_x,
231 mwindow->theme->vslider_y,
232 mwindow->theme->vslider_w);
233 // Recalibrate pointer motion range
234 slider->set_position();
235 timebar->resize_event();
236 transport->reposition_buttons(mwindow->theme->vtransport_x,
237 mwindow->theme->vtransport_y);
238 clock->reposition_window(mwindow->theme->vtime_x,
239 mwindow->theme->vtime_y,
240 mwindow->theme->vtime_w);
241 canvas->reposition_window(0,
242 mwindow->theme->vcanvas_x,
243 mwindow->theme->vcanvas_y,
244 mwindow->theme->vcanvas_w,
245 mwindow->theme->vcanvas_h);
246 // source->reposition_window(mwindow->theme->vsource_x,
247 // mwindow->theme->vsource_y);
248 meters->reposition_window(mwindow->theme->vmeter_x,
249 mwindow->theme->vmeter_y,
250 mwindow->theme->vmeter_h);
252 BC_WindowBase::resize_event(w, h);
260 int VWindowGUI::translation_event()
262 mwindow->session->vwindow_x = get_x();
263 mwindow->session->vwindow_y = get_y();
267 int VWindowGUI::close_event()
270 mwindow->session->show_vwindow = 0;
274 mwindow->gui->lock_window("VWindowGUI::close_event");
275 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
276 mwindow->gui->unlock_window();
278 lock_window("VWindowGUI::close_event");
279 mwindow->save_defaults();
283 int VWindowGUI::keypress_event()
286 switch(get_keypress())
294 mwindow->undo_entry(this);
297 mwindow->redo_entry(this);
301 if(mwindow->session->vwindow_fullscreen)
302 canvas->stop_fullscreen();
304 canvas->start_fullscreen();
305 lock_window("VWindowGUI::keypress_event 1");
309 if(mwindow->session->vwindow_fullscreen)
310 canvas->stop_fullscreen();
311 lock_window("VWindowGUI::keypress_event 2");
314 if(!result) result = transport->keypress_event();
319 int VWindowGUI::button_press_event()
321 if(canvas->get_canvas())
322 return canvas->button_press_event_base(canvas->get_canvas());
326 int VWindowGUI::cursor_leave_event()
328 if(canvas->get_canvas())
329 return canvas->cursor_leave_event_base(canvas->get_canvas());
333 int VWindowGUI::cursor_enter_event()
335 if(canvas->get_canvas())
336 return canvas->cursor_enter_event_base(canvas->get_canvas());
340 int VWindowGUI::button_release_event()
342 if(canvas->get_canvas())
343 return canvas->button_release_event();
347 int VWindowGUI::cursor_motion_event()
349 if(canvas->get_canvas())
351 canvas->get_canvas()->unhide_cursor();
352 return canvas->cursor_motion_event();
358 void VWindowGUI::drag_motion()
360 if(get_hidden()) return;
361 if(mwindow->session->current_operation != DRAG_ASSET) return;
363 int old_status = mwindow->session->vcanvas_highlighted;
365 int cursor_x = get_relative_cursor_x();
366 int cursor_y = get_relative_cursor_y();
368 mwindow->session->vcanvas_highlighted = (get_cursor_over_window() &&
369 cursor_x >= canvas->x &&
370 cursor_x < canvas->x + canvas->w &&
371 cursor_y >= canvas->y &&
372 cursor_y < canvas->y + canvas->h);
373 //printf("VWindowGUI::drag_motion 1 %d\n", mwindow->session->vcanvas_highlighted);
376 if(old_status != mwindow->session->vcanvas_highlighted)
377 canvas->draw_refresh();
380 int VWindowGUI::drag_stop()
382 if(get_hidden()) return 0;
384 if(mwindow->session->vcanvas_highlighted &&
385 mwindow->session->current_operation == DRAG_ASSET)
387 mwindow->session->vcanvas_highlighted = 0;
388 canvas->draw_refresh();
390 Asset *asset = mwindow->session->drag_assets->total ?
391 mwindow->session->drag_assets->values[0] :
393 EDL *edl = mwindow->session->drag_clips->total ?
394 mwindow->session->drag_clips->values[0] :
398 vwindow->change_source(asset);
401 vwindow->change_source(edl);
412 VWindowMeters::VWindowMeters(MWindow *mwindow,
417 : MeterPanel(mwindow,
422 mwindow->edl->session->audio_channels,
423 mwindow->edl->session->vwindow_meter)
425 this->mwindow = mwindow;
429 VWindowMeters::~VWindowMeters()
433 int VWindowMeters::change_status_event()
435 mwindow->edl->session->vwindow_meter = use_meters;
436 //printf("VWindowMeters::change_status_event 1 %d\n", mwindow->edl->session->vwindow_meter);
437 mwindow->theme->get_vwindow_sizes(gui);
438 gui->resize_event(gui->get_w(), gui->get_h());
448 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
451 mwindow->theme->vedit_x,
452 mwindow->theme->vedit_y,
470 this->mwindow = mwindow;
471 this->vwindow = vwindow;
474 VWindowEditing::~VWindowEditing()
478 void VWindowEditing::copy_selection()
483 void VWindowEditing::splice_selection()
485 if(vwindow->get_edl())
487 mwindow->gui->lock_window("VWindowEditing::splice_selection");
488 mwindow->splice(vwindow->get_edl());
489 mwindow->gui->unlock_window();
493 void VWindowEditing::overwrite_selection()
495 if(vwindow->get_edl())
497 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
498 mwindow->overwrite(vwindow->get_edl());
499 mwindow->gui->unlock_window();
503 void VWindowEditing::toggle_label()
505 if(vwindow->get_edl())
507 EDL *edl = vwindow->get_edl();
508 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
509 edl->local_session->get_selectionend(1));
510 vwindow->gui->timebar->update();
514 void VWindowEditing::prev_label()
516 if(vwindow->get_edl())
518 EDL *edl = vwindow->get_edl();
519 vwindow->gui->unlock_window();
520 vwindow->playback_engine->interrupt_playback(1);
521 vwindow->gui->lock_window("VWindowEditing::prev_label");
523 Label *current = edl->labels->prev_label(
524 edl->local_session->get_selectionstart(1));
529 edl->local_session->set_selectionstart(0);
530 edl->local_session->set_selectionend(0);
531 vwindow->update_position(CHANGE_NONE, 0, 1);
532 vwindow->gui->timebar->update();
536 edl->local_session->set_selectionstart(current->position);
537 edl->local_session->set_selectionend(current->position);
538 vwindow->update_position(CHANGE_NONE, 0, 1);
539 vwindow->gui->timebar->update();
544 void VWindowEditing::next_label()
546 if(vwindow->get_edl())
548 EDL *edl = vwindow->get_edl();
549 Label *current = edl->labels->next_label(
550 edl->local_session->get_selectionstart(1));
553 vwindow->gui->unlock_window();
554 vwindow->playback_engine->interrupt_playback(1);
555 vwindow->gui->lock_window("VWindowEditing::next_label 1");
557 double position = edl->tracks->total_length();
558 edl->local_session->set_selectionstart(position);
559 edl->local_session->set_selectionend(position);
560 vwindow->update_position(CHANGE_NONE, 0, 1);
561 vwindow->gui->timebar->update();
565 vwindow->gui->unlock_window();
566 vwindow->playback_engine->interrupt_playback(1);
567 vwindow->gui->lock_window("VWindowEditing::next_label 2");
569 edl->local_session->set_selectionstart(current->position);
570 edl->local_session->set_selectionend(current->position);
571 vwindow->update_position(CHANGE_NONE, 0, 1);
572 vwindow->gui->timebar->update();
577 void VWindowEditing::set_inpoint()
579 vwindow->set_inpoint();
582 void VWindowEditing::set_outpoint()
584 vwindow->set_outpoint();
587 void VWindowEditing::clear_inpoint()
589 vwindow->clear_inpoint();
592 void VWindowEditing::clear_outpoint()
594 vwindow->clear_outpoint();
597 void VWindowEditing::to_clip()
599 if(vwindow->get_edl())
602 EDL *edl = vwindow->get_edl();
603 double start = edl->local_session->get_selectionstart();
604 double end = edl->local_session->get_selectionend();
606 if(EQUIV(start, end))
608 end = edl->tracks->total_length();
627 EDL *new_edl = new EDL(mwindow->edl);
628 new_edl->create_objects();
629 new_edl->load_xml(mwindow->plugindb, &file, LOAD_ALL);
630 sprintf(new_edl->local_session->clip_title, _("Clip %d"), mwindow->session->clip_number++);
631 new_edl->local_session->set_selectionstart(0);
632 new_edl->local_session->set_selectionend(0);
635 //printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title);
636 new_edl->local_session->set_selectionstart(0.0);
637 new_edl->local_session->set_selectionend(0.0);
638 vwindow->clip_edit->create_clip(new_edl);
647 VWindowSlider::VWindowSlider(MWindow *mwindow,
653 : BC_PercentageSlider(x,
662 this->mwindow = mwindow;
663 this->vwindow = vwindow;
665 set_precision(0.00001);
668 VWindowSlider::~VWindowSlider()
672 int VWindowSlider::handle_event()
675 vwindow->playback_engine->interrupt_playback(1);
676 lock_window("VWindowSlider::handle_event");
678 vwindow->update_position(CHANGE_NONE, 1, 0);
679 gui->timebar->update();
683 void VWindowSlider::set_position()
685 EDL *edl = vwindow->get_edl();
688 double new_length = edl->tracks->total_playable_length();
689 if(EQUIV(edl->local_session->preview_end, 0))
690 edl->local_session->preview_end = new_length;
691 if(edl->local_session->preview_end > new_length)
692 edl->local_session->preview_end = new_length;
693 if(edl->local_session->preview_start > new_length)
694 edl->local_session->preview_start = 0;
696 update(mwindow->theme->vslider_w,
697 edl->local_session->get_selectionstart(1),
698 edl->local_session->preview_start,
699 edl->local_session->preview_end);
711 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
712 : BC_PopupTextBox(vwindow,
720 this->mwindow = mwindow;
721 this->vwindow = vwindow;
724 VWindowSource::~VWindowSource()
728 int VWindowSource::handle_event()
739 VWindowTransport::VWindowTransport(MWindow *mwindow,
743 : PlayTransport(mwindow,
751 EDL* VWindowTransport::get_edl()
753 return gui->vwindow->get_edl();
757 void VWindowTransport::goto_start()
759 gui->unlock_window();
760 handle_transport(REWIND, 1);
761 gui->lock_window("VWindowTransport::goto_start");
762 gui->vwindow->goto_start();
765 void VWindowTransport::goto_end()
767 gui->unlock_window();
768 handle_transport(GOTO_END, 1);
769 gui->lock_window("VWindowTransport::goto_end");
770 gui->vwindow->goto_end();
776 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
779 mwindow->theme->vcanvas_x,
780 mwindow->theme->vcanvas_y,
781 mwindow->theme->vcanvas_w,
782 mwindow->theme->vcanvas_h,
790 this->mwindow = mwindow;
794 void VWindowCanvas::zoom_resize_window(float percentage)
796 EDL *edl = mwindow->vwindow->get_edl();
797 if(!edl) edl = mwindow->edl;
799 int canvas_w, canvas_h;
800 calculate_sizes(edl->get_aspect_ratio(),
801 edl->session->output_w,
802 edl->session->output_h,
807 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
808 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
809 gui->resize_window(new_w, new_h);
810 gui->resize_event(new_w, new_h);
813 void VWindowCanvas::close_source()
815 mwindow->vwindow->remove_source();
819 void VWindowCanvas::draw_refresh()
821 EDL *edl = gui->vwindow->get_edl();
823 if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
824 if(!get_canvas()->get_video_on() && refresh_frame && edl)
826 float in_x1, in_y1, in_x2, in_y2;
827 float out_x1, out_y1, out_x2, out_y2;
837 get_canvas()->draw_vframe(refresh_frame,
840 (int)(out_x2 - out_x1),
841 (int)(out_y2 - out_y1),
844 (int)(in_x2 - in_x1),
845 (int)(in_y2 - in_y1),
849 if(!get_canvas()->get_video_on())
852 get_canvas()->flash();
856 void VWindowCanvas::draw_overlays()
858 if(mwindow->session->vcanvas_highlighted)
860 get_canvas()->set_color(WHITE);
861 get_canvas()->set_inverse();
862 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
863 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
864 get_canvas()->set_opaque();
868 int VWindowCanvas::get_fullscreen()
870 return mwindow->session->vwindow_fullscreen;
873 void VWindowCanvas::set_fullscreen(int value)
875 mwindow->session->vwindow_fullscreen = value;
915 void VWindowGUI::update_points()
917 EDL *edl = vwindow->get_edl();
919 //printf("VWindowGUI::update_points 1\n");
922 //printf("VWindowGUI::update_points 2\n");
923 long pixel = (long)((double)edl->local_session->in_point /
924 edl->tracks->total_playable_length() *
925 (mwindow->theme->vtimebar_w -
927 mwindow->theme->in_point[0]->get_w())) +
928 mwindow->theme->in_point[0]->get_w();
930 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
933 //printf("VWindowGUI::update_points 3.1\n");
934 if(edl->local_session->in_point >= 0)
936 //printf("VWindowGUI::update_points 4\n");
937 if(edl->local_session->in_point != in_point->position ||
938 in_point->pixel != pixel)
940 in_point->pixel = pixel;
941 in_point->reposition();
944 //printf("VWindowGUI::update_points 5\n");
945 in_point->position = edl->local_session->in_point;
947 //printf("VWindowGUI::update_points 6\n");
948 if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
949 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
953 //printf("VWindowGUI::update_points 7\n");
962 if(edl->local_session->in_point >= 0)
964 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
965 add_subwindow(in_point =
966 new VWindowInPoint(mwindow,
970 edl->local_session->in_point));
971 //printf("VWindowGUI::update_points 9\n");
973 //printf("VWindowGUI::update_points 10\n");
975 pixel = (long)((double)edl->local_session->out_point /
976 (edl->tracks->total_playable_length() + 0.5) *
977 (mwindow->theme->vtimebar_w -
979 mwindow->theme->in_point[0]->get_w())) +
980 mwindow->theme->in_point[0]->get_w() *
985 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
987 if(edl->local_session->out_point != out_point->position ||
988 out_point->pixel != pixel)
990 out_point->pixel = pixel;
991 out_point->reposition();
993 out_point->position = edl->local_session->out_point;
995 if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
996 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
997 out_point->update(1);
999 out_point->update(0);
1008 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1010 add_subwindow(out_point =
1011 new VWindowOutPoint(mwindow,
1015 edl->local_session->out_point));
1020 void VWindowGUI::update_labels()
1022 EDL *edl = vwindow->get_edl();
1025 for(Label *current = edl->labels->first;
1029 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1031 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1034 if(output >= labels.total)
1036 LabelGUI *new_label;
1037 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1038 labels.append(new_label);
1041 // Reposition old label
1042 if(labels.values[output]->pixel != pixel)
1044 labels.values[output]->pixel = pixel;
1045 labels.values[output]->position = current->position;
1046 labels.values[output]->reposition();
1049 if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1050 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1051 labels.values[output]->update(1);
1053 if(labels.values[output]->get_value())
1054 labels.values[output]->update(0);
1059 // Delete excess labels
1060 while(labels.total > output)
1062 labels.remove_object();
1068 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1073 : InPointGUI(mwindow,
1081 int VWindowInPoint::handle_event()
1083 EDL *edl = gui->vwindow->get_edl();
1087 double position = edl->align_to_frame(this->position, 0);
1089 edl->local_session->set_selectionstart(position);
1090 edl->local_session->set_selectionend(position);
1091 gui->timebar->update();
1094 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1101 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1106 : OutPointGUI(mwindow,
1114 int VWindowOutPoint::handle_event()
1116 EDL *edl = gui->vwindow->get_edl();
1120 double position = edl->align_to_frame(this->position, 0);
1122 edl->local_session->set_selectionstart(position);
1123 edl->local_session->set_selectionend(position);
1124 gui->timebar->update();
1127 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);