3 #include "awindowgui.h"
9 #include "edlsession.h"
10 #include "filesystem.h"
15 #include "localsession.h"
16 #include "mainclock.h"
18 #include "mainsession.h"
20 #include "meterpanel.h"
21 #include "mwindowgui.h"
23 #include "playtransport.h"
24 #include "preferences.h"
29 #include "vplayback.h"
31 #include "vwindowgui.h"
37 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
38 : BC_Window(PROGRAM_NAME ": Viewer",
39 mwindow->session->vwindow_x,
40 mwindow->session->vwindow_y,
41 mwindow->session->vwindow_w,
42 mwindow->session->vwindow_h,
49 this->mwindow = mwindow;
50 this->vwindow = vwindow;
53 VWindowGUI::~VWindowGUI()
59 void VWindowGUI::change_source(EDL *edl, char *title)
61 update_sources(title);
62 char string[BCTEXTLEN];
64 sprintf(string, PROGRAM_NAME ": %s", title);
66 sprintf(string, PROGRAM_NAME);
68 lock_window("VWindowGUI::change_source");
69 slider->set_position();
76 // Get source list from master EDL
77 void VWindowGUI::update_sources(char *title)
79 lock_window("VWindowGUI::update_sources");
81 //printf("VWindowGUI::update_sources 1\n");
82 sources.remove_all_objects();
83 //printf("VWindowGUI::update_sources 2\n");
88 i < mwindow->edl->clips.total;
91 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
94 for(int j = 0; j < sources.total; j++)
96 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
104 sources.append(new BC_ListBoxItem(clip_title));
107 //printf("VWindowGUI::update_sources 3\n");
110 for(Asset *current = mwindow->edl->assets->first;
114 char clip_title[BCTEXTLEN];
115 fs.extract_name(clip_title, current->path);
118 for(int j = 0; j < sources.total; j++)
120 if(!strcasecmp(sources.values[j]->get_text(), clip_title))
128 sources.append(new BC_ListBoxItem(clip_title));
132 //printf("VWindowGUI::update_sources 4\n");
134 // source->update_list(&sources);
135 // source->update(title);
139 int VWindowGUI::create_objects()
143 set_icon(mwindow->theme->get_image("vwindow_icon"));
145 //printf("VWindowGUI::create_objects 1\n");
146 mwindow->theme->get_vwindow_sizes(this);
147 mwindow->theme->draw_vwindow_bg(this);
150 meters = new VWindowMeters(mwindow,
152 mwindow->theme->vmeter_x,
153 mwindow->theme->vmeter_y,
154 mwindow->theme->vmeter_h);
155 meters->create_objects();
157 //printf("VWindowGUI::create_objects 1\n");
158 // Requires meters to build
159 edit_panel = new VWindowEditing(mwindow, vwindow);
160 edit_panel->set_meters(meters);
161 edit_panel->create_objects();
163 //printf("VWindowGUI::create_objects 1\n");
164 add_subwindow(slider = new VWindowSlider(mwindow,
167 mwindow->theme->vslider_x,
168 mwindow->theme->vslider_y,
169 mwindow->theme->vslider_w));
171 //printf("VWindowGUI::create_objects 1\n");
172 transport = new VWindowTransport(mwindow,
174 mwindow->theme->vtransport_x,
175 mwindow->theme->vtransport_y);
176 transport->create_objects();
177 transport->set_slider(slider);
179 //printf("VWindowGUI::create_objects 1\n");
180 // add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
181 add_subwindow(clock = new MainClock(mwindow,
182 mwindow->theme->vtime_x,
183 mwindow->theme->vtime_y,
184 mwindow->theme->vtime_w));
186 //printf("VWindowGUI::create_objects 1\n");
187 // add_subwindow(new BC_Title(mwindow->theme->vzoom_x, mwindow->theme->vzoom_y, "Zoom:"));
188 // zoom_panel = new VWindowZoom(mwindow,
190 // mwindow->theme->vzoom_x + 60,
191 // mwindow->theme->vzoom_y);
192 // zoom_panel->create_objects();
194 canvas = new VWindowCanvas(mwindow, this);
195 canvas->create_objects(mwindow->edl);
199 //printf("VWindowGUI::create_objects 1\n");
200 add_subwindow(timebar = new VTimeBar(mwindow,
202 mwindow->theme->vtimebar_x,
203 mwindow->theme->vtimebar_y,
204 mwindow->theme->vtimebar_w,
205 mwindow->theme->vtimebar_h));
206 timebar->create_objects();
207 //printf("VWindowGUI::create_objects 2\n");
210 //printf("VWindowGUI::create_objects 1\n");
211 // source = new VWindowSource(mwindow,
213 // mwindow->theme->vsource_x,
214 // mwindow->theme->vsource_y);
215 // source->create_objects();
216 update_sources(_("None"));
218 //printf("VWindowGUI::create_objects 2\n");
224 int VWindowGUI::resize_event(int w, int h)
226 mwindow->session->vwindow_x = get_x();
227 mwindow->session->vwindow_y = get_y();
228 mwindow->session->vwindow_w = w;
229 mwindow->session->vwindow_h = h;
231 mwindow->theme->get_vwindow_sizes(this);
232 mwindow->theme->draw_vwindow_bg(this);
235 edit_panel->reposition_buttons(mwindow->theme->vedit_x,
236 mwindow->theme->vedit_y);
237 slider->reposition_window(mwindow->theme->vslider_x,
238 mwindow->theme->vslider_y,
239 mwindow->theme->vslider_w);
240 // Recalibrate pointer motion range
241 slider->set_position();
242 timebar->resize_event();
243 transport->reposition_buttons(mwindow->theme->vtransport_x,
244 mwindow->theme->vtransport_y);
245 clock->reposition_window(mwindow->theme->vtime_x,
246 mwindow->theme->vtime_y,
247 mwindow->theme->vtime_w);
248 canvas->reposition_window(0,
249 mwindow->theme->vcanvas_x,
250 mwindow->theme->vcanvas_y,
251 mwindow->theme->vcanvas_w,
252 mwindow->theme->vcanvas_h);
253 // source->reposition_window(mwindow->theme->vsource_x,
254 // mwindow->theme->vsource_y);
255 meters->reposition_window(mwindow->theme->vmeter_x,
256 mwindow->theme->vmeter_y,
257 mwindow->theme->vmeter_h);
259 BC_WindowBase::resize_event(w, h);
267 int VWindowGUI::translation_event()
269 mwindow->session->vwindow_x = get_x();
270 mwindow->session->vwindow_y = get_y();
274 int VWindowGUI::close_event()
277 mwindow->session->show_vwindow = 0;
281 mwindow->gui->lock_window("VWindowGUI::close_event");
282 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
283 mwindow->gui->unlock_window();
285 lock_window("VWindowGUI::close_event");
286 mwindow->save_defaults();
290 int VWindowGUI::keypress_event()
293 switch(get_keypress())
301 mwindow->undo_entry(this);
304 mwindow->redo_entry(this);
307 if(!result) result = transport->keypress_event();
312 void VWindowGUI::drag_motion()
314 if(get_hidden()) return;
315 if(mwindow->session->current_operation != DRAG_ASSET) return;
317 int old_status = mwindow->session->vcanvas_highlighted;
319 int cursor_x = get_relative_cursor_x();
320 int cursor_y = get_relative_cursor_y();
322 mwindow->session->vcanvas_highlighted = (get_cursor_over_window() &&
323 cursor_x >= canvas->x &&
324 cursor_x < canvas->x + canvas->w &&
325 cursor_y >= canvas->y &&
326 cursor_y < canvas->y + canvas->h);
327 //printf("VWindowGUI::drag_motion 1 %d\n", mwindow->session->vcanvas_highlighted);
330 if(old_status != mwindow->session->vcanvas_highlighted)
331 canvas->draw_refresh();
334 int VWindowGUI::drag_stop()
336 if(get_hidden()) return 0;
338 if(mwindow->session->vcanvas_highlighted &&
339 mwindow->session->current_operation == DRAG_ASSET)
341 mwindow->session->vcanvas_highlighted = 0;
342 canvas->draw_refresh();
344 Asset *asset = mwindow->session->drag_assets->total ?
345 mwindow->session->drag_assets->values[0] :
347 EDL *edl = mwindow->session->drag_clips->total ?
348 mwindow->session->drag_clips->values[0] :
352 vwindow->change_source(asset);
355 vwindow->change_source(edl);
366 VWindowMeters::VWindowMeters(MWindow *mwindow,
371 : MeterPanel(mwindow,
376 mwindow->edl->session->audio_channels,
377 mwindow->edl->session->vwindow_meter)
379 this->mwindow = mwindow;
383 VWindowMeters::~VWindowMeters()
387 int VWindowMeters::change_status_event()
389 mwindow->edl->session->vwindow_meter = use_meters;
390 //printf("VWindowMeters::change_status_event 1 %d\n", mwindow->edl->session->vwindow_meter);
391 mwindow->theme->get_vwindow_sizes(gui);
392 gui->resize_event(gui->get_w(), gui->get_h());
402 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
405 mwindow->theme->vedit_x,
406 mwindow->theme->vedit_y,
424 this->mwindow = mwindow;
425 this->vwindow = vwindow;
428 VWindowEditing::~VWindowEditing()
432 void VWindowEditing::copy_selection()
437 void VWindowEditing::splice_selection()
439 if(vwindow->get_edl())
441 mwindow->gui->lock_window("VWindowEditing::splice_selection");
442 mwindow->splice(vwindow->get_edl());
443 mwindow->gui->unlock_window();
447 void VWindowEditing::overwrite_selection()
449 if(vwindow->get_edl())
451 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
452 mwindow->overwrite(vwindow->get_edl());
453 mwindow->gui->unlock_window();
457 void VWindowEditing::toggle_label()
459 if(vwindow->get_edl())
461 EDL *edl = vwindow->get_edl();
462 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
463 edl->local_session->get_selectionend(1));
464 vwindow->gui->timebar->update();
468 void VWindowEditing::prev_label()
470 if(vwindow->get_edl())
472 EDL *edl = vwindow->get_edl();
473 vwindow->gui->unlock_window();
474 vwindow->playback_engine->interrupt_playback(1);
475 vwindow->gui->lock_window("VWindowEditing::prev_label");
477 Label *current = edl->labels->prev_label(
478 edl->local_session->get_selectionstart(1));
483 edl->local_session->set_selectionstart(0);
484 edl->local_session->set_selectionend(0);
485 vwindow->update_position(CHANGE_NONE, 0, 1);
486 vwindow->gui->timebar->update();
490 edl->local_session->set_selectionstart(current->position);
491 edl->local_session->set_selectionend(current->position);
492 vwindow->update_position(CHANGE_NONE, 0, 1);
493 vwindow->gui->timebar->update();
498 void VWindowEditing::next_label()
500 if(vwindow->get_edl())
502 EDL *edl = vwindow->get_edl();
503 Label *current = edl->labels->next_label(
504 edl->local_session->get_selectionstart(1));
507 vwindow->gui->unlock_window();
508 vwindow->playback_engine->interrupt_playback(1);
509 vwindow->gui->lock_window("VWindowEditing::next_label 1");
511 double position = edl->tracks->total_length();
512 edl->local_session->set_selectionstart(position);
513 edl->local_session->set_selectionend(position);
514 vwindow->update_position(CHANGE_NONE, 0, 1);
515 vwindow->gui->timebar->update();
519 vwindow->gui->unlock_window();
520 vwindow->playback_engine->interrupt_playback(1);
521 vwindow->gui->lock_window("VWindowEditing::next_label 2");
523 edl->local_session->set_selectionstart(current->position);
524 edl->local_session->set_selectionend(current->position);
525 vwindow->update_position(CHANGE_NONE, 0, 1);
526 vwindow->gui->timebar->update();
531 void VWindowEditing::set_inpoint()
533 vwindow->set_inpoint();
536 void VWindowEditing::set_outpoint()
538 vwindow->set_outpoint();
541 void VWindowEditing::clear_inpoint()
543 vwindow->clear_inpoint();
546 void VWindowEditing::clear_outpoint()
548 vwindow->clear_outpoint();
551 void VWindowEditing::to_clip()
553 if(vwindow->get_edl())
556 EDL *edl = vwindow->get_edl();
557 double start = edl->local_session->get_selectionstart();
558 double end = edl->local_session->get_selectionend();
560 if(EQUIV(start, end))
562 end = edl->tracks->total_length();
581 EDL *new_edl = new EDL(mwindow->edl);
582 new_edl->create_objects();
583 new_edl->load_xml(mwindow->plugindb, &file, LOAD_ALL);
584 sprintf(new_edl->local_session->clip_title, _("Clip %d"), mwindow->session->clip_number++);
585 new_edl->local_session->set_selectionstart(0);
586 new_edl->local_session->set_selectionend(0);
589 //printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title);
590 new_edl->local_session->set_selectionstart(0.0);
591 new_edl->local_session->set_selectionend(0.0);
592 vwindow->clip_edit->create_clip(new_edl);
601 VWindowSlider::VWindowSlider(MWindow *mwindow,
607 : BC_PercentageSlider(x,
616 this->mwindow = mwindow;
617 this->vwindow = vwindow;
619 set_precision(0.00001);
622 VWindowSlider::~VWindowSlider()
626 int VWindowSlider::handle_event()
629 vwindow->playback_engine->interrupt_playback(1);
630 lock_window("VWindowSlider::handle_event");
632 vwindow->update_position(CHANGE_NONE, 1, 0);
633 gui->timebar->update();
637 void VWindowSlider::set_position()
639 EDL *edl = vwindow->get_edl();
642 double new_length = edl->tracks->total_playable_length();
643 if(EQUIV(edl->local_session->preview_end, 0))
644 edl->local_session->preview_end = new_length;
645 if(edl->local_session->preview_end > new_length)
646 edl->local_session->preview_end = new_length;
647 if(edl->local_session->preview_start > new_length)
648 edl->local_session->preview_start = 0;
650 update(mwindow->theme->vslider_w,
651 edl->local_session->get_selectionstart(1),
652 edl->local_session->preview_start,
653 edl->local_session->preview_end);
665 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
666 : BC_PopupTextBox(vwindow,
674 this->mwindow = mwindow;
675 this->vwindow = vwindow;
678 VWindowSource::~VWindowSource()
682 int VWindowSource::handle_event()
693 VWindowTransport::VWindowTransport(MWindow *mwindow,
697 : PlayTransport(mwindow,
705 EDL* VWindowTransport::get_edl()
707 return gui->vwindow->get_edl();
711 void VWindowTransport::goto_start()
713 gui->unlock_window();
714 handle_transport(REWIND, 1);
715 gui->lock_window("VWindowTransport::goto_start");
716 gui->vwindow->goto_start();
719 void VWindowTransport::goto_end()
721 gui->unlock_window();
722 handle_transport(GOTO_END, 1);
723 gui->lock_window("VWindowTransport::goto_end");
724 gui->vwindow->goto_end();
730 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
732 mwindow->theme->vcanvas_x,
733 mwindow->theme->vcanvas_y,
734 mwindow->theme->vcanvas_w,
735 mwindow->theme->vcanvas_h,
743 this->mwindow = mwindow;
747 void VWindowCanvas::zoom_resize_window(float percentage)
749 EDL *edl = mwindow->vwindow->get_edl();
750 if(!edl) edl = mwindow->edl;
752 int canvas_w, canvas_h;
753 calculate_sizes(edl->get_aspect_ratio(),
754 edl->session->output_w,
755 edl->session->output_h,
760 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
761 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
762 gui->resize_window(new_w, new_h);
763 gui->resize_event(new_w, new_h);
766 void VWindowCanvas::close_source()
768 mwindow->vwindow->remove_source();
772 void VWindowCanvas::draw_refresh()
774 EDL *edl = gui->vwindow->get_edl();
776 if(!canvas->video_is_on()) canvas->clear_box(0, 0, canvas->get_w(), canvas->get_h());
777 if(!canvas->video_is_on() && refresh_frame && edl)
779 int in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h;
789 canvas->draw_vframe(refresh_frame,
801 if(!canvas->video_is_on())
809 void VWindowCanvas::draw_overlays()
811 if(mwindow->session->vcanvas_highlighted)
813 canvas->set_color(WHITE);
814 canvas->set_inverse();
815 canvas->draw_rectangle(0, 0, canvas->get_w(), canvas->get_h());
816 canvas->draw_rectangle(1, 1, canvas->get_w() - 2, canvas->get_h() - 2);
817 canvas->set_opaque();
858 void VWindowGUI::update_points()
860 EDL *edl = vwindow->get_edl();
862 //printf("VWindowGUI::update_points 1\n");
865 //printf("VWindowGUI::update_points 2\n");
866 long pixel = (long)((double)edl->local_session->in_point /
867 edl->tracks->total_playable_length() *
868 (mwindow->theme->vtimebar_w -
870 mwindow->theme->in_point[0]->get_w())) +
871 mwindow->theme->in_point[0]->get_w();
873 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
876 //printf("VWindowGUI::update_points 3.1\n");
877 if(edl->local_session->in_point >= 0)
879 //printf("VWindowGUI::update_points 4\n");
880 if(edl->local_session->in_point != in_point->position ||
881 in_point->pixel != pixel)
883 in_point->pixel = pixel;
884 in_point->reposition();
887 //printf("VWindowGUI::update_points 5\n");
888 in_point->position = edl->local_session->in_point;
890 //printf("VWindowGUI::update_points 6\n");
891 if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
892 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
896 //printf("VWindowGUI::update_points 7\n");
905 if(edl->local_session->in_point >= 0)
907 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
908 add_subwindow(in_point =
909 new VWindowInPoint(mwindow,
913 edl->local_session->in_point));
914 //printf("VWindowGUI::update_points 9\n");
916 //printf("VWindowGUI::update_points 10\n");
918 pixel = (long)((double)edl->local_session->out_point /
919 (edl->tracks->total_playable_length() + 0.5) *
920 (mwindow->theme->vtimebar_w -
922 mwindow->theme->in_point[0]->get_w())) +
923 mwindow->theme->in_point[0]->get_w() *
928 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
930 if(edl->local_session->out_point != out_point->position ||
931 out_point->pixel != pixel)
933 out_point->pixel = pixel;
934 out_point->reposition();
936 out_point->position = edl->local_session->out_point;
938 if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
939 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
940 out_point->update(1);
942 out_point->update(0);
951 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
953 add_subwindow(out_point =
954 new VWindowOutPoint(mwindow,
958 edl->local_session->out_point));
963 void VWindowGUI::update_labels()
965 EDL *edl = vwindow->get_edl();
968 for(Label *current = edl->labels->first;
972 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
974 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
977 if(output >= labels.total)
980 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
981 labels.append(new_label);
984 // Reposition old label
985 if(labels.values[output]->pixel != pixel)
987 labels.values[output]->pixel = pixel;
988 labels.values[output]->position = current->position;
989 labels.values[output]->reposition();
992 if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
993 mwindow->edl->local_session->get_selectionend(1) >= current->position)
994 labels.values[output]->update(1);
996 if(labels.values[output]->get_value())
997 labels.values[output]->update(0);
1002 // Delete excess labels
1003 while(labels.total > output)
1005 labels.remove_object();
1011 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1016 : InPointGUI(mwindow,
1024 int VWindowInPoint::handle_event()
1026 EDL *edl = gui->vwindow->get_edl();
1030 double position = edl->align_to_frame(this->position, 0);
1032 edl->local_session->set_selectionstart(position);
1033 edl->local_session->set_selectionend(position);
1034 gui->timebar->update();
1037 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1044 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1049 : OutPointGUI(mwindow,
1057 int VWindowOutPoint::handle_event()
1059 EDL *edl = gui->vwindow->get_edl();
1063 double position = edl->align_to_frame(this->position, 0);
1065 edl->local_session->set_selectionstart(position);
1066 edl->local_session->set_selectionend(position);
1067 gui->timebar->update();
1070 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);