6 #include "edlsession.h"
10 #include "localsession.h"
11 #include "maincursor.h"
14 #include "mwindowgui.h"
16 #include "preferences.h"
17 #include "recordlabel.h"
18 #include "localsession.h"
19 #include "mainsession.h"
22 #include "trackcanvas.h"
24 #include "transportque.h"
28 #include "vwindowgui.h"
32 LabelGUI::LabelGUI(MWindow *mwindow,
38 : BC_Toggle(translate_pixel(mwindow, pixel),
40 data ? data : mwindow->theme->label_toggle,
43 this->mwindow = mwindow;
44 this->timebar = timebar;
47 this->position = position;
54 int LabelGUI::get_y(MWindow *mwindow, TimeBar *timebar)
60 return timebar->get_h() -
61 mwindow->theme->label_toggle[0]->get_h();
64 int LabelGUI::translate_pixel(MWindow *mwindow, int pixel)
66 int result = pixel - mwindow->theme->label_toggle[0]->get_w() / 2;
70 void LabelGUI::reposition()
72 reposition_window(translate_pixel(mwindow, pixel), BC_Toggle::get_y());
75 int LabelGUI::handle_event()
78 timebar->select_label(position);
89 InPointGUI::InPointGUI(MWindow *mwindow,
96 get_y(mwindow, timebar),
98 mwindow->theme->in_point)
100 //printf("InPointGUI::InPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
102 InPointGUI::~InPointGUI()
105 int InPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
108 result = timebar->get_h() -
109 mwindow->theme->in_point[0]->get_h();
114 OutPointGUI::OutPointGUI(MWindow *mwindow,
121 get_y(mwindow, timebar),
123 mwindow->theme->out_point)
125 //printf("OutPointGUI::OutPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
127 OutPointGUI::~OutPointGUI()
130 int OutPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
132 return timebar->get_h() -
133 mwindow->theme->out_point[0]->get_h();
137 PresentationGUI::PresentationGUI(MWindow *mwindow,
141 : LabelGUI(mwindow, timebar, pixel, get_y(mwindow, timebar), position)
144 PresentationGUI::~PresentationGUI()
154 TimeBar::TimeBar(MWindow *mwindow,
160 : BC_SubWindow(x, y, w, h)
162 //printf("TimeBar::TimeBar %d %d %d %d\n", x, y, w, h);
164 this->mwindow = mwindow;
169 if(in_point) delete in_point;
170 if(out_point) delete out_point;
171 labels.remove_all_objects();
172 presentations.remove_all_objects();
175 int TimeBar::create_objects()
179 current_operation = TIMEBAR_NONE;
185 int64_t TimeBar::position_to_pixel(double position)
188 return (int64_t)(position / time_per_pixel);
192 void TimeBar::update_labels()
195 EDL *edl = get_edl();
197 //printf("TimeBar::update_labels 1\n");
200 for(Label *current = edl->labels->first;
204 //printf("TimeBar::update_labels 1 %p\n", current);
205 int64_t pixel = position_to_pixel(current->position);
206 //printf("TimeBar::update_labels 2 %d\n", pixel);
208 if(pixel >= 0 && pixel < get_w())
210 //printf("TimeBar::update_labels 3\n");
212 if(output >= labels.total)
215 add_subwindow(new_label =
216 new LabelGUI(mwindow,
219 LabelGUI::get_y(mwindow, this),
221 new_label->set_cursor(ARROW_CURSOR);
222 labels.append(new_label);
225 // Reposition old label
227 LabelGUI *gui = labels.values[output];
228 if(gui->pixel != pixel)
232 //printf("TimeBar::update_labels 4 %d\n", pixel);
239 labels.values[output]->position = current->position;
242 if(edl->local_session->selectionstart <= current->position &&
243 edl->local_session->selectionend >= current->position)
244 labels.values[output]->update(1);
246 if(labels.values[output]->get_value())
247 labels.values[output]->update(0);
254 // Delete excess labels
255 while(labels.total > output)
257 //printf("TimeBar::update_labels 9\n");
258 labels.remove_object();
260 //printf("TimeBar::update_labels 10\n");
263 void TimeBar::update_highlights()
265 for(int i = 0; i < labels.total; i++)
267 LabelGUI *label = labels.values[i];
268 if(mwindow->edl->equivalent(label->position, mwindow->edl->local_session->selectionstart) ||
269 mwindow->edl->equivalent(label->position, mwindow->edl->local_session->selectionend))
271 if(!label->get_value()) label->update(1);
274 if(label->get_value()) label->update(0);
277 if(mwindow->edl->equivalent(mwindow->edl->local_session->in_point, mwindow->edl->local_session->selectionstart) ||
278 mwindow->edl->equivalent(mwindow->edl->local_session->in_point, mwindow->edl->local_session->selectionend))
280 if(in_point) in_point->update(1);
283 if(in_point) in_point->update(0);
285 if(mwindow->edl->equivalent(mwindow->edl->local_session->out_point, mwindow->edl->local_session->selectionstart) ||
286 mwindow->edl->equivalent(mwindow->edl->local_session->out_point, mwindow->edl->local_session->selectionend))
288 if(out_point) out_point->update(1);
291 if(out_point) out_point->update(0);
294 void TimeBar::update_points()
296 EDL *edl = get_edl();
299 if(edl) pixel = position_to_pixel(edl->local_session->in_point);
300 //printf("TimeBar::update_points 1 %d\n", pixel);
306 edl->local_session->in_point >= 0 &&
310 if(edl->local_session->in_point != in_point->position ||
311 in_point->pixel != pixel)
313 in_point->pixel = pixel;
314 in_point->position = edl->local_session->in_point;
315 in_point->reposition();
319 in_point->draw_face();
329 if(edl && edl->local_session->in_point >= 0 && pixel >= 0 && pixel < get_w())
331 //printf("TimeBar::update_points 1 %p\n", edl);
332 add_subwindow(in_point = new InPointGUI(mwindow,
335 edl->local_session->in_point));
336 in_point->set_cursor(ARROW_CURSOR);
337 //printf("TimeBar::update_points 2\n");
340 if(edl) pixel = position_to_pixel(edl->local_session->out_point);
342 //printf("TimeBar::update_points 2 %d\n", pixel);
346 edl->local_session->out_point >= 0 &&
350 if(edl->local_session->out_point != out_point->position ||
351 out_point->pixel != pixel)
353 out_point->pixel = pixel;
354 out_point->position = edl->local_session->out_point;
355 out_point->reposition();
359 out_point->draw_face();
370 edl->local_session->out_point >= 0 &&
371 pixel >= 0 && pixel < get_w())
373 add_subwindow(out_point = new OutPointGUI(mwindow,
376 edl->local_session->out_point));
377 out_point->set_cursor(ARROW_CURSOR);
381 void TimeBar::update_presentations()
386 void TimeBar::update(int do_range, int do_others)
389 // Need to redo these when range is drawn to get the background updated.
392 update_presentations();
398 int TimeBar::delete_project()
400 // labels->delete_all();
404 int TimeBar::save(FileXML *xml)
406 // labels->save(xml);
413 void TimeBar::draw_time()
417 EDL* TimeBar::get_edl()
424 void TimeBar::draw_range()
429 get_preview_pixels(x1, x2);
431 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
432 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
433 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
434 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
437 draw_line(x1, 0, x1, get_h());
438 draw_line(x2, 0, x2, get_h());
443 int64_t pixel = position_to_pixel(edl->local_session->selectionstart);
444 // Draw insertion point position if this timebar beint64_ts to a window which
445 // has something other than the master EDL.
446 //printf("TimeBar::draw_range %f\n", edl->local_session->selectionstart);
448 draw_line(pixel, 0, pixel, get_h());
452 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
455 void TimeBar::select_label(double position)
466 void TimeBar::get_edl_length()
472 //printf("TimeBar::get_edl_length 1 %f\n", get_edl()->tracks->total_playable_length());
473 edl_length = get_edl()->tracks->total_playable_length();
476 //printf("TimeBar::get_edl_length 2\n");
477 if(!EQUIV(edl_length, 0))
479 //printf("TimeBar::get_edl_length 3\n");
480 time_per_pixel = edl_length / get_w();
481 //printf("TimeBar::get_edl_length 4\n");
487 //printf("TimeBar::get_edl_length 5\n");
490 int TimeBar::get_preview_pixels(int &x1, int &x2)
499 if(!EQUIV(edl_length, 0))
501 if(get_edl()->local_session->preview_end <= 0 ||
502 get_edl()->local_session->preview_end > edl_length)
503 get_edl()->local_session->preview_end = edl_length;
504 if(get_edl()->local_session->preview_start >
505 get_edl()->local_session->preview_end)
506 get_edl()->local_session->preview_start = 0;
507 x1 = (int)(get_edl()->local_session->preview_start / time_per_pixel);
508 x2 = (int)(get_edl()->local_session->preview_end / time_per_pixel);
516 // printf("TimeBar::get_preview_pixels %f %f %d %d\n",
517 // get_edl()->local_session->preview_start,
518 // get_edl()->local_session->preview_end,
525 int TimeBar::test_preview(int buttonpress)
530 get_preview_pixels(x1, x2);
531 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, get_cursor_x());
535 // Inside left handle
536 if(cursor_inside() &&
537 get_cursor_x() >= x1 - HANDLE_W &&
538 get_cursor_x() < x1 + HANDLE_W &&
539 // Ignore left handle if both handles are up against the left side
544 current_operation = TIMEBAR_DRAG_LEFT;
545 start_position = get_edl()->local_session->preview_start;
546 start_cursor_x = get_cursor_x();
550 if(get_cursor() != LEFT_CURSOR)
553 set_cursor(LEFT_CURSOR);
557 // Inside right handle
558 if(cursor_inside() &&
559 get_cursor_x() >= x2 - HANDLE_W &&
560 get_cursor_x() < x2 + HANDLE_W &&
561 // Ignore right handle if both handles are up against the right side
562 x1 < get_w() - HANDLE_W)
566 current_operation = TIMEBAR_DRAG_RIGHT;
567 start_position = get_edl()->local_session->preview_end;
568 start_cursor_x = get_cursor_x();
572 if(get_cursor() != RIGHT_CURSOR)
575 set_cursor(RIGHT_CURSOR);
579 if(cursor_inside() &&
580 get_cursor_x() >= x1 &&
585 current_operation = TIMEBAR_DRAG_CENTER;
586 starting_start_position = get_edl()->local_session->preview_start;
587 starting_end_position = get_edl()->local_session->preview_end;
588 start_cursor_x = get_cursor_x();
594 set_cursor(HSEPARATE_CURSOR);
599 // Trap all buttonpresses inside timebar
600 if(cursor_inside() && buttonpress)
603 if(get_cursor() == LEFT_CURSOR ||
604 get_cursor() == RIGHT_CURSOR)
607 set_cursor(ARROW_CURSOR);
617 int TimeBar::move_preview(int &redraw)
621 if(current_operation == TIMEBAR_DRAG_LEFT)
623 get_edl()->local_session->preview_start =
625 time_per_pixel * (get_cursor_x() - start_cursor_x);
626 CLAMP(get_edl()->local_session->preview_start,
628 get_edl()->local_session->preview_end);
632 if(current_operation == TIMEBAR_DRAG_RIGHT)
634 get_edl()->local_session->preview_end =
636 time_per_pixel * (get_cursor_x() - start_cursor_x);
637 CLAMP(get_edl()->local_session->preview_end,
638 get_edl()->local_session->preview_start,
643 if(current_operation == TIMEBAR_DRAG_CENTER)
645 get_edl()->local_session->preview_start =
646 starting_start_position +
647 time_per_pixel * (get_cursor_x() - start_cursor_x);
648 get_edl()->local_session->preview_end =
649 starting_end_position +
650 time_per_pixel * (get_cursor_x() - start_cursor_x);
651 if(get_edl()->local_session->preview_start < 0)
653 get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
654 get_edl()->local_session->preview_start = 0;
657 if(get_edl()->local_session->preview_end > edl_length)
659 get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
660 get_edl()->local_session->preview_end = edl_length;
665 //printf("TimeBar::move_preview %f %f\n", get_edl()->local_session->preview_start, get_edl()->local_session->preview_end);
676 void TimeBar::update_preview()
680 int TimeBar::samplemovement()
685 void TimeBar::stop_playback()
689 int TimeBar::button_press_event()
691 //printf("TimeBar::button_press_event 1\n");
692 if(is_event_win() && cursor_inside())
694 // Change time format
697 mwindow->next_time_format();
708 // Select region between two labels
709 if(get_double_click())
711 double position = (double)get_cursor_x() *
712 mwindow->edl->local_session->zoom_sample /
713 mwindow->edl->session->sample_rate +
714 (double)mwindow->edl->local_session->view_start *
715 mwindow->edl->local_session->zoom_sample /
716 mwindow->edl->session->sample_rate;
718 select_region(position);
722 // Reposition highlight cursor
723 if(is_event_win() && cursor_inside())
725 //printf("TimeBar::button_press_event 4\n");
727 //printf("TimeBar::button_press_event 5\n");
728 mwindow->gui->canvas->activate();
729 //printf("TimeBar::button_press_event 6\n");
737 int TimeBar::repeat_event(int64_t duration)
739 if(!mwindow->gui->canvas->drag_scroll) return 0;
740 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
744 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
745 if(current_operation == TIMEBAR_DRAG)
747 if(relative_cursor_x >= mwindow->gui->canvas->get_w())
749 distance = relative_cursor_x - mwindow->gui->canvas->get_w();
753 if(relative_cursor_x < 0)
755 distance = relative_cursor_x;
764 mwindow->samplemovement(mwindow->edl->local_session->view_start +
772 int TimeBar::cursor_motion_event()
777 switch(current_operation)
782 //printf("TimeBar::cursor_motion_event 1\n");
783 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
784 if(relative_cursor_x >= mwindow->gui->canvas->get_w() ||
785 relative_cursor_x < 0)
787 mwindow->gui->canvas->start_dragscroll();
790 if(relative_cursor_x < mwindow->gui->canvas->get_w() &&
791 relative_cursor_x >= 0)
793 mwindow->gui->canvas->stop_dragscroll();
796 //printf("TimeBar::cursor_motion_event 10\n");
801 case TIMEBAR_DRAG_LEFT:
802 case TIMEBAR_DRAG_RIGHT:
803 case TIMEBAR_DRAG_CENTER:
804 result = move_preview(redraw);
808 //printf("TimeBar::cursor_motion_event 20\n");
809 result = test_preview(0);
810 //printf("TimeBar::cursor_motion_event 30\n");
822 int TimeBar::button_release_event()
824 //printf("TimeBar::button_release_event %d\n", current_operation);
826 switch(current_operation)
829 mwindow->gui->canvas->stop_dragscroll();
830 current_operation = TIMEBAR_NONE;
835 if(current_operation != TIMEBAR_NONE)
837 current_operation = TIMEBAR_NONE;
845 // Update the selection cursor during a dragging operation
846 void TimeBar::update_cursor()
848 double position = (double)get_cursor_x() *
849 mwindow->edl->local_session->zoom_sample /
850 mwindow->edl->session->sample_rate +
851 (double)mwindow->edl->local_session->view_start *
852 mwindow->edl->local_session->zoom_sample /
853 mwindow->edl->session->sample_rate;
855 position = mwindow->edl->align_to_frame(position, 0);
856 position = MAX(0, position);
857 current_operation = TIMEBAR_DRAG;
859 mwindow->select_point(position);
864 int TimeBar::select_region(double position)
866 Label *start = 0, *end = 0, *current;
867 for(current = mwindow->edl->labels->first; current; current = NEXT)
869 if(current->position > position)
876 for(current = mwindow->edl->labels->last ; current; current = PREVIOUS)
878 if(current->position <= position)
889 mwindow->edl->local_session->selectionstart = 0;
891 mwindow->edl->local_session->selectionstart = start->position;
894 mwindow->edl->local_session->selectionend = mwindow->edl->tracks->total_length();
896 mwindow->edl->local_session->selectionend = end->position;
901 mwindow->edl->local_session->selectionstart =
902 mwindow->edl->local_session->selectionend =
907 mwindow->cwindow->update(1, 0, 0);
908 mwindow->gui->cursor->hide();
909 mwindow->gui->cursor->draw();
910 mwindow->gui->canvas->flash();
911 mwindow->gui->canvas->activate();
912 mwindow->gui->zoombar->update();
917 int TimeBar::copy(int64_t start, int64_t end, FileXML *xml)
919 // labels->copy(start, end, xml);
923 int TimeBar::paste(int64_t start, int64_t end, int64_t sample_length, FileXML *xml)
925 // labels->paste(start, end, sample_length, xml);
929 int TimeBar::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, RecordLabels *new_labels)
931 // labels->paste_output(startproject, endproject, startsource, endsource, new_labels);
935 int TimeBar::clear(int64_t start, int64_t end)
937 //labels->clear(start, end);
941 int TimeBar::paste_silence(int64_t start, int64_t end)
943 //labels->paste_silence(start, end);
947 int TimeBar::modify_handles(int64_t oldposition, int64_t newposition, int currentend)
949 //labels->modify_handles(oldposition, newposition, currentend);
956 int TimeBar::delete_arrows()