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"
32 #include "ardour/smf_source.h"
34 #include "ardour_ui.h"
36 #include "global_signals.h"
38 #include "simplerect.h"
39 #include "simpleline.h"
40 #include "waveview_p.h"
41 #include "simplerect_p.h"
42 #include "simpleline_p.h"
43 #include "canvas_impl.h"
44 #include "canvas-noevent-text.h"
46 #include "rgb_macros.h"
48 #include "audio_time_axis.h"
49 #include "editor_drag.h"
50 #include "region_view.h"
51 #include "editor_group_tabs.h"
52 #include "editor_summary.h"
53 #include "video_timeline.h"
55 #include "editor_cursors.h"
56 #include "mouse_cursors.h"
57 #include "verbose_cursor.h"
62 using namespace ARDOUR;
66 using namespace Gtkmm2ext;
67 using namespace Editing;
69 /* XXX this is a hack. it ought to be the maximum value of an framepos_t */
71 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
76 GType gnome_canvas_simpleline_get_type(void);
77 GType gnome_canvas_simplerect_get_type(void);
78 GType gnome_canvas_waveview_get_type(void);
79 GType gnome_canvas_imageframe_get_type(void);
83 static void ardour_canvas_type_init()
85 // Map gtypes to gtkmm wrapper-creation functions:
87 Glib::wrap_register(gnome_canvas_simpleline_get_type(), &Gnome::Canvas::SimpleLine_Class::wrap_new);
88 Glib::wrap_register(gnome_canvas_simplerect_get_type(), &Gnome::Canvas::SimpleRect_Class::wrap_new);
89 Glib::wrap_register(gnome_canvas_waveview_get_type(), &Gnome::Canvas::WaveView_Class::wrap_new);
91 // Register the gtkmm gtypes:
93 (void) Gnome::Canvas::WaveView::get_type();
94 (void) Gnome::Canvas::SimpleLine::get_type();
95 (void) Gnome::Canvas::SimpleRect::get_type();
99 Editor::initialize_canvas ()
101 if (getenv ("ARDOUR_NON_AA_CANVAS")) {
102 track_canvas = new ArdourCanvas::Canvas ();
104 track_canvas = new ArdourCanvas::CanvasAA ();
107 track_canvas->set_can_default (true);
108 set_default (*track_canvas);
110 ArdourCanvas::init ();
111 ardour_canvas_type_init ();
113 /* don't try to center the canvas */
115 track_canvas->set_center_scroll_region (false);
116 track_canvas->set_dither (Gdk::RGB_DITHER_NONE);
118 gint phys_width = physical_screen_width (Glib::RefPtr<Gdk::Window>());
119 gint phys_height = physical_screen_height (Glib::RefPtr<Gdk::Window>());
121 _verbose_cursor = new VerboseCursor (this);
123 /* on the bottom, an image */
125 if (Profile->get_sae()) {
126 Image img (::get_icon (X_("saelogo")));
127 logo_item = new ArdourCanvas::Pixbuf (*track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
128 // logo_item->property_height_in_pixels() = true;
129 // logo_item->property_width_in_pixels() = true;
130 // logo_item->property_height_set() = true;
131 // logo_item->property_width_set() = true;
135 /* a group to hold time (measure) lines */
136 time_line_group = new ArdourCanvas::Group (*track_canvas->root());
139 /*XXX please don't laugh. this actually improves canvas performance on osx */
140 bogus_background_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, max_canvas_coordinate/3, phys_height);
141 bogus_background_rect->property_outline_pixels() = 0;
143 transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
144 transport_loop_range_rect->property_outline_pixels() = 1;
145 transport_loop_range_rect->hide();
147 transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
148 transport_punch_range_rect->property_outline_pixels() = 0;
149 transport_punch_range_rect->hide();
151 _background_group = new ArdourCanvas::Group (*track_canvas->root());
152 _master_group = new ArdourCanvas::Group (*track_canvas->root());
154 _trackview_group = new ArdourCanvas::Group (*_master_group);
155 _region_motion_group = new ArdourCanvas::Group (*_trackview_group);
157 meter_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
158 meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, phys_width, timebar_height - 1);
159 meter_bar->property_outline_pixels() = 1;
160 meter_bar->property_outline_what() = 0x8;
162 tempo_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
163 tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
164 tempo_bar->property_outline_pixels() = 1;
165 tempo_bar->property_outline_what() = 0x8;
167 range_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
168 range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
169 range_marker_bar->property_outline_pixels() = 1;
170 range_marker_bar->property_outline_what() = 0x8;
172 transport_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
173 transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
174 transport_marker_bar->property_outline_pixels() = 1;
175 transport_marker_bar->property_outline_what() = 0x8;
177 marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
178 marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
179 marker_bar->property_outline_pixels() = 1;
180 marker_bar->property_outline_what() = 0x8;
182 cd_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
183 cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
184 cd_marker_bar->property_outline_pixels() = 1;
185 cd_marker_bar->property_outline_what() = 0x8;
187 videotl_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
188 if (Profile->get_sae()) {
189 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height - 1));
190 videotl_bar->property_outline_pixels() = 1;
192 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height));
193 videotl_bar->property_outline_pixels() = 0;
195 videotl_bar->property_outline_what() = (0x1 | 0x8);
196 ARDOUR_UI::instance()->video_timeline = new VideoTimeLine(this, videotl_bar_group, (timebar_height * videotl_bar_height));
198 timebar_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
199 cursor_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
201 meter_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 5.0);
202 tempo_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 4.0);
203 range_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 3.0);
204 transport_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 2.0);
205 marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height);
206 cd_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
207 videotl_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
209 cd_marker_bar_drag_rect = new ArdourCanvas::SimpleRect (*cd_marker_group, 0.0, 0.0, 100, timebar_height);
210 cd_marker_bar_drag_rect->property_outline_pixels() = 0;
211 cd_marker_bar_drag_rect->hide ();
213 range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, 100, timebar_height);
214 range_bar_drag_rect->property_outline_pixels() = 0;
215 range_bar_drag_rect->hide ();
217 transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, 100, timebar_height);
218 transport_bar_drag_rect->property_outline_pixels() = 0;
219 transport_bar_drag_rect->hide ();
221 transport_punchin_line = new ArdourCanvas::SimpleLine (*_master_group);
222 transport_punchin_line->property_x1() = 0.0;
223 transport_punchin_line->property_y1() = 0.0;
224 transport_punchin_line->property_x2() = 0.0;
225 transport_punchin_line->property_y2() = phys_height;
226 transport_punchin_line->hide ();
228 transport_punchout_line = new ArdourCanvas::SimpleLine (*_master_group);
229 transport_punchout_line->property_x1() = 0.0;
230 transport_punchout_line->property_y1() = 0.0;
231 transport_punchout_line->property_x2() = 0.0;
232 transport_punchout_line->property_y2() = phys_height;
233 transport_punchout_line->hide();
235 // used to show zoom mode active zooming
236 zoom_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
237 zoom_rect->property_outline_pixels() = 1;
240 zoom_rect->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
242 // used as rubberband rect
243 rubberband_rect = new ArdourCanvas::SimpleRect (*_trackview_group, 0.0, 0.0, 0.0, 0.0);
245 rubberband_rect->property_outline_pixels() = 1;
246 rubberband_rect->hide();
248 tempo_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
249 meter_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
250 marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
251 cd_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
252 videotl_bar_group->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
253 range_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
254 transport_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
256 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
259 logo_item->lower_to_bottom ();
261 /* need to handle 4 specific types of events as catch-alls */
263 track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
264 track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
265 track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
266 track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
267 track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
268 track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
269 track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
271 track_canvas->set_name ("EditorMainCanvas");
272 track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
273 track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
274 track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
275 track_canvas->set_flags (CAN_FOCUS);
277 /* set up drag-n-drop */
279 vector<TargetEntry> target_table;
281 // Drag-N-Drop from the region list can generate this target
282 target_table.push_back (TargetEntry ("regions"));
284 target_table.push_back (TargetEntry ("text/plain"));
285 target_table.push_back (TargetEntry ("text/uri-list"));
286 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
288 track_canvas->drag_dest_set (target_table);
289 track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
291 track_canvas->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_allocate));
293 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
299 Editor::track_canvas_allocate (Gtk::Allocation alloc)
301 canvas_allocation = alloc;
302 track_canvas_size_allocated ();
306 Editor::track_canvas_size_allocated ()
308 bool height_changed = _canvas_height != canvas_allocation.get_height();
310 _canvas_width = canvas_allocation.get_width();
311 _canvas_height = canvas_allocation.get_height();
314 TrackViewList::iterator i;
316 for (i = track_views.begin(); i != track_views.end(); ++i) {
317 (*i)->clip_to_viewport ();
321 if (height_changed) {
322 if (playhead_cursor) {
323 playhead_cursor->set_length (_canvas_height);
326 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
327 i->second->canvas_height_set (_canvas_height);
330 vertical_adjustment.set_page_size (_canvas_height);
331 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
332 if ((vertical_adjustment.get_value() + _canvas_height) >= vertical_adjustment.get_upper()) {
334 We're increasing the size of the canvas while the bottom is visible.
335 We scroll down to keep in step with the controls layout.
337 vertical_adjustment.set_value (full_canvas_height - _canvas_height);
341 update_fixed_rulers();
342 redisplay_tempo (false);
343 _summary->set_overlays_dirty ();
349 Editor::reset_controls_layout_width ()
354 edit_controls_vbox.size_request (req);
357 if (_group_tabs->is_mapped()) {
358 _group_tabs->size_request (req);
362 /* the controls layout has no horizontal scrolling, its visible
363 width is always equal to the total width of its contents.
366 controls_layout.property_width() = w;
367 controls_layout.property_width_request() = w;
371 Editor::reset_controls_layout_height (int32_t h)
373 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
376 controls_layout.property_height() = h;
378 /* size request is set elsewhere, see ::track_canvas_allocate() */
382 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
384 if (current_canvas_cursor) {
385 set_canvas_cursor (current_canvas_cursor);
390 /** This is called when something is dropped onto the track canvas */
392 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
394 const SelectionData& data,
395 guint info, guint time)
397 if (data.get_target() == "regions") {
398 drop_regions (context, x, y, data, info, time);
400 drop_paths (context, x, y, data, info, time);
405 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
407 drop_paths_part_two (paths, frame, ypos, copy);
412 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
414 RouteTimeAxisView* tv;
416 /* MIDI files must always be imported, because we consider them
417 * writable. So split paths into two vectors, and follow the import
418 * path on the MIDI part.
421 vector<string> midi_paths;
422 vector<string> audio_paths;
424 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
425 if (SMFSource::safe_midi_file_extension (*i)) {
426 midi_paths.push_back (*i);
428 audio_paths.push_back (*i);
433 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
434 if (tvp.first == 0) {
436 /* drop onto canvas background: create new tracks */
440 do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, frame);
442 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
443 do_import (audio_paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
445 do_embed (audio_paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
448 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
450 /* check that its a track, not a bus */
453 /* select the track, then embed/import */
456 do_import (midi_paths, Editing::ImportSerializeFiles, ImportToTrack, SrcBest, frame);
458 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
459 do_import (audio_paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
461 do_embed (audio_paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
468 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
470 const SelectionData& data,
471 guint info, guint time)
473 vector<string> paths;
480 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
482 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
485 track_canvas->window_to_world (x, y, wx, wy);
487 ev.type = GDK_BUTTON_RELEASE;
491 frame = event_frame (&ev, 0, &cy);
495 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
497 /* We are not allowed to call recursive main event loops from within
498 the main event loop with GTK/Quartz. Since import/embed wants
499 to push up a progress dialog, defer all this till we go idle.
501 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
503 drop_paths_part_two (paths, frame, cy, copy);
507 context->drag_finish (true, false, time);
510 /** If the editor window is arranged such that the edge of the trackview is right up
511 * against the edge of the screen, autoscroll will not work very well. In this situation,
512 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
513 * this is the distance at which that happens.
516 Editor::autoscroll_fudge_threshold () const
518 return current_page_frames() / 6;
521 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
522 * @param allow_vert true to allow vertical autoscroll, otherwise false.
523 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
524 * otherwise false, so we only want to autoscroll on the right of the canvas.
525 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
526 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
529 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
531 if (!Config->get_autoscroll_editor ()) {
535 bool startit = false;
537 /* Work out the distance between the right hand edge of the trackview and the edge of
538 the monitor that it is on.
541 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
542 Gdk::Rectangle window_rect;
543 gdk_window->get_frame_extents (window_rect);
545 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
546 Gdk::Rectangle root_rect;
547 screen->get_root_window()->get_frame_extents (root_rect);
549 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
551 framecnt_t distance = pixel_to_frame (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
552 if (_the_notebook.is_visible ()) {
553 distance += pixel_to_frame (editor_list.get_width());
556 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
557 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
559 double const ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
563 if (ty < canvas_timebars_vsize && moving_up && allow_vert) {
566 } else if (ty > _canvas_height && !moving_up && allow_vert) {
571 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
572 if (_autoscroll_fudging) {
573 rightmost_frame -= autoscroll_fudge_threshold ();
576 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
577 if (rightmost_frame < max_framepos && !moving_left) {
581 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
582 if (leftmost_frame > 0 && moving_left) {
588 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
589 stop_canvas_autoscroll ();
592 if (startit && autoscroll_timeout_tag < 0) {
593 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
596 last_autoscroll_x = autoscroll_x;
597 last_autoscroll_y = autoscroll_y;
601 Editor::_autoscroll_canvas (void *arg)
603 return ((Editor *) arg)->autoscroll_canvas ();
607 Editor::autoscroll_canvas ()
609 framepos_t new_frame;
610 framepos_t limit = max_framepos - current_page_frames();
615 if (autoscroll_x_distance != 0) {
617 if (autoscroll_x > 0) {
618 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
619 if (_autoscroll_fudging) {
620 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
622 } else if (autoscroll_x < 0) {
623 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
628 if (autoscroll_y_distance != 0) {
629 if (autoscroll_y > 0) {
630 autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
631 } else if (autoscroll_y < 0) {
633 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
637 if (autoscroll_x < 0) {
638 if (leftmost_frame < autoscroll_x_distance) {
641 new_frame = leftmost_frame - autoscroll_x_distance;
643 } else if (autoscroll_x > 0) {
644 if (leftmost_frame > limit - autoscroll_x_distance) {
647 new_frame = leftmost_frame + autoscroll_x_distance;
650 new_frame = leftmost_frame;
653 double vertical_pos = vertical_adjustment.get_value();
655 if (autoscroll_y < 0) {
657 if (vertical_pos < autoscroll_y_distance) {
660 new_pixel = vertical_pos - autoscroll_y_distance;
663 target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
664 target_pixel = max (target_pixel, 0.0);
666 } else if (autoscroll_y > 0) {
668 double top_of_bottom_of_canvas = full_canvas_height - _canvas_height;
670 if (vertical_pos > full_canvas_height - autoscroll_y_distance) {
671 new_pixel = full_canvas_height;
673 new_pixel = vertical_pos + autoscroll_y_distance;
676 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
678 target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
680 /* don't move to the full canvas height because the item will be invisible
681 (its top edge will line up with the bottom of the visible canvas.
684 target_pixel = min (target_pixel, full_canvas_height - 10);
687 target_pixel = _drags->current_pointer_y();
688 new_pixel = vertical_pos;
691 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
696 if (new_frame != leftmost_frame) {
697 reset_x_origin (new_frame);
700 vertical_adjustment.set_value (new_pixel);
704 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas->get_window();
706 Gdk::ModifierType mask;
707 canvas_window->get_pointer (x, y, mask);
708 ev.type = GDK_MOTION_NOTIFY;
709 ev.state = Gdk::BUTTON1_MASK;
713 motion_handler (0, (GdkEvent*) &ev, true);
717 if (autoscroll_cnt == 1) {
719 /* connect the timeout so that we get called repeatedly */
721 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
730 Editor::start_canvas_autoscroll (int dx, int dy)
732 if (!_session || autoscroll_active) {
736 stop_canvas_autoscroll ();
738 autoscroll_active = true;
741 autoscroll_x_distance = (framepos_t) floor (current_page_frames()/50.0);
742 autoscroll_y_distance = fabs (dy * 5); /* pixels */
745 /* do it right now, which will start the repeated callbacks */
747 autoscroll_canvas ();
751 Editor::stop_canvas_autoscroll ()
753 if (autoscroll_timeout_tag >= 0) {
754 g_source_remove (autoscroll_timeout_tag);
755 autoscroll_timeout_tag = -1;
758 autoscroll_active = false;
762 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
765 within_track_canvas = false;
766 //cerr << "left track canvas\n";
767 set_entered_track (0);
768 set_entered_regionview (0);
769 reset_canvas_action_sensitivity (false);
774 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
776 //cerr << "entered track canvas\n";
777 within_track_canvas = true;
778 reset_canvas_action_sensitivity (true);
783 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
785 double begin = tav.y_position();
787 double v = vertical_adjustment.get_value ();
789 if (begin < v || begin + tav.current_height() > v + _canvas_height - canvas_timebars_vsize) {
790 /* try to put the TimeAxisView roughly central */
791 if (begin >= _canvas_height/2.0) {
792 begin -= _canvas_height/2.0;
794 vertical_adjustment.set_value (begin);
799 Editor::tie_vertical_scrolling ()
801 scroll_canvas_vertically ();
803 /* this will do an immediate redraw */
805 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
807 if (pending_visual_change.idle_handler_id < 0) {
808 _summary->set_overlays_dirty ();
813 Editor::set_horizontal_position (double p)
815 /* horizontal scrolling only */
816 double x1, y1, x2, y2, x_delta;
817 _master_group->get_bounds (x1, y1, x2, y2);
819 x_delta = - (x1 + p);
821 _master_group->move (x_delta, 0);
822 timebar_group->move (x_delta, 0);
823 time_line_group->move (x_delta, 0);
824 cursor_group->move (x_delta, 0);
826 leftmost_frame = (framepos_t) floor (p * frames_per_unit);
828 update_fixed_rulers ();
829 redisplay_tempo (true);
831 if (pending_visual_change.idle_handler_id < 0) {
832 _summary->set_overlays_dirty ();
835 update_video_timeline();
837 HorizontalPositionChanged (); /* EMIT SIGNAL */
840 if (!autoscroll_active && !_stationary_playhead) {
841 /* force rulers and canvas to move in lock step */
842 while (gtk_events_pending ()) {
843 gtk_main_iteration ();
850 Editor::scroll_canvas_vertically ()
852 /* vertical scrolling only */
856 y_delta = last_trackview_group_vertical_offset - get_trackview_group_vertical_offset ();
857 _trackview_group->move (0, y_delta);
858 _background_group->move (0, y_delta);
860 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
861 (*i)->clip_to_viewport ();
863 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
864 /* required to keep the controls_layout in lock step with the canvas group */
865 update_canvas_now ();
869 Editor::color_handler()
871 playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
872 _verbose_cursor->set_color (ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get());
874 meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
875 meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
877 tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
878 tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
880 marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
881 marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
883 cd_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CDMarkerBar.get();
884 cd_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
886 videotl_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VideoBar.get();
887 videotl_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
889 range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
890 range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
892 transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
893 transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
895 cd_marker_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
896 cd_marker_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
898 range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
899 range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
901 transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
902 transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
904 transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
905 transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
907 transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
908 transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
910 transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
911 transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
913 zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
914 zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
916 rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
917 rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
919 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
920 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
921 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
922 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
923 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
925 refresh_location_display ();
927 redisplay_tempo (true);
930 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
935 Editor::flush_canvas ()
938 update_canvas_now ();
939 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);
944 Editor::update_canvas_now ()
946 /* GnomeCanvas has a bug whereby if its idle handler is not scheduled between
947 two calls to update_now, an assert will trip. This wrapper works around
948 that problem by only calling update_now if the assert will not trip.
950 I think the GC bug is due to the fact that its code will reset need_update
951 and need_redraw to FALSE without checking to see if an idle handler is scheduled.
952 If one is scheduled, GC should probably remove it.
955 GnomeCanvas* c = track_canvas->gobj ();
956 if (c->need_update || c->need_redraw) {
957 track_canvas->update_now ();
962 Editor::horizontal_position () const
964 return frame_to_unit (leftmost_frame);
968 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
971 current_canvas_cursor = cursor;
974 Glib::RefPtr<Gdk::Window> win = track_canvas->get_window();
977 track_canvas->get_window()->set_cursor (*cursor);
982 Editor::track_canvas_key_press (GdkEventKey*)
984 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
985 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
986 set_canvas_cursor (_cursors->zoom_out, true);
993 Editor::track_canvas_key_release (GdkEventKey*)
995 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
996 set_canvas_cursor (_cursors->zoom_in, true);