Considerable re-work to allow scrolling of the checkbutton area of the dialogue....
[ardour.git] / gtk2_ardour / editor_canvas.cc
1 /*
2     Copyright (C) 2005 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <libgnomecanvasmm/init.h>
21 #include <jack/types.h>
22 #include <gtkmm2ext/utils.h>
23
24 #include <ardour/audioregion.h>
25 #include <ardour/profile.h>
26
27 #include "ardour_ui.h"
28 #include "editor.h"
29 #include "waveview.h"
30 #include "simplerect.h"
31 #include "simpleline.h"
32 #include "waveview_p.h"
33 #include "simplerect_p.h"
34 #include "simpleline_p.h"
35 #include "canvas_impl.h"
36 #include "editing.h"
37 #include "rgb_macros.h"
38 #include "utils.h"
39 #include "time_axis_view.h"
40 #include "audio_time_axis.h"
41
42 #ifdef WITH_CMT
43 #include "imageframe.h"
44 #include "imageframe_p.h"
45 #endif
46
47 #include "i18n.h"
48
49 using namespace std;
50 using namespace sigc;
51 using namespace ARDOUR;
52 using namespace PBD;
53 using namespace Gtk;
54 using namespace Glib;
55 using namespace Gtkmm2ext;
56 using namespace Editing;
57
58 /* XXX this is a hack. it ought to be the maximum value of an nframes_t */
59
60 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
61
62 extern "C"
63 {
64
65 GType gnome_canvas_simpleline_get_type(void);
66 GType gnome_canvas_simplerect_get_type(void);
67 GType gnome_canvas_waveview_get_type(void);
68
69 #ifdef WITH_CMT
70 GType gnome_canvas_imageframe_get_type(void);
71 #endif
72
73 }
74
75 static void ardour_canvas_type_init() 
76 {
77         // Map gtypes to gtkmm wrapper-creation functions:
78         
79         Glib::wrap_register(gnome_canvas_simpleline_get_type(), &Gnome::Canvas::SimpleLine_Class::wrap_new);
80         Glib::wrap_register(gnome_canvas_simplerect_get_type(), &Gnome::Canvas::SimpleRect_Class::wrap_new);
81         Glib::wrap_register(gnome_canvas_waveview_get_type(), &Gnome::Canvas::WaveView_Class::wrap_new);
82
83 #ifdef WITH_CMT
84         Glib::wrap_register(gnome_canvas_imageframe_get_type(), &Gnome::Canvas::ImageFrame_Class::wrap_new);
85 #endif
86         
87         // Register the gtkmm gtypes:
88
89         (void) Gnome::Canvas::WaveView::get_type();
90         (void) Gnome::Canvas::SimpleLine::get_type();
91         (void) Gnome::Canvas::SimpleRect::get_type();
92         
93 #ifdef WITH_CMT
94         (void) Gnome::Canvas::ImageFrame::get_type();
95 #endif
96
97
98 void
99 Editor::initialize_canvas ()
100 {
101         ArdourCanvas::init ();
102         ardour_canvas_type_init ();
103
104         /* don't try to center the canvas */
105
106         track_canvas.set_center_scroll_region (false);
107         track_canvas.set_dither         (Gdk::RGB_DITHER_NONE);
108
109         /* need to handle 4 specific types of events as catch-alls */
110
111         track_canvas.signal_scroll_event().connect (mem_fun (*this, &Editor::track_canvas_scroll_event));
112         track_canvas.signal_motion_notify_event().connect (mem_fun (*this, &Editor::track_canvas_motion_notify_event));
113         track_canvas.signal_button_press_event().connect (mem_fun (*this, &Editor::track_canvas_button_press_event));
114         track_canvas.signal_button_release_event().connect (mem_fun (*this, &Editor::track_canvas_button_release_event));
115
116         track_canvas.set_name ("EditorMainCanvas");
117         track_canvas.add_events (Gdk::POINTER_MOTION_HINT_MASK|Gdk::SCROLL_MASK);
118         track_canvas.signal_leave_notify_event().connect (mem_fun(*this, &Editor::left_track_canvas));
119         track_canvas.set_flags (CAN_FOCUS);
120
121         /* set up drag-n-drop */
122
123         vector<TargetEntry> target_table;
124         
125         // Drag-N-Drop from the region list can generate this target
126         target_table.push_back (TargetEntry ("regions"));
127
128         target_table.push_back (TargetEntry ("text/plain"));
129         target_table.push_back (TargetEntry ("text/uri-list"));
130         target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
131
132         track_canvas.drag_dest_set (target_table);
133         track_canvas.signal_drag_data_received().connect (mem_fun(*this, &Editor::track_canvas_drag_data_received));
134
135         /* stuff for the verbose canvas cursor */
136
137         Pango::FontDescription* font = get_font_for_style (N_("VerboseCanvasCursor"));
138
139         verbose_canvas_cursor = new ArdourCanvas::Text (*track_canvas.root());
140         verbose_canvas_cursor->property_font_desc() = *font;
141         verbose_canvas_cursor->property_anchor() = ANCHOR_NW;
142         
143         delete font;
144
145         verbose_cursor_visible = false;
146         
147         if (Profile->get_sae()) {
148                 Image img (::get_icon (X_("saelogo")));
149                 logo_item = new ArdourCanvas::Pixbuf (*track_canvas.root(), 0.0, 0.0, img.get_pixbuf());
150                 // logo_item->property_height_in_pixels() = true;
151                 // logo_item->property_width_in_pixels() = true;
152                 // logo_item->property_height_set() = true;
153                 // logo_item->property_width_set() = true;
154                 logo_item->show ();
155         }
156         
157         /* a group to hold time (measure) lines */
158         
159         time_line_group = new ArdourCanvas::Group (*track_canvas.root(), 0.0, 0.0);
160         tempo_lines = new TempoLines(track_canvas, time_line_group);
161         cursor_group = new ArdourCanvas::Group (*track_canvas.root(), 0.0, 0.0);
162         time_canvas.set_name ("EditorTimeCanvas");
163         time_canvas.add_events (Gdk::POINTER_MOTION_HINT_MASK);
164         time_canvas.set_flags (CAN_FOCUS);
165         time_canvas.set_center_scroll_region (false);
166         time_canvas.set_dither          (Gdk::RGB_DITHER_NONE);
167         
168         marker_time_line_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, 0.0);
169         marker_tempo_lines = new TempoLines(time_canvas, marker_time_line_group);
170         
171         meter_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, 0.0);
172         tempo_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, timebar_height);
173         marker_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, timebar_height * 2.0);
174         range_marker_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, timebar_height * 3.0);
175         transport_marker_group = new ArdourCanvas::Group (*time_canvas.root(), 0.0, timebar_height * 4.0);
176         
177         tempo_bar = new ArdourCanvas::SimpleRect (*tempo_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
178         tempo_bar->property_outline_what() = (0x1 | 0x8);
179         tempo_bar->property_outline_pixels() = 1;
180         
181         meter_bar = new ArdourCanvas::SimpleRect (*meter_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
182         meter_bar->property_outline_what() = (0x1 | 0x8);
183         meter_bar->property_outline_pixels() = 1;
184         
185         marker_bar = new ArdourCanvas::SimpleRect (*marker_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
186         marker_bar->property_outline_what() = (0x1 | 0x8);
187         marker_bar->property_outline_pixels() = 1;
188         
189         range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
190         range_marker_bar->property_outline_what() = (0x1 | 0x8);
191         range_marker_bar->property_outline_pixels() = 1;
192         
193         transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
194         transport_marker_bar->property_outline_what() = (0x1 | 0x8);
195         transport_marker_bar->property_outline_pixels() = 1;
196
197         range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
198         range_bar_drag_rect->property_outline_pixels() = 0;
199         range_bar_drag_rect->hide ();
200         
201         transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
202         transport_bar_drag_rect->property_outline_pixels() = 0;
203         transport_bar_drag_rect->hide ();
204         
205         marker_drag_line_points.push_back(Gnome::Art::Point(0.0, 0.0));
206         marker_drag_line_points.push_back(Gnome::Art::Point(0.0, 0.0));
207
208         marker_drag_line = new ArdourCanvas::Line (*track_canvas.root());
209         marker_drag_line->property_width_pixels() = 1;
210         marker_drag_line->property_points() = marker_drag_line_points;
211         marker_drag_line->hide();
212
213         range_marker_drag_rect = new ArdourCanvas::SimpleRect (*track_canvas.root(), 0.0, 0.0, 0.0, 0.0);
214         range_marker_drag_rect->hide ();
215         
216         transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, 0.0);
217         transport_loop_range_rect->property_outline_pixels() = 1;
218         transport_loop_range_rect->hide();
219
220         transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, 0.0);
221         transport_punch_range_rect->property_outline_pixels() = 0;
222         transport_punch_range_rect->hide();
223         
224         transport_loop_range_rect->lower_to_bottom (); // loop on the bottom
225
226         transport_punchin_line = new ArdourCanvas::SimpleLine (*time_line_group);
227         transport_punchin_line->property_x1() = 0.0;
228         transport_punchin_line->property_y1() = 0.0;
229         transport_punchin_line->property_x2() = 0.0;
230         transport_punchin_line->property_y2() = 0.0;
231         transport_punchin_line->hide ();
232         
233         transport_punchout_line  = new ArdourCanvas::SimpleLine (*time_line_group);
234         transport_punchout_line->property_x1() = 0.0;
235         transport_punchout_line->property_y1() = 0.0;
236         transport_punchout_line->property_x2() = 0.0;
237         transport_punchout_line->property_y2() = 0.0;
238         transport_punchout_line->hide();
239         
240         // used to show zoom mode active zooming
241         zoom_rect = new ArdourCanvas::SimpleRect (*track_canvas.root(), 0.0, 0.0, 0.0, 0.0);
242         zoom_rect->property_outline_pixels() = 1;
243         zoom_rect->hide();
244         
245         zoom_rect->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
246         
247         // used as rubberband rect
248         rubberband_rect = new ArdourCanvas::SimpleRect (*track_canvas.root(), 0.0, 0.0, 0.0, 0.0);
249         rubberband_rect->property_outline_pixels() = 1;
250         rubberband_rect->hide();
251         
252         tempo_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
253         meter_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
254         marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
255         range_marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
256         transport_marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
257         
258         ZoomChanged.connect (bind (mem_fun(*this, &Editor::update_loop_range_view), false));
259         ZoomChanged.connect (bind (mem_fun(*this, &Editor::update_punch_range_view), false));
260         
261         double time_height = timebar_height * 5;
262         double time_width = FLT_MAX/frames_per_unit;
263         time_canvas.set_scroll_region(0.0, 0.0, time_width, time_height);
264
265         edit_cursor = new Cursor (*this, &Editor::canvas_edit_cursor_event);
266         playhead_cursor = new Cursor (*this, &Editor::canvas_playhead_cursor_event);
267
268         initial_ruler_update_required = true;
269         track_canvas.signal_size_allocate().connect (mem_fun(*this, &Editor::track_canvas_allocate));
270
271         if (logo_item) {
272                 logo_item->lower_to_bottom ();
273         }
274
275         ColorsChanged.connect (mem_fun (*this, &Editor::color_handler));
276         color_handler();
277
278 }
279
280 void
281 Editor::track_canvas_allocate (Gtk::Allocation alloc)
282 {
283         canvas_allocation = alloc;
284
285         if (!initial_ruler_update_required) {
286                 if (!canvas_idle_queued) {
287                         /* call this first so that we do stuff before any pending redraw */
288                         Glib::signal_idle().connect (mem_fun (*this, &Editor::track_canvas_size_allocated), false);
289                         canvas_idle_queued = true;
290                 }
291                 return;
292         } 
293
294         initial_ruler_update_required = false;
295         
296         track_canvas_size_allocated ();
297 }
298
299 bool
300 Editor::track_canvas_size_allocated ()
301 {
302         if (canvas_idle_queued) {
303                 canvas_idle_queued = false;
304         }
305
306         canvas_width = canvas_allocation.get_width();
307         canvas_height = canvas_allocation.get_height();
308
309         full_canvas_height = canvas_height;
310
311         if (session) {
312                 TrackViewList::iterator i;
313                 double height = 0;
314
315                 for (i = track_views.begin(); i != track_views.end(); ++i) {
316                         if ((*i)->control_parent) {
317                                 height += (*i)->effective_height;
318                         }
319                 }
320                 
321                 full_canvas_height = height;
322         }
323
324         zoom_range_clock.set ((nframes_t) floor ((canvas_width * frames_per_unit)));
325         edit_cursor->set_position (edit_cursor->current_frame);
326         playhead_cursor->set_position (playhead_cursor->current_frame);
327
328         reset_hscrollbar_stepping ();
329         reset_scrolling_region ();
330
331         if (edit_cursor) edit_cursor->set_length (canvas_height);
332         if (playhead_cursor) playhead_cursor->set_length (canvas_height);
333
334         if (marker_drag_line) {
335                 marker_drag_line_points.back().set_y(canvas_height);
336                 marker_drag_line->property_points() = marker_drag_line_points;
337         }
338
339         if (range_marker_drag_rect) {
340                 range_marker_drag_rect->property_y1() = 0.0;
341                 range_marker_drag_rect->property_y2() = canvas_height;
342         }
343
344         if (transport_loop_range_rect) {
345                 transport_loop_range_rect->property_y1() = 0.0;
346                 transport_loop_range_rect->property_y2() = canvas_height;
347         }
348
349         if (transport_punch_range_rect) {
350                 transport_punch_range_rect->property_y1() = 0.0;
351                 transport_punch_range_rect->property_y2() = canvas_height;
352         }
353
354         if (transport_punchin_line) {
355                 transport_punchin_line->property_y1() = 0.0;
356                 transport_punchin_line->property_y2() = canvas_height;
357         }
358
359         if (transport_punchout_line) {
360                 transport_punchout_line->property_y1() = 0.0;
361                 transport_punchout_line->property_y2() = canvas_height;
362         }
363                 
364         update_fixed_rulers();
365         redisplay_tempo (true);
366
367         if (logo_item) {
368                 // logo_item->property_height() = canvas_height;
369                 // logo_item->property_width() = canvas_width;
370         }
371         
372         Resized (); /* EMIT_SIGNAL */
373
374         return false;
375 }
376
377 void
378 Editor::reset_scrolling_region (Gtk::Allocation* alloc)
379 {
380         TreeModel::Children rows = route_display_model->children();
381         TreeModel::Children::iterator i;
382         double pos;
383
384         for (pos = 0, i = rows.begin(); i != rows.end(); ++i) {
385                 TimeAxisView *tv = (*i)[route_display_columns.tv];
386                 if (tv != 0 && !tv->hidden()) {
387                         pos += tv->effective_height;
388                 }
389         }
390
391         double last_canvas_unit =  last_canvas_frame / frames_per_unit;
392
393         track_canvas.set_scroll_region (0.0, 0.0, max (last_canvas_unit, canvas_width), pos);
394
395         // XXX what is the correct height value for the time canvas ? this overstates it
396         time_canvas.set_scroll_region ( 0.0, 0.0, max (last_canvas_unit, canvas_width), canvas_height);
397
398         controls_layout.queue_resize();
399 }
400
401 void
402 Editor::controls_layout_size_request (Requisition* req)
403 {
404         TreeModel::Children rows = route_display_model->children();
405         TreeModel::Children::iterator i;
406         double pos;
407
408         for (pos = 0, i = rows.begin(); i != rows.end(); ++i) {
409                 TimeAxisView *tv = (*i)[route_display_columns.tv];
410                 if (tv != 0) {
411                         pos += tv->effective_height;
412                 }
413         }
414
415         RefPtr<Gdk::Screen> screen = get_screen();
416
417         if (!screen) {
418                 screen = Gdk::Screen::get_default();
419         }
420
421         /* never let the width of the controls area shrink horizontally */
422
423         edit_controls_vbox.check_resize();
424
425         req->width = max (edit_controls_vbox.get_width(),  controls_layout.get_width());
426         
427         /* don't get too big. the fudge factors here are just guesses */
428         
429         req->width = min (req->width, screen->get_width() - 300);
430         req->height = min ((gint) pos, (screen->get_height() - 400));
431
432         /* this one is important: it determines how big the layout thinks it really is, as 
433            opposed to what it displays on the screen
434         */
435
436         controls_layout.set_size (req->width, (gint) pos);
437 }
438
439 bool
440 Editor::track_canvas_map_handler (GdkEventAny* ev)
441 {
442         track_canvas.get_window()->set_cursor (*current_canvas_cursor);
443         return false;
444 }
445
446 bool
447 Editor::time_canvas_map_handler (GdkEventAny* ev)
448 {
449         time_canvas.get_window()->set_cursor (*timebar_cursor);
450         return false;
451 }
452
453 void  
454 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
455                                          int x, int y, 
456                                          const SelectionData& data,
457                                          guint info, guint time)
458 {
459         if (data.get_target() == "regions") {
460                 drop_regions (context, x, y, data, info, time);
461         } else {
462                 drop_paths (context, x, y, data, info, time);
463         }
464 }
465
466 void
467 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
468                     int x, int y, 
469                     const SelectionData& data,
470                     guint info, guint time)
471 {
472         TimeAxisView* tvp;
473         RouteTimeAxisView* tv;
474         double cy;
475         vector<ustring> paths;
476         string spath;
477         GdkEvent ev;
478         nframes64_t frame;
479
480         if (convert_drop_to_paths (paths, context, x, y, data, info, time)) {
481                 goto out;
482         }
483
484         /* D-n-D coordinates are window-relative, so convert to "world" coordinates
485          */
486
487         double wx;
488         double wy;
489
490         track_canvas.window_to_world (x, y, wx, wy);
491         wx += horizontal_adjustment.get_value();
492         wy += vertical_adjustment.get_value();
493         
494         ev.type = GDK_BUTTON_RELEASE;
495         ev.button.x = wx;
496         ev.button.y = wy;
497
498         frame = event_frame (&ev, 0, &cy);
499
500         snap_to (frame);
501
502         if ((tvp = trackview_by_y_position (cy)) == 0) {
503
504                 /* drop onto canvas background: create new tracks */
505
506                 do_embed (paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
507                 
508         } else if ((tv = dynamic_cast<RouteTimeAxisView*>(tvp)) != 0) {
509
510                 /* check that its an audio track, not a bus */
511                 
512                 /* check that its an audio track, not a bus */
513                 
514                 if (tv->get_diskstream()) {
515                         /* select the track, then embed */
516                         selection->set (tv);
517                         do_embed (paths, Editing::ImportDistinctFiles, ImportToTrack, frame);
518                 }
519         }
520
521   out:
522         context->drag_finish (true, false, time);
523 }
524
525 void
526 Editor::drop_regions (const RefPtr<Gdk::DragContext>& context,
527                       int x, int y, 
528                       const SelectionData& data,
529                       guint info, guint time)
530 {
531         const SerializedObjectPointers<boost::shared_ptr<Region> >* sr = 
532                 reinterpret_cast<const SerializedObjectPointers<boost::shared_ptr<Region> > *> (data.get_data());
533
534         for (uint32_t i = 0; i < sr->cnt; ++i) {
535
536                 boost::shared_ptr<Region> r = sr->data[i];
537                 
538                 insert_region_list_drag (r, x, y);
539         }
540
541         context->drag_finish (true, false, time);
542 }
543
544 void
545 Editor::maybe_autoscroll (GdkEvent* event)
546 {
547         nframes_t rightmost_frame = leftmost_frame + current_page_frames();
548         nframes_t frame = drag_info.current_pointer_frame;
549         bool startit = false;
550
551         static int last_autoscroll_direction = 0;
552
553         if (frame > rightmost_frame) {
554
555                 if (rightmost_frame < max_frames) {
556                         autoscroll_direction = 1;
557                         startit = true;
558                 }
559
560         } else if (frame < leftmost_frame) {
561
562                 if (leftmost_frame > 0) {
563                         autoscroll_direction = -1;
564                         startit = true;
565                 }
566
567         } else {
568
569                 if (drag_info.last_pointer_frame > drag_info.current_pointer_frame) {
570                         autoscroll_direction = -1;
571                 } else {
572                         autoscroll_direction = 1;
573                 }
574         }
575
576
577         if ((autoscroll_direction != last_autoscroll_direction) || (leftmost_frame < frame < rightmost_frame)) {
578                 stop_canvas_autoscroll ();
579         }
580         
581         if (startit && autoscroll_timeout_tag < 0) {
582                 start_canvas_autoscroll (autoscroll_direction);
583         }
584
585         last_autoscroll_direction = autoscroll_direction;
586 }
587
588 gint
589 Editor::_autoscroll_canvas (void *arg)
590 {
591         return ((Editor *) arg)->autoscroll_canvas ();
592 }
593
594 bool
595 Editor::autoscroll_canvas ()
596 {
597         nframes_t new_frame;
598         nframes_t limit = max_frames - current_page_frames();
599         GdkEventMotion ev;
600         nframes_t target_frame;
601
602         if (autoscroll_direction < 0) {
603                 if (leftmost_frame < autoscroll_distance) {
604                         new_frame = 0;
605                 } else {
606                         new_frame = leftmost_frame - autoscroll_distance;
607                 }
608                 target_frame = drag_info.current_pointer_frame - autoscroll_distance;
609         } else {
610                 if (leftmost_frame > limit - autoscroll_distance) {
611                         new_frame = limit;
612                 } else {
613                         new_frame = leftmost_frame + autoscroll_distance;
614                 }
615                 target_frame = drag_info.current_pointer_frame + autoscroll_distance;
616         }
617
618         /* now fake a motion event to get the object that is being dragged to move too */
619
620         ev.type = GDK_MOTION_NOTIFY;
621         ev.state &= Gdk::BUTTON1_MASK;
622         ev.x = frame_to_unit (target_frame);
623         ev.y = drag_info.current_pointer_y;
624         motion_handler (drag_info.item, (GdkEvent*) &ev, drag_info.item_type, true);
625
626         if (new_frame == 0 || new_frame == limit) {
627                 /* we are done */
628                 return false;
629         }
630
631         autoscroll_cnt++;
632
633         if (autoscroll_cnt == 1) {
634
635                 /* connect the timeout so that we get called repeatedly */
636
637                 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
638                 return false;
639
640         } 
641
642         if (new_frame != leftmost_frame) {
643                 reset_x_origin (new_frame);
644         }
645
646         if (autoscroll_cnt == 50) { /* 0.5 seconds */
647                 
648                 /* after about a while, speed up a bit by changing the timeout interval */
649
650                 autoscroll_distance = (nframes_t) floor (current_page_frames()/30.0f);
651                 
652         } else if (autoscroll_cnt == 150) { /* 1.0 seconds */
653
654                 autoscroll_distance = (nframes_t) floor (current_page_frames()/20.0f);
655
656         } else if (autoscroll_cnt == 300) { /* 1.5 seconds */
657
658                 /* after about another while, speed up by increasing the shift per callback */
659
660                 autoscroll_distance =  (nframes_t) floor (current_page_frames()/10.0f);
661
662         } 
663
664         return true;
665 }
666
667 void
668 Editor::start_canvas_autoscroll (int dir)
669 {
670         if (!session || autoscroll_active) {
671                 return;
672         }
673
674         stop_canvas_autoscroll ();
675
676         autoscroll_active = true;
677         autoscroll_direction = dir;
678         autoscroll_distance = (nframes_t) floor (current_page_frames()/50.0);
679         autoscroll_cnt = 0;
680         
681         /* do it right now, which will start the repeated callbacks */
682
683         autoscroll_canvas ();
684 }
685
686 void
687 Editor::stop_canvas_autoscroll ()
688 {
689         if (autoscroll_timeout_tag >= 0) {
690                 g_source_remove (autoscroll_timeout_tag);
691                 autoscroll_timeout_tag = -1;
692         }
693
694         autoscroll_active = false;
695 }
696
697 gint
698 Editor::left_track_canvas (GdkEventCrossing *ev)
699 {
700         set_entered_track (0);
701         set_entered_regionview (0);
702         return FALSE;
703 }
704
705
706 void 
707 Editor::canvas_horizontally_scrolled ()
708 {
709         /* this is the core function that controls horizontal scrolling of the canvas. it is called
710            whenever the horizontal_adjustment emits its "value_changed" signal. it typically executes in an
711            idle handler, which is important because tempo_map_changed() should issue redraws immediately
712            and not defer them to an idle handler.
713         */
714
715         leftmost_frame = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
716         nframes_t rightmost_frame = leftmost_frame + current_page_frames ();
717         
718         if (rightmost_frame > last_canvas_frame) {
719                 last_canvas_frame = rightmost_frame;
720                 reset_scrolling_region ();
721         }
722         
723         if (logo_item) {
724                 logo_item->property_x() = horizontal_adjustment.get_value ();
725         }
726
727         update_fixed_rulers ();
728
729         redisplay_tempo (!_dragging_hscrollbar);
730 }
731
732 void
733 Editor::color_handler()
734 {
735         edit_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_EditCursor.get();
736         playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
737         verbose_canvas_cursor->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get();
738         
739         meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
740         meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
741
742         tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
743         tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
744
745         marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
746         marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
747
748         range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
749         range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
750
751         transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
752         transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
753
754         range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
755         range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
756
757         transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
758         transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
759
760         marker_drag_line->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerDragLine.get();
761
762         range_marker_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
763         range_marker_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
764
765         transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
766         transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
767
768         transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
769         transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
770
771         transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
772         transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
773
774         zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
775         zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
776
777         rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
778         rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
779
780         location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
781         location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
782         location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
783         location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
784         location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
785
786         refresh_location_display ();
787         redisplay_tempo (true);
788
789         if (session)
790                 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
791 }
792