2 Copyright (C) 2005 Paul Davis
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.
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.
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.
21 #include "gtk2ardour-config.h"
24 #include <libgnomecanvasmm/init.h>
25 #include <libgnomecanvasmm/pixbuf.h>
26 #include <jack/types.h>
28 #include "gtkmm2ext/utils.h"
30 #include "ardour/profile.h"
31 #include "ardour/rc_configuration.h"
33 #include "ardour_ui.h"
35 #include "global_signals.h"
37 #include "simplerect.h"
38 #include "simpleline.h"
39 #include "imageframe.h"
40 #include "waveview_p.h"
41 #include "simplerect_p.h"
42 #include "simpleline_p.h"
43 #include "imageframe_p.h"
44 #include "canvas_impl.h"
45 #include "canvas-noevent-text.h"
47 #include "rgb_macros.h"
49 #include "audio_time_axis.h"
50 #include "editor_drag.h"
51 #include "region_view.h"
52 #include "editor_group_tabs.h"
53 #include "editor_summary.h"
54 #include "video_timeline.h"
56 #include "editor_cursors.h"
57 #include "mouse_cursors.h"
58 #include "verbose_cursor.h"
63 using namespace ARDOUR;
67 using namespace Gtkmm2ext;
68 using namespace Editing;
70 /* XXX this is a hack. it ought to be the maximum value of an framepos_t */
72 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
77 GType gnome_canvas_simpleline_get_type(void);
78 GType gnome_canvas_simplerect_get_type(void);
79 GType gnome_canvas_waveview_get_type(void);
80 GType gnome_canvas_imageframe_get_type(void);
84 static void ardour_canvas_type_init()
86 // Map gtypes to gtkmm wrapper-creation functions:
88 Glib::wrap_register(gnome_canvas_simpleline_get_type(), &Gnome::Canvas::SimpleLine_Class::wrap_new);
89 Glib::wrap_register(gnome_canvas_simplerect_get_type(), &Gnome::Canvas::SimpleRect_Class::wrap_new);
90 Glib::wrap_register(gnome_canvas_waveview_get_type(), &Gnome::Canvas::WaveView_Class::wrap_new);
91 // Glib::wrap_register(gnome_canvas_imageframe_get_type(), &Gnome::Canvas::ImageFrame_Class::wrap_new);
93 // Register the gtkmm gtypes:
95 (void) Gnome::Canvas::WaveView::get_type();
96 (void) Gnome::Canvas::SimpleLine::get_type();
97 (void) Gnome::Canvas::SimpleRect::get_type();
98 (void) Gnome::Canvas::ImageFrame::get_type();
102 Editor::initialize_canvas ()
104 if (getenv ("ARDOUR_NON_AA_CANVAS")) {
105 track_canvas = new ArdourCanvas::Canvas ();
107 track_canvas = new ArdourCanvas::CanvasAA ();
110 track_canvas->set_can_default (true);
111 set_default (*track_canvas);
113 ArdourCanvas::init ();
114 ardour_canvas_type_init ();
116 /* don't try to center the canvas */
118 track_canvas->set_center_scroll_region (false);
119 track_canvas->set_dither (Gdk::RGB_DITHER_NONE);
121 gint phys_width = physical_screen_width (Glib::RefPtr<Gdk::Window>());
122 gint phys_height = physical_screen_height (Glib::RefPtr<Gdk::Window>());
124 _verbose_cursor = new VerboseCursor (this);
126 /* on the bottom, an image */
128 if (Profile->get_sae()) {
129 Image img (::get_icon (X_("saelogo")));
130 logo_item = new ArdourCanvas::Pixbuf (*track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
131 // logo_item->property_height_in_pixels() = true;
132 // logo_item->property_width_in_pixels() = true;
133 // logo_item->property_height_set() = true;
134 // logo_item->property_width_set() = true;
138 /* a group to hold time (measure) lines */
139 time_line_group = new ArdourCanvas::Group (*track_canvas->root());
142 /*XXX please don't laugh. this actually improves canvas performance on osx */
143 bogus_background_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, max_canvas_coordinate/3, phys_height);
144 bogus_background_rect->property_outline_pixels() = 0;
146 transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
147 transport_loop_range_rect->property_outline_pixels() = 1;
148 transport_loop_range_rect->hide();
150 transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
151 transport_punch_range_rect->property_outline_pixels() = 0;
152 transport_punch_range_rect->hide();
154 _background_group = new ArdourCanvas::Group (*track_canvas->root());
155 _master_group = new ArdourCanvas::Group (*track_canvas->root());
157 _trackview_group = new ArdourCanvas::Group (*_master_group);
158 _region_motion_group = new ArdourCanvas::Group (*_trackview_group);
160 meter_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
161 meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, phys_width, timebar_height - 1);
162 meter_bar->property_outline_pixels() = 1;
163 meter_bar->property_outline_what() = 0x8;
165 tempo_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
166 tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
167 tempo_bar->property_outline_pixels() = 1;
168 tempo_bar->property_outline_what() = 0x8;
170 range_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
171 range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
172 range_marker_bar->property_outline_pixels() = 1;
173 range_marker_bar->property_outline_what() = 0x8;
175 transport_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
176 transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
177 transport_marker_bar->property_outline_pixels() = 1;
178 transport_marker_bar->property_outline_what() = 0x8;
180 marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
181 marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
182 marker_bar->property_outline_pixels() = 1;
183 marker_bar->property_outline_what() = 0x8;
185 cd_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
186 cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
187 cd_marker_bar->property_outline_pixels() = 1;
188 cd_marker_bar->property_outline_what() = 0x8;
190 #ifdef WITH_VIDEOTIMELINE
191 videotl_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
192 if (Profile->get_sae()) {
193 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height - 1));
194 videotl_bar->property_outline_pixels() = 1;
196 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height));
197 videotl_bar->property_outline_pixels() = 0;
199 videotl_bar->property_outline_what() = (0x1 | 0x8);
200 ARDOUR_UI::instance()->video_timeline = new VideoTimeLine(this, videotl_bar_group, (timebar_height * videotl_bar_height));
203 timebar_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
204 cursor_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
206 meter_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 5.0);
207 tempo_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 4.0);
208 range_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 3.0);
209 transport_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 2.0);
210 marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height);
211 cd_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
212 #ifdef WITH_VIDEOTIMELINE
213 videotl_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
216 cd_marker_bar_drag_rect = new ArdourCanvas::SimpleRect (*cd_marker_group, 0.0, 0.0, 100, timebar_height);
217 cd_marker_bar_drag_rect->property_outline_pixels() = 0;
218 cd_marker_bar_drag_rect->hide ();
220 range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, 100, timebar_height);
221 range_bar_drag_rect->property_outline_pixels() = 0;
222 range_bar_drag_rect->hide ();
224 transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, 100, timebar_height);
225 transport_bar_drag_rect->property_outline_pixels() = 0;
226 transport_bar_drag_rect->hide ();
228 transport_punchin_line = new ArdourCanvas::SimpleLine (*_master_group);
229 transport_punchin_line->property_x1() = 0.0;
230 transport_punchin_line->property_y1() = 0.0;
231 transport_punchin_line->property_x2() = 0.0;
232 transport_punchin_line->property_y2() = phys_height;
233 transport_punchin_line->hide ();
235 transport_punchout_line = new ArdourCanvas::SimpleLine (*_master_group);
236 transport_punchout_line->property_x1() = 0.0;
237 transport_punchout_line->property_y1() = 0.0;
238 transport_punchout_line->property_x2() = 0.0;
239 transport_punchout_line->property_y2() = phys_height;
240 transport_punchout_line->hide();
242 // used to show zoom mode active zooming
243 zoom_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
244 zoom_rect->property_outline_pixels() = 1;
247 zoom_rect->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
249 // used as rubberband rect
250 rubberband_rect = new ArdourCanvas::SimpleRect (*_trackview_group, 0.0, 0.0, 0.0, 0.0);
252 rubberband_rect->property_outline_pixels() = 1;
253 rubberband_rect->hide();
255 tempo_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
256 meter_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
257 marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
258 cd_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
259 #ifdef WITH_VIDEOTIMELINE
260 videotl_bar_group->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
261 //videotl_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
263 range_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
264 transport_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
266 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
269 logo_item->lower_to_bottom ();
271 /* need to handle 4 specific types of events as catch-alls */
273 track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
274 track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
275 track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
276 track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
277 track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
278 track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
279 track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
281 track_canvas->set_name ("EditorMainCanvas");
282 track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
283 track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
284 track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
285 track_canvas->set_flags (CAN_FOCUS);
287 /* set up drag-n-drop */
289 vector<TargetEntry> target_table;
291 // Drag-N-Drop from the region list can generate this target
292 target_table.push_back (TargetEntry ("regions"));
294 target_table.push_back (TargetEntry ("text/plain"));
295 target_table.push_back (TargetEntry ("text/uri-list"));
296 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
298 track_canvas->drag_dest_set (target_table);
299 track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
301 track_canvas->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_allocate));
303 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
309 Editor::track_canvas_allocate (Gtk::Allocation alloc)
311 canvas_allocation = alloc;
312 track_canvas_size_allocated ();
316 Editor::track_canvas_size_allocated ()
318 bool height_changed = _canvas_height != canvas_allocation.get_height();
320 _canvas_width = canvas_allocation.get_width();
321 _canvas_height = canvas_allocation.get_height();
324 TrackViewList::iterator i;
326 for (i = track_views.begin(); i != track_views.end(); ++i) {
327 (*i)->clip_to_viewport ();
331 if (height_changed) {
332 if (playhead_cursor) {
333 playhead_cursor->set_length (_canvas_height);
336 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
337 i->second->canvas_height_set (_canvas_height);
340 vertical_adjustment.set_page_size (_canvas_height);
341 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
342 if ((vertical_adjustment.get_value() + _canvas_height) >= vertical_adjustment.get_upper()) {
344 We're increasing the size of the canvas while the bottom is visible.
345 We scroll down to keep in step with the controls layout.
347 vertical_adjustment.set_value (full_canvas_height - _canvas_height);
351 update_fixed_rulers();
352 redisplay_tempo (false);
353 _summary->set_overlays_dirty ();
359 Editor::reset_controls_layout_width ()
364 edit_controls_vbox.size_request (req);
367 if (_group_tabs->is_mapped()) {
368 _group_tabs->size_request (req);
372 /* the controls layout has no horizontal scrolling, its visible
373 width is always equal to the total width of its contents.
376 controls_layout.property_width() = w;
377 controls_layout.property_width_request() = w;
381 Editor::reset_controls_layout_height (int32_t h)
383 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
386 controls_layout.property_height() = h;
388 /* size request is set elsewhere, see ::track_canvas_allocate() */
392 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
394 if (current_canvas_cursor) {
395 set_canvas_cursor (current_canvas_cursor);
400 /** This is called when something is dropped onto the track canvas */
402 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
404 const SelectionData& data,
405 guint info, guint time)
407 if (data.get_target() == "regions") {
408 drop_regions (context, x, y, data, info, time);
410 drop_paths (context, x, y, data, info, time);
415 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
417 drop_paths_part_two (paths, frame, ypos, copy);
422 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
424 RouteTimeAxisView* tv;
426 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
427 if (tvp.first == 0) {
429 /* drop onto canvas background: create new tracks */
433 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
434 do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
436 do_embed (paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
439 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
441 /* check that its an audio track, not a bus */
444 /* select the track, then embed/import */
447 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
448 do_import (paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
450 do_embed (paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
457 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
459 const SelectionData& data,
460 guint info, guint time)
462 vector<string> paths;
469 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
471 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
474 track_canvas->window_to_world (x, y, wx, wy);
476 ev.type = GDK_BUTTON_RELEASE;
480 frame = event_frame (&ev, 0, &cy);
484 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
486 /* We are not allowed to call recursive main event loops from within
487 the main event loop with GTK/Quartz. Since import/embed wants
488 to push up a progress dialog, defer all this till we go idle.
490 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
492 drop_paths_part_two (paths, frame, cy, copy);
496 context->drag_finish (true, false, time);
499 /** If the editor window is arranged such that the edge of the trackview is right up
500 * against the edge of the screen, autoscroll will not work very well. In this situation,
501 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
502 * this is the distance at which that happens.
505 Editor::autoscroll_fudge_threshold () const
507 return current_page_frames() / 6;
510 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
511 * @param allow_vert true to allow vertical autoscroll, otherwise false.
512 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
513 * otherwise false, so we only want to autoscroll on the right of the canvas.
514 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
515 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
518 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
520 if (!Config->get_autoscroll_editor ()) {
524 bool startit = false;
526 /* Work out the distance between the right hand edge of the trackview and the edge of
527 the monitor that it is on.
530 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
531 Gdk::Rectangle window_rect;
532 gdk_window->get_frame_extents (window_rect);
534 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
535 Gdk::Rectangle root_rect;
536 screen->get_root_window()->get_frame_extents (root_rect);
538 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
540 framecnt_t distance = pixel_to_frame (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
541 if (_the_notebook.is_visible ()) {
542 distance += pixel_to_frame (editor_list.get_width());
545 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
546 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
548 double const ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
552 if (ty < canvas_timebars_vsize && moving_up && allow_vert) {
555 } else if (ty > _canvas_height && !moving_up && allow_vert) {
560 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
561 if (_autoscroll_fudging) {
562 rightmost_frame -= autoscroll_fudge_threshold ();
565 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
566 if (rightmost_frame < max_framepos && !moving_left) {
570 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
571 if (leftmost_frame > 0 && moving_left) {
577 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
578 stop_canvas_autoscroll ();
581 if (startit && autoscroll_timeout_tag < 0) {
582 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
585 last_autoscroll_x = autoscroll_x;
586 last_autoscroll_y = autoscroll_y;
590 Editor::_autoscroll_canvas (void *arg)
592 return ((Editor *) arg)->autoscroll_canvas ();
596 Editor::autoscroll_canvas ()
598 framepos_t new_frame;
599 framepos_t limit = max_framepos - current_page_frames();
604 if (autoscroll_x_distance != 0) {
606 if (autoscroll_x > 0) {
607 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
608 if (_autoscroll_fudging) {
609 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
611 } else if (autoscroll_x < 0) {
612 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
617 if (autoscroll_y_distance != 0) {
618 if (autoscroll_y > 0) {
619 autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
620 } else if (autoscroll_y < 0) {
622 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
626 if (autoscroll_x < 0) {
627 if (leftmost_frame < autoscroll_x_distance) {
630 new_frame = leftmost_frame - autoscroll_x_distance;
632 } else if (autoscroll_x > 0) {
633 if (leftmost_frame > limit - autoscroll_x_distance) {
636 new_frame = leftmost_frame + autoscroll_x_distance;
639 new_frame = leftmost_frame;
642 double vertical_pos = vertical_adjustment.get_value();
644 if (autoscroll_y < 0) {
646 if (vertical_pos < autoscroll_y_distance) {
649 new_pixel = vertical_pos - autoscroll_y_distance;
652 target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
653 target_pixel = max (target_pixel, 0.0);
655 } else if (autoscroll_y > 0) {
657 double top_of_bottom_of_canvas = full_canvas_height - _canvas_height;
659 if (vertical_pos > full_canvas_height - autoscroll_y_distance) {
660 new_pixel = full_canvas_height;
662 new_pixel = vertical_pos + autoscroll_y_distance;
665 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
667 target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
669 /* don't move to the full canvas height because the item will be invisible
670 (its top edge will line up with the bottom of the visible canvas.
673 target_pixel = min (target_pixel, full_canvas_height - 10);
676 target_pixel = _drags->current_pointer_y();
677 new_pixel = vertical_pos;
680 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
685 if (new_frame != leftmost_frame) {
686 reset_x_origin (new_frame);
689 vertical_adjustment.set_value (new_pixel);
693 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas->get_window();
695 Gdk::ModifierType mask;
696 canvas_window->get_pointer (x, y, mask);
697 ev.type = GDK_MOTION_NOTIFY;
698 ev.state = Gdk::BUTTON1_MASK;
702 motion_handler (0, (GdkEvent*) &ev, true);
706 if (autoscroll_cnt == 1) {
708 /* connect the timeout so that we get called repeatedly */
710 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
719 Editor::start_canvas_autoscroll (int dx, int dy)
721 if (!_session || autoscroll_active) {
725 stop_canvas_autoscroll ();
727 autoscroll_active = true;
730 autoscroll_x_distance = (framepos_t) floor (current_page_frames()/50.0);
731 autoscroll_y_distance = fabs (dy * 5); /* pixels */
734 /* do it right now, which will start the repeated callbacks */
736 autoscroll_canvas ();
740 Editor::stop_canvas_autoscroll ()
742 if (autoscroll_timeout_tag >= 0) {
743 g_source_remove (autoscroll_timeout_tag);
744 autoscroll_timeout_tag = -1;
747 autoscroll_active = false;
751 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
754 within_track_canvas = false;
755 //cerr << "left track canvas\n";
756 set_entered_track (0);
757 set_entered_regionview (0);
758 reset_canvas_action_sensitivity (false);
763 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
765 //cerr << "entered track canvas\n";
766 within_track_canvas = true;
767 reset_canvas_action_sensitivity (true);
772 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
774 double begin = tav.y_position();
776 double v = vertical_adjustment.get_value ();
778 if (begin < v || begin + tav.current_height() > v + _canvas_height - canvas_timebars_vsize) {
779 /* try to put the TimeAxisView roughly central */
780 if (begin >= _canvas_height/2.0) {
781 begin -= _canvas_height/2.0;
783 vertical_adjustment.set_value (begin);
788 Editor::tie_vertical_scrolling ()
790 scroll_canvas_vertically ();
792 /* this will do an immediate redraw */
794 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
796 if (pending_visual_change.idle_handler_id < 0) {
797 _summary->set_overlays_dirty ();
802 Editor::set_horizontal_position (double p)
804 /* horizontal scrolling only */
805 double x1, y1, x2, y2, x_delta;
806 _master_group->get_bounds (x1, y1, x2, y2);
808 x_delta = - (x1 + p);
810 _master_group->move (x_delta, 0);
811 timebar_group->move (x_delta, 0);
812 time_line_group->move (x_delta, 0);
813 cursor_group->move (x_delta, 0);
815 leftmost_frame = (framepos_t) floor (p * frames_per_unit);
817 update_fixed_rulers ();
818 redisplay_tempo (true);
820 if (pending_visual_change.idle_handler_id < 0) {
821 _summary->set_overlays_dirty ();
824 #ifdef WITH_VIDEOTIMELINE
825 update_video_timeline();
828 HorizontalPositionChanged (); /* EMIT SIGNAL */
831 if (!autoscroll_active && !_stationary_playhead) {
832 /* force rulers and canvas to move in lock step */
833 while (gtk_events_pending ()) {
834 gtk_main_iteration ();
841 Editor::scroll_canvas_vertically ()
843 /* vertical scrolling only */
847 y_delta = last_trackview_group_vertical_offset - get_trackview_group_vertical_offset ();
848 _trackview_group->move (0, y_delta);
849 _background_group->move (0, y_delta);
851 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
852 (*i)->clip_to_viewport ();
854 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
855 /* required to keep the controls_layout in lock step with the canvas group */
856 update_canvas_now ();
860 Editor::color_handler()
862 playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
863 _verbose_cursor->set_color (ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get());
865 meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
866 meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
868 tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
869 tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
871 marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
872 marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
874 cd_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CDMarkerBar.get();
875 cd_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
877 #ifdef WITH_VIDEOTIMELINE
878 videotl_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VideoBar.get();
879 videotl_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
882 range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
883 range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
885 transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
886 transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
888 cd_marker_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
889 cd_marker_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
891 range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
892 range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
894 transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
895 transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
897 transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
898 transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
900 transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
901 transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
903 transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
904 transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
906 zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
907 zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
909 rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
910 rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
912 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
913 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
914 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
915 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
916 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
918 refresh_location_display ();
920 redisplay_tempo (true);
923 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
928 Editor::flush_canvas ()
931 update_canvas_now ();
932 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);
937 Editor::update_canvas_now ()
939 /* GnomeCanvas has a bug whereby if its idle handler is not scheduled between
940 two calls to update_now, an assert will trip. This wrapper works around
941 that problem by only calling update_now if the assert will not trip.
943 I think the GC bug is due to the fact that its code will reset need_update
944 and need_redraw to FALSE without checking to see if an idle handler is scheduled.
945 If one is scheduled, GC should probably remove it.
948 GnomeCanvas* c = track_canvas->gobj ();
949 if (c->need_update || c->need_redraw) {
950 track_canvas->update_now ();
955 Editor::horizontal_position () const
957 return frame_to_unit (leftmost_frame);
961 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
964 current_canvas_cursor = cursor;
967 Glib::RefPtr<Gdk::Window> win = track_canvas->get_window();
970 track_canvas->get_window()->set_cursor (*cursor);
975 Editor::track_canvas_key_press (GdkEventKey*)
977 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
978 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
979 set_canvas_cursor (_cursors->zoom_out, true);
986 Editor::track_canvas_key_release (GdkEventKey*)
988 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
989 set_canvas_cursor (_cursors->zoom_in, true);