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)
402 // Need to redo these when range is drawn to get the background updated.
405 update_presentations();
411 int TimeBar::delete_project()
413 // labels->delete_all();
417 int TimeBar::save(FileXML *xml)
419 // labels->save(xml);
426 void TimeBar::draw_time()
430 EDL* TimeBar::get_edl()
437 void TimeBar::draw_range()
442 get_preview_pixels(x1, x2);
444 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
445 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
446 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
447 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
450 draw_line(x1, 0, x1, get_h());
451 draw_line(x2, 0, x2, get_h());
456 int64_t pixel = position_to_pixel(
457 edl->local_session->get_selectionstart(1));
458 // Draw insertion point position if this timebar beint64_ts to a window which
459 // has something other than the master EDL.
461 draw_line(pixel, 0, pixel, get_h());
465 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
468 void TimeBar::select_label(double position)
479 void TimeBar::get_edl_length()
485 //printf("TimeBar::get_edl_length 1 %f\n", get_edl()->tracks->total_playable_length());
486 edl_length = get_edl()->tracks->total_playable_length();
489 //printf("TimeBar::get_edl_length 2\n");
490 if(!EQUIV(edl_length, 0))
492 //printf("TimeBar::get_edl_length 3\n");
493 time_per_pixel = edl_length / get_w();
494 //printf("TimeBar::get_edl_length 4\n");
500 //printf("TimeBar::get_edl_length 5\n");
503 int TimeBar::get_preview_pixels(int &x1, int &x2)
512 if(!EQUIV(edl_length, 0))
514 if(get_edl()->local_session->preview_end <= 0 ||
515 get_edl()->local_session->preview_end > edl_length)
516 get_edl()->local_session->preview_end = edl_length;
517 if(get_edl()->local_session->preview_start >
518 get_edl()->local_session->preview_end)
519 get_edl()->local_session->preview_start = 0;
520 x1 = (int)(get_edl()->local_session->preview_start / time_per_pixel);
521 x2 = (int)(get_edl()->local_session->preview_end / time_per_pixel);
529 // printf("TimeBar::get_preview_pixels %f %f %d %d\n",
530 // get_edl()->local_session->preview_start,
531 // get_edl()->local_session->preview_end,
538 int TimeBar::test_preview(int buttonpress)
543 get_preview_pixels(x1, x2);
544 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, get_cursor_x());
548 // Inside left handle
549 if(cursor_inside() &&
550 get_cursor_x() >= x1 - HANDLE_W &&
551 get_cursor_x() < x1 + HANDLE_W &&
552 // Ignore left handle if both handles are up against the left side
557 current_operation = TIMEBAR_DRAG_LEFT;
558 start_position = get_edl()->local_session->preview_start;
559 start_cursor_x = get_cursor_x();
563 if(get_cursor() != LEFT_CURSOR)
566 set_cursor(LEFT_CURSOR);
570 // Inside right handle
571 if(cursor_inside() &&
572 get_cursor_x() >= x2 - HANDLE_W &&
573 get_cursor_x() < x2 + HANDLE_W &&
574 // Ignore right handle if both handles are up against the right side
575 x1 < get_w() - HANDLE_W)
579 current_operation = TIMEBAR_DRAG_RIGHT;
580 start_position = get_edl()->local_session->preview_end;
581 start_cursor_x = get_cursor_x();
585 if(get_cursor() != RIGHT_CURSOR)
588 set_cursor(RIGHT_CURSOR);
592 if(cursor_inside() &&
593 get_cursor_x() >= x1 &&
598 current_operation = TIMEBAR_DRAG_CENTER;
599 starting_start_position = get_edl()->local_session->preview_start;
600 starting_end_position = get_edl()->local_session->preview_end;
601 start_cursor_x = get_cursor_x();
607 set_cursor(HSEPARATE_CURSOR);
612 // Trap all buttonpresses inside timebar
613 if(cursor_inside() && buttonpress)
616 if(get_cursor() == LEFT_CURSOR ||
617 get_cursor() == RIGHT_CURSOR)
620 set_cursor(ARROW_CURSOR);
630 int TimeBar::move_preview(int &redraw)
634 if(current_operation == TIMEBAR_DRAG_LEFT)
636 get_edl()->local_session->preview_start =
638 time_per_pixel * (get_cursor_x() - start_cursor_x);
639 CLAMP(get_edl()->local_session->preview_start,
641 get_edl()->local_session->preview_end);
645 if(current_operation == TIMEBAR_DRAG_RIGHT)
647 get_edl()->local_session->preview_end =
649 time_per_pixel * (get_cursor_x() - start_cursor_x);
650 CLAMP(get_edl()->local_session->preview_end,
651 get_edl()->local_session->preview_start,
656 if(current_operation == TIMEBAR_DRAG_CENTER)
658 get_edl()->local_session->preview_start =
659 starting_start_position +
660 time_per_pixel * (get_cursor_x() - start_cursor_x);
661 get_edl()->local_session->preview_end =
662 starting_end_position +
663 time_per_pixel * (get_cursor_x() - start_cursor_x);
664 if(get_edl()->local_session->preview_start < 0)
666 get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
667 get_edl()->local_session->preview_start = 0;
670 if(get_edl()->local_session->preview_end > edl_length)
672 get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
673 get_edl()->local_session->preview_end = edl_length;
678 //printf("TimeBar::move_preview %f %f\n", get_edl()->local_session->preview_start, get_edl()->local_session->preview_end);
689 void TimeBar::update_preview()
693 int TimeBar::samplemovement()
698 void TimeBar::stop_playback()
702 int TimeBar::button_press_event()
704 if(is_event_win() && cursor_inside())
706 // Change time format
709 if(get_buttonpress() == 1)
710 mwindow->next_time_format();
712 if(get_buttonpress() == 2)
713 mwindow->prev_time_format();
724 // Select region between two labels
725 if(get_double_click())
727 double position = (double)get_cursor_x() *
728 mwindow->edl->local_session->zoom_sample /
729 mwindow->edl->session->sample_rate +
730 (double)mwindow->edl->local_session->view_start *
731 mwindow->edl->local_session->zoom_sample /
732 mwindow->edl->session->sample_rate;
734 select_region(position);
738 // Reposition highlight cursor
739 if(is_event_win() && cursor_inside())
742 mwindow->gui->canvas->activate();
750 int TimeBar::repeat_event(int64_t duration)
752 if(!mwindow->gui->canvas->drag_scroll) return 0;
753 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
757 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
758 if(current_operation == TIMEBAR_DRAG)
760 if(relative_cursor_x >= mwindow->gui->canvas->get_w())
762 distance = relative_cursor_x - mwindow->gui->canvas->get_w();
766 if(relative_cursor_x < 0)
768 distance = relative_cursor_x;
777 mwindow->samplemovement(mwindow->edl->local_session->view_start +
785 int TimeBar::cursor_motion_event()
790 switch(current_operation)
795 //printf("TimeBar::cursor_motion_event 1\n");
796 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
797 if(relative_cursor_x >= mwindow->gui->canvas->get_w() ||
798 relative_cursor_x < 0)
800 mwindow->gui->canvas->start_dragscroll();
803 if(relative_cursor_x < mwindow->gui->canvas->get_w() &&
804 relative_cursor_x >= 0)
806 mwindow->gui->canvas->stop_dragscroll();
809 //printf("TimeBar::cursor_motion_event 10\n");
814 case TIMEBAR_DRAG_LEFT:
815 case TIMEBAR_DRAG_RIGHT:
816 case TIMEBAR_DRAG_CENTER:
817 result = move_preview(redraw);
821 //printf("TimeBar::cursor_motion_event 20\n");
822 result = test_preview(0);
823 //printf("TimeBar::cursor_motion_event 30\n");
835 int TimeBar::button_release_event()
837 //printf("TimeBar::button_release_event %d\n", current_operation);
839 switch(current_operation)
842 mwindow->undo->update_undo(_("select"), LOAD_SESSION, 0, 0);
843 mwindow->gui->canvas->stop_dragscroll();
844 current_operation = TIMEBAR_NONE;
849 if(current_operation != TIMEBAR_NONE)
851 current_operation = TIMEBAR_NONE;
859 // Update the selection cursor during a dragging operation
860 void TimeBar::update_cursor()
862 double position = (double)get_cursor_x() *
863 mwindow->edl->local_session->zoom_sample /
864 mwindow->edl->session->sample_rate +
865 (double)mwindow->edl->local_session->view_start *
866 mwindow->edl->local_session->zoom_sample /
867 mwindow->edl->session->sample_rate;
869 position = mwindow->edl->align_to_frame(position, 0);
870 position = MAX(0, position);
871 current_operation = TIMEBAR_DRAG;
873 mwindow->select_point(position);
878 int TimeBar::select_region(double position)
880 Label *start = 0, *end = 0, *current;
881 for(current = mwindow->edl->labels->first; current; current = NEXT)
883 if(current->position > position)
890 for(current = mwindow->edl->labels->last ; current; current = PREVIOUS)
892 if(current->position <= position)
903 mwindow->edl->local_session->set_selectionstart(0);
905 mwindow->edl->local_session->set_selectionstart(start->position);
908 mwindow->edl->local_session->set_selectionend(mwindow->edl->tracks->total_length());
910 mwindow->edl->local_session->set_selectionend(end->position);
915 mwindow->edl->local_session->set_selectionstart(start->position);
916 mwindow->edl->local_session->set_selectionend(start->position);
920 mwindow->cwindow->update(1, 0, 0);
921 mwindow->gui->cursor->hide(0);
922 mwindow->gui->cursor->draw(1);
923 mwindow->gui->canvas->flash();
924 mwindow->gui->canvas->activate();
925 mwindow->gui->zoombar->update();
926 mwindow->undo->update_undo(_("select"), LOAD_SESSION, 0, 0);
934 int TimeBar::delete_arrows()