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 "imageframe.h"
41 #include "waveview_p.h"
42 #include "simplerect_p.h"
43 #include "simpleline_p.h"
44 #include "imageframe_p.h"
45 #include "canvas_impl.h"
46 #include "canvas-noevent-text.h"
48 #include "rgb_macros.h"
50 #include "audio_time_axis.h"
51 #include "editor_drag.h"
52 #include "region_view.h"
53 #include "editor_group_tabs.h"
54 #include "editor_summary.h"
55 #include "video_timeline.h"
57 #include "editor_cursors.h"
58 #include "mouse_cursors.h"
59 #include "verbose_cursor.h"
64 using namespace ARDOUR;
68 using namespace Gtkmm2ext;
69 using namespace Editing;
71 /* XXX this is a hack. it ought to be the maximum value of an framepos_t */
73 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
78 GType gnome_canvas_simpleline_get_type(void);
79 GType gnome_canvas_simplerect_get_type(void);
80 GType gnome_canvas_waveview_get_type(void);
81 GType gnome_canvas_imageframe_get_type(void);
85 static void ardour_canvas_type_init()
87 // Map gtypes to gtkmm wrapper-creation functions:
89 Glib::wrap_register(gnome_canvas_simpleline_get_type(), &Gnome::Canvas::SimpleLine_Class::wrap_new);
90 Glib::wrap_register(gnome_canvas_simplerect_get_type(), &Gnome::Canvas::SimpleRect_Class::wrap_new);
91 Glib::wrap_register(gnome_canvas_waveview_get_type(), &Gnome::Canvas::WaveView_Class::wrap_new);
92 // Glib::wrap_register(gnome_canvas_imageframe_get_type(), &Gnome::Canvas::ImageFrame_Class::wrap_new);
94 // Register the gtkmm gtypes:
96 (void) Gnome::Canvas::WaveView::get_type();
97 (void) Gnome::Canvas::SimpleLine::get_type();
98 (void) Gnome::Canvas::SimpleRect::get_type();
99 (void) Gnome::Canvas::ImageFrame::get_type();
103 Editor::initialize_canvas ()
105 if (getenv ("ARDOUR_NON_AA_CANVAS")) {
106 track_canvas = new ArdourCanvas::Canvas ();
108 track_canvas = new ArdourCanvas::CanvasAA ();
111 track_canvas->set_can_default (true);
112 set_default (*track_canvas);
114 ArdourCanvas::init ();
115 ardour_canvas_type_init ();
117 /* don't try to center the canvas */
119 track_canvas->set_center_scroll_region (false);
120 track_canvas->set_dither (Gdk::RGB_DITHER_NONE);
122 gint phys_width = physical_screen_width (Glib::RefPtr<Gdk::Window>());
123 gint phys_height = physical_screen_height (Glib::RefPtr<Gdk::Window>());
125 _verbose_cursor = new VerboseCursor (this);
127 /* on the bottom, an image */
129 if (Profile->get_sae()) {
130 Image img (::get_icon (X_("saelogo")));
131 logo_item = new ArdourCanvas::Pixbuf (*track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
132 // logo_item->property_height_in_pixels() = true;
133 // logo_item->property_width_in_pixels() = true;
134 // logo_item->property_height_set() = true;
135 // logo_item->property_width_set() = true;
139 /* a group to hold time (measure) lines */
140 time_line_group = new ArdourCanvas::Group (*track_canvas->root());
143 /*XXX please don't laugh. this actually improves canvas performance on osx */
144 bogus_background_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, max_canvas_coordinate/3, phys_height);
145 bogus_background_rect->property_outline_pixels() = 0;
147 transport_loop_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
148 transport_loop_range_rect->property_outline_pixels() = 1;
149 transport_loop_range_rect->hide();
151 transport_punch_range_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, phys_height);
152 transport_punch_range_rect->property_outline_pixels() = 0;
153 transport_punch_range_rect->hide();
155 _background_group = new ArdourCanvas::Group (*track_canvas->root());
156 _master_group = new ArdourCanvas::Group (*track_canvas->root());
158 _trackview_group = new ArdourCanvas::Group (*_master_group);
159 _region_motion_group = new ArdourCanvas::Group (*_trackview_group);
161 meter_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
162 meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, phys_width, timebar_height - 1);
163 meter_bar->property_outline_pixels() = 1;
164 meter_bar->property_outline_what() = 0x8;
166 tempo_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
167 tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
168 tempo_bar->property_outline_pixels() = 1;
169 tempo_bar->property_outline_what() = 0x8;
171 range_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
172 range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
173 range_marker_bar->property_outline_pixels() = 1;
174 range_marker_bar->property_outline_what() = 0x8;
176 transport_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
177 transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
178 transport_marker_bar->property_outline_pixels() = 1;
179 transport_marker_bar->property_outline_what() = 0x8;
181 marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
182 marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
183 marker_bar->property_outline_pixels() = 1;
184 marker_bar->property_outline_what() = 0x8;
186 cd_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
187 cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, phys_width, (timebar_height - 1));
188 cd_marker_bar->property_outline_pixels() = 1;
189 cd_marker_bar->property_outline_what() = 0x8;
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));
202 timebar_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
203 cursor_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
205 meter_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 5.0);
206 tempo_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 4.0);
207 range_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 3.0);
208 transport_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 2.0);
209 marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height);
210 cd_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
211 videotl_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
213 cd_marker_bar_drag_rect = new ArdourCanvas::SimpleRect (*cd_marker_group, 0.0, 0.0, 100, timebar_height);
214 cd_marker_bar_drag_rect->property_outline_pixels() = 0;
215 cd_marker_bar_drag_rect->hide ();
217 range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, 100, timebar_height);
218 range_bar_drag_rect->property_outline_pixels() = 0;
219 range_bar_drag_rect->hide ();
221 transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, 100, timebar_height);
222 transport_bar_drag_rect->property_outline_pixels() = 0;
223 transport_bar_drag_rect->hide ();
225 transport_punchin_line = new ArdourCanvas::SimpleLine (*_master_group);
226 transport_punchin_line->property_x1() = 0.0;
227 transport_punchin_line->property_y1() = 0.0;
228 transport_punchin_line->property_x2() = 0.0;
229 transport_punchin_line->property_y2() = phys_height;
230 transport_punchin_line->hide ();
232 transport_punchout_line = new ArdourCanvas::SimpleLine (*_master_group);
233 transport_punchout_line->property_x1() = 0.0;
234 transport_punchout_line->property_y1() = 0.0;
235 transport_punchout_line->property_x2() = 0.0;
236 transport_punchout_line->property_y2() = phys_height;
237 transport_punchout_line->hide();
239 // used to show zoom mode active zooming
240 zoom_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
241 zoom_rect->property_outline_pixels() = 1;
244 zoom_rect->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
246 // used as rubberband rect
247 rubberband_rect = new ArdourCanvas::SimpleRect (*_trackview_group, 0.0, 0.0, 0.0, 0.0);
249 rubberband_rect->property_outline_pixels() = 1;
250 rubberband_rect->hide();
252 tempo_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
253 meter_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
254 marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
255 cd_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
256 videotl_bar_group->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
257 range_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
258 transport_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
260 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
263 logo_item->lower_to_bottom ();
265 /* need to handle 4 specific types of events as catch-alls */
267 track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
268 track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
269 track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
270 track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
271 track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
272 track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
273 track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
275 track_canvas->set_name ("EditorMainCanvas");
276 track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
277 track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
278 track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
279 track_canvas->set_flags (CAN_FOCUS);
281 /* set up drag-n-drop */
283 vector<TargetEntry> target_table;
285 // Drag-N-Drop from the region list can generate this target
286 target_table.push_back (TargetEntry ("regions"));
288 target_table.push_back (TargetEntry ("text/plain"));
289 target_table.push_back (TargetEntry ("text/uri-list"));
290 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
292 track_canvas->drag_dest_set (target_table);
293 track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
295 track_canvas->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_allocate));
297 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
303 Editor::track_canvas_allocate (Gtk::Allocation alloc)
305 canvas_allocation = alloc;
306 track_canvas_size_allocated ();
310 Editor::track_canvas_size_allocated ()
312 bool height_changed = _canvas_height != canvas_allocation.get_height();
314 _canvas_width = canvas_allocation.get_width();
315 _canvas_height = canvas_allocation.get_height();
318 TrackViewList::iterator i;
320 for (i = track_views.begin(); i != track_views.end(); ++i) {
321 (*i)->clip_to_viewport ();
325 if (height_changed) {
326 if (playhead_cursor) {
327 playhead_cursor->set_length (_canvas_height);
330 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
331 i->second->canvas_height_set (_canvas_height);
334 vertical_adjustment.set_page_size (_canvas_height);
335 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
336 if ((vertical_adjustment.get_value() + _canvas_height) >= vertical_adjustment.get_upper()) {
338 We're increasing the size of the canvas while the bottom is visible.
339 We scroll down to keep in step with the controls layout.
341 vertical_adjustment.set_value (full_canvas_height - _canvas_height);
345 update_fixed_rulers();
346 redisplay_tempo (false);
347 _summary->set_overlays_dirty ();
353 Editor::reset_controls_layout_width ()
358 edit_controls_vbox.size_request (req);
361 if (_group_tabs->is_mapped()) {
362 _group_tabs->size_request (req);
366 /* the controls layout has no horizontal scrolling, its visible
367 width is always equal to the total width of its contents.
370 controls_layout.property_width() = w;
371 controls_layout.property_width_request() = w;
375 Editor::reset_controls_layout_height (int32_t h)
377 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
380 controls_layout.property_height() = h;
382 /* size request is set elsewhere, see ::track_canvas_allocate() */
386 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
388 if (current_canvas_cursor) {
389 set_canvas_cursor (current_canvas_cursor);
394 /** This is called when something is dropped onto the track canvas */
396 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
398 const SelectionData& data,
399 guint info, guint time)
401 if (data.get_target() == "regions") {
402 drop_regions (context, x, y, data, info, time);
404 drop_paths (context, x, y, data, info, time);
409 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
411 drop_paths_part_two (paths, frame, ypos, copy);
416 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
418 RouteTimeAxisView* tv;
420 /* MIDI files must always be imported, because we consider them
421 * writable. So split paths into two vectors, and follow the import
422 * path on the MIDI part.
425 vector<string> midi_paths;
426 vector<string> audio_paths;
428 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
429 if (SMFSource::safe_midi_file_extension (*i)) {
430 midi_paths.push_back (*i);
432 audio_paths.push_back (*i);
437 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
438 if (tvp.first == 0) {
440 /* drop onto canvas background: create new tracks */
444 do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, frame);
446 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
447 do_import (audio_paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
449 do_embed (audio_paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
452 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
454 /* check that its a track, not a bus */
457 /* select the track, then embed/import */
460 do_import (midi_paths, Editing::ImportSerializeFiles, ImportToTrack, SrcBest, frame);
462 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
463 do_import (audio_paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
465 do_embed (audio_paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
472 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
474 const SelectionData& data,
475 guint info, guint time)
477 vector<string> paths;
484 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
486 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
489 track_canvas->window_to_world (x, y, wx, wy);
491 ev.type = GDK_BUTTON_RELEASE;
495 frame = event_frame (&ev, 0, &cy);
499 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
501 /* We are not allowed to call recursive main event loops from within
502 the main event loop with GTK/Quartz. Since import/embed wants
503 to push up a progress dialog, defer all this till we go idle.
505 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
507 drop_paths_part_two (paths, frame, cy, copy);
511 context->drag_finish (true, false, time);
514 /** If the editor window is arranged such that the edge of the trackview is right up
515 * against the edge of the screen, autoscroll will not work very well. In this situation,
516 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
517 * this is the distance at which that happens.
520 Editor::autoscroll_fudge_threshold () const
522 return current_page_frames() / 6;
525 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
526 * @param allow_vert true to allow vertical autoscroll, otherwise false.
527 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
528 * otherwise false, so we only want to autoscroll on the right of the canvas.
529 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
530 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
533 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
535 if (!Config->get_autoscroll_editor ()) {
539 bool startit = false;
541 /* Work out the distance between the right hand edge of the trackview and the edge of
542 the monitor that it is on.
545 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
546 Gdk::Rectangle window_rect;
547 gdk_window->get_frame_extents (window_rect);
549 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
550 Gdk::Rectangle root_rect;
551 screen->get_root_window()->get_frame_extents (root_rect);
553 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
555 framecnt_t distance = pixel_to_frame (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
556 if (_the_notebook.is_visible ()) {
557 distance += pixel_to_frame (editor_list.get_width());
560 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
561 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
563 double const ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
567 if (ty < canvas_timebars_vsize && moving_up && allow_vert) {
570 } else if (ty > _canvas_height && !moving_up && allow_vert) {
575 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
576 if (_autoscroll_fudging) {
577 rightmost_frame -= autoscroll_fudge_threshold ();
580 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
581 if (rightmost_frame < max_framepos && !moving_left) {
585 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
586 if (leftmost_frame > 0 && moving_left) {
592 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
593 stop_canvas_autoscroll ();
596 if (startit && autoscroll_timeout_tag < 0) {
597 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
600 last_autoscroll_x = autoscroll_x;
601 last_autoscroll_y = autoscroll_y;
605 Editor::_autoscroll_canvas (void *arg)
607 return ((Editor *) arg)->autoscroll_canvas ();
611 Editor::autoscroll_canvas ()
613 framepos_t new_frame;
614 framepos_t limit = max_framepos - current_page_frames();
619 if (autoscroll_x_distance != 0) {
621 if (autoscroll_x > 0) {
622 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
623 if (_autoscroll_fudging) {
624 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
626 } else if (autoscroll_x < 0) {
627 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
632 if (autoscroll_y_distance != 0) {
633 if (autoscroll_y > 0) {
634 autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
635 } else if (autoscroll_y < 0) {
637 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
641 if (autoscroll_x < 0) {
642 if (leftmost_frame < autoscroll_x_distance) {
645 new_frame = leftmost_frame - autoscroll_x_distance;
647 } else if (autoscroll_x > 0) {
648 if (leftmost_frame > limit - autoscroll_x_distance) {
651 new_frame = leftmost_frame + autoscroll_x_distance;
654 new_frame = leftmost_frame;
657 double vertical_pos = vertical_adjustment.get_value();
659 if (autoscroll_y < 0) {
661 if (vertical_pos < autoscroll_y_distance) {
664 new_pixel = vertical_pos - autoscroll_y_distance;
667 target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
668 target_pixel = max (target_pixel, 0.0);
670 } else if (autoscroll_y > 0) {
672 double top_of_bottom_of_canvas = full_canvas_height - _canvas_height;
674 if (vertical_pos > full_canvas_height - autoscroll_y_distance) {
675 new_pixel = full_canvas_height;
677 new_pixel = vertical_pos + autoscroll_y_distance;
680 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
682 target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
684 /* don't move to the full canvas height because the item will be invisible
685 (its top edge will line up with the bottom of the visible canvas.
688 target_pixel = min (target_pixel, full_canvas_height - 10);
691 target_pixel = _drags->current_pointer_y();
692 new_pixel = vertical_pos;
695 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
700 if (new_frame != leftmost_frame) {
701 reset_x_origin (new_frame);
704 vertical_adjustment.set_value (new_pixel);
708 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas->get_window();
710 Gdk::ModifierType mask;
711 canvas_window->get_pointer (x, y, mask);
712 ev.type = GDK_MOTION_NOTIFY;
713 ev.state = Gdk::BUTTON1_MASK;
717 motion_handler (0, (GdkEvent*) &ev, true);
721 if (autoscroll_cnt == 1) {
723 /* connect the timeout so that we get called repeatedly */
725 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
734 Editor::start_canvas_autoscroll (int dx, int dy)
736 if (!_session || autoscroll_active) {
740 stop_canvas_autoscroll ();
742 autoscroll_active = true;
745 autoscroll_x_distance = (framepos_t) floor (current_page_frames()/50.0);
746 autoscroll_y_distance = fabs (dy * 5); /* pixels */
749 /* do it right now, which will start the repeated callbacks */
751 autoscroll_canvas ();
755 Editor::stop_canvas_autoscroll ()
757 if (autoscroll_timeout_tag >= 0) {
758 g_source_remove (autoscroll_timeout_tag);
759 autoscroll_timeout_tag = -1;
762 autoscroll_active = false;
766 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
769 within_track_canvas = false;
770 //cerr << "left track canvas\n";
771 set_entered_track (0);
772 set_entered_regionview (0);
773 reset_canvas_action_sensitivity (false);
778 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
780 //cerr << "entered track canvas\n";
781 within_track_canvas = true;
782 reset_canvas_action_sensitivity (true);
787 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
789 double begin = tav.y_position();
791 double v = vertical_adjustment.get_value ();
793 if (begin < v || begin + tav.current_height() > v + _canvas_height - canvas_timebars_vsize) {
794 /* try to put the TimeAxisView roughly central */
795 if (begin >= _canvas_height/2.0) {
796 begin -= _canvas_height/2.0;
798 vertical_adjustment.set_value (begin);
803 Editor::tie_vertical_scrolling ()
805 scroll_canvas_vertically ();
807 /* this will do an immediate redraw */
809 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
811 if (pending_visual_change.idle_handler_id < 0) {
812 _summary->set_overlays_dirty ();
817 Editor::set_horizontal_position (double p)
819 /* horizontal scrolling only */
820 double x1, y1, x2, y2, x_delta;
821 _master_group->get_bounds (x1, y1, x2, y2);
823 x_delta = - (x1 + p);
825 _master_group->move (x_delta, 0);
826 timebar_group->move (x_delta, 0);
827 time_line_group->move (x_delta, 0);
828 cursor_group->move (x_delta, 0);
830 leftmost_frame = (framepos_t) floor (p * frames_per_unit);
832 update_fixed_rulers ();
833 redisplay_tempo (true);
835 if (pending_visual_change.idle_handler_id < 0) {
836 _summary->set_overlays_dirty ();
839 update_video_timeline();
841 HorizontalPositionChanged (); /* EMIT SIGNAL */
844 if (!autoscroll_active && !_stationary_playhead) {
845 /* force rulers and canvas to move in lock step */
846 while (gtk_events_pending ()) {
847 gtk_main_iteration ();
854 Editor::scroll_canvas_vertically ()
856 /* vertical scrolling only */
860 y_delta = last_trackview_group_vertical_offset - get_trackview_group_vertical_offset ();
861 _trackview_group->move (0, y_delta);
862 _background_group->move (0, y_delta);
864 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
865 (*i)->clip_to_viewport ();
867 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
868 /* required to keep the controls_layout in lock step with the canvas group */
869 update_canvas_now ();
873 Editor::color_handler()
875 playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
876 _verbose_cursor->set_color (ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get());
878 meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
879 meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
881 tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
882 tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
884 marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
885 marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
887 cd_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CDMarkerBar.get();
888 cd_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
890 videotl_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VideoBar.get();
891 videotl_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
893 range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
894 range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
896 transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
897 transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
899 cd_marker_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
900 cd_marker_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
902 range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
903 range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
905 transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
906 transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
908 transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
909 transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
911 transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
912 transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
914 transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
915 transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
917 zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
918 zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
920 rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
921 rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
923 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
924 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
925 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
926 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
927 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
929 refresh_location_display ();
931 redisplay_tempo (true);
934 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
939 Editor::flush_canvas ()
942 update_canvas_now ();
943 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);
948 Editor::update_canvas_now ()
950 /* GnomeCanvas has a bug whereby if its idle handler is not scheduled between
951 two calls to update_now, an assert will trip. This wrapper works around
952 that problem by only calling update_now if the assert will not trip.
954 I think the GC bug is due to the fact that its code will reset need_update
955 and need_redraw to FALSE without checking to see if an idle handler is scheduled.
956 If one is scheduled, GC should probably remove it.
959 GnomeCanvas* c = track_canvas->gobj ();
960 if (c->need_update || c->need_redraw) {
961 track_canvas->update_now ();
966 Editor::horizontal_position () const
968 return frame_to_unit (leftmost_frame);
972 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
975 current_canvas_cursor = cursor;
978 Glib::RefPtr<Gdk::Window> win = track_canvas->get_window();
981 track_canvas->get_window()->set_cursor (*cursor);
986 Editor::track_canvas_key_press (GdkEventKey*)
988 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
989 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
990 set_canvas_cursor (_cursors->zoom_out, true);
997 Editor::track_canvas_key_release (GdkEventKey*)
999 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
1000 set_canvas_cursor (_cursors->zoom_in, true);