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"
37 #include "ardour_ui.h"
39 #include "global_signals.h"
41 #include "rgb_macros.h"
43 #include "audio_time_axis.h"
44 #include "editor_drag.h"
45 #include "region_view.h"
46 #include "editor_group_tabs.h"
47 #include "editor_summary.h"
48 #include "video_timeline.h"
50 #include "editor_cursors.h"
51 #include "mouse_cursors.h"
52 #include "verbose_cursor.h"
57 using namespace ARDOUR;
61 using namespace Gtkmm2ext;
62 using namespace Editing;
64 /* XXX this is a hack. it ought to be the maximum value of an framepos_t */
66 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
69 Editor::initialize_canvas ()
73 _track_canvas_hadj = new Adjustment (0, 0, 1e16);
74 _track_canvas_vadj = new Adjustment (0, 0, 1e16);
75 _track_canvas_viewport = new ArdourCanvas::GtkCanvasViewport (*_track_canvas_hadj, *_track_canvas_vadj);
76 _track_canvas = _track_canvas_viewport->canvas ();
78 _time_bars_canvas_hadj = new Adjustment (0, 0, 1e16);
79 _time_bars_canvas_vadj = new Adjustment (0, 0, 1e16);
80 _time_bars_canvas_viewport = new ArdourCanvas::GtkCanvasViewport (*_time_bars_canvas_hadj, *_time_bars_canvas_vadj);
81 _time_bars_canvas = _time_bars_canvas_viewport->canvas ();
83 _verbose_cursor = new VerboseCursor (this);
85 /* on the bottom, an image */
87 if (Profile->get_sae()) {
88 Image img (::get_icon (X_("saelogo")));
89 // logo_item = new ArdourCanvas::Pixbuf (_track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
90 // logo_item->property_height_in_pixels() = true;
91 // logo_item->property_width_in_pixels() = true;
92 // logo_item->property_height_set() = true;
93 // logo_item->property_width_set() = true;
97 /* a group to hold time (measure) lines */
98 time_line_group = new ArdourCanvas::Group (_track_canvas->root());
100 transport_loop_range_rect = new ArdourCanvas::Rectangle (time_line_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, ArdourCanvas::COORD_MAX));
101 transport_loop_range_rect->set_outline_width (1);
102 transport_loop_range_rect->hide();
104 transport_punch_range_rect = new ArdourCanvas::Rectangle (time_line_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, ArdourCanvas::COORD_MAX));
105 transport_punch_range_rect->set_outline_width (0);
106 transport_punch_range_rect->hide();
109 _background_group = new ArdourCanvas::Group (_track_canvas->root());
110 _master_group = new ArdourCanvas::Group (_track_canvas->root());
112 _trackview_group = new ArdourCanvas::Group (_master_group);
113 _region_motion_group = new ArdourCanvas::Group (_trackview_group);
115 meter_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
116 meter_bar = new ArdourCanvas::Rectangle (meter_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
117 meter_bar->set_outline_width (1);
118 meter_bar->set_outline_what (0x8);
120 tempo_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
121 tempo_bar = new ArdourCanvas::Rectangle (tempo_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
122 tempo_bar->set_outline_width (1);
123 tempo_bar->set_outline_what (0x8);
125 range_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
126 range_marker_bar = new ArdourCanvas::Rectangle (range_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
127 range_marker_bar->set_outline_width (1);
128 range_marker_bar->set_outline_what (0x8);
130 transport_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
131 transport_marker_bar = new ArdourCanvas::Rectangle (transport_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
132 transport_marker_bar->set_outline_width (1);
133 transport_marker_bar->set_outline_what (0x8);
135 marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
136 marker_bar = new ArdourCanvas::Rectangle (marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
137 marker_bar->set_outline_width (1);
138 marker_bar->set_outline_what (0x8);
140 cd_marker_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
141 cd_marker_bar = new ArdourCanvas::Rectangle (cd_marker_bar_group, ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, timebar_height - 1));
142 cd_marker_bar->set_outline_width (1);
143 cd_marker_bar->set_outline_what (0x8);
145 _time_markers_group = new ArdourCanvas::Group (_time_bars_canvas->root());
147 meter_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 5.0));
148 tempo_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 4.0));
149 range_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 3.0));
150 transport_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height * 2.0));
151 marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, timebar_height));
152 cd_marker_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple (0.0, 0.0));
153 videotl_group = new ArdourCanvas::Group (_time_markers_group, ArdourCanvas::Duple(0.0, 0.0));
156 videotl_bar_group = new ArdourCanvas::Group (_time_bars_canvas->root ());
157 videotl_bar = new ArdourCanvas::Rectangle (videotl_bar_group, ArdourCanvas::Rect (0.0, 0.0, 100,(timebar_height * videotl_bar_height)));
158 ARDOUR_UI::instance()->video_timeline = new VideoTimeLine(this, videotl_bar_group, (timebar_height * videotl_bar_height));
160 cd_marker_bar_drag_rect = new ArdourCanvas::Rectangle (cd_marker_group, ArdourCanvas::Rect (0.0, 0.0, 100, timebar_height));
161 cd_marker_bar_drag_rect->set_outline (false);
162 cd_marker_bar_drag_rect->hide ();
164 range_bar_drag_rect = new ArdourCanvas::Rectangle (range_marker_group, ArdourCanvas::Rect (0.0, 0.0, 100, timebar_height));
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 transport_bar_drag_rect->set_outline (false);
170 transport_bar_drag_rect->hide ();
172 transport_punchin_line = new ArdourCanvas::Line (_master_group);
173 transport_punchin_line->set_x0 (0);
174 transport_punchin_line->set_y0 (0);
175 transport_punchin_line->set_x1 (0);
176 transport_punchin_line->set_y1 (ArdourCanvas::COORD_MAX);
177 transport_punchin_line->hide ();
179 transport_punchout_line = new ArdourCanvas::Line (_master_group);
180 transport_punchout_line->set_x0 (0);
181 transport_punchout_line->set_y0 (0);
182 transport_punchout_line->set_x1 (0);
183 transport_punchout_line->set_y1 (ArdourCanvas::COORD_MAX);
184 transport_punchout_line->hide();
186 // used to show zoom mode active zooming
187 zoom_rect = new ArdourCanvas::Rectangle (_master_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, 0.0));
188 zoom_rect->set_outline_width (1);
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->set_outline_width (1);
197 rubberband_rect->hide();
199 tempo_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
200 meter_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
201 marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
202 cd_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
203 videotl_bar_group->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_videotl_bar_event), videotl_bar));
204 range_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
205 transport_marker_bar->Event.connect (sigc::bind (sigc::mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
207 playhead_cursor = new EditorCursor (*this, &Editor::canvas_playhead_cursor_event);
210 logo_item->lower_to_bottom ();
212 /* need to handle 4 specific types of events as catch-alls */
214 _track_canvas->signal_scroll_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_scroll_event));
215 _track_canvas->signal_motion_notify_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_motion_notify_event));
216 _track_canvas->signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_press_event));
217 _track_canvas->signal_button_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_button_release_event));
218 _track_canvas->signal_drag_motion().connect (sigc::mem_fun (*this, &Editor::track_canvas_drag_motion));
219 _track_canvas->signal_key_press_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_press));
220 _track_canvas->signal_key_release_event().connect (sigc::mem_fun (*this, &Editor::track_canvas_key_release));
222 _track_canvas->set_name ("EditorMainCanvas");
223 _track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
224 _track_canvas->signal_leave_notify_event().connect (sigc::mem_fun(*this, &Editor::left_track_canvas), false);
225 _track_canvas->signal_enter_notify_event().connect (sigc::mem_fun(*this, &Editor::entered_track_canvas), false);
226 _track_canvas->set_flags (CAN_FOCUS);
228 /* set up drag-n-drop */
230 vector<TargetEntry> target_table;
232 // Drag-N-Drop from the region list can generate this target
233 target_table.push_back (TargetEntry ("regions"));
235 target_table.push_back (TargetEntry ("text/plain"));
236 target_table.push_back (TargetEntry ("text/uri-list"));
237 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
239 _track_canvas->drag_dest_set (target_table);
240 _track_canvas->signal_drag_data_received().connect (sigc::mem_fun(*this, &Editor::track_canvas_drag_data_received));
242 _track_canvas_viewport->signal_size_allocate().connect (sigc::mem_fun(*this, &Editor::track_canvas_viewport_allocate));
244 ColorsChanged.connect (sigc::mem_fun (*this, &Editor::color_handler));
250 Editor::track_canvas_viewport_allocate (Gtk::Allocation alloc)
252 _canvas_viewport_allocation = alloc;
253 track_canvas_viewport_size_allocated ();
257 Editor::track_canvas_viewport_size_allocated ()
259 bool height_changed = _visible_canvas_height != _canvas_viewport_allocation.get_height();
261 _visible_canvas_width = _canvas_viewport_allocation.get_width ();
262 _visible_canvas_height = _canvas_viewport_allocation.get_height ();
264 cerr << "VISIBLE CANVAS now: " << _visible_canvas_width << " x " << _visible_canvas_height << endl;
267 TrackViewList::iterator i;
269 for (i = track_views.begin(); i != track_views.end(); ++i) {
270 (*i)->clip_to_viewport ();
274 if (height_changed) {
276 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
277 i->second->canvas_height_set (_visible_canvas_height);
280 vertical_adjustment.set_page_size (_visible_canvas_height);
281 if ((vertical_adjustment.get_value() + _visible_canvas_height) >= vertical_adjustment.get_upper()) {
283 We're increasing the size of the canvas while the bottom is visible.
284 We scroll down to keep in step with the controls layout.
286 vertical_adjustment.set_value (_full_canvas_height - _visible_canvas_height);
290 update_fixed_rulers();
291 redisplay_tempo (false);
292 _summary->set_overlays_dirty ();
298 Editor::reset_controls_layout_width ()
303 edit_controls_vbox.size_request (req);
306 if (_group_tabs->is_mapped()) {
307 _group_tabs->size_request (req);
311 /* the controls layout has no horizontal scrolling, its visible
312 width is always equal to the total width of its contents.
315 controls_layout.property_width() = w;
316 controls_layout.property_width_request() = w;
320 Editor::reset_controls_layout_height (int32_t h)
322 /* set the height of the scrollable area (i.e. the sum of all contained widgets)
325 controls_layout.property_height() = h;
327 /* size request is set elsewhere, see ::track_canvas_allocate() */
331 Editor::track_canvas_map_handler (GdkEventAny* /*ev*/)
333 if (current_canvas_cursor) {
334 set_canvas_cursor (current_canvas_cursor);
339 /** This is called when something is dropped onto the track canvas */
341 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
343 const SelectionData& data,
344 guint info, guint time)
346 if (data.get_target() == "regions") {
347 drop_regions (context, x, y, data, info, time);
349 drop_paths (context, x, y, data, info, time);
354 Editor::idle_drop_paths (vector<string> paths, framepos_t frame, double ypos, bool copy)
356 drop_paths_part_two (paths, frame, ypos, copy);
361 Editor::drop_paths_part_two (const vector<string>& paths, framepos_t frame, double ypos, bool copy)
363 RouteTimeAxisView* tv;
365 /* MIDI files must always be imported, because we consider them
366 * writable. So split paths into two vectors, and follow the import
367 * path on the MIDI part.
370 vector<string> midi_paths;
371 vector<string> audio_paths;
373 for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
374 if (SMFSource::safe_midi_file_extension (*i)) {
375 midi_paths.push_back (*i);
377 audio_paths.push_back (*i);
382 std::pair<TimeAxisView*, int> const tvp = trackview_by_y_position (ypos);
383 if (tvp.first == 0) {
385 /* drop onto canvas background: create new tracks */
389 do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, frame);
391 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
392 do_import (audio_paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
394 do_embed (audio_paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
397 } else if ((tv = dynamic_cast<RouteTimeAxisView*> (tvp.first)) != 0) {
399 /* check that its a track, not a bus */
402 /* select the track, then embed/import */
405 do_import (midi_paths, Editing::ImportSerializeFiles, ImportToTrack, SrcBest, frame);
407 if (Profile->get_sae() || Config->get_only_copy_imported_files() || copy) {
408 do_import (audio_paths, Editing::ImportSerializeFiles, Editing::ImportToTrack, SrcBest, frame);
410 do_embed (audio_paths, Editing::ImportSerializeFiles, ImportToTrack, frame);
417 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
419 const SelectionData& data,
420 guint info, guint time)
422 vector<string> paths;
429 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
431 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
434 _track_canvas_viewport->window_to_canvas (x, y, wx, wy);
436 ev.type = GDK_BUTTON_RELEASE;
440 frame = event_frame (&ev, 0, &cy);
444 bool copy = ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY);
446 /* We are not allowed to call recursive main event loops from within
447 the main event loop with GTK/Quartz. Since import/embed wants
448 to push up a progress dialog, defer all this till we go idle.
450 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &Editor::idle_drop_paths), paths, frame, cy, copy));
452 drop_paths_part_two (paths, frame, cy, copy);
456 context->drag_finish (true, false, time);
459 /** If the editor window is arranged such that the edge of the trackview is right up
460 * against the edge of the screen, autoscroll will not work very well. In this situation,
461 * we start autoscrolling some distance in from the right-hand-side of the screen edge;
462 * this is the distance at which that happens.
465 Editor::autoscroll_fudge_threshold () const
467 return current_page_frames() / 6;
470 /** @param allow_horiz true to allow horizontal autoscroll, otherwise false.
471 * @param allow_vert true to allow vertical autoscroll, otherwise false.
472 * @param moving_left true if we are moving left, so we only want to autoscroll on the left of the canvas,
473 * otherwise false, so we only want to autoscroll on the right of the canvas.
474 * @param moving_up true if we are moving up, so we only want to autoscroll at the top of the canvas,
475 * otherwise false, so we only want to autoscroll at the bottom of the canvas.
478 Editor::maybe_autoscroll (bool allow_horiz, bool allow_vert, bool moving_left, bool moving_up)
480 if (!Config->get_autoscroll_editor ()) {
484 bool startit = false;
486 /* Work out the distance between the right hand edge of the trackview and the edge of
487 the monitor that it is on.
490 Glib::RefPtr<Gdk::Window> gdk_window = get_window ();
491 Gdk::Rectangle window_rect;
492 gdk_window->get_frame_extents (window_rect);
494 Glib::RefPtr<Gdk::Screen> screen = get_screen ();
495 Gdk::Rectangle root_rect;
496 screen->get_root_window()->get_frame_extents (root_rect);
498 Gtk::Allocation editor_list = _the_notebook.get_allocation ();
500 framecnt_t distance = pixel_to_frame (root_rect.get_x() + root_rect.get_width() - window_rect.get_x() - window_rect.get_width());
501 if (_the_notebook.is_visible ()) {
502 distance += pixel_to_frame (editor_list.get_width());
505 /* Note whether we're fudging the autoscroll (see autoscroll_fudge_threshold) */
506 _autoscroll_fudging = (distance < autoscroll_fudge_threshold ());
508 double const ty = _drags->current_pointer_y() - get_trackview_group_vertical_offset ();
512 if (ty < 0 && moving_up && allow_vert) {
515 } else if (ty > _visible_canvas_height && !moving_up && allow_vert) {
520 framepos_t rightmost_frame = leftmost_frame + current_page_frames();
521 if (_autoscroll_fudging) {
522 rightmost_frame -= autoscroll_fudge_threshold ();
525 if (_drags->current_pointer_frame() > rightmost_frame && allow_horiz) {
526 if (rightmost_frame < max_framepos && !moving_left) {
530 } else if (_drags->current_pointer_frame() < leftmost_frame && allow_horiz) {
531 if (leftmost_frame > 0 && moving_left) {
537 if (autoscroll_active && ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0))) {
538 stop_canvas_autoscroll ();
541 if (startit && autoscroll_timeout_tag < 0) {
542 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
545 last_autoscroll_x = autoscroll_x;
546 last_autoscroll_y = autoscroll_y;
550 Editor::_autoscroll_canvas (void *arg)
552 return ((Editor *) arg)->autoscroll_canvas ();
556 Editor::autoscroll_canvas ()
558 framepos_t new_frame;
559 framepos_t limit = max_framepos - current_page_frames();
564 if (autoscroll_x_distance != 0) {
566 if (autoscroll_x > 0) {
567 autoscroll_x_distance = (_drags->current_pointer_frame() - (leftmost_frame + current_page_frames())) / 3;
568 if (_autoscroll_fudging) {
569 autoscroll_x_distance += autoscroll_fudge_threshold () / 3;
571 } else if (autoscroll_x < 0) {
572 autoscroll_x_distance = (leftmost_frame - _drags->current_pointer_frame()) / 3;
577 if (autoscroll_y_distance != 0) {
578 if (autoscroll_y > 0) {
579 autoscroll_y_distance = (_drags->current_pointer_y() - (get_trackview_group_vertical_offset() + _visible_canvas_height)) / 3;
580 } else if (autoscroll_y < 0) {
582 autoscroll_y_distance = (vertical_adjustment.get_value () - _drags->current_pointer_y()) / 3;
586 if (autoscroll_x < 0) {
587 if (leftmost_frame < autoscroll_x_distance) {
590 new_frame = leftmost_frame - autoscroll_x_distance;
592 } else if (autoscroll_x > 0) {
593 if (leftmost_frame > limit - autoscroll_x_distance) {
596 new_frame = leftmost_frame + autoscroll_x_distance;
599 new_frame = leftmost_frame;
602 double vertical_pos = vertical_adjustment.get_value();
604 if (autoscroll_y < 0) {
606 if (vertical_pos < autoscroll_y_distance) {
609 new_pixel = vertical_pos - autoscroll_y_distance;
612 target_pixel = _drags->current_pointer_y() - autoscroll_y_distance;
613 target_pixel = max (target_pixel, 0.0);
615 } else if (autoscroll_y > 0) {
617 double const top_of_bottom_of_canvas = _full_canvas_height - _visible_canvas_height;
619 if (vertical_pos > _full_canvas_height - autoscroll_y_distance) {
620 new_pixel = _full_canvas_height;
622 new_pixel = vertical_pos + autoscroll_y_distance;
625 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
627 target_pixel = _drags->current_pointer_y() + autoscroll_y_distance;
629 /* don't move to the full canvas height because the item will be invisible
630 (its top edge will line up with the bottom of the visible canvas.
633 target_pixel = min (target_pixel, _full_canvas_height - 10);
636 target_pixel = _drags->current_pointer_y();
637 new_pixel = vertical_pos;
640 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
645 if (new_frame != leftmost_frame) {
646 reset_x_origin (new_frame);
649 vertical_adjustment.set_value (new_pixel);
653 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->_track_canvas->get_window();
655 Gdk::ModifierType mask;
656 canvas_window->get_pointer (x, y, mask);
657 ev.type = GDK_MOTION_NOTIFY;
658 ev.state = Gdk::BUTTON1_MASK;
662 motion_handler (0, (GdkEvent*) &ev, true);
666 if (autoscroll_cnt == 1) {
668 /* connect the timeout so that we get called repeatedly */
670 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
679 Editor::start_canvas_autoscroll (int dx, int dy)
681 if (!_session || autoscroll_active) {
685 stop_canvas_autoscroll ();
687 autoscroll_active = true;
690 autoscroll_x_distance = (framepos_t) floor (current_page_frames()/50.0);
691 autoscroll_y_distance = fabs (dy * 5); /* pixels */
694 /* do it right now, which will start the repeated callbacks */
696 autoscroll_canvas ();
700 Editor::stop_canvas_autoscroll ()
702 if (autoscroll_timeout_tag >= 0) {
703 g_source_remove (autoscroll_timeout_tag);
704 autoscroll_timeout_tag = -1;
707 autoscroll_active = false;
711 Editor::left_track_canvas (GdkEventCrossing */*ev*/)
714 within_track_canvas = false;
715 //cerr << "left track canvas\n";
716 set_entered_track (0);
717 set_entered_regionview (0);
718 reset_canvas_action_sensitivity (false);
723 Editor::entered_track_canvas (GdkEventCrossing */*ev*/)
725 //cerr << "entered track canvas\n";
726 within_track_canvas = true;
727 reset_canvas_action_sensitivity (true);
732 Editor::ensure_time_axis_view_is_visible (const TimeAxisView& tav)
734 double begin = tav.y_position();
736 double v = vertical_adjustment.get_value ();
738 if (begin < v || begin + tav.current_height() > v + _visible_canvas_height) {
739 /* try to put the TimeAxisView roughly central */
740 if (begin >= _visible_canvas_height/2.0) {
741 begin -= _visible_canvas_height/2.0;
743 vertical_adjustment.set_value (begin);
747 /** Called when the main vertical_adjustment has changed */
749 Editor::tie_vertical_scrolling ()
752 _track_canvas_vadj->set_value (vertical_adjustment.get_value ());
754 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
755 (*i)->clip_to_viewport ();
758 /* required to keep the controls_layout in lock step with the canvas group */
760 update_canvas_now ();
762 /* this will do an immediate redraw */
764 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
766 if (pending_visual_change.idle_handler_id < 0) {
767 _summary->set_overlays_dirty ();
772 Editor::set_horizontal_position (double p)
774 _track_canvas_hadj->set_value (p);
775 _time_bars_canvas_hadj->set_value (p);
777 leftmost_frame = (framepos_t) floor (p * frames_per_pixel);
779 update_fixed_rulers ();
780 redisplay_tempo (true);
782 if (pending_visual_change.idle_handler_id < 0) {
783 _summary->set_overlays_dirty ();
786 update_video_timeline();
788 HorizontalPositionChanged (); /* EMIT SIGNAL */
791 if (!autoscroll_active && !_stationary_playhead) {
792 /* force rulers and canvas to move in lock step */
793 while (gtk_events_pending ()) {
794 gtk_main_iteration ();
803 Editor::scroll_canvas_vertically ()
805 /* vertical scrolling only */
809 y_delta = last_trackview_group_vertical_offset - get_trackview_group_vertical_offset ();
810 _trackview_group->move (0, y_delta);
811 _background_group->move (0, y_delta);
813 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
814 (*i)->clip_to_viewport ();
816 last_trackview_group_vertical_offset = get_trackview_group_vertical_offset ();
817 /* required to keep the controls_layout in lock step with the canvas group */
818 update_canvas_now ();
823 Editor::color_handler()
825 playhead_cursor->set_color (ARDOUR_UI::config()->canvasvar_PlayHead.get());
826 _verbose_cursor->set_color (ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get());
828 meter_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_MeterBar.get());
829 meter_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
831 tempo_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_TempoBar.get());
832 tempo_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
834 marker_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_MarkerBar.get());
835 marker_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
837 cd_marker_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_CDMarkerBar.get());
838 cd_marker_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
840 videotl_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_VideoBar.get());
841 videotl_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
843 range_marker_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get());
844 range_marker_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
846 transport_marker_bar->set_fill_color (ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get());
847 transport_marker_bar->set_outline_color (ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get());
849 cd_marker_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get());
850 cd_marker_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get());
852 range_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get());
853 range_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get());
855 transport_bar_drag_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_TransportDragRect.get());
856 transport_bar_drag_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_TransportDragRect.get());
858 transport_loop_range_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_TransportLoopRect.get());
859 transport_loop_range_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_TransportLoopRect.get());
861 transport_punch_range_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_TransportPunchRect.get());
862 transport_punch_range_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_TransportPunchRect.get());
864 transport_punchin_line->set_outline_color (ARDOUR_UI::config()->canvasvar_PunchLine.get());
865 transport_punchout_line->set_outline_color (ARDOUR_UI::config()->canvasvar_PunchLine.get());
867 zoom_rect->set_fill_color (ARDOUR_UI::config()->canvasvar_ZoomRect.get());
868 zoom_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_ZoomRect.get());
870 rubberband_rect->set_outline_color (ARDOUR_UI::config()->canvasvar_RubberBandRect.get());
871 rubberband_rect->set_fill_color ((guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get());
873 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
874 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
875 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
876 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
877 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
879 refresh_location_display ();
881 redisplay_tempo (true);
884 _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
889 Editor::flush_canvas ()
892 update_canvas_now ();
893 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);
898 Editor::update_canvas_now ()
900 /* GnomeCanvas has a bug whereby if its idle handler is not scheduled between
901 two calls to update_now, an assert will trip. This wrapper works around
902 that problem by only calling update_now if the assert will not trip.
904 I think the GC bug is due to the fact that its code will reset need_update
905 and need_redraw to FALSE without checking to see if an idle handler is scheduled.
906 If one is scheduled, GC should probably remove it.
910 // GnomeCanvas* c = track_canvas->gobj ();
911 // if (c->need_update || c->need_redraw) {
912 // track_canvas->update_now ();
917 Editor::horizontal_position () const
919 return frame_to_unit (leftmost_frame);
923 Editor::set_canvas_cursor (Gdk::Cursor* cursor, bool save)
926 current_canvas_cursor = cursor;
929 Glib::RefPtr<Gdk::Window> win = _track_canvas->get_window();
932 _track_canvas->get_window()->set_cursor (*cursor);
937 Editor::track_canvas_key_press (GdkEventKey*)
939 /* XXX: event does not report the modifier key pressed down, AFAICS, so use the Keyboard object instead */
940 if (mouse_mode == Editing::MouseZoom && Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
941 set_canvas_cursor (_cursors->zoom_out, true);
948 Editor::track_canvas_key_release (GdkEventKey*)
950 if (mouse_mode == Editing::MouseZoom && !Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
951 set_canvas_cursor (_cursors->zoom_in, true);
958 Editor::clamp_verbose_cursor_x (double x)
963 x = min (_visible_canvas_width - 200.0, x);
969 Editor::clamp_verbose_cursor_y (double y)
972 y = min (_visible_canvas_height - 50, y);