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