6 #include "edlsession.h"
10 #include "localsession.h"
13 #include "mwindowgui.h"
15 #include "preferences.h"
16 #include "recordlabel.h"
17 #include "localsession.h"
18 #include "mainsession.h"
21 #include "trackcanvas.h"
23 #include "transportque.h"
27 #include "vwindowgui.h"
31 LabelGUI::LabelGUI(MWindow *mwindow,
37 : BC_Toggle(translate_pixel(mwindow, pixel),
39 data ? data : mwindow->theme->label_toggle,
42 this->mwindow = mwindow;
43 this->timebar = timebar;
46 this->position = position;
53 int LabelGUI::get_y(MWindow *mwindow, TimeBar *timebar)
59 return timebar->get_h() -
60 mwindow->theme->label_toggle[0]->get_h();
63 int LabelGUI::translate_pixel(MWindow *mwindow, int pixel)
65 int result = pixel - mwindow->theme->label_toggle[0]->get_w() / 2;
69 void LabelGUI::reposition()
71 reposition_window(translate_pixel(mwindow, pixel), BC_Toggle::get_y());
74 int LabelGUI::handle_event()
77 timebar->select_label(position);
88 InPointGUI::InPointGUI(MWindow *mwindow,
95 get_y(mwindow, timebar),
97 mwindow->theme->in_point)
99 //printf("InPointGUI::InPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
101 InPointGUI::~InPointGUI()
104 int InPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
107 result = timebar->get_h() -
108 mwindow->theme->in_point[0]->get_h();
113 OutPointGUI::OutPointGUI(MWindow *mwindow,
120 get_y(mwindow, timebar),
122 mwindow->theme->out_point)
124 //printf("OutPointGUI::OutPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
126 OutPointGUI::~OutPointGUI()
129 int OutPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
131 return timebar->get_h() -
132 mwindow->theme->out_point[0]->get_h();
136 PresentationGUI::PresentationGUI(MWindow *mwindow,
140 : LabelGUI(mwindow, timebar, pixel, get_y(mwindow, timebar), position)
143 PresentationGUI::~PresentationGUI()
153 TimeBar::TimeBar(MWindow *mwindow,
159 : BC_SubWindow(x, y, w, h)
161 //printf("TimeBar::TimeBar %d %d %d %d\n", x, y, w, h);
163 this->mwindow = mwindow;
168 if(in_point) delete in_point;
169 if(out_point) delete out_point;
170 labels.remove_all_objects();
171 presentations.remove_all_objects();
174 int TimeBar::create_objects()
178 current_operation = TIMEBAR_NONE;
184 int64_t TimeBar::position_to_pixel(double position)
187 return (int64_t)(position / time_per_pixel);
191 void TimeBar::update_labels()
194 EDL *edl = get_edl();
196 //printf("TimeBar::update_labels 1\n");
199 for(Label *current = edl->labels->first;
203 //printf("TimeBar::update_labels 1 %p\n", current);
204 int64_t pixel = position_to_pixel(current->position);
205 //printf("TimeBar::update_labels 2 %d\n", pixel);
207 if(pixel >= 0 && pixel < get_w())
209 //printf("TimeBar::update_labels 3\n");
211 if(output >= labels.total)
214 add_subwindow(new_label =
215 new LabelGUI(mwindow,
218 LabelGUI::get_y(mwindow, this),
220 new_label->set_cursor(ARROW_CURSOR);
221 labels.append(new_label);
224 // Reposition old label
226 LabelGUI *gui = labels.values[output];
227 if(gui->pixel != pixel)
231 //printf("TimeBar::update_labels 4 %d\n", pixel);
238 labels.values[output]->position = current->position;
241 if(edl->local_session->selectionstart <= current->position &&
242 edl->local_session->selectionend >= current->position)
243 labels.values[output]->update(1);
245 if(labels.values[output]->get_value())
246 labels.values[output]->update(0);
253 // Delete excess labels
254 while(labels.total > output)
256 //printf("TimeBar::update_labels 9\n");
257 labels.remove_object();
259 //printf("TimeBar::update_labels 10\n");
262 void TimeBar::update_highlights()
264 for(int i = 0; i < labels.total; i++)
266 LabelGUI *label = labels.values[i];
267 if(mwindow->edl->equivalent(label->position, mwindow->edl->local_session->selectionstart) ||
268 mwindow->edl->equivalent(label->position, mwindow->edl->local_session->selectionend))
270 if(!label->get_value()) label->update(1);
273 if(label->get_value()) label->update(0);
276 if(mwindow->edl->equivalent(mwindow->edl->local_session->in_point, mwindow->edl->local_session->selectionstart) ||
277 mwindow->edl->equivalent(mwindow->edl->local_session->in_point, mwindow->edl->local_session->selectionend))
279 if(in_point) in_point->update(1);
282 if(in_point) in_point->update(0);
284 if(mwindow->edl->equivalent(mwindow->edl->local_session->out_point, mwindow->edl->local_session->selectionstart) ||
285 mwindow->edl->equivalent(mwindow->edl->local_session->out_point, mwindow->edl->local_session->selectionend))
287 if(out_point) out_point->update(1);
290 if(out_point) out_point->update(0);
293 void TimeBar::update_points()
295 EDL *edl = get_edl();
298 if(edl) pixel = position_to_pixel(edl->local_session->in_point);
299 //printf("TimeBar::update_points 1 %d\n", pixel);
305 edl->local_session->in_point >= 0 &&
309 if(edl->local_session->in_point != in_point->position ||
310 in_point->pixel != pixel)
312 in_point->pixel = pixel;
313 in_point->position = edl->local_session->in_point;
314 in_point->reposition();
318 in_point->draw_face();
328 if(edl && edl->local_session->in_point >= 0 && pixel >= 0 && pixel < get_w())
330 //printf("TimeBar::update_points 1 %p\n", edl);
331 add_subwindow(in_point = new InPointGUI(mwindow,
334 edl->local_session->in_point));
335 in_point->set_cursor(ARROW_CURSOR);
336 //printf("TimeBar::update_points 2\n");
339 if(edl) pixel = position_to_pixel(edl->local_session->out_point);
341 //printf("TimeBar::update_points 2 %d\n", pixel);
345 edl->local_session->out_point >= 0 &&
349 if(edl->local_session->out_point != out_point->position ||
350 out_point->pixel != pixel)
352 out_point->pixel = pixel;
353 out_point->position = edl->local_session->out_point;
354 out_point->reposition();
358 out_point->draw_face();
369 edl->local_session->out_point >= 0 &&
370 pixel >= 0 && pixel < get_w())
372 add_subwindow(out_point = new OutPointGUI(mwindow,
375 edl->local_session->out_point));
376 out_point->set_cursor(ARROW_CURSOR);
380 void TimeBar::update_presentations()
385 void TimeBar::update(int do_range, int do_others)
388 // Need to redo these when range is drawn to get the background updated.
391 update_presentations();
397 int TimeBar::delete_project()
399 // labels->delete_all();
403 int TimeBar::save(FileXML *xml)
405 // labels->save(xml);
412 void TimeBar::draw_time()
416 EDL* TimeBar::get_edl()
423 void TimeBar::draw_range()
428 get_preview_pixels(x1, x2);
430 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
431 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
432 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
433 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
436 draw_line(x1, 0, x1, get_h());
437 draw_line(x2, 0, x2, get_h());
442 int64_t pixel = position_to_pixel(edl->local_session->selectionstart);
443 // Draw insertion point position if this timebar beint64_ts to a window which
444 // has something other than the master EDL.
445 //printf("TimeBar::draw_range %f\n", edl->local_session->selectionstart);
447 draw_line(pixel, 0, pixel, get_h());
451 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
454 void TimeBar::select_label(double position)
465 void TimeBar::get_edl_length()
471 //printf("TimeBar::get_edl_length 1 %f\n", get_edl()->tracks->total_playable_length());
472 edl_length = get_edl()->tracks->total_playable_length();
475 //printf("TimeBar::get_edl_length 2\n");
476 if(!EQUIV(edl_length, 0))
478 //printf("TimeBar::get_edl_length 3\n");
479 time_per_pixel = edl_length / get_w();
480 //printf("TimeBar::get_edl_length 4\n");
486 //printf("TimeBar::get_edl_length 5\n");
489 int TimeBar::get_preview_pixels(int &x1, int &x2)
498 if(!EQUIV(edl_length, 0))
500 if(get_edl()->local_session->preview_end <= 0 ||
501 get_edl()->local_session->preview_end > edl_length)
502 get_edl()->local_session->preview_end = edl_length;
503 if(get_edl()->local_session->preview_start >
504 get_edl()->local_session->preview_end)
505 get_edl()->local_session->preview_start = 0;
506 x1 = (int)(get_edl()->local_session->preview_start / time_per_pixel);
507 x2 = (int)(get_edl()->local_session->preview_end / time_per_pixel);
515 // printf("TimeBar::get_preview_pixels %f %f %d %d\n",
516 // get_edl()->local_session->preview_start,
517 // get_edl()->local_session->preview_end,
524 int TimeBar::test_preview(int buttonpress)
529 get_preview_pixels(x1, x2);
530 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, get_cursor_x());
534 // Inside left handle
535 if(cursor_inside() &&
536 get_cursor_x() >= x1 - HANDLE_W &&
537 get_cursor_x() < x1 + HANDLE_W &&
538 // Ignore left handle if both handles are up against the left side
543 current_operation = TIMEBAR_DRAG_LEFT;
544 start_position = get_edl()->local_session->preview_start;
545 start_cursor_x = get_cursor_x();
549 if(get_cursor() != LEFT_CURSOR)
552 set_cursor(LEFT_CURSOR);
556 // Inside right handle
557 if(cursor_inside() &&
558 get_cursor_x() >= x2 - HANDLE_W &&
559 get_cursor_x() < x2 + HANDLE_W &&
560 // Ignore right handle if both handles are up against the right side
561 x1 < get_w() - HANDLE_W)
565 current_operation = TIMEBAR_DRAG_RIGHT;
566 start_position = get_edl()->local_session->preview_end;
567 start_cursor_x = get_cursor_x();
571 if(get_cursor() != RIGHT_CURSOR)
574 set_cursor(RIGHT_CURSOR);
578 if(cursor_inside() &&
579 get_cursor_x() >= x1 &&
584 current_operation = TIMEBAR_DRAG_CENTER;
585 starting_start_position = get_edl()->local_session->preview_start;
586 starting_end_position = get_edl()->local_session->preview_end;
587 start_cursor_x = get_cursor_x();
593 set_cursor(HSEPARATE_CURSOR);
598 // Trap all buttonpresses inside timebar
599 if(cursor_inside() && buttonpress)
602 if(get_cursor() == LEFT_CURSOR ||
603 get_cursor() == RIGHT_CURSOR)
606 set_cursor(ARROW_CURSOR);
616 int TimeBar::move_preview(int &redraw)
620 if(current_operation == TIMEBAR_DRAG_LEFT)
622 get_edl()->local_session->preview_start =
624 time_per_pixel * (get_cursor_x() - start_cursor_x);
625 CLAMP(get_edl()->local_session->preview_start,
627 get_edl()->local_session->preview_end);
631 if(current_operation == TIMEBAR_DRAG_RIGHT)
633 get_edl()->local_session->preview_end =
635 time_per_pixel * (get_cursor_x() - start_cursor_x);
636 CLAMP(get_edl()->local_session->preview_end,
637 get_edl()->local_session->preview_start,
642 if(current_operation == TIMEBAR_DRAG_CENTER)
644 get_edl()->local_session->preview_start =
645 starting_start_position +
646 time_per_pixel * (get_cursor_x() - start_cursor_x);
647 get_edl()->local_session->preview_end =
648 starting_end_position +
649 time_per_pixel * (get_cursor_x() - start_cursor_x);
650 if(get_edl()->local_session->preview_start < 0)
652 get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
653 get_edl()->local_session->preview_start = 0;
656 if(get_edl()->local_session->preview_end > edl_length)
658 get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
659 get_edl()->local_session->preview_end = edl_length;
664 //printf("TimeBar::move_preview %f %f\n", get_edl()->local_session->preview_start, get_edl()->local_session->preview_end);
675 void TimeBar::update_preview()
679 int TimeBar::samplemovement()
684 void TimeBar::stop_playback()
688 int TimeBar::button_press_event()
690 //printf("TimeBar::button_press_event 1\n");
691 if(is_event_win() && cursor_inside())
693 // Change time format
696 mwindow->next_time_format();
707 // Select region between two labels
708 if(get_double_click())
710 double position = (double)get_cursor_x() *
711 mwindow->edl->local_session->zoom_sample /
712 mwindow->edl->session->sample_rate +
713 (double)mwindow->edl->local_session->view_start *
714 mwindow->edl->local_session->zoom_sample /
715 mwindow->edl->session->sample_rate;
717 select_region(position);
721 // Reposition highlight cursor
722 if(is_event_win() && cursor_inside())
724 //printf("TimeBar::button_press_event 4\n");
726 //printf("TimeBar::button_press_event 5\n");
727 mwindow->gui->canvas->activate();
728 //printf("TimeBar::button_press_event 6\n");
736 int TimeBar::repeat_event(int64_t duration)
738 if(!mwindow->gui->canvas->drag_scroll) return 0;
739 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
743 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
744 if(current_operation == TIMEBAR_DRAG)
746 if(relative_cursor_x >= mwindow->gui->canvas->get_w())
748 distance = relative_cursor_x - mwindow->gui->canvas->get_w();
752 if(relative_cursor_x < 0)
754 distance = relative_cursor_x;
763 mwindow->samplemovement(mwindow->edl->local_session->view_start +
771 int TimeBar::cursor_motion_event()
776 switch(current_operation)
781 // printf("TimeBar::cursor_motion_event %d %d %d\n",
785 int relative_cursor_x = mwindow->gui->canvas->get_relative_cursor_x();
786 if(relative_cursor_x >= mwindow->gui->canvas->get_w() ||
787 relative_cursor_x < 0)
789 mwindow->gui->canvas->start_dragscroll();
792 if(relative_cursor_x < mwindow->gui->canvas->get_w() &&
793 relative_cursor_x >= 0)
795 mwindow->gui->canvas->stop_dragscroll();
802 case TIMEBAR_DRAG_LEFT:
803 case TIMEBAR_DRAG_RIGHT:
804 case TIMEBAR_DRAG_CENTER:
805 result = move_preview(redraw);
809 result = test_preview(0);
821 int TimeBar::button_release_event()
823 //printf("TimeBar::button_release_event %d\n", current_operation);
825 switch(current_operation)
828 mwindow->gui->canvas->stop_dragscroll();
829 current_operation = TIMEBAR_NONE;
834 if(current_operation != TIMEBAR_NONE)
836 current_operation = TIMEBAR_NONE;
844 // Update the selection cursor during a dragging operation
845 void TimeBar::update_cursor()
847 double position = (double)get_cursor_x() *
848 mwindow->edl->local_session->zoom_sample /
849 mwindow->edl->session->sample_rate +
850 (double)mwindow->edl->local_session->view_start *
851 mwindow->edl->local_session->zoom_sample /
852 mwindow->edl->session->sample_rate;
854 position = mwindow->edl->align_to_frame(position, 0);
855 position = MAX(0, position);
856 current_operation = TIMEBAR_DRAG;
858 mwindow->select_point(position);
863 int TimeBar::select_region(double position)
865 Label *start = 0, *end = 0, *current;
866 for(current = mwindow->edl->labels->first; current; current = NEXT)
868 if(current->position > position)
875 for(current = mwindow->edl->labels->last ; current; current = PREVIOUS)
877 if(current->position <= position)
888 mwindow->edl->local_session->selectionstart = 0;
890 mwindow->edl->local_session->selectionstart = start->position;
893 mwindow->edl->local_session->selectionend = mwindow->edl->tracks->total_length();
895 mwindow->edl->local_session->selectionend = end->position;
900 mwindow->edl->local_session->selectionstart =
901 mwindow->edl->local_session->selectionend =
906 mwindow->cwindow->update(1, 0, 0);
907 mwindow->gui->cursor->hide();
908 mwindow->gui->cursor->draw();
909 mwindow->gui->canvas->flash();
910 mwindow->gui->canvas->activate();
911 mwindow->gui->zoombar->update();
916 int TimeBar::copy(int64_t start, int64_t end, FileXML *xml)
918 // labels->copy(start, end, xml);
922 int TimeBar::paste(int64_t start, int64_t end, int64_t sample_length, FileXML *xml)
924 // labels->paste(start, end, sample_length, xml);
928 int TimeBar::paste_output(int64_t startproject, int64_t endproject, int64_t startsource, int64_t endsource, RecordLabels *new_labels)
930 // labels->paste_output(startproject, endproject, startsource, endsource, new_labels);
934 int TimeBar::clear(int64_t start, int64_t end)
936 //labels->clear(start, end);
940 int TimeBar::paste_silence(int64_t start, int64_t end)
942 //labels->paste_silence(start, end);
946 int TimeBar::modify_handles(int64_t oldposition, int64_t newposition, int currentend)
948 //labels->modify_handles(oldposition, newposition, currentend);
955 int TimeBar::delete_arrows()