prev/next label fix in viewer, inout highlight, modify folder layout, ffmpeg scan...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / timebar.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcsignals.h"
23 #include "clip.h"
24 #include "cplayback.h"
25 #include "cursors.h"
26 #include "cwindow.h"
27 #include "cwindowgui.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "filexml.h"
31 #include "fonts.h"
32 #include "labels.h"
33 #include "labeledit.h"
34 #include "localsession.h"
35 #include "maincursor.h"
36 #include "mainundo.h"
37 #include "mbuttons.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "patchbay.h"
41 #include "preferences.h"
42 #include "recordlabel.h"
43 #include "localsession.h"
44 #include "mainsession.h"
45 #include "theme.h"
46 #include "timebar.h"
47 #include "timelinepane.h"
48 #include "trackcanvas.h"
49 #include "tracks.h"
50 #include "transportque.h"
51 #include "units.h"
52 #include "vframe.h"
53 #include "vwindow.h"
54 #include "vwindowgui.h"
55 #include "zoombar.h"
56
57
58 LabelGUI::LabelGUI(MWindow *mwindow, TimeBar *timebar,
59         int64_t pixel, int y,
60         double position, VFrame **data)
61  : BC_Toggle(translate_pixel(mwindow, pixel), y,
62                 data ? data : mwindow->theme->label_toggle, 0)
63 {
64         this->mwindow = mwindow;
65         this->timebar = timebar;
66         this->gui = 0;
67         this->pixel = pixel;
68         this->position = position;
69         this->label = 0;
70 }
71
72 LabelGUI::~LabelGUI()
73 {
74 }
75
76 int LabelGUI::get_y(MWindow *mwindow, TimeBar *timebar)
77 {
78         return timebar->get_h() -
79                 mwindow->theme->label_toggle[0]->get_h();
80 }
81
82 int LabelGUI::translate_pixel(MWindow *mwindow, int pixel)
83 {
84         int result = pixel - mwindow->theme->label_toggle[0]->get_w() / 2;
85         return result;
86 }
87
88 void LabelGUI::reposition(int flush)
89 {
90         reposition_window(translate_pixel(mwindow, pixel),
91                 BC_Toggle::get_y());
92 }
93
94 int LabelGUI::button_press_event()
95 {
96         int result = 0;
97
98         if( this->is_event_win() && get_buttonpress() == 3 ) {
99                 if( label ) {
100                         int cur_x, cur_y;
101                         get_abs_cursor(cur_x, cur_y, 0);
102                         timebar->label_edit->start(label, cur_x, cur_y);
103                 }
104                 result = 1;
105         } else {
106                 result = BC_Toggle::button_press_event();
107         }
108         if( label )
109                 set_tooltip(this->label->textstr);
110         return result;
111 }
112
113 int LabelGUI::handle_event()
114 {
115         timebar->select_label(position);
116         return 1;
117 }
118
119
120 InPointGUI::InPointGUI(MWindow *mwindow, TimeBar *timebar,
121         int64_t pixel, double position)
122  : LabelGUI(mwindow, timebar,
123         pixel, get_y(mwindow, timebar),
124         position, mwindow->theme->in_point)
125 {
126 //printf("InPointGUI::InPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
127 }
128 InPointGUI::~InPointGUI()
129 {
130 }
131 int InPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
132 {
133         int result;
134         result = timebar->get_h() -
135                 mwindow->theme->in_point[0]->get_h();
136         return result;
137 }
138
139
140 OutPointGUI::OutPointGUI(MWindow *mwindow, TimeBar *timebar,
141         int64_t pixel, double position)
142  : LabelGUI(mwindow, timebar,
143         pixel, get_y(mwindow, timebar),
144         position, mwindow->theme->out_point)
145 {
146 //printf("OutPointGUI::OutPointGUI %d %d\n", pixel, get_y(mwindow, timebar));
147 }
148 OutPointGUI::~OutPointGUI()
149 {
150 }
151 int OutPointGUI::get_y(MWindow *mwindow, TimeBar *timebar)
152 {
153         return timebar->get_h() -
154                 mwindow->theme->out_point[0]->get_h();
155 }
156
157
158 PresentationGUI::PresentationGUI(MWindow *mwindow, TimeBar *timebar,
159         int64_t pixel, double position)
160  : LabelGUI(mwindow, timebar, pixel, get_y(mwindow, timebar), position)
161 {
162 }
163 PresentationGUI::~PresentationGUI()
164 {
165 }
166
167 TimeBar::TimeBar(MWindow *mwindow, BC_WindowBase *gui,
168         int x, int y, int w, int h)
169  : BC_SubWindow(x, y, w, h)
170 {
171 //printf("TimeBar::TimeBar %d %d %d %d\n", x, y, w, h);
172         this->gui = gui;
173         this->mwindow = mwindow;
174         label_edit = new LabelEdit(mwindow, mwindow->awindow, 0);
175         pane = 0;
176         highlighted = 0;
177 }
178
179 TimeBar::~TimeBar()
180 {
181         delete in_point;
182         delete out_point;
183         delete label_edit;
184         labels.remove_all_objects();
185         presentations.remove_all_objects();
186 }
187
188 void TimeBar::create_objects()
189 {
190         in_point = 0;
191         out_point = 0;
192 //printf("TimeBar::create_objects %d\n", __LINE__);
193         current_operation = TIMEBAR_NONE;
194         set_cursor(UPRIGHT_ARROW_CURSOR, 0, 0);
195         update(0);
196 }
197
198
199 int64_t TimeBar::position_to_pixel(double position)
200 {
201         get_edl_length();
202         return (int64_t)(position / time_per_pixel);
203 }
204
205
206 double TimeBar::pixel_to_position(int pixel)
207 {
208         if( pane ) {
209                 pixel += get_edl()->local_session->view_start[pane->number];
210         }
211
212         return (double)pixel *
213                 get_edl()->local_session->zoom_sample /
214                 get_edl()->session->sample_rate;
215 }
216
217 void TimeBar::update_labels()
218 {
219         int output = 0;
220         EDL *edl = get_edl();
221
222         if( edl ) {
223                 for( Label *current=edl->labels->first; current; current=NEXT ) {
224                         int64_t pixel = position_to_pixel(current->position);
225                         if( pixel >= 0 && pixel < get_w()  ) {
226 // Create new label
227                                 if( output >= labels.total ) {
228                                         LabelGUI *new_label;
229                                         add_subwindow(new_label =
230                                                 new LabelGUI(mwindow,
231                                                         this,
232                                                         pixel,
233                                                         LabelGUI::get_y(mwindow, this),
234                                                         current->position));
235                                         new_label->set_cursor(INHERIT_CURSOR, 0, 0);
236                                         new_label->set_tooltip(current->textstr);
237                                         new_label->label = current;
238                                         labels.append(new_label);
239                                 }
240                                 else
241 // Reposition old label
242                                 {
243                                         LabelGUI *gui = labels.values[output];
244                                         if( gui->pixel != pixel ) {
245                                                 gui->pixel = pixel;
246                                                 gui->reposition(0);
247                                         }
248                                         else {
249                                                 gui->draw_face(1,0);
250                                         }
251
252                                         labels.values[output]->position = current->position;
253                                         labels.values[output]->set_tooltip(current->textstr);
254                                         labels.values[output]->label = current;
255                                 }
256
257                                 if( edl->local_session->get_selectionstart(1) <= current->position &&
258                                     edl->local_session->get_selectionend(1) >= current->position )
259                                         labels.values[output]->update(1);
260                                 else
261                                 if( labels.values[output]->get_value() )
262                                         labels.values[output]->update(0);
263
264                                 output++;
265                         }
266                 }
267         }
268
269 // Delete excess labels
270         while(labels.total > output)
271         {
272                 labels.remove_object();
273         }
274
275 // Get the labels to show
276         show_window(0);
277 }
278
279 void TimeBar::update_highlights()
280 {
281         EDL *edl = get_edl();
282         if( !edl ) return;
283         for( int i = 0; i < labels.total; i++ ) {
284                 LabelGUI *label = labels.values[i];
285                 if( edl->equivalent(label->position,
286                                 edl->local_session->get_selectionstart(1)) ||
287                     edl->equivalent(label->position,
288                                 edl->local_session->get_selectionend(1)) ) {
289                         if( !label->get_value() ) label->update(1);
290                 }
291                 else
292                         if( label->get_value() ) label->update(0);
293         }
294
295         if( edl->equivalent(edl->local_session->get_inpoint(),
296                         edl->local_session->get_selectionstart(1)) ||
297                 edl->equivalent(edl->local_session->get_inpoint(),
298                         edl->local_session->get_selectionend(1)) ) {
299                 if( in_point ) in_point->update(1);
300         }
301         else
302                 if( in_point ) in_point->update(0);
303
304         if( edl->equivalent(edl->local_session->get_outpoint(),
305                         edl->local_session->get_selectionstart(1)) ||
306                 edl->equivalent(edl->local_session->get_outpoint(),
307                         edl->local_session->get_selectionend(1)) ) {
308                 if( out_point ) out_point->update(1);
309         }
310         else
311                 if( out_point ) out_point->update(0);
312
313         draw_inout_highlight();
314 }
315
316 void TimeBar::draw_inout_highlight()
317 {
318         EDL *edl = get_edl();
319         if( !edl->local_session->inpoint_valid() ) return;
320         if( !edl->local_session->outpoint_valid() ) return;
321         double in_position = edl->local_session->get_inpoint();
322         double out_position = edl->local_session->get_outpoint();
323         if( in_position >= out_position ) return;
324         int in_x = position_to_pixel(in_position);
325         int out_x = position_to_pixel(out_position);
326         CLAMP(in_x, 0, get_w());
327         CLAMP(out_x, 0, get_w());
328         set_color(GREEN);
329         int lw = 5;
330         set_line_width(lw);
331         set_inverse();
332         draw_line(in_x, get_h()-2*lw, out_x, get_h()-2*lw);
333         set_opaque();
334         set_line_width(1);
335 }
336
337 void TimeBar::update_points()
338 {
339         EDL *edl = get_edl();
340         int64_t pixel = !edl ? 0 :
341                 position_to_pixel(edl->local_session->get_inpoint());
342
343         if( in_point ) {
344                 if( edl && edl->local_session->inpoint_valid() &&
345                     pixel >= 0 && pixel < get_w() ) {
346                         if( !EQUIV(edl->local_session->get_inpoint(), in_point->position) ||
347                             in_point->pixel != pixel ) {
348                                 in_point->pixel = pixel;
349                                 in_point->position = edl->local_session->get_inpoint();
350                                 in_point->reposition(0);
351                         }
352                         else {
353                                 in_point->draw_face(1, 0);
354                         }
355                 }
356                 else {
357                         delete in_point;
358                         in_point = 0;
359                 }
360         }
361         else
362         if( edl && edl->local_session->inpoint_valid() &&
363             pixel >= 0 && pixel < get_w() ) {
364                 add_subwindow(in_point = new InPointGUI(mwindow,
365                         this, pixel, edl->local_session->get_inpoint()));
366                 in_point->set_cursor(ARROW_CURSOR, 0, 0);
367         }
368
369         pixel = !edl ? 0 :
370                  position_to_pixel(edl->local_session->get_outpoint());
371
372         if( out_point ) {
373                 if( edl && edl->local_session->outpoint_valid() &&
374                     pixel >= 0 && pixel < get_w()) {
375                         if( !EQUIV(edl->local_session->get_outpoint(), out_point->position) ||
376                             out_point->pixel != pixel ) {
377                                 out_point->pixel = pixel;
378                                 out_point->position = edl->local_session->get_outpoint();
379                                 out_point->reposition(0);
380                         }
381                         else {
382                                 out_point->draw_face(1, 0);
383                         }
384                 }
385                 else {
386                         delete out_point;
387                         out_point = 0;
388                 }
389         }
390         else
391         if( edl && edl->local_session->outpoint_valid() &&
392             pixel >= 0 && pixel < get_w() ) {
393                 add_subwindow(out_point = new OutPointGUI(mwindow,
394                         this, pixel, edl->local_session->get_outpoint()));
395                 out_point->set_cursor(ARROW_CURSOR, 0, 0);
396         }
397
398 //      flush();
399 }
400
401 void TimeBar::update_clock(double position)
402 {
403 }
404
405 void TimeBar::update(int flush)
406 {
407         draw_time();
408 // Need to redo these when range is drawn to get the background updated.
409         update_labels();
410         update_points();
411
412
413         EDL *edl = get_edl();
414         int64_t pixel = -1;
415         int x = get_relative_cursor_x();
416 // Draw highlight position
417         if( edl && (highlighted || current_operation == TIMEBAR_DRAG) &&
418             x >= 0 && x < get_w() ) {
419 //printf("TimeBar::update %d %d\n", __LINE__, x);
420                 double position = pixel_to_position(x);
421
422                 position = mwindow->edl->align_to_frame(position, 0);
423                 pixel = position_to_pixel(position);
424                 update_clock(position);
425         }
426
427         if( pixel < 0 ) {
428                 double position = test_highlight();
429                 if( position >= 0 ) pixel = position_to_pixel(position);
430         }
431
432
433         if( pixel >= 0 && pixel < get_w() ) {
434                 set_color(mwindow->theme->timebar_cursor_color);
435                 set_line_dashes(1);
436 //printf("TimeBar::update %d pane=%d pixel=%jd\n", __LINE__, pane->number, pixel);
437                 draw_line(pixel, 0, pixel, get_h());
438                 set_line_dashes(0);
439         }
440
441
442         if( edl ) {
443                 double playback_start = edl->local_session->playback_start;
444                 if( playback_start >= 0 ) {
445                         int64_t pixel = position_to_pixel(playback_start);
446                         set_color(mwindow->theme->timebar_cursor_color ^ 0x0000ff);
447                         draw_line(pixel, 0, pixel, get_h());
448                         double playback_end = edl->local_session->playback_end;
449                         if( playback_end > playback_start ) {
450                                 pixel = position_to_pixel(playback_end);
451                                 set_color(mwindow->theme->timebar_cursor_color ^ 0x00ff00);
452                                 draw_line(pixel, 0, pixel, get_h());
453                         }
454                 }
455
456                 double position = edl->local_session->get_selectionstart(1);
457                 int64_t pixel = position_to_pixel(position);
458 // Draw insertion point position.
459                 int color = mwindow->theme->timebar_cursor_color;
460                 if( mwindow->preferences->forward_render_displacement )
461                         color ^= 0x00ffff;
462                 set_color(color);
463                 draw_line(pixel, 0, pixel, get_h());
464         }
465
466         update_highlights();
467
468 // Get the labels to show
469         show_window(0);
470         flash(flush);
471 //printf("TimeBar::update %d this=%p %d\n", __LINE__, this, current_operation);
472 }
473
474
475
476 int TimeBar::delete_project()
477 {
478 //      labels->delete_all();
479         return 0;
480 }
481
482 int TimeBar::save(FileXML *xml)
483 {
484 //      labels->save(xml);
485         return 0;
486 }
487
488
489
490
491 void TimeBar::draw_time()
492 {
493 }
494
495 EDL* TimeBar::get_edl()
496 {
497         return mwindow->edl;
498 }
499
500
501
502 void TimeBar::draw_range()
503 {
504
505
506 //printf("TimeBar::draw_range %d %p\n", __LINE__, get_edl());
507         if( has_preview() && get_edl() ) {
508                 int x1, x2;
509                 get_preview_pixels(x1, x2);
510
511 //printf("TimeBar::draw_range %f %d %d\n", edl_length, x1, x2);
512                 draw_3segmenth(0, 0, x1, mwindow->theme->timebar_view_data);
513                 draw_top_background(get_parent(), x1, 0, x2 - x1, get_h());
514                 draw_3segmenth(x2, 0, get_w() - x2, mwindow->theme->timebar_view_data);
515
516                 set_color(BLACK);
517                 draw_line(x1, 0, x1, get_h());
518                 draw_line(x2, 0, x2, get_h());
519
520
521                 EDL *edl = get_edl();
522                 if( edl ) {
523                         int64_t pixel = position_to_pixel(
524                                 edl->local_session->get_selectionstart(1));
525 // Draw insertion point position if this timebar belongs to a window which
526 // has something other than the master EDL.
527                         set_color(mwindow->theme->timebar_cursor_color);
528                         draw_line(pixel, 0, pixel, get_h());
529                 }
530         }
531         else
532                 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
533 }
534
535 void TimeBar::select_label(double position)
536 {
537 }
538
539
540
541 int TimeBar::draw()
542 {
543         return 0;
544 }
545
546 double TimeBar::get_edl_length()
547 {
548         edl_length = get_edl() ? get_edl()->tracks->total_length() : 0;
549         int w1 = get_w()-1;
550         time_per_pixel = !EQUIV(edl_length, 0) ? edl_length/w1 : w1;
551         return edl_length;
552 }
553
554 int TimeBar::get_preview_pixels(int &x1, int &x2)
555 {
556         x1 = 0;  x2 = get_w();
557         get_edl_length();
558         EDL *edl = get_edl();
559         if( edl && !EQUIV(edl_length, 0) ) {
560                 double preview_start = edl->local_session->preview_start;
561                 double preview_end = edl->local_session->preview_end;
562                 if( preview_end < 0 || preview_end > edl_length )
563                         preview_end = edl_length;
564                 if( preview_end >= preview_start ) {
565                         x1 = (int)(preview_start / time_per_pixel);
566                         x2 = (int)(preview_end / time_per_pixel);
567                 }
568         }
569         return 0;
570 }
571
572
573 int TimeBar::test_preview(int buttonpress)
574 {
575         int result = 0;
576
577
578         if( get_edl() && cursor_inside() && buttonpress >= 0 ) {
579                 int x1, x2, x = get_relative_cursor_x();
580                 get_preview_pixels(x1, x2);
581 //printf("TimeBar::test_preview %d %d %d\n", x1, x2, x);
582 // Inside left handle
583                 if( x >= x1 - HANDLE_W && x < x1 + HANDLE_W &&
584 // Ignore left handle if both handles are up against the left side
585                     x2 > HANDLE_W ) {
586                         if( buttonpress ) {
587                                 current_operation = TIMEBAR_DRAG_LEFT;
588                                 start_position = get_edl()->local_session->preview_start;
589                                 start_cursor_x = x;
590                         }
591                         else if( get_cursor() != LEFT_CURSOR )
592                                 set_cursor(LEFT_CURSOR, 0, 1);
593                         result = 1;
594                 }
595 // Inside right handle
596                 else if( x >= x2 - HANDLE_W && x < x2 + HANDLE_W &&
597 // Ignore right handle if both handles are up against the right side
598                     x1 < get_w() - HANDLE_W ) {
599                         if( buttonpress ) {
600                                 current_operation = TIMEBAR_DRAG_RIGHT;
601                                 start_position = get_edl()->local_session->preview_end;
602                                 if( start_position < 0 || start_position > edl_length )
603                                         start_position = edl_length;
604                                 start_cursor_x = x;
605                         }
606                         else if( get_cursor() != RIGHT_CURSOR )
607                                 set_cursor(RIGHT_CURSOR, 0, 1);
608                         result = 1;
609                 }
610 // Inside preview
611                 else if( get_button_down() && get_buttonpress() == 3 &&
612                     x >= x1 && x < x2 ) {
613                         if( buttonpress ) {
614                                 current_operation = TIMEBAR_DRAG_CENTER;
615                                 starting_start_position = get_edl()->local_session->preview_start;
616                                 starting_end_position = get_edl()->local_session->preview_end;
617                                 if( starting_end_position < 0 || starting_end_position > edl_length )
618                                         starting_end_position = edl_length;
619                                 start_cursor_x = x;
620                         }
621                         if( get_cursor() != HSEPARATE_CURSOR )
622                                 set_cursor(HSEPARATE_CURSOR, 0, 1);
623                         result = 1;
624                 }
625         }
626
627         if( !result && get_cursor() != ARROW_CURSOR )
628                 set_cursor(ARROW_CURSOR, 0, 1);
629
630
631         return result;
632 }
633
634 int TimeBar::move_preview(int &redraw)
635 {
636         int result = 0, x = get_relative_cursor_x();
637         switch( current_operation ) {
638         case TIMEBAR_DRAG_LEFT: {
639                 get_edl()->local_session->preview_start =
640                         start_position + time_per_pixel * (x - start_cursor_x);
641                 double preview_end = get_edl()->local_session->preview_end;
642                 if( preview_end < 0 || preview_end > edl_length )
643                         preview_end = get_edl()->local_session->preview_end = edl_length;
644                 CLAMP(get_edl()->local_session->preview_start, 0, preview_end);
645                 result = 1;
646                 break; }
647         case TIMEBAR_DRAG_RIGHT: {
648                 double preview_end = get_edl()->local_session->preview_end =
649                         start_position + time_per_pixel * (x - start_cursor_x);
650                 double preview_start = get_edl()->local_session->preview_start;
651                 if( preview_end >= edl_length && !preview_start ) {
652                         get_edl()->local_session->preview_end = -1;
653                         if( preview_start > preview_end )
654                                 preview_start = get_edl()->local_session->preview_start = preview_end;
655                 }
656                 else
657                         CLAMP(get_edl()->local_session->preview_end, preview_start, edl_length);
658                 result = 1;
659                 break; }
660         case TIMEBAR_DRAG_CENTER: {
661                 double dt = time_per_pixel * (x - start_cursor_x);
662                 get_edl()->local_session->preview_start = starting_start_position + dt;
663                 get_edl()->local_session->preview_end = starting_end_position + dt;
664                 if( get_edl()->local_session->preview_start < 0 ) {
665                         get_edl()->local_session->preview_end -= get_edl()->local_session->preview_start;
666                         get_edl()->local_session->preview_start = 0;
667                 }
668                 else
669                 if( get_edl()->local_session->preview_end > edl_length ) {
670                         get_edl()->local_session->preview_start -= get_edl()->local_session->preview_end - edl_length;
671                         get_edl()->local_session->preview_end = edl_length;
672                 }
673                 result = 1;
674                 break; }
675         }
676
677 //printf("TimeBar::move_preview %d %d\n", __LINE__, current_operation);
678
679         if( result ) {
680                 update_preview();
681                 redraw = 1;
682         }
683 //printf("TimeBar::move_preview %d %d\n", __LINE__, current_operation);
684
685         return result;
686 }
687
688 void TimeBar::update_preview()
689 {
690 }
691
692 int TimeBar::samplemovement()
693 {
694         return 0;
695 }
696
697 void TimeBar::stop_playback()
698 {
699 }
700
701 int TimeBar::button_press_event()
702 {
703         int result = 0;
704         if( is_event_win() && cursor_above() ) {
705                 if( has_preview() && get_buttonpress() == 3 ) {
706                         result = test_preview(1);
707                 }
708 // Change time format
709                 else if( ctrl_down() ) {
710                         if( get_buttonpress() == 1 )
711                                 mwindow->next_time_format();
712                         else
713                         if( get_buttonpress() == 2 )
714                                 mwindow->prev_time_format();
715                         result = 1;
716                 }
717                 else if( get_buttonpress() == 1 ) {
718                         stop_playback();
719
720 // Select region between two labels
721                         if( !is_vwindow() && get_double_click() ) {
722                                 int x = get_relative_cursor_x();
723                                 double position = pixel_to_position(x);
724 // Test labels
725                                 select_region(position);
726                         }
727                         else {
728
729 // Reposition highlight cursor
730                                 update_cursor();
731                                 current_operation = TIMEBAR_DRAG;
732                                 activate_timeline();
733                         }
734                         result = 1;
735                 }
736         }
737         return result;
738 }
739
740 void TimeBar::activate_timeline()
741 {
742         mwindow->gui->activate_timeline();
743 }
744
745 int TimeBar::cursor_motion_event()
746 {
747         int result = 0;
748         int redraw = 0;
749
750 //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation);
751         switch( current_operation )
752         {
753                 case TIMEBAR_DRAG:
754                 {
755                         update_cursor();
756                         handle_mwindow_drag();
757                         result = 1;
758 //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation);
759                         break;
760                 }
761
762
763                 case TIMEBAR_DRAG_LEFT:
764                 case TIMEBAR_DRAG_RIGHT:
765                 case TIMEBAR_DRAG_CENTER:
766                         if( has_preview() )
767                                 result = move_preview(redraw);
768                         break;
769
770                 default:
771                         if( cursor_above() ) {
772                                 highlighted = 1;
773                                 redraw = 1;
774                         }
775
776 //printf("TimeBar::cursor_motion_event 20\n");
777                         if( has_preview() )
778                                 result = test_preview(0);
779 //printf("TimeBar::cursor_motion_event 30\n");
780                         break;
781         }
782
783
784 //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation);
785         if( redraw ) {
786                 update(1);
787         }
788 //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation);
789
790         return result;
791 }
792
793 int TimeBar::cursor_leave_event()
794 {
795         if( highlighted ) {
796                 highlighted = 0;
797                 update(1);
798         }
799         return 0;
800 }
801
802 int TimeBar::button_release_event()
803 {
804 //printf("TimeBar::button_release_event %d %d\n", __LINE__, current_operation);
805         int result = 0;
806         int need_redraw = 0;
807         switch( current_operation )
808         {
809                 case TIMEBAR_DRAG:
810                         mwindow->gui->get_focused_pane()->canvas->stop_dragscroll();
811                         current_operation = TIMEBAR_NONE;
812                         need_redraw = 1;
813                         result = 1;
814                         break;
815
816                 default:
817                         if( current_operation != TIMEBAR_NONE ) {
818                                 current_operation = TIMEBAR_NONE;
819                                 result = 1;
820                         }
821                         break;
822         }
823
824         if( (!cursor_above() && highlighted) || need_redraw ) {
825                 highlighted = 0;
826                 update(1);
827         }
828
829         return result;
830 }
831
832 // Update the selection cursor during a dragging operation
833 void TimeBar::update_cursor()
834 {
835 }
836
837 void TimeBar::handle_mwindow_drag()
838 {
839 }
840
841 int TimeBar::select_region(double position)
842 {
843         Label *start = 0, *end = 0, *current;
844         for( current = get_edl()->labels->first; current; current = NEXT ) {
845                 if( current->position > position ) {
846                         end = current;
847                         break;
848                 }
849         }
850
851         for( current = get_edl()->labels->last ; current; current = PREVIOUS ) {
852                 if( current->position <= position ) {
853                         start = current;
854                         break;
855                 }
856         }
857
858 // Select region
859         if( end != start ) {
860                 if( !start )
861                         get_edl()->local_session->set_selectionstart(0);
862                 else
863                         get_edl()->local_session->set_selectionstart(start->position);
864
865                 if( !end )
866                         get_edl()->local_session->set_selectionend(get_edl()->tracks->total_length());
867                 else
868                         get_edl()->local_session->set_selectionend(end->position);
869         }
870         else
871         if( end || start ) {
872                 get_edl()->local_session->set_selectionstart(start->position);
873                 get_edl()->local_session->set_selectionend(start->position);
874         }
875
876 // Que the CWindow
877         mwindow->cwindow->gui->lock_window("TimeBar::select_region");
878         mwindow->cwindow->update(1, 0, 0);
879         mwindow->cwindow->gui->unlock_window();
880         mwindow->gui->lock_window("TimeBar::select_region");
881         mwindow->gui->hide_cursor(0);
882         mwindow->gui->draw_cursor(1);
883         mwindow->gui->flash_canvas(0);
884         mwindow->gui->activate_timeline();
885         mwindow->gui->zoombar->update();
886         mwindow->gui->unlock_window();
887         update_highlights();
888         return 0;
889 }
890
891
892
893
894 int TimeBar::delete_arrows()
895 {
896         return 0;
897 }
898
899 double TimeBar::test_highlight()
900 {
901         return -1;
902 }
903
904