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 #ifdef WITH_VIDEOTIMELINE
192 videotl_bar_group = new ArdourCanvas::Group (*track_canvas->root ());
193 if (Profile->get_sae()) {
194 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height - 1));
195 videotl_bar->property_outline_pixels() = 1;
197 videotl_bar = new ArdourCanvas::SimpleRect (*videotl_bar_group, 0.0, 0.0, phys_width, (timebar_height * videotl_bar_height));
198 videotl_bar->property_outline_pixels() = 0;
200 videotl_bar->property_outline_what() = (0x1 | 0x8);
201 ARDOUR_UI::instance()->video_timeline = new VideoTimeLine(this, videotl_bar_group, (timebar_height * videotl_bar_height));
204 timebar_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
205 cursor_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
207 meter_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 5.0);
208 tempo_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 4.0);
209 range_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 3.0);
210 transport_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 2.0);
211 marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height);
212 cd_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
213 #ifdef WITH_VIDEOTIMELINE
214 videotl_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
217 cd_marker_bar_drag_rect = new ArdourCanvas::SimpleRect (*cd_marker_group, 0.0, 0.0, 100, timebar_height);
218 cd_marker_bar_drag_rect->property_outline_pixels() = 0;
219 cd_marker_bar_drag_rect->hide ();
221 range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, 100, timebar_height);
222 range_bar_drag_rect->property_outline_pixels() = 0;
223 range_bar_drag_rect->hide ();
225 transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, 100, timebar_height);
226 transport_bar_drag_rect->property_outline_pixels() = 0;
227 transport_bar_drag_rect->hide ();
229 transport_punchin_line = new ArdourCanvas::SimpleLine (*_master_group);
230 transport_punchin_line->property_x1() = 0.0;
231 transport_punchin_line->property_y1() = 0.0;
232 transport_punchin_line->property_x2() = 0.0;
233 transport_punchin_line->property_y2() = phys_height;
234 transport_punchin_line->hide ();
236 transport_punchout_line = new ArdourCanvas::SimpleLine (*_master_group);
237 transport_punchout_line->property_x1() = 0.0;
238 transport_punchout_line->property_y1() = 0.0;
239 transport_punchout_line->property_x2() = 0.0;
240 transport_punchout_line->property_y2() = phys_height;
241 transport_punchout_line->hide();
243 // used to show zoom mode active zooming
244 zoom_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
245 zoom_rect->property_outline_pixels() = 1;
248 zoom_rect->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
250 // used as rubberband rect
251 rubberband_rect = new ArdourCanvas::SimpleRect (*_trackview_group, 0.0, 0.0, 0.0, 0.0);
253 rubberband_rect->property_outline_pixels() = 1;
254 rubberband_rect->hide();
256 tempo_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
257 meter_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
258 marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
259 cd_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
260 #ifdef WITH_VIDEOTIMELINE
261 videotl_bar_group->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
262 //videotl_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
264 range_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
265 transport_marker_bar->signal_event().connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
267 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
270 logo_item->lower_to_bottom ();
272 /* need to handle 4 specific types of events as catch-alls */
274 track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
275 track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
276 track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
277 track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
278 track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
279 track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
280 track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
282 track_canvas->set_name ("EditorMainCanvas");
283 track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
284 track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
285 track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
286 track_canvas->set_flags (CAN_FOCUS);
288 /* set up drag-n-drop */
290 vector<TargetEntry> target_table;
292 // Drag-N-Drop from the region list can generate this target
293 target_table.push_back (TargetEntry ("regions"));
295 target_table.push_back (TargetEntry ("text/plain"));
296 target_table.push_back (TargetEntry ("text/uri-list"));
297 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
299 track_canvas->drag_dest_set (target_table);
300 track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
302 track_canvas->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_allocate));
304 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
310 Editor::track_canvas_allocate (Gtk::Allocation alloc)
312 canvas_allocation = alloc;
313 track_canvas_size_allocated ();
317 Editor::track_canvas_size_allocated ()
319 bool height_changed = _canvas_height != canvas_allocation.get_height();
321 _canvas_width = canvas_allocation.get_width();
322 _canvas_height = canvas_allocation.get_height();
325 TrackViewList::iterator i;
327 for (i = track_views.begin(); i != track_views.end(); ++i) {
328 (*i)->clip_to_viewport ();
332 if (height_changed) {
333 if (playhead_cursor) {
334 playhead_cursor->set_length (_canvas_height);
337 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
338 i->second->canvas_height_set (_canvas_height);
341 vertical_adjustment.set_page_size (_canvas_height);
342 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
343 if ((vertical_adjustment.get_value() + _canvas_height) >= vertical_adjustment.get_upper()) {
345 We're increasing the size of the canvas while the bottom is visible.
346 We scroll down to keep in step with the controls layout.
348 vertical_adjustment.set_value (full_canvas_height - _canvas_height);
352 update_fixed_rulers();
353 redisplay_tempo (false);
354 _summary->set_overlays_dirty ();
360 Editor::reset_controls_layout_width ()
365 edit_controls_vbox.size_request (req);
368 if (_group_tabs->is_mapped()) {
369 _group_tabs->size_request (req);
373 /* the controls layout has no horizontal scrolling, its visible
374 width is always equal to the total width of its contents.
377 controls_layout.property_width() = w;
378 controls_layout.property_width_request() = w;
382 Editor::reset_controls_layout_height (int32_t h)
384 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
387 controls_layout.property_height() = h;
389 /* size request is set elsewhere, see ::track_canvas_allocate() */
393 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
395 if (current_canvas_cursor) {
396 set_canvas_cursor (current_canvas_cursor);
401 /** This is called when something is dropped onto the track canvas */
403 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
405 const SelectionData& data,
406 guint info, guint time)
408 if (data.get_target() == "regions") {
409 drop_regions (context, x, y, data, info, time);
411 drop_paths (context, x, y, data, info, time);
416 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
418 drop_paths_part_two (paths, frame, ypos, copy);
423 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
425 RouteTimeAxisView* tv;
427 /* MIDI files must always be imported, because we consider them
428 * writable. So split paths into two vectors, and follow the import
429 * path on the MIDI part.
432 vector<string> midi_paths;
433 vector<string> audio_paths;
435 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
436 if (SMFSource::safe_midi_file_extension (*i)) {
437 midi_paths.push_back (*i);
439 audio_paths.push_back (*i);
444 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
445 if (tvp.first == 0) {
447 /* drop onto canvas background: create new tracks */
451 do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, frame);
453 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
454 do_import (audio_paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
456 do_embed (audio_paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
459 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
461 /* check that its a track, not a bus */
464 /* select the track, then embed/import */
467 do_import (midi_paths, Editing::ImportSerializeFiles, ImportToTrack, SrcBest, frame);
469 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
470 do_import (audio_paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
472 do_embed (audio_paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
479 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
481 const SelectionData& data,
482 guint info, guint time)
484 vector<string> paths;
491 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
493 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
496 track_canvas->window_to_world (x, y, wx, wy);
498 ev.type = GDK_BUTTON_RELEASE;
502 frame = event_frame (&ev, 0, &cy);
506 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
508 /* We are not allowed to call recursive main event loops from within
509 the main event loop with GTK/Quartz. Since import/embed wants
510 to push up a progress dialog, defer all this till we go idle.
512 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
514 drop_paths_part_two (paths, frame, cy, copy);
518 context->drag_finish (true, false, time);
521 /** If the editor window is arranged such that the edge of the trackview is right up
522 * against the edge of the screen, autoscroll will not work very well. In this situation,
523 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
524 * this is the distance at which that happens.
527 Editor::autoscroll_fudge_threshold () const
529 return current_page_frames() / 6;
532 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
533 * @param allow_vert true to allow vertical autoscroll, otherwise false.
534 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
535 * otherwise false, so we only want to autoscroll on the right of the canvas.
536 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
537 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
540 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
542 if (!Config->get_autoscroll_editor ()) {
546 bool startit = false;
548 /* Work out the distance between the right hand edge of the trackview and the edge of
549 the monitor that it is on.
552 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
553 Gdk::Rectangle window_rect;
554 gdk_window->get_frame_extents (window_rect);
556 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
557 Gdk::Rectangle root_rect;
558 screen->get_root_window()->get_frame_extents (root_rect);
560 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
562 framecnt_t distance = pixel_to_frame (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
563 if (_the_notebook.is_visible ()) {
564 distance += pixel_to_frame (editor_list.get_width());
567 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
568 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
570 double const ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
574 if (ty < canvas_timebars_vsize && moving_up && allow_vert) {
577 } else if (ty > _canvas_height && !moving_up && allow_vert) {
582 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
583 if (_autoscroll_fudging) {
584 rightmost_frame -= autoscroll_fudge_threshold ();
587 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
588 if (rightmost_frame < max_framepos && !moving_left) {
592 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
593 if (leftmost_frame > 0 && moving_left) {
599 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
600 stop_canvas_autoscroll ();
603 if (startit && autoscroll_timeout_tag < 0) {
604 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
607 last_autoscroll_x = autoscroll_x;
608 last_autoscroll_y = autoscroll_y;
612 Editor::_autoscroll_canvas (void *arg)
614 return ((Editor *) arg)->autoscroll_canvas ();
618 Editor::autoscroll_canvas ()
620 framepos_t new_frame;
621 framepos_t limit = max_framepos - current_page_frames();
626 if (autoscroll_x_distance != 0) {
628 if (autoscroll_x > 0) {
629 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
630 if (_autoscroll_fudging) {
631 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
633 } else if (autoscroll_x < 0) {
634 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
639 if (autoscroll_y_distance != 0) {
640 if (autoscroll_y > 0) {
641 autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _canvas_height)) / 3;
642 } else if (autoscroll_y < 0) {
644 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
648 if (autoscroll_x < 0) {
649 if (leftmost_frame < autoscroll_x_distance) {
652 new_frame = leftmost_frame - autoscroll_x_distance;
654 } else if (autoscroll_x > 0) {
655 if (leftmost_frame > limit - autoscroll_x_distance) {
658 new_frame = leftmost_frame + autoscroll_x_distance;
661 new_frame = leftmost_frame;
664 double vertical_pos = vertical_adjustment.get_value();
666 if (autoscroll_y < 0) {
668 if (vertical_pos < autoscroll_y_distance) {
671 new_pixel = vertical_pos - autoscroll_y_distance;
674 target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
675 target_pixel = max (target_pixel, 0.0);
677 } else if (autoscroll_y > 0) {
679 double top_of_bottom_of_canvas = full_canvas_height - _canvas_height;
681 if (vertical_pos > full_canvas_height - autoscroll_y_distance) {
682 new_pixel = full_canvas_height;
684 new_pixel = vertical_pos + autoscroll_y_distance;
687 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
689 target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
691 /* don't move to the full canvas height because the item will be invisible
692 (its top edge will line up with the bottom of the visible canvas.
695 target_pixel = min (target_pixel, full_canvas_height - 10);
698 target_pixel = _drags->current_pointer_y();
699 new_pixel = vertical_pos;
702 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
707 if (new_frame != leftmost_frame) {
708 reset_x_origin (new_frame);
711 vertical_adjustment.set_value (new_pixel);
715 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas->get_window();
717 Gdk::ModifierType mask;
718 canvas_window->get_pointer (x, y, mask);
719 ev.type = GDK_MOTION_NOTIFY;
720 ev.state = Gdk::BUTTON1_MASK;
724 motion_handler (0, (GdkEvent*) &ev, true);
728 if (autoscroll_cnt == 1) {
730 /* connect the timeout so that we get called repeatedly */
732 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
741 Editor::start_canvas_autoscroll (int dx, int dy)
743 if (!_session || autoscroll_active) {
747 stop_canvas_autoscroll ();
749 autoscroll_active = true;
752 autoscroll_x_distance = (framepos_t) floor (current_page_frames()/50.0);
753 autoscroll_y_distance = fabs (dy * 5); /* pixels */
756 /* do it right now, which will start the repeated callbacks */
758 autoscroll_canvas ();
762 Editor::stop_canvas_autoscroll ()
764 if (autoscroll_timeout_tag >= 0) {
765 g_source_remove (autoscroll_timeout_tag);
766 autoscroll_timeout_tag = -1;
769 autoscroll_active = false;
773 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
776 within_track_canvas = false;
777 //cerr << "left track canvas\n";
778 set_entered_track (0);
779 set_entered_regionview (0);
780 reset_canvas_action_sensitivity (false);
785 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
787 //cerr << "entered track canvas\n";
788 within_track_canvas = true;
789 reset_canvas_action_sensitivity (true);
794 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
796 double begin = tav.y_position();
798 double v = vertical_adjustment.get_value ();
800 if (begin < v || begin + tav.current_height() > v + _canvas_height - canvas_timebars_vsize) {
801 /* try to put the TimeAxisView roughly central */
802 if (begin >= _canvas_height/2.0) {
803 begin -= _canvas_height/2.0;
805 vertical_adjustment.set_value (begin);
810 Editor::tie_vertical_scrolling ()
812 scroll_canvas_vertically ();
814 /* this will do an immediate redraw */
816 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
818 if (pending_visual_change.idle_handler_id < 0) {
819 _summary->set_overlays_dirty ();
824 Editor::set_horizontal_position (double p)
826 /* horizontal scrolling only */
827 double x1, y1, x2, y2, x_delta;
828 _master_group->get_bounds (x1, y1, x2, y2);
830 x_delta = - (x1 + p);
832 _master_group->move (x_delta, 0);
833 timebar_group->move (x_delta, 0);
834 time_line_group->move (x_delta, 0);
835 cursor_group->move (x_delta, 0);
837 leftmost_frame = (framepos_t) floor (p * frames_per_unit);
839 update_fixed_rulers ();
840 redisplay_tempo (true);
842 if (pending_visual_change.idle_handler_id < 0) {
843 _summary->set_overlays_dirty ();
846 #ifdef WITH_VIDEOTIMELINE
847 update_video_timeline();
850 HorizontalPositionChanged (); /* EMIT SIGNAL */
853 if (!autoscroll_active && !_stationary_playhead) {
854 /* force rulers and canvas to move in lock step */
855 while (gtk_events_pending ()) {
856 gtk_main_iteration ();
863 Editor::scroll_canvas_vertically ()
865 /* vertical scrolling only */
869 y_delta = last_trackview_group_vertical_offset - get_trackview_group_vertical_offset ();
870 _trackview_group->move (0, y_delta);
871 _background_group->move (0, y_delta);
873 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
874 (*i)->clip_to_viewport ();
876 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
877 /* required to keep the controls_layout in lock step with the canvas group */
878 update_canvas_now ();
882 Editor::color_handler()
884 playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
885 _verbose_cursor->set_color (ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get());
887 meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
888 meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
890 tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
891 tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
893 marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
894 marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
896 cd_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CDMarkerBar.get();
897 cd_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
899 #ifdef WITH_VIDEOTIMELINE
900 videotl_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VideoBar.get();
901 videotl_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
904 range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
905 range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
907 transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
908 transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
910 cd_marker_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
911 cd_marker_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
913 range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
914 range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
916 transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
917 transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
919 transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
920 transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
922 transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
923 transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
925 transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
926 transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
928 zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
929 zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
931 rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
932 rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
934 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
935 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
936 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
937 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
938 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
940 refresh_location_display ();
942 redisplay_tempo (true);
945 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
950 Editor::flush_canvas ()
953 update_canvas_now ();
954 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);
959 Editor::update_canvas_now ()
961 /* GnomeCanvas has a bug whereby if its idle handler is not scheduled between
962 two calls to update_now, an assert will trip. This wrapper works around
963 that problem by only calling update_now if the assert will not trip.
965 I think the GC bug is due to the fact that its code will reset need_update
966 and need_redraw to FALSE without checking to see if an idle handler is scheduled.
967 If one is scheduled, GC should probably remove it.
970 GnomeCanvas* c = track_canvas->gobj ();
971 if (c->need_update || c->need_redraw) {
972 track_canvas->update_now ();
977 Editor::horizontal_position () const
979 return frame_to_unit (leftmost_frame);
983 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
986 current_canvas_cursor = cursor;
989 Glib::RefPtr<Gdk::Window> win = track_canvas->get_window();
992 track_canvas->get_window()->set_cursor (*cursor);
997 Editor::track_canvas_key_press (GdkEventKey*)
999 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
1000 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
1001 set_canvas_cursor (_cursors->zoom_out, true);
1008 Editor::track_canvas_key_release (GdkEventKey*)
1010 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
1011 set_canvas_cursor (_cursors->zoom_in, true);