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 <jack/types.h>
26 #include "gtkmm2ext/utils.h"
28 #include "ardour/profile.h"
29 #include "ardour/rc_configuration.h"
30 #include "ardour/smf_source.h"
32 #include "canvas/canvas.h"
33 #include "canvas/rectangle.h"
34 #include "canvas/pixbuf.h"
35 #include "canvas/text.h"
36 #include "canvas/debug.h"
38 #include "ardour_ui.h"
40 #include "global_signals.h"
42 #include "rgb_macros.h"
44 #include "audio_time_axis.h"
45 #include "editor_drag.h"
46 #include "region_view.h"
47 #include "editor_group_tabs.h"
48 #include "editor_summary.h"
49 #include "video_timeline.h"
51 #include "editor_cursors.h"
52 #include "mouse_cursors.h"
53 #include "verbose_cursor.h"
58 using namespace ARDOUR;
62 using namespace Gtkmm2ext;
63 using namespace Editing;
65 /* XXX this is a hack. it ought to be the maximum value of an framepos_t */
67 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
70 Editor::initialize_canvas ()
72 _track_canvas_viewport = new ArdourCanvas::GtkCanvasViewport (horizontal_adjustment, vertical_adjustment);
73 _track_canvas = _track_canvas_viewport->canvas ();
75 _time_bars_canvas_viewport = new ArdourCanvas::GtkCanvasViewport (horizontal_adjustment, unused_adjustment);
76 _time_bars_canvas = _time_bars_canvas_viewport->canvas ();
78 _verbose_cursor = new VerboseCursor (this);
80 /* on the bottom, an image */
82 if (Profile->get_sae()) {
83 Image img (::get_icon (X_("saelogo")));
84 // logo_item = new ArdourCanvas::Pixbuf (_track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
85 // logo_item->property_height_in_pixels() = true;
86 // logo_item->property_width_in_pixels() = true;
87 // logo_item->property_height_set() = true;
88 // logo_item->property_width_set() = true;
92 /* a group to hold time (measure) lines */
93 time_line_group = new ArdourCanvas::Group (_track_canvas->root());
94 CANVAS_DEBUG_NAME (time_line_group, "time line group");
96 transport_loop_range_rect = new ArdourCanvas::Rectangle (time_line_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, ArdourCanvas::COORD_MAX));
97 CANVAS_DEBUG_NAME (transport_loop_range_rect, "loop rect");
98 transport_loop_range_rect->hide();
100 transport_punch_range_rect = new ArdourCanvas::Rectangle (time_line_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, ArdourCanvas::COORD_MAX));
101 CANVAS_DEBUG_NAME (transport_punch_range_rect, "punch rect");
102 transport_punch_range_rect->hide();
104 _trackview_group = new ArdourCanvas::Group (_track_canvas->root());
105 CANVAS_DEBUG_NAME (_trackview_group, "Canvas TrackViews");
106 _region_motion_group = new ArdourCanvas::Group (_trackview_group);
107 CANVAS_DEBUG_NAME (_region_motion_group, "Canvas Region Motion");
109 meter_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
110 meter_bar = new ArdourCanvas::Rectangle (meter_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
111 CANVAS_DEBUG_NAME (meter_bar, "meter Bar");
112 meter_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
114 tempo_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
115 tempo_bar = new ArdourCanvas::Rectangle (tempo_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
116 CANVAS_DEBUG_NAME (tempo_bar, "Tempo Bar");
117 tempo_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
119 range_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
120 range_marker_bar = new ArdourCanvas::Rectangle (range_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
121 CANVAS_DEBUG_NAME (range_marker_bar, "Range Marker Bar");
122 range_marker_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
124 transport_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
125 transport_marker_bar = new ArdourCanvas::Rectangle (transport_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
126 CANVAS_DEBUG_NAME (transport_marker_bar, "transport Marker Bar");
127 transport_marker_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
129 marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
130 marker_bar = new ArdourCanvas::Rectangle (marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
131 CANVAS_DEBUG_NAME (marker_bar, "Marker Bar");
132 marker_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
134 cd_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
135 cd_marker_bar = new ArdourCanvas::Rectangle (cd_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height));
136 CANVAS_DEBUG_NAME (cd_marker_bar, "CD Marker Bar");
137 cd_marker_bar->set_outline_what (ArdourCanvas::Rectangle::BOTTOM);
139 _time_markers_group = new ArdourCanvas::Group (_time_bars_canvas->root());
141 meter_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 5.0));
142 CANVAS_DEBUG_NAME (meter_group, "meter group");
143 tempo_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 4.0));
144 CANVAS_DEBUG_NAME (tempo_group, "tempo group");
145 range_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 3.0));
146 CANVAS_DEBUG_NAME (range_marker_group, "range marker group");
147 transport_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 2.0));
148 CANVAS_DEBUG_NAME (transport_marker_group, "transport marker group");
149 marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height));
150 CANVAS_DEBUG_NAME (marker_group, "marker group");
151 cd_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, 0.0));
152 CANVAS_DEBUG_NAME (cd_marker_group, "cd marker group");
153 videotl_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple(0.0, 0.0));
154 CANVAS_DEBUG_NAME (videotl_group, "videotl group");
156 ARDOUR_UI::instance()->video_timeline = new VideoTimeLine(this, videotl_group, (timebar_height * videotl_bar_height));
158 cd_marker_bar_drag_rect = new ArdourCanvas::Rectangle (cd_marker_group, ArdourCanvas::Rect (0.0, 0.0, 100, timebar_height));
159 CANVAS_DEBUG_NAME (cd_marker_bar_drag_rect, "cd marker drag");
160 cd_marker_bar_drag_rect->set_outline (false);
161 cd_marker_bar_drag_rect->hide ();
163 range_bar_drag_rect = new ArdourCanvas::Rectangle (range_marker_group, ArdourCanvas::Rect (0.0, 0.0, 100, timebar_height));
164 CANVAS_DEBUG_NAME (range_bar_drag_rect, "range drag");
165 range_bar_drag_rect->set_outline (false);
166 range_bar_drag_rect->hide ();
168 transport_bar_drag_rect = new ArdourCanvas::Rectangle (transport_marker_group, ArdourCanvas::Rect (0.0, 0.0, 100, timebar_height));
169 CANVAS_DEBUG_NAME (transport_bar_drag_rect, "transport drag");
170 transport_bar_drag_rect->set_outline (false);
171 transport_bar_drag_rect->hide ();
173 transport_punchin_line = new ArdourCanvas::Line (_track_canvas->root());
174 transport_punchin_line->set_x0 (0);
175 transport_punchin_line->set_y0 (0);
176 transport_punchin_line->set_x1 (0);
177 transport_punchin_line->set_y1 (ArdourCanvas::COORD_MAX);
178 transport_punchin_line->hide ();
180 transport_punchout_line = new ArdourCanvas::Line (_track_canvas->root());
181 transport_punchout_line->set_x0 (0);
182 transport_punchout_line->set_y0 (0);
183 transport_punchout_line->set_x1 (0);
184 transport_punchout_line->set_y1 (ArdourCanvas::COORD_MAX);
185 transport_punchout_line->hide();
187 // used to show zoom mode active zooming
188 zoom_rect = new ArdourCanvas::Rectangle (_track_canvas->root(), ArdourCanvas::Rect (0.0, 0.0, 0.0, 0.0));
191 zoom_rect->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
193 // used as rubberband rect
194 rubberband_rect = new ArdourCanvas::Rectangle (_trackview_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, 0.0));
196 rubberband_rect->hide();
198 tempo_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
199 meter_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
200 marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
201 cd_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
202 videotl_group->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_group));
203 range_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
204 transport_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
206 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
209 logo_item->lower_to_bottom ();
211 /* need to handle 4 specific types of events as catch-alls */
213 _track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
214 _track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
215 _track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
216 _track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
217 _track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
218 _track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
219 _track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
221 _track_canvas->set_name ("EditorMainCanvas");
222 _track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
223 _track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
224 _track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
225 _track_canvas->set_flags (CAN_FOCUS);
227 /* set up drag-n-drop */
229 vector<TargetEntry> target_table;
231 // Drag-N-Drop from the region list can generate this target
232 target_table.push_back (TargetEntry ("regions"));
234 target_table.push_back (TargetEntry ("text/plain"));
235 target_table.push_back (TargetEntry ("text/uri-list"));
236 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
238 _track_canvas->drag_dest_set (target_table);
239 _track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
241 _track_canvas_viewport->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_viewport_allocate));
243 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
249 Editor::track_canvas_viewport_allocate (Gtk::Allocation alloc)
251 _canvas_viewport_allocation = alloc;
252 track_canvas_viewport_size_allocated ();
256 Editor::track_canvas_viewport_size_allocated ()
258 bool height_changed = _visible_canvas_height != _canvas_viewport_allocation.get_height();
260 _visible_canvas_width = _canvas_viewport_allocation.get_width ();
261 _visible_canvas_height = _canvas_viewport_allocation.get_height ();
265 if (height_changed) {
267 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
268 i->second->canvas_height_set (_visible_canvas_height);
271 vertical_adjustment.set_page_size (_visible_canvas_height);
272 if ((vertical_adjustment.get_value() + _visible_canvas_height) >= vertical_adjustment.get_upper()) {
274 We're increasing the size of the canvas while the bottom is visible.
275 We scroll down to keep in step with the controls layout.
277 vertical_adjustment.set_value (_full_canvas_height - _visible_canvas_height);
281 update_fixed_rulers();
282 redisplay_tempo (false);
283 _summary->set_overlays_dirty ();
289 Editor::reset_controls_layout_width ()
294 edit_controls_vbox.size_request (req);
297 if (_group_tabs->is_mapped()) {
298 _group_tabs->size_request (req);
302 /* the controls layout has no horizontal scrolling, its visible
303 width is always equal to the total width of its contents.
306 controls_layout.property_width() = w;
307 controls_layout.property_width_request() = w;
311 Editor::reset_controls_layout_height (int32_t h)
313 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
316 controls_layout.property_height() = h;
318 /* size request is set elsewhere, see ::track_canvas_allocate() */
322 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
324 if (current_canvas_cursor) {
325 set_canvas_cursor (current_canvas_cursor);
330 /** This is called when something is dropped onto the track canvas */
332 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
334 const SelectionData& data,
335 guint info, guint time)
337 if (data.get_target() == "regions") {
338 drop_regions (context, x, y, data, info, time);
340 drop_paths (context, x, y, data, info, time);
345 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
347 drop_paths_part_two (paths, frame, ypos, copy);
352 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
354 RouteTimeAxisView* tv;
356 /* MIDI files must always be imported, because we consider them
357 * writable. So split paths into two vectors, and follow the import
358 * path on the MIDI part.
361 vector<string> midi_paths;
362 vector<string> audio_paths;
364 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
365 if (SMFSource::safe_midi_file_extension (*i)) {
366 midi_paths.push_back (*i);
368 audio_paths.push_back (*i);
373 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
374 if (tvp.first == 0) {
376 /* drop onto canvas background: create new tracks */
380 do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, frame);
382 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
383 do_import (audio_paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
385 do_embed (audio_paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
388 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
390 /* check that its a track, not a bus */
393 /* select the track, then embed/import */
396 do_import (midi_paths, Editing::ImportSerializeFiles, ImportToTrack, SrcBest, frame);
398 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
399 do_import (audio_paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
401 do_embed (audio_paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
408 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
410 const SelectionData& data,
411 guint info, guint time)
413 vector<string> paths;
418 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
420 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
423 ev.type = GDK_BUTTON_RELEASE;
427 frame = window_event_frame (&ev, 0, &cy);
431 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
433 /* We are not allowed to call recursive main event loops from within
434 the main event loop with GTK/Quartz. Since import/embed wants
435 to push up a progress dialog, defer all this till we go idle.
437 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
439 drop_paths_part_two (paths, frame, cy, copy);
443 context->drag_finish (true, false, time);
446 /** If the editor window is arranged such that the edge of the trackview is right up
447 * against the edge of the screen, autoscroll will not work very well. In this situation,
448 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
449 * this is the distance at which that happens.
452 Editor::autoscroll_fudge_threshold () const
454 return current_page_samples() / 6;
457 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
459 * @param allow_vert true to allow vertical autoscroll, otherwise false.
461 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
462 * otherwise false, so we only want to autoscroll on the right of the canvas.
464 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
465 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
468 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
470 if (!Config->get_autoscroll_editor ()) {
474 bool startit = false;
476 /* Work out the distance between the right hand edge of the trackview and the edge of
477 the monitor that it is on.
480 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
481 Gdk::Rectangle window_rect;
482 gdk_window->get_frame_extents (window_rect);
484 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
485 Gdk::Rectangle root_rect;
486 screen->get_root_window()->get_frame_extents (root_rect);
488 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
490 framecnt_t distance = pixel_to_sample (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
491 if (_the_notebook.is_visible ()) {
492 distance += pixel_to_sample (editor_list.get_width());
495 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
496 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
498 /* ty is in canvas-coordinate space */
500 double const ty = _drags->current_pointer_y();
501 ArdourCanvas::Rect visible = _track_canvas->visible_area();
505 if (ty < visible.y0 && moving_up && allow_vert) {
508 } else if (ty > visible.y1 && !moving_up && allow_vert) {
513 framepos_t rightmost_frame = leftmost_frame + current_page_samples();
514 if (_autoscroll_fudging) {
515 rightmost_frame -= autoscroll_fudge_threshold ();
518 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
519 if (rightmost_frame < max_framepos && !moving_left) {
523 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
524 if (leftmost_frame > 0 && moving_left) {
530 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
531 stop_canvas_autoscroll ();
534 if (startit && autoscroll_timeout_tag < 0) {
535 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
538 last_autoscroll_x = autoscroll_x;
539 last_autoscroll_y = autoscroll_y;
543 Editor::_autoscroll_canvas (void *arg)
545 return ((Editor *) arg)->autoscroll_canvas ();
549 Editor::autoscroll_canvas ()
551 framepos_t new_frame;
552 framepos_t limit = max_framepos - current_page_samples();
555 if (autoscroll_x_distance != 0) {
557 if (autoscroll_x > 0) {
558 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_samples())) / 3;
559 if (_autoscroll_fudging) {
560 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
562 } else if (autoscroll_x < 0) {
563 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
568 if (autoscroll_y_distance != 0) {
569 if (autoscroll_y > 0) {
570 autoscroll_y_distance = (_drags->current_pointer_y() - _visible_canvas_height) / 3;
571 } else if (autoscroll_y < 0) {
573 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
577 if (autoscroll_x < 0) {
578 if (leftmost_frame < autoscroll_x_distance) {
581 new_frame = leftmost_frame - autoscroll_x_distance;
583 } else if (autoscroll_x > 0) {
584 if (leftmost_frame > limit - autoscroll_x_distance) {
587 new_frame = leftmost_frame + autoscroll_x_distance;
590 new_frame = leftmost_frame;
593 double vertical_pos = vertical_adjustment.get_value();
595 if (autoscroll_y < 0) {
597 if (vertical_pos < autoscroll_y_distance) {
600 new_pixel = vertical_pos - autoscroll_y_distance;
603 } else if (autoscroll_y > 0) {
605 new_pixel = min (_full_canvas_height - _visible_canvas_height, min (_full_canvas_height, (vertical_adjustment.get_value() + autoscroll_y_distance)));
608 new_pixel = vertical_pos;
611 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
616 if (new_frame != leftmost_frame) {
617 reset_x_origin (new_frame);
620 if (new_pixel != vertical_pos) {
621 vertical_adjustment.set_value (new_pixel);
626 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->_track_canvas->get_window();
628 Gdk::ModifierType mask;
630 canvas_window->get_pointer (x, y, mask);
631 ev.type = GDK_MOTION_NOTIFY;
632 ev.state = Gdk::BUTTON1_MASK;
634 /* the motion handler expects events in canvas coordinate space */
635 ArdourCanvas::Duple d = _track_canvas->window_to_canvas (ArdourCanvas::Duple (x, y));
639 motion_handler (0, (GdkEvent*) &ev, true);
643 if (autoscroll_cnt == 1) {
645 /* connect the timeout so that we get called repeatedly */
647 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
656 Editor::start_canvas_autoscroll (int dx, int dy)
658 if (!_session || autoscroll_active) {
662 stop_canvas_autoscroll ();
664 autoscroll_active = true;
667 autoscroll_x_distance = (framepos_t) floor (current_page_samples()/50.0);
668 autoscroll_y_distance = fabs ((double)dy * 5); /* pixels */
671 /* do it right now, which will start the repeated callbacks */
673 autoscroll_canvas ();
677 Editor::stop_canvas_autoscroll ()
679 if (autoscroll_timeout_tag >= 0) {
680 g_source_remove (autoscroll_timeout_tag);
681 autoscroll_timeout_tag = -1;
684 autoscroll_active = false;
688 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
691 within_track_canvas = false;
692 set_entered_track (0);
693 set_entered_regionview (0);
694 reset_canvas_action_sensitivity (false);
699 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
701 within_track_canvas = true;
702 reset_canvas_action_sensitivity (true);
707 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
709 double begin = tav.y_position();
711 double v = vertical_adjustment.get_value ();
713 if (begin < v || begin + tav.current_height() > v + _visible_canvas_height) {
714 /* try to put the TimeAxisView roughly central */
715 if (begin >= _visible_canvas_height/2.0) {
716 begin -= _visible_canvas_height/2.0;
718 vertical_adjustment.set_value (begin);
722 /** Called when the main vertical_adjustment has changed */
724 Editor::tie_vertical_scrolling ()
726 if (pending_visual_change.idle_handler_id < 0) {
727 _summary->set_overlays_dirty ();
732 Editor::set_horizontal_position (double p)
734 horizontal_adjustment.set_value (p);
736 leftmost_frame = (framepos_t) floor (p * samples_per_pixel);
738 update_fixed_rulers ();
739 redisplay_tempo (true);
741 if (pending_visual_change.idle_handler_id < 0) {
742 _summary->set_overlays_dirty ();
745 update_video_timeline();
747 HorizontalPositionChanged (); /* EMIT SIGNAL */
751 Editor::color_handler()
753 playhead_cursor->set_color (ARDOUR_UI::config()->get_canvasvar_PlayHead());
754 _verbose_cursor->set_color (ARDOUR_UI::config()->get_canvasvar_VerboseCanvasCursor());
756 meter_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_MeterBar());
757 meter_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
759 tempo_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_TempoBar());
760 tempo_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
762 marker_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_MarkerBar());
763 marker_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
765 cd_marker_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_CDMarkerBar());
766 cd_marker_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
768 range_marker_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeMarkerBar());
769 range_marker_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
771 transport_marker_bar->set_fill_color (ARDOUR_UI::config()->get_canvasvar_TransportMarkerBar());
772 transport_marker_bar->set_outline_color (ARDOUR_UI::config()->get_canvasvar_MarkerBarSeparator());
774 cd_marker_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeDragBarRect());
775 cd_marker_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RangeDragBarRect());
777 range_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeDragBarRect());
778 range_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RangeDragBarRect());
780 transport_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_TransportDragRect());
781 transport_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_TransportDragRect());
783 transport_loop_range_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_TransportLoopRect());
784 transport_loop_range_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_TransportLoopRect());
786 transport_punch_range_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_TransportPunchRect());
787 transport_punch_range_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_TransportPunchRect());
789 transport_punchin_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_PunchLine());
790 transport_punchout_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_PunchLine());
792 zoom_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ZoomRect());
793 zoom_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_ZoomRect());
795 rubberband_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RubberBandRect());
796 rubberband_rect->set_fill_color ((guint32) ARDOUR_UI::config()->get_canvasvar_RubberBandRect());
798 location_marker_color = ARDOUR_UI::config()->get_canvasvar_LocationMarker();
799 location_range_color = ARDOUR_UI::config()->get_canvasvar_LocationRange();
800 location_cd_marker_color = ARDOUR_UI::config()->get_canvasvar_LocationCDMarker();
801 location_loop_color = ARDOUR_UI::config()->get_canvasvar_LocationLoop();
802 location_punch_color = ARDOUR_UI::config()->get_canvasvar_LocationPunch();
804 refresh_location_display ();
806 redisplay_tempo (true);
809 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
814 Editor::horizontal_position () const
816 return sample_to_pixel (leftmost_frame);
820 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
823 current_canvas_cursor = cursor;
826 Glib::RefPtr<Gdk::Window> win = _track_canvas->get_window();
829 _track_canvas->get_window()->set_cursor (*cursor);
834 Editor::track_canvas_key_press (GdkEventKey*)
836 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
837 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
838 set_canvas_cursor (_cursors->zoom_out, true);
845 Editor::track_canvas_key_release (GdkEventKey*)
847 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
848 set_canvas_cursor (_cursors->zoom_in, true);
855 Editor::clamp_verbose_cursor_x (double x)
860 x = min (_visible_canvas_width - 200.0, x);
866 Editor::clamp_verbose_cursor_y (double y)
869 y = min (_visible_canvas_height - 50, y);
874 Editor::get_time_bars_group () const
876 return _time_bars_canvas->root();
880 Editor::get_track_canvas_group() const
882 return _track_canvas->root();
885 ArdourCanvas::GtkCanvasViewport*
886 Editor::get_time_bars_canvas() const
888 return _time_bars_canvas_viewport;
891 ArdourCanvas::GtkCanvasViewport*
892 Editor::get_track_canvas() const
894 return _track_canvas_viewport;