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(Assets_list::iterator current = mwindow->edl->assets->begin();
113 current != mwindow->edl->assets->end();
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();
392 if (!mwindow->session->drag_assets.empty())
393 asset = mwindow->session->drag_assets[0];
395 EDL *edl = mwindow->session->drag_clips->total ?
396 mwindow->session->drag_clips->values[0] :
400 vwindow->change_source(asset);
403 vwindow->change_source(edl);
414 VWindowMeters::VWindowMeters(MWindow *mwindow,
419 : MeterPanel(mwindow,
424 mwindow->edl->session->audio_channels,
425 mwindow->edl->session->vwindow_meter)
427 this->mwindow = mwindow;
431 VWindowMeters::~VWindowMeters()
435 int VWindowMeters::change_status_event()
437 mwindow->edl->session->vwindow_meter = use_meters;
438 //printf("VWindowMeters::change_status_event 1 %d\n", mwindow->edl->session->vwindow_meter);
439 mwindow->theme->get_vwindow_sizes(gui);
440 gui->resize_event(gui->get_w(), gui->get_h());
450 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
453 mwindow->theme->vedit_x,
454 mwindow->theme->vedit_y,
473 this->mwindow = mwindow;
474 this->vwindow = vwindow;
477 VWindowEditing::~VWindowEditing()
481 void VWindowEditing::copy_selection()
486 void VWindowEditing::splice_selection()
488 if(vwindow->get_edl())
490 mwindow->gui->lock_window("VWindowEditing::splice_selection");
491 mwindow->splice(vwindow->get_edl());
492 mwindow->gui->unlock_window();
496 void VWindowEditing::overwrite_selection()
498 if(vwindow->get_edl())
500 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
501 mwindow->overwrite(vwindow->get_edl());
502 mwindow->gui->unlock_window();
506 void VWindowEditing::toggle_label()
508 if(vwindow->get_edl())
510 EDL *edl = vwindow->get_edl();
511 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
512 edl->local_session->get_selectionend(1));
513 vwindow->gui->timebar->update();
517 void VWindowEditing::prev_label()
519 if(vwindow->get_edl())
521 EDL *edl = vwindow->get_edl();
522 vwindow->gui->unlock_window();
523 vwindow->playback_engine->interrupt_playback(1);
524 vwindow->gui->lock_window("VWindowEditing::prev_label");
526 Label *current = edl->labels->prev_label(
527 edl->local_session->get_selectionstart(1));
532 edl->local_session->set_selectionstart(0);
533 edl->local_session->set_selectionend(0);
534 vwindow->update_position(CHANGE_NONE, 0, 1);
535 vwindow->gui->timebar->update();
539 edl->local_session->set_selectionstart(current->position);
540 edl->local_session->set_selectionend(current->position);
541 vwindow->update_position(CHANGE_NONE, 0, 1);
542 vwindow->gui->timebar->update();
547 void VWindowEditing::next_label()
549 if(vwindow->get_edl())
551 EDL *edl = vwindow->get_edl();
552 Label *current = edl->labels->next_label(
553 edl->local_session->get_selectionstart(1));
556 vwindow->gui->unlock_window();
557 vwindow->playback_engine->interrupt_playback(1);
558 vwindow->gui->lock_window("VWindowEditing::next_label 1");
560 double position = edl->tracks->total_length();
561 edl->local_session->set_selectionstart(position);
562 edl->local_session->set_selectionend(position);
563 vwindow->update_position(CHANGE_NONE, 0, 1);
564 vwindow->gui->timebar->update();
568 vwindow->gui->unlock_window();
569 vwindow->playback_engine->interrupt_playback(1);
570 vwindow->gui->lock_window("VWindowEditing::next_label 2");
572 edl->local_session->set_selectionstart(current->position);
573 edl->local_session->set_selectionend(current->position);
574 vwindow->update_position(CHANGE_NONE, 0, 1);
575 vwindow->gui->timebar->update();
580 void VWindowEditing::set_inpoint()
582 vwindow->set_inpoint();
585 void VWindowEditing::set_outpoint()
587 vwindow->set_outpoint();
590 void VWindowEditing::clear_inpoint()
592 vwindow->clear_inpoint();
595 void VWindowEditing::clear_outpoint()
597 vwindow->clear_outpoint();
600 void VWindowEditing::to_clip()
602 if(vwindow->get_edl())
605 EDL *edl = vwindow->get_edl();
606 double start = edl->local_session->get_selectionstart();
607 double end = edl->local_session->get_selectionend();
609 if(EQUIV(start, end))
611 end = edl->tracks->total_length();
630 EDL *new_edl = new EDL(mwindow->edl);
631 new_edl->create_objects();
632 new_edl->load_xml(mwindow->plugindb, &file, LOAD_ALL);
633 sprintf(new_edl->local_session->clip_title, _("Clip %d"), mwindow->session->clip_number++);
634 char string[BCTEXTLEN];
635 Units::totext(string,
637 edl->session->time_format,
638 edl->session->sample_rate,
639 edl->session->frame_rate,
640 edl->session->frames_per_foot);
642 sprintf(new_edl->local_session->clip_notes, _("%s\n Created from:\n%s"), string, vwindow->gui->loaded_title);
644 new_edl->local_session->set_selectionstart(0);
645 new_edl->local_session->set_selectionend(0);
648 //printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title);
649 new_edl->local_session->set_selectionstart(0.0);
650 new_edl->local_session->set_selectionend(0.0);
651 vwindow->clip_edit->create_clip(new_edl);
660 VWindowSlider::VWindowSlider(MWindow *mwindow,
666 : BC_PercentageSlider(x,
675 this->mwindow = mwindow;
676 this->vwindow = vwindow;
678 set_precision(0.00001);
679 set_pagination(1.0, 10.0);
682 VWindowSlider::~VWindowSlider()
686 int VWindowSlider::handle_event()
689 vwindow->playback_engine->interrupt_playback(1);
690 lock_window("VWindowSlider::handle_event");
692 vwindow->update_position(CHANGE_NONE, 1, 0);
693 gui->timebar->update();
697 void VWindowSlider::set_position()
699 EDL *edl = vwindow->get_edl();
702 double new_length = edl->tracks->total_playable_length();
703 if(EQUIV(edl->local_session->preview_end, 0))
704 edl->local_session->preview_end = new_length;
705 if(edl->local_session->preview_end > new_length)
706 edl->local_session->preview_end = new_length;
707 if(edl->local_session->preview_start > new_length)
708 edl->local_session->preview_start = 0;
710 update(mwindow->theme->vslider_w,
711 edl->local_session->get_selectionstart(1),
712 edl->local_session->preview_start,
713 edl->local_session->preview_end);
725 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
726 : BC_PopupTextBox(vwindow,
734 this->mwindow = mwindow;
735 this->vwindow = vwindow;
738 VWindowSource::~VWindowSource()
742 int VWindowSource::handle_event()
753 VWindowTransport::VWindowTransport(MWindow *mwindow,
757 : PlayTransport(mwindow,
765 EDL* VWindowTransport::get_edl()
767 return gui->vwindow->get_edl();
771 void VWindowTransport::goto_start()
773 gui->unlock_window();
774 handle_transport(REWIND, 1);
775 gui->lock_window("VWindowTransport::goto_start");
776 gui->vwindow->goto_start();
779 void VWindowTransport::goto_end()
781 gui->unlock_window();
782 handle_transport(GOTO_END, 1);
783 gui->lock_window("VWindowTransport::goto_end");
784 gui->vwindow->goto_end();
790 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
793 mwindow->theme->vcanvas_x,
794 mwindow->theme->vcanvas_y,
795 mwindow->theme->vcanvas_w,
796 mwindow->theme->vcanvas_h,
804 this->mwindow = mwindow;
808 void VWindowCanvas::zoom_resize_window(float percentage)
810 EDL *edl = mwindow->vwindow->get_edl();
811 if(!edl) edl = mwindow->edl;
813 int canvas_w, canvas_h;
814 calculate_sizes(edl->get_aspect_ratio(),
815 edl->session->output_w,
816 edl->session->output_h,
821 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
822 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
823 gui->resize_window(new_w, new_h);
824 gui->resize_event(new_w, new_h);
827 void VWindowCanvas::close_source()
829 mwindow->vwindow->remove_source();
833 void VWindowCanvas::draw_refresh()
835 EDL *edl = gui->vwindow->get_edl();
837 if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
838 if(!get_canvas()->get_video_on() && refresh_frame && edl)
840 float in_x1, in_y1, in_x2, in_y2;
841 float out_x1, out_y1, out_x2, out_y2;
851 get_canvas()->draw_vframe(refresh_frame,
854 (int)(out_x2 - out_x1),
855 (int)(out_y2 - out_y1),
858 (int)(in_x2 - in_x1),
859 (int)(in_y2 - in_y1),
863 if(!get_canvas()->get_video_on())
866 get_canvas()->flash();
870 void VWindowCanvas::draw_overlays()
872 if(mwindow->session->vcanvas_highlighted)
874 get_canvas()->set_color(WHITE);
875 get_canvas()->set_inverse();
876 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
877 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
878 get_canvas()->set_opaque();
882 int VWindowCanvas::get_fullscreen()
884 return mwindow->session->vwindow_fullscreen;
887 void VWindowCanvas::set_fullscreen(int value)
889 mwindow->session->vwindow_fullscreen = value;
929 void VWindowGUI::update_points()
931 EDL *edl = vwindow->get_edl();
933 //printf("VWindowGUI::update_points 1\n");
936 //printf("VWindowGUI::update_points 2\n");
937 long pixel = (long)((double)edl->local_session->in_point /
938 edl->tracks->total_playable_length() *
939 (mwindow->theme->vtimebar_w -
941 mwindow->theme->in_point[0]->get_w())) +
942 mwindow->theme->in_point[0]->get_w();
944 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
947 //printf("VWindowGUI::update_points 3.1\n");
948 if(edl->local_session->in_point >= 0)
950 //printf("VWindowGUI::update_points 4\n");
951 if(edl->local_session->in_point != in_point->position ||
952 in_point->pixel != pixel)
954 in_point->pixel = pixel;
955 in_point->reposition();
958 //printf("VWindowGUI::update_points 5\n");
959 in_point->position = edl->local_session->in_point;
961 //printf("VWindowGUI::update_points 6\n");
962 if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
963 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
967 //printf("VWindowGUI::update_points 7\n");
976 if(edl->local_session->in_point >= 0)
978 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
979 add_subwindow(in_point =
980 new VWindowInPoint(mwindow,
984 edl->local_session->in_point));
985 //printf("VWindowGUI::update_points 9\n");
987 //printf("VWindowGUI::update_points 10\n");
989 pixel = (long)((double)edl->local_session->out_point /
990 (edl->tracks->total_playable_length() + 0.5) *
991 (mwindow->theme->vtimebar_w -
993 mwindow->theme->in_point[0]->get_w())) +
994 mwindow->theme->in_point[0]->get_w() *
999 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1001 if(edl->local_session->out_point != out_point->position ||
1002 out_point->pixel != pixel)
1004 out_point->pixel = pixel;
1005 out_point->reposition();
1007 out_point->position = edl->local_session->out_point;
1009 if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
1010 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
1011 out_point->update(1);
1013 out_point->update(0);
1022 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1024 add_subwindow(out_point =
1025 new VWindowOutPoint(mwindow,
1029 edl->local_session->out_point));
1034 void VWindowGUI::update_labels()
1036 EDL *edl = vwindow->get_edl();
1039 for(Label *current = edl->labels->first;
1043 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1045 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1048 if(output >= labels.total)
1050 LabelGUI *new_label;
1051 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1052 labels.append(new_label);
1055 // Reposition old label
1056 if(labels.values[output]->pixel != pixel)
1058 labels.values[output]->pixel = pixel;
1059 labels.values[output]->position = current->position;
1060 labels.values[output]->reposition();
1063 if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1064 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1065 labels.values[output]->update(1);
1067 if(labels.values[output]->get_value())
1068 labels.values[output]->update(0);
1073 // Delete excess labels
1074 while(labels.total > output)
1076 labels.remove_object();
1082 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1087 : InPointGUI(mwindow,
1095 int VWindowInPoint::handle_event()
1097 EDL *edl = gui->vwindow->get_edl();
1101 double position = edl->align_to_frame(this->position, 0);
1103 edl->local_session->set_selectionstart(position);
1104 edl->local_session->set_selectionend(position);
1105 gui->timebar->update();
1108 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1115 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1120 : OutPointGUI(mwindow,
1128 int VWindowOutPoint::handle_event()
1130 EDL *edl = gui->vwindow->get_edl();
1134 double position = edl->align_to_frame(this->position, 0);
1136 edl->local_session->set_selectionstart(position);
1137 edl->local_session->set_selectionend(position);
1138 gui->timebar->update();
1141 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1154 // c-file-style: "linux"