2 #include "awindowgui.h"
8 #include "edlsession.h"
9 #include "filesystem.h"
12 #include "localsession.h"
13 #include "mainclock.h"
15 #include "mainsession.h"
17 #include "meterpanel.h"
18 #include "mwindowgui.h"
20 #include "playtransport.h"
21 #include "preferences.h"
26 #include "vplayback.h"
28 #include "vwindowgui.h"
33 #define _(String) gettext(String)
34 #define gettext_noop(String) String
35 #define N_(String) gettext_noop (String)
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);
69 slider->set_position();
76 // Get source list from master EDL
77 void VWindowGUI::update_sources(char *title)
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->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");
222 int VWindowGUI::resize_event(int w, int h)
224 mwindow->session->vwindow_x = get_x();
225 mwindow->session->vwindow_y = get_y();
226 mwindow->session->vwindow_w = w;
227 mwindow->session->vwindow_h = h;
229 mwindow->theme->get_vwindow_sizes(this);
230 mwindow->theme->draw_vwindow_bg(this);
233 edit_panel->reposition_buttons(mwindow->theme->vedit_x,
234 mwindow->theme->vedit_y);
235 slider->reposition_window(mwindow->theme->vslider_x,
236 mwindow->theme->vslider_y,
237 mwindow->theme->vslider_w);
238 // Recalibrate pointer motion range
239 slider->set_position();
240 timebar->resize_event();
241 transport->reposition_buttons(mwindow->theme->vtransport_x,
242 mwindow->theme->vtransport_y);
243 clock->reposition_window(mwindow->theme->vtime_x,
244 mwindow->theme->vtime_y,
245 mwindow->theme->vtime_w);
246 canvas->reposition_window(0,
247 mwindow->theme->vcanvas_x,
248 mwindow->theme->vcanvas_y,
249 mwindow->theme->vcanvas_w,
250 mwindow->theme->vcanvas_h);
251 // source->reposition_window(mwindow->theme->vsource_x,
252 // mwindow->theme->vsource_y);
253 meters->reposition_window(mwindow->theme->vmeter_x,
254 mwindow->theme->vmeter_y,
255 mwindow->theme->vmeter_h);
257 BC_WindowBase::resize_event(w, h);
265 int VWindowGUI::translation_event()
267 mwindow->session->vwindow_x = get_x();
268 mwindow->session->vwindow_y = get_y();
272 int VWindowGUI::close_event()
275 mwindow->session->show_vwindow = 0;
276 mwindow->gui->lock_window();
277 mwindow->gui->mainmenu->show_vwindow->set_checked(0);
278 mwindow->gui->unlock_window();
279 mwindow->save_defaults();
283 int VWindowGUI::keypress_event()
286 switch(get_keypress())
295 if(!result) result = transport->keypress_event();
300 void VWindowGUI::drag_motion()
302 if(get_hidden()) return;
303 if(mwindow->session->current_operation != DRAG_ASSET) return;
305 int old_status = mwindow->session->vcanvas_highlighted;
307 int cursor_x = get_relative_cursor_x();
308 int cursor_y = get_relative_cursor_y();
310 mwindow->session->vcanvas_highlighted = (get_cursor_over_window() &&
311 cursor_x >= canvas->x &&
312 cursor_x < canvas->x + canvas->w &&
313 cursor_y >= canvas->y &&
314 cursor_y < canvas->y + canvas->h);
315 //printf("VWindowGUI::drag_motion 1 %d\n", mwindow->session->vcanvas_highlighted);
318 if(old_status != mwindow->session->vcanvas_highlighted)
319 canvas->draw_refresh();
322 int VWindowGUI::drag_stop()
324 if(get_hidden()) return 0;
326 if(mwindow->session->vcanvas_highlighted &&
327 mwindow->session->current_operation == DRAG_ASSET)
329 mwindow->session->vcanvas_highlighted = 0;
330 canvas->draw_refresh();
332 Asset *asset = mwindow->session->drag_assets->total ?
333 mwindow->session->drag_assets->values[0] :
335 EDL *edl = mwindow->session->drag_clips->total ?
336 mwindow->session->drag_clips->values[0] :
340 vwindow->change_source(asset);
343 vwindow->change_source(edl);
354 VWindowMeters::VWindowMeters(MWindow *mwindow,
359 : MeterPanel(mwindow,
364 mwindow->edl->session->audio_channels,
365 mwindow->edl->session->vwindow_meter)
367 this->mwindow = mwindow;
371 VWindowMeters::~VWindowMeters()
375 int VWindowMeters::change_status_event()
377 mwindow->edl->session->vwindow_meter = use_meters;
378 //printf("VWindowMeters::change_status_event 1 %d\n", mwindow->edl->session->vwindow_meter);
379 mwindow->theme->get_vwindow_sizes(gui);
380 gui->resize_event(gui->get_w(), gui->get_h());
390 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
393 mwindow->theme->vedit_x,
394 mwindow->theme->vedit_y,
412 this->mwindow = mwindow;
413 this->vwindow = vwindow;
416 VWindowEditing::~VWindowEditing()
420 void VWindowEditing::copy_selection()
425 void VWindowEditing::splice_selection()
427 if(vwindow->get_edl())
429 mwindow->gui->lock_window();
430 mwindow->splice(vwindow->get_edl());
431 mwindow->gui->unlock_window();
435 void VWindowEditing::overwrite_selection()
437 if(vwindow->get_edl())
439 mwindow->gui->lock_window();
440 mwindow->overwrite(vwindow->get_edl());
441 mwindow->gui->unlock_window();
445 void VWindowEditing::toggle_label()
447 if(vwindow->get_edl())
449 EDL *edl = vwindow->get_edl();
450 edl->labels->toggle_label(edl->local_session->selectionstart,
451 edl->local_session->selectionend);
452 vwindow->gui->timebar->update();
456 void VWindowEditing::prev_label()
458 if(vwindow->get_edl())
460 EDL *edl = vwindow->get_edl();
461 vwindow->gui->unlock_window();
462 vwindow->playback_engine->interrupt_playback(1);
463 vwindow->gui->lock_window();
465 //printf("VWindowEditing::prev_label 1 %f\n", edl->local_session->selectionstart);
466 Label *current = edl->labels->prev_label(edl->local_session->selectionstart);
468 //printf("VWindowEditing::prev_label 2 %f\n", current->position);
472 edl->local_session->selectionstart =
473 edl->local_session->selectionend = 0;
474 vwindow->update_position(CHANGE_NONE, 0, 1);
475 vwindow->gui->timebar->update();
479 edl->local_session->selectionstart =
480 edl->local_session->selectionend = current->position;
481 vwindow->update_position(CHANGE_NONE, 0, 1);
482 vwindow->gui->timebar->update();
484 //printf("VWindowEditing::prev_label 3 %f\n", edl->local_session->selectionstart);
488 void VWindowEditing::next_label()
490 if(vwindow->get_edl())
492 EDL *edl = vwindow->get_edl();
493 Label *current = edl->labels->next_label(edl->local_session->selectionstart);
496 vwindow->gui->unlock_window();
497 vwindow->playback_engine->interrupt_playback(1);
498 vwindow->gui->lock_window();
500 edl->local_session->selectionstart =
501 edl->local_session->selectionend = edl->tracks->total_length();
502 vwindow->update_position(CHANGE_NONE, 0, 1);
503 vwindow->gui->timebar->update();
507 vwindow->gui->unlock_window();
508 vwindow->playback_engine->interrupt_playback(1);
509 vwindow->gui->lock_window();
511 edl->local_session->selectionstart =
512 edl->local_session->selectionend = current->position;
513 vwindow->update_position(CHANGE_NONE, 0, 1);
514 vwindow->gui->timebar->update();
519 void VWindowEditing::set_inpoint()
521 vwindow->set_inpoint();
524 void VWindowEditing::set_outpoint()
526 vwindow->set_outpoint();
529 void VWindowEditing::clear_inpoint()
531 vwindow->clear_inpoint();
534 void VWindowEditing::clear_outpoint()
536 vwindow->clear_outpoint();
539 void VWindowEditing::to_clip()
541 if(vwindow->get_edl())
544 EDL *edl = vwindow->get_edl();
545 double start = edl->local_session->get_selectionstart();
546 double end = edl->local_session->get_selectionend();
548 if(EQUIV(start, end))
550 end = edl->tracks->total_length();
569 EDL *new_edl = new EDL(mwindow->edl);
570 new_edl->create_objects();
571 new_edl->load_xml(mwindow->plugindb, &file, LOAD_ALL);
572 sprintf(new_edl->local_session->clip_title, _("Clip %d\n"), mwindow->session->clip_number++);
574 printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title);
576 vwindow->clip_edit->create_clip(new_edl);
585 VWindowSlider::VWindowSlider(MWindow *mwindow,
591 : BC_PercentageSlider(x,
600 this->mwindow = mwindow;
601 this->vwindow = vwindow;
605 VWindowSlider::~VWindowSlider()
609 int VWindowSlider::handle_event()
612 vwindow->playback_engine->interrupt_playback(1);
615 vwindow->update_position(CHANGE_NONE, 1, 0);
616 gui->timebar->update();
620 void VWindowSlider::set_position()
622 EDL *edl = vwindow->get_edl();
625 double new_length = edl->tracks->total_playable_length();
626 if(EQUIV(edl->local_session->preview_end, 0))
627 edl->local_session->preview_end = new_length;
628 if(edl->local_session->preview_end > new_length)
629 edl->local_session->preview_end = new_length;
630 if(edl->local_session->preview_start > new_length)
631 edl->local_session->preview_start = 0;
633 // printf("VWindowSlider::set_position 1 %f %f %f\n", edl->local_session->selectionstart,
634 // edl->local_session->preview_start,
635 // edl->local_session->preview_end);
636 update(mwindow->theme->vslider_w,
637 edl->local_session->selectionstart,
638 edl->local_session->preview_start,
639 edl->local_session->preview_end);
651 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
652 : BC_PopupTextBox(vwindow,
660 this->mwindow = mwindow;
661 this->vwindow = vwindow;
664 VWindowSource::~VWindowSource()
668 int VWindowSource::handle_event()
679 VWindowTransport::VWindowTransport(MWindow *mwindow,
683 : PlayTransport(mwindow,
691 EDL* VWindowTransport::get_edl()
693 return gui->vwindow->get_edl();
697 void VWindowTransport::goto_start()
699 gui->unlock_window();
700 handle_transport(REWIND, 1);
702 gui->vwindow->goto_start();
705 void VWindowTransport::goto_end()
707 gui->unlock_window();
708 handle_transport(GOTO_END, 1);
710 gui->vwindow->goto_end();
716 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
718 mwindow->theme->vcanvas_x,
719 mwindow->theme->vcanvas_y,
720 mwindow->theme->vcanvas_w,
721 mwindow->theme->vcanvas_h,
729 this->mwindow = mwindow;
733 void VWindowCanvas::zoom_resize_window(float percentage)
735 EDL *edl = mwindow->vwindow->get_edl();
736 if(!edl) edl = mwindow->edl;
738 int canvas_w, canvas_h;
739 calculate_sizes(edl->get_aspect_ratio(),
740 edl->calculate_output_w(0),
741 edl->calculate_output_h(0),
746 new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
747 new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
748 gui->resize_window(new_w, new_h);
749 gui->resize_event(new_w, new_h);
752 void VWindowCanvas::close_source()
754 mwindow->vwindow->remove_source();
758 void VWindowCanvas::draw_refresh()
760 EDL *edl = gui->vwindow->get_edl();
762 if(!canvas->video_is_on()) canvas->clear_box(0, 0, canvas->get_w(), canvas->get_h());
763 if(!canvas->video_is_on() && refresh_frame && edl)
765 int in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h;
775 canvas->draw_vframe(refresh_frame,
787 if(!canvas->video_is_on())
795 void VWindowCanvas::draw_overlays()
797 if(mwindow->session->vcanvas_highlighted)
799 canvas->set_color(WHITE);
800 canvas->set_inverse();
801 canvas->draw_rectangle(0, 0, canvas->get_w(), canvas->get_h());
802 canvas->draw_rectangle(1, 1, canvas->get_w() - 2, canvas->get_h() - 2);
803 canvas->set_opaque();
844 void VWindowGUI::update_points()
846 EDL *edl = vwindow->get_edl();
848 //printf("VWindowGUI::update_points 1\n");
851 //printf("VWindowGUI::update_points 2\n");
852 long pixel = (long)((double)edl->local_session->in_point /
853 edl->tracks->total_playable_length() *
854 (mwindow->theme->vtimebar_w -
856 mwindow->theme->in_point[0]->get_w())) +
857 mwindow->theme->in_point[0]->get_w();
859 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
862 //printf("VWindowGUI::update_points 3.1\n");
863 if(edl->local_session->in_point >= 0)
865 //printf("VWindowGUI::update_points 4\n");
866 if(edl->local_session->in_point != in_point->position ||
867 in_point->pixel != pixel)
869 in_point->pixel = pixel;
870 in_point->reposition();
873 //printf("VWindowGUI::update_points 5\n");
874 in_point->position = edl->local_session->in_point;
876 //printf("VWindowGUI::update_points 6\n");
877 if(edl->equivalent(in_point->position, edl->local_session->selectionstart) ||
878 edl->equivalent(in_point->position, edl->local_session->selectionend))
882 //printf("VWindowGUI::update_points 7\n");
891 if(edl->local_session->in_point >= 0)
893 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
894 add_subwindow(in_point =
895 new VWindowInPoint(mwindow,
899 edl->local_session->in_point));
900 //printf("VWindowGUI::update_points 9\n");
902 //printf("VWindowGUI::update_points 10\n");
904 pixel = (long)((double)edl->local_session->out_point /
905 (edl->tracks->total_playable_length() + 0.5) *
906 (mwindow->theme->vtimebar_w -
908 mwindow->theme->in_point[0]->get_w())) +
909 mwindow->theme->in_point[0]->get_w() *
914 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
916 if(edl->local_session->out_point != out_point->position ||
917 out_point->pixel != pixel)
919 out_point->pixel = pixel;
920 out_point->reposition();
922 out_point->position = edl->local_session->out_point;
924 if(edl->equivalent(out_point->position, edl->local_session->selectionstart) ||
925 edl->equivalent(out_point->position, edl->local_session->selectionend))
926 out_point->update(1);
928 out_point->update(0);
937 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
939 add_subwindow(out_point =
940 new VWindowOutPoint(mwindow,
944 edl->local_session->out_point));
949 void VWindowGUI::update_labels()
951 EDL *edl = vwindow->get_edl();
954 for(Label *current = edl->labels->first;
958 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
960 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
963 if(output >= labels.total)
966 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
967 labels.append(new_label);
970 // Reposition old label
971 if(labels.values[output]->pixel != pixel)
973 labels.values[output]->pixel = pixel;
974 labels.values[output]->position = current->position;
975 labels.values[output]->reposition();
978 if(mwindow->edl->local_session->selectionstart <= current->position &&
979 mwindow->edl->local_session->selectionend >= current->position)
980 labels.values[output]->update(1);
982 if(labels.values[output]->get_value())
983 labels.values[output]->update(0);
988 // Delete excess labels
989 while(labels.total > output)
991 labels.remove_object();
997 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1002 : InPointGUI(mwindow,
1010 int VWindowInPoint::handle_event()
1012 EDL *edl = gui->vwindow->get_edl();
1016 double position = edl->align_to_frame(this->position, 0);
1018 edl->local_session->selectionstart =
1019 edl->local_session->selectionend =
1021 gui->timebar->update();
1024 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);
1031 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1036 : OutPointGUI(mwindow,
1044 int VWindowOutPoint::handle_event()
1046 EDL *edl = gui->vwindow->get_edl();
1050 double position = edl->align_to_frame(this->position, 0);
1052 edl->local_session->selectionstart =
1053 edl->local_session->selectionend =
1055 gui->timebar->update();
1058 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1);