7 #include "edlsession.h"
11 #include "labeledit.h"
12 #include "localsession.h"
13 #include "maincursor.h"
17 #include "mwindowgui.h"
19 #include "preferences.h"
20 #include "recordlabel.h"
21 #include "localsession.h"
22 #include "mainsession.h"
25 #include "trackcanvas.h"
27 #include "transportque.h"
31 #include "vwindowgui.h"
35 LabelGUI::LabelGUI(MWindow *mwindow,
41 : BC_Toggle(translate_pixel(mwindow, pixel),
43 data ? data : mwindow->theme->label_toggle,
46 this->mwindow = mwindow;
47 this->timebar = timebar;
50 this->position = position;
58 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::button_press_event()
77 if (this->is_event_win() && get_buttonpress() == 3) {
79 timebar->label_edit->edit_label(label);
81 BC_Toggle::button_press_event();
84 set_tooltip(this->label->textstr);
87 int LabelGUI::handle_event()
89 timebar->select_label(position);
100 InPointGUI::InPointGUI(MWindow *mwindow,
107 get_y(mwindow, timebar),
109 mwindow->theme->in_point)
111 //printf("InPointGUI::InPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
113 InPointGUI::~InPointGUI()
116 int InPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
119 result = timebar->get_h() -
120 mwindow->theme->in_point[0]->get_h();
125 OutPointGUI::OutPointGUI(MWindow *mwindow,
132 get_y(mwindow, timebar),
134 mwindow->theme->out_point)
136 //printf("OutPointGUI::OutPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
138 OutPointGUI::~OutPointGUI()
141 int OutPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
143 return timebar->get_h() -
144 mwindow->theme->out_point[0]->get_h();
148 PresentationGUI::PresentationGUI(MWindow *mwindow,
152 : LabelGUI(mwindow, timebar, pixel, get_y(mwindow, timebar), position)
155 PresentationGUI::~PresentationGUI()
165 TimeBar::TimeBar(MWindow *mwindow,
171 : BC_SubWindow(x, y, w, h)
173 //printf("TimeBar::TimeBar %d %d %d %d\n", x, y, w, h);
175 this->mwindow = mwindow;
176 label_edit = new LabelEdit(mwindow, mwindow->awindow, 0);
181 if(in_point) delete in_point;
182 if(out_point) delete out_point;
183 if(label_edit) delete label_edit;
184 labels.remove_all_objects();
185 presentations.remove_all_objects();
188 int TimeBar::create_objects()
192 current_operation = TIMEBAR_NONE;
198 int64_t TimeBar::position_to_pixel(double position)
201 return (int64_t)(position / time_per_pixel);
205 void TimeBar::update_labels()
208 EDL *edl = get_edl();
212 for(Label *current = edl->labels->first;
216 int64_t pixel = position_to_pixel(current->position);
218 if(pixel >= 0 && pixel < get_w())
221 if(output >= labels.total)
224 add_subwindow(new_label =
225 new LabelGUI(mwindow,
228 LabelGUI::get_y(mwindow, this),
230 new_label->set_cursor(ARROW_CURSOR);
231 new_label->set_tooltip(current->textstr);
232 new_label->label = current;
233 labels.append(new_label);
236 // Reposition old label
238 LabelGUI *gui = labels.values[output];
239 if(gui->pixel != pixel)
249 labels.values[output]->position = current->position;
250 labels.values[output]->set_tooltip(current->textstr);
251 labels.values[output]->label = current;
254 if(edl->local_session->get_selectionstart(1) <= current->position &&
255 edl->local_session->get_selectionend(1) >= current->position)
256 labels.values[output]->update(1);
258 if(labels.values[output]->get_value())
259 labels.values[output]->update(0);
266 // Delete excess labels
267 while(labels.total > output)
269 labels.remove_object();
273 void TimeBar::update_highlights()
275 for(int i = 0; i < labels.total; i++)
277 LabelGUI *label = labels.values[i];
278 if(mwindow->edl->equivalent(label->position,
279 mwindow->edl->local_session->get_selectionstart(1)) ||
280 mwindow->edl->equivalent(label->position,
281 mwindow->edl->local_session->get_selectionend(1)))
283 if(!label->get_value()) label->update(1);
286 if(label->get_value()) label->update(0);
289 if(mwindow->edl->equivalent(mwindow->edl->local_session->get_inpoint(),
290 mwindow->edl->local_session->get_selectionstart(1)) ||
291 mwindow->edl->equivalent(mwindow->edl->local_session->get_inpoint(),
292 mwindow->edl->local_session->get_selectionend(1)))
294 if(in_point) in_point->update(1);
297 if(in_point) in_point->update(0);
299 if(mwindow->edl->equivalent(mwindow->edl->local_session->get_outpoint(),
300 mwindow->edl->local_session->get_selectionstart(1)) ||
301 mwindow->edl->equivalent(mwindow->edl->local_session->get_outpoint(),
302 mwindow->edl->local_session->get_selectionend(1)))
304 if(out_point) out_point->update(1);
307 if(out_point) out_point->update(0);
310 void TimeBar::update_points()
312 EDL *edl = get_edl();
315 if(edl) pixel = position_to_pixel(edl->local_session->get_inpoint());
321 edl->local_session->inpoint_valid() &&
325 if(!EQUIV(edl->local_session->get_inpoint(), in_point->position) ||
326 in_point->pixel != pixel)
328 in_point->pixel = pixel;
329 in_point->position = edl->local_session->get_inpoint();
330 in_point->reposition();
334 in_point->draw_face();
344 if(edl && edl->local_session->inpoint_valid() &&
345 pixel >= 0 && pixel < get_w())
347 add_subwindow(in_point = new InPointGUI(mwindow,
350 edl->local_session->get_inpoint()));
351 in_point->set_cursor(ARROW_CURSOR);
354 if(edl) pixel = position_to_pixel(edl->local_session->get_outpoint());
359 edl->local_session->outpoint_valid() &&
363 if(!EQUIV(edl->local_session->get_outpoint(), out_point->position) ||
364 out_point->pixel != pixel)
366 out_point->pixel = pixel;
367 out_point->position = edl->local_session->get_outpoint();
368 out_point->reposition();
372 out_point->draw_face();
383 edl->local_session->outpoint_valid() &&
384 pixel >= 0 && pixel < get_w())
386 add_subwindow(out_point = new OutPointGUI(mwindow,
389 edl->local_session->get_outpoint()));
390 out_point->set_cursor(ARROW_CURSOR);
394 void TimeBar::update_presentations()
399 void TimeBar::update(int do_range, int do_others)
404 // Need to redo these when range is drawn to get the background updated.
409 update_presentations();
417 int TimeBar::delete_project()
419 // labels->delete_all();
423 int TimeBar::save(FileXML *xml)
425 // labels->save(xml);
432 void TimeBar::draw_time()
436 EDL* TimeBar::get_edl()
443 void TimeBar::draw_range()
448 get_preview_pixels(x1, x2);
450 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
451 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
452 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
453 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
456 draw_line(x1, 0, x1, get_h());
457 draw_line(x2, 0, x2, get_h());
462 int64_t pixel = position_to_pixel(
463 edl->local_session->get_selectionstart(1));
464 // Draw insertion point position if this timebar beint64_ts to a window which
465 // has something other than the master EDL.
467 draw_line(pixel, 0, pixel, get_h());
471 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
474 void TimeBar::select_label(double position)
485 void TimeBar::get_edl_length()
491 //printf("TimeBar::get_edl_length 1 %f\n", get_edl()->tracks->total_playable_length());
492 edl_length = get_edl()->tracks->total_playable_length();
495 //printf("TimeBar::get_edl_length 2\n");
496 if(!EQUIV(edl_length, 0))
498 //printf("TimeBar::get_edl_length 3\n");
499 time_per_pixel = edl_length / get_w();
500 //printf("TimeBar::get_edl_length 4\n");
506 //printf("TimeBar::get_edl_length 5\n");
509 int TimeBar::get_preview_pixels(int &x1, int &x2)
518 if(!EQUIV(edl_length, 0))
520 if(get_edl()->local_session->preview_end <= 0 ||
521 get_edl()->local_session->preview_end > edl_length)
522 get_edl()->local_session->preview_end = edl_length;
523 if(get_edl()->local_session->preview_start >
524 get_edl()->local_session->preview_end)
525 get_edl()->local_session->preview_start = 0;
526 x1 = (int)(get_edl()->local_session->preview_start / time_per_pixel);
527 x2 = (int)(get_edl()->local_session->preview_end / time_per_pixel);
535 // printf("TimeBar::get_preview_pixels %f %f %d %d\n",
536 // get_edl()->local_session->preview_start,
537 // get_edl()->local_session->preview_end,
544 int TimeBar::test_preview(int buttonpress)
549 get_preview_pixels(x1, x2);
550 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, get_cursor_x());
554 // Inside left handle
555 if(cursor_inside() &&
556 get_cursor_x() >= x1 - HANDLE_W &&
557 get_cursor_x() < x1 + HANDLE_W &&
558 // Ignore left handle if both handles are up against the left side
563 current_operation = TIMEBAR_DRAG_LEFT;
564 start_position = get_edl()->local_session->preview_start;
565 start_cursor_x = get_cursor_x();
569 if(get_cursor() != LEFT_CURSOR)
572 set_cursor(LEFT_CURSOR);
576 // Inside right handle
577 if(cursor_inside() &&
578 get_cursor_x() >= x2 - HANDLE_W &&
579 get_cursor_x() < x2 + HANDLE_W &&
580 // Ignore right handle if both handles are up against the right side
581 x1 < get_w() - HANDLE_W)
585 current_operation = TIMEBAR_DRAG_RIGHT;
586 start_position = get_edl()->local_session->preview_end;
587 start_cursor_x = get_cursor_x();
591 if(get_cursor() != RIGHT_CURSOR)
594 set_cursor(RIGHT_CURSOR);
598 if(cursor_inside() &&
599 get_cursor_x() >= x1 &&
604 current_operation = TIMEBAR_DRAG_CENTER;
605 starting_start_position = get_edl()->local_session->preview_start;
606 starting_end_position = get_edl()->local_session->preview_end;
607 start_cursor_x = get_cursor_x();
613 set_cursor(HSEPARATE_CURSOR);
618 // Trap all buttonpresses inside timebar
619 if(cursor_inside() && buttonpress)
622 if(get_cursor() == LEFT_CURSOR ||
623 get_cursor() == RIGHT_CURSOR)
626 set_cursor(ARROW_CURSOR);
636 int TimeBar::move_preview(int &redraw)
640 if(current_operation == TIMEBAR_DRAG_LEFT)
642 get_edl()->local_session->preview_start =
644 time_per_pixel * (get_cursor_x() - start_cursor_x);
645 CLAMP(get_edl()->local_session->preview_start,
647 get_edl()->local_session->preview_end);
651 if(current_operation == TIMEBAR_DRAG_RIGHT)
653 get_edl()->local_session->preview_end =
655 time_per_pixel * (get_cursor_x() - start_cursor_x);
656 CLAMP(get_edl()->local_session->preview_end,
657 get_edl()->local_session->preview_start,
662 if(current_operation == TIMEBAR_DRAG_CENTER)
664 get_edl()->local_session->preview_start =
665 starting_start_position +
666 time_per_pixel * (get_cursor_x() - start_cursor_x);
667 get_edl()->local_session->preview_end =
668 starting_end_position +
669 time_per_pixel * (get_cursor_x() - start_cursor_x);
670 if(get_edl()->local_session->preview_start < 0)
672 get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
673 get_edl()->local_session->preview_start = 0;
676 if(get_edl()->local_session->preview_end > edl_length)
678 get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
679 get_edl()->local_session->preview_end = edl_length;
684 //printf("TimeBar::move_preview %f %f\n", get_edl()->local_session->preview_start, get_edl()->local_session->preview_end);
695 void TimeBar::update_preview()
699 int TimeBar::samplemovement()
704 void TimeBar::stop_playback()
708 int TimeBar::button_press_event()
710 if(is_event_win() && cursor_inside())
712 // Change time format
715 if(get_buttonpress() == 1)
716 mwindow->next_time_format();
718 if(get_buttonpress() == 2)
719 mwindow->prev_time_format();
730 // Select region between two labels
731 if(get_double_click())
733 double position = (double)get_cursor_x() *
734 mwindow->edl->local_session->zoom_sample /
735 mwindow->edl->session->sample_rate +
736 (double)mwindow->edl->local_session->view_start *
737 mwindow->edl->local_session->zoom_sample /
738 mwindow->edl->session->sample_rate;
740 select_region(position);
744 // Reposition highlight cursor
745 if(is_event_win() && cursor_inside())
748 mwindow->gui->canvas->activate();
756 int TimeBar::repeat_event(int64_t duration)
758 if(!mwindow->gui->canvas->drag_scroll) return 0;
759 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
763 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
764 if(current_operation == TIMEBAR_DRAG)
766 if(relative_cursor_x >= mwindow->gui->canvas->get_w())
768 distance = relative_cursor_x - mwindow->gui->canvas->get_w();
772 if(relative_cursor_x < 0)
774 distance = relative_cursor_x;
783 mwindow->samplemovement(mwindow->edl->local_session->view_start +
791 int TimeBar::cursor_motion_event()
796 switch(current_operation)
801 //printf("TimeBar::cursor_motion_event 1\n");
802 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
803 if(relative_cursor_x >= mwindow->gui->canvas->get_w() ||
804 relative_cursor_x < 0)
806 mwindow->gui->canvas->start_dragscroll();
809 if(relative_cursor_x < mwindow->gui->canvas->get_w() &&
810 relative_cursor_x >= 0)
812 mwindow->gui->canvas->stop_dragscroll();
815 //printf("TimeBar::cursor_motion_event 10\n");
820 case TIMEBAR_DRAG_LEFT:
821 case TIMEBAR_DRAG_RIGHT:
822 case TIMEBAR_DRAG_CENTER:
823 result = move_preview(redraw);
827 //printf("TimeBar::cursor_motion_event 20\n");
828 result = test_preview(0);
829 //printf("TimeBar::cursor_motion_event 30\n");
841 int TimeBar::button_release_event()
843 //printf("TimeBar::button_release_event %d\n", current_operation);
845 switch(current_operation)
848 mwindow->undo->update_undo(_("select"), LOAD_SESSION, 0, 0);
849 mwindow->gui->canvas->stop_dragscroll();
850 current_operation = TIMEBAR_NONE;
855 if(current_operation != TIMEBAR_NONE)
857 current_operation = TIMEBAR_NONE;
865 // Update the selection cursor during a dragging operation
866 void TimeBar::update_cursor()
868 double position = (double)get_cursor_x() *
869 mwindow->edl->local_session->zoom_sample /
870 mwindow->edl->session->sample_rate +
871 (double)mwindow->edl->local_session->view_start *
872 mwindow->edl->local_session->zoom_sample /
873 mwindow->edl->session->sample_rate;
875 position = mwindow->edl->align_to_frame(position, 0);
876 position = MAX(0, position);
877 current_operation = TIMEBAR_DRAG;
879 mwindow->select_point(position);
884 int TimeBar::select_region(double position)
886 Label *start = 0, *end = 0, *current;
887 for(current = mwindow->edl->labels->first; current; current = NEXT)
889 if(current->position > position)
896 for(current = mwindow->edl->labels->last ; current; current = PREVIOUS)
898 if(current->position <= position)
909 mwindow->edl->local_session->set_selectionstart(0);
911 mwindow->edl->local_session->set_selectionstart(start->position);
914 mwindow->edl->local_session->set_selectionend(mwindow->edl->tracks->total_length());
916 mwindow->edl->local_session->set_selectionend(end->position);
921 mwindow->edl->local_session->set_selectionstart(start->position);
922 mwindow->edl->local_session->set_selectionend(start->position);
926 mwindow->cwindow->update(1, 0, 0);
927 mwindow->gui->cursor->hide();
928 mwindow->gui->cursor->draw();
929 mwindow->gui->canvas->flash();
930 mwindow->gui->canvas->activate();
931 mwindow->gui->zoombar->update();
932 mwindow->undo->update_undo(_("select"), LOAD_SESSION, 0, 0);
940 int TimeBar::delete_arrows()