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.
20 #include <libgnomecanvasmm/init.h>
21 #include <jack/types.h>
22 #include <gtkmm2ext/utils.h>
24 #include <ardour/audioregion.h>
25 #include <ardour/profile.h>
27 #include "ardour_ui.h"
30 #include "simplerect.h"
31 #include "simpleline.h"
32 #include "waveview_p.h"
33 #include "simplerect_p.h"
34 #include "simpleline_p.h"
35 #include "canvas_impl.h"
37 #include "rgb_macros.h"
39 #include "time_axis_view.h"
40 #include "audio_time_axis.h"
43 #include "imageframe.h"
44 #include "imageframe_p.h"
51 using namespace ARDOUR;
55 using namespace Gtkmm2ext;
56 using namespace Editing;
58 /* XXX this is a hack. it ought to be the maximum value of an nframes64_t */
60 const double max_canvas_coordinate = (double) JACK_MAX_FRAMES;
65 GType gnome_canvas_simpleline_get_type(void);
66 GType gnome_canvas_simplerect_get_type(void);
67 GType gnome_canvas_waveview_get_type(void);
70 GType gnome_canvas_imageframe_get_type(void);
75 static void ardour_canvas_type_init()
77 // Map gtypes to gtkmm wrapper-creation functions:
79 Glib::wrap_register(gnome_canvas_simpleline_get_type(), &Gnome::Canvas::SimpleLine_Class::wrap_new);
80 Glib::wrap_register(gnome_canvas_simplerect_get_type(), &Gnome::Canvas::SimpleRect_Class::wrap_new);
81 Glib::wrap_register(gnome_canvas_waveview_get_type(), &Gnome::Canvas::WaveView_Class::wrap_new);
84 Glib::wrap_register(gnome_canvas_imageframe_get_type(), &Gnome::Canvas::ImageFrame_Class::wrap_new);
87 // Register the gtkmm gtypes:
89 (void) Gnome::Canvas::WaveView::get_type();
90 (void) Gnome::Canvas::SimpleLine::get_type();
91 (void) Gnome::Canvas::SimpleRect::get_type();
94 (void) Gnome::Canvas::ImageFrame::get_type();
100 Editor::initialize_canvas ()
102 if (getenv ("ARDOUR_NON_AA_CANVAS")) {
103 track_canvas = new ArdourCanvas::Canvas ();
105 track_canvas = new ArdourCanvas::CanvasAA ();
108 ArdourCanvas::init ();
109 ardour_canvas_type_init ();
111 /* don't try to center the canvas */
113 track_canvas->set_center_scroll_region (false);
114 track_canvas->set_dither (Gdk::RGB_DITHER_NONE);
116 /* stuff for the verbose canvas cursor */
118 Pango::FontDescription* font = get_font_for_style (N_("VerboseCanvasCursor"));
120 verbose_canvas_cursor = new ArdourCanvas::Text (*track_canvas->root());
121 verbose_canvas_cursor->property_font_desc() = *font;
122 verbose_canvas_cursor->property_anchor() = ANCHOR_NW;
126 verbose_cursor_visible = false;
128 if (Profile->get_sae()) {
129 Image img (::get_icon (X_("saelogo")));
130 logo_item = new ArdourCanvas::Pixbuf (*track_canvas->root(), 0.0, 0.0, img.get_pixbuf());
131 // logo_item->property_height_in_pixels() = true;
132 // logo_item->property_width_in_pixels() = true;
133 // logo_item->property_height_set() = true;
134 // logo_item->property_width_set() = true;
138 _master_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
140 transport_loop_range_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
141 transport_loop_range_rect->property_outline_pixels() = 1;
142 transport_loop_range_rect->hide();
144 transport_punch_range_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
145 transport_punch_range_rect->property_outline_pixels() = 0;
146 transport_punch_range_rect->hide();
148 /* a group to hold time (measure) lines */
149 time_line_group = new ArdourCanvas::Group (*_master_group, 0.0, 0.0);
151 range_marker_drag_rect = new ArdourCanvas::SimpleRect (*time_line_group, 0.0, 0.0, 0.0, 0.0);
152 range_marker_drag_rect->hide ();
154 _trackview_group = new ArdourCanvas::Group (*_master_group, 0.0, 0.0);
155 _region_motion_group = new ArdourCanvas::Group (*_trackview_group, 0.0, 0.0);
159 meter_bar_group = new ArdourCanvas::Group (*track_canvas->root());
160 meter_bar = new ArdourCanvas::SimpleRect (*meter_bar_group, 0.0, 0.0, max_canvas_coordinate, timebar_height-1.0);
161 meter_bar->property_outline_what() = (0x1 | 0x8);
162 meter_bar->property_outline_pixels() = 1;
164 tempo_bar_group = new ArdourCanvas::Group (*track_canvas->root());
165 tempo_bar = new ArdourCanvas::SimpleRect (*tempo_bar_group, 0.0, 0.0, max_canvas_coordinate, (timebar_height-1.0));
166 tempo_bar->property_outline_what() = (0x1 | 0x8);
167 tempo_bar->property_outline_pixels() = 1;
169 range_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root());
170 range_marker_bar = new ArdourCanvas::SimpleRect (*range_marker_bar_group, 0.0, 0.0, max_canvas_coordinate, (timebar_height-1.0));
171 range_marker_bar->property_outline_what() = (0x1 | 0x8);
172 range_marker_bar->property_outline_pixels() = 1;
174 transport_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root());
175 transport_marker_bar = new ArdourCanvas::SimpleRect (*transport_marker_bar_group, 0.0, 0.0, max_canvas_coordinate, (timebar_height-1.0));
176 transport_marker_bar->property_outline_what() = (0x1 | 0x8);
177 transport_marker_bar->property_outline_pixels() = 1;
179 marker_bar_group = new ArdourCanvas::Group (*track_canvas->root());
180 marker_bar = new ArdourCanvas::SimpleRect (*marker_bar_group, 0.0, 0.0, max_canvas_coordinate, (timebar_height-1.0));
181 marker_bar->property_outline_what() = (0x1 | 0x8);
182 marker_bar->property_outline_pixels() = 1;
184 cd_marker_bar_group = new ArdourCanvas::Group (*track_canvas->root());
185 cd_marker_bar = new ArdourCanvas::SimpleRect (*cd_marker_bar_group, 0.0, 0.0, max_canvas_coordinate, (timebar_height-1.0));
186 cd_marker_bar->property_outline_what() = (0x1 | 0x8);
187 cd_marker_bar->property_outline_pixels() = 1;
189 timebar_group = new ArdourCanvas::Group (*track_canvas->root());
190 cursor_group = new ArdourCanvas::Group (*track_canvas->root(), 0.0, 0.0);
192 meter_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 5.0);
193 tempo_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 4.0);
194 range_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 3.0);
195 transport_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height * 2.0);
196 marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, timebar_height);
197 cd_marker_group = new ArdourCanvas::Group (*timebar_group, 0.0, 0.0);
199 marker_drag_line_points.push_back(Gnome::Art::Point(0.0, 0.0));
200 marker_drag_line_points.push_back(Gnome::Art::Point(0.0, 1.0));
202 marker_drag_line = new ArdourCanvas::Line (*timebar_group);
203 marker_drag_line->property_width_pixels() = 1;
204 marker_drag_line->property_points() = marker_drag_line_points;
205 marker_drag_line->hide();
207 cd_marker_bar_drag_rect = new ArdourCanvas::SimpleRect (*cd_marker_group, 0.0, 0.0, 100, timebar_height);
208 cd_marker_bar_drag_rect->property_outline_pixels() = 0;
209 cd_marker_bar_drag_rect->hide ();
211 range_bar_drag_rect = new ArdourCanvas::SimpleRect (*range_marker_group, 0.0, 0.0, 100, timebar_height);
212 range_bar_drag_rect->property_outline_pixels() = 0;
213 range_bar_drag_rect->hide ();
215 transport_bar_drag_rect = new ArdourCanvas::SimpleRect (*transport_marker_group, 0.0, 0.0, 100, timebar_height);
216 transport_bar_drag_rect->property_outline_pixels() = 0;
217 transport_bar_drag_rect->hide ();
219 transport_punchin_line = new ArdourCanvas::SimpleLine (*_master_group);
220 transport_punchin_line->property_x1() = 0.0;
221 transport_punchin_line->property_y1() = 0.0;
222 transport_punchin_line->property_x2() = 0.0;
223 transport_punchin_line->property_y2() = 0.0;
224 transport_punchin_line->hide ();
226 transport_punchout_line = new ArdourCanvas::SimpleLine (*_master_group);
227 transport_punchout_line->property_x1() = 0.0;
228 transport_punchout_line->property_y1() = 0.0;
229 transport_punchout_line->property_x2() = 0.0;
230 transport_punchout_line->property_y2() = 0.0;
231 transport_punchout_line->hide();
233 // used to show zoom mode active zooming
234 zoom_rect = new ArdourCanvas::SimpleRect (*_master_group, 0.0, 0.0, 0.0, 0.0);
235 zoom_rect->property_outline_pixels() = 1;
238 zoom_rect->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_zoom_rect_event), (ArdourCanvas::Item*) 0));
240 // used as rubberband rect
241 rubberband_rect = new ArdourCanvas::SimpleRect (*_trackview_group, 0.0, 0.0, 0.0, 0.0);
243 rubberband_rect->property_outline_pixels() = 1;
244 rubberband_rect->hide();
246 tempo_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_tempo_bar_event), tempo_bar));
247 meter_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_meter_bar_event), meter_bar));
248 marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_marker_bar_event), marker_bar));
249 cd_marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_cd_marker_bar_event), cd_marker_bar));
250 range_marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_range_marker_bar_event), range_marker_bar));
251 transport_marker_bar->signal_event().connect (bind (mem_fun (*this, &Editor::canvas_transport_marker_bar_event), transport_marker_bar));
253 playhead_cursor = new Cursor (*this, &Editor::canvas_playhead_cursor_event);
256 logo_item->lower_to_bottom ();
259 /* need to handle 4 specific types of events as catch-alls */
261 track_canvas->signal_scroll_event().connect (mem_fun (*this, &Editor::track_canvas_scroll_event));
262 track_canvas->signal_motion_notify_event().connect (mem_fun (*this, &Editor::track_canvas_motion_notify_event));
263 track_canvas->signal_button_press_event().connect (mem_fun (*this, &Editor::track_canvas_button_press_event));
264 track_canvas->signal_button_release_event().connect (mem_fun (*this, &Editor::track_canvas_button_release_event));
266 track_canvas->set_name ("EditorMainCanvas");
267 track_canvas->add_events (Gdk::POINTER_MOTION_HINT_MASK|Gdk::SCROLL_MASK);
268 track_canvas->signal_leave_notify_event().connect (mem_fun(*this, &Editor::left_track_canvas));
269 track_canvas->signal_enter_notify_event().connect (mem_fun(*this, &Editor::entered_track_canvas));
270 track_canvas->set_flags (CAN_FOCUS);
272 /* set up drag-n-drop */
274 vector<TargetEntry> target_table;
276 // Drag-N-Drop from the region list can generate this target
277 target_table.push_back (TargetEntry ("regions"));
278 target_table.push_back (TargetEntry ("routes"));
280 target_table.push_back (TargetEntry ("text/plain"));
281 target_table.push_back (TargetEntry ("text/uri-list"));
282 target_table.push_back (TargetEntry ("application/x-rootwin-drop"));
284 track_canvas->drag_dest_set (target_table);
285 track_canvas->signal_drag_data_received().connect (mem_fun(*this, &Editor::track_canvas_drag_data_received));
287 track_canvas->signal_size_allocate().connect (mem_fun(*this, &Editor::track_canvas_allocate));
289 ColorsChanged.connect (mem_fun (*this, &Editor::color_handler));
295 Editor::track_canvas_allocate (Gtk::Allocation alloc)
297 canvas_allocation = alloc;
298 track_canvas_size_allocated ();
302 Editor::track_canvas_size_allocated ()
304 bool height_changed = canvas_height != canvas_allocation.get_height();
306 canvas_width = canvas_allocation.get_width();
307 canvas_height = canvas_allocation.get_height();
309 full_canvas_height = canvas_height;
312 TrackViewList::iterator i;
315 for (i = track_views.begin(); i != track_views.end(); ++i) {
316 if ((*i)->control_parent) {
317 height += (*i)->effective_height;
321 full_canvas_height = height + canvas_timebars_vsize;
326 if (height_changed) {
327 if (playhead_cursor) {
328 playhead_cursor->set_length (canvas_height);
331 vertical_adjustment.set_page_size (canvas_height);
333 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
334 (*x)->set_line_vpos (0, canvas_height);
337 // marker_drag_line_points.back().set_y(canvas_height);
338 range_marker_drag_rect->property_y2() = canvas_height;
339 transport_loop_range_rect->property_y2() = canvas_height;
340 transport_punch_range_rect->property_y2() = canvas_height;
341 transport_punchin_line->property_y2() = canvas_height;
342 transport_punchout_line->property_y2() = canvas_height;
344 horizontal_adjustment.set_upper (session->current_end_frame()/frames_per_unit);
345 horizontal_adjustment.set_page_size (current_page_frames()/frames_per_unit);
346 reset_hscrollbar_stepping ();
347 update_fixed_rulers();
348 redisplay_tempo (false);
350 Resized (); /* EMIT_SIGNAL */
356 Editor::controls_layout_size_request (Requisition* req)
358 TreeModel::Children rows = route_display_model->children();
359 TreeModel::Children::iterator i;
361 bool changed = false;
363 for (pos = 0, i = rows.begin(); i != rows.end(); ++i) {
364 TimeAxisView *tv = (*i)[route_display_columns.tv];
366 pos += tv->effective_height;
370 RefPtr<Gdk::Screen> screen = get_screen();
373 screen = Gdk::Screen::get_default();
375 gint height = min ( (gint) pos, (screen->get_height() - 400));
376 gint width = max (edit_controls_vbox.get_width(), controls_layout.get_width());
378 /* don't get too big. the fudge factors here are just guesses */
380 width = min (width, screen->get_width() - 300);
382 if ((req->width != width) || (req->height != height)) {
384 controls_layout_size_request_connection.disconnect ();
387 if (req->width != width) {
388 gint vbox_width = edit_controls_vbox.get_width();
391 /* this one is important: it determines how big the layout thinks it really is, as
392 opposed to what it displays on the screen
394 controls_layout.property_width () = vbox_width;
395 controls_layout.property_width_request () = vbox_width;
397 time_button_event_box.property_width_request () = vbox_width;
398 zoom_box.property_width_request () = vbox_width;
401 if (req->height != height) {
402 req->height = height;
403 controls_layout.property_height () = (guint) floor (pos);
407 controls_layout_size_request_connection = controls_layout.signal_size_request().connect (mem_fun (*this, &Editor::controls_layout_size_request));
412 Editor::track_canvas_map_handler (GdkEventAny* ev)
414 track_canvas->get_window()->set_cursor (*current_canvas_cursor);
419 Editor::track_canvas_drag_data_received (const RefPtr<Gdk::DragContext>& context,
421 const SelectionData& data,
422 guint info, guint time)
424 cerr << "drop on canvas, target = " << data.get_target() << endl;
426 if (data.get_target() == "regions") {
427 drop_regions (context, x, y, data, info, time);
429 else if(data.get_target() == "routes") {
430 drop_routes (context, x, y, data, info, time);
433 drop_paths (context, x, y, data, info, time);
438 Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
440 const SelectionData& data,
441 guint info, guint time)
444 RouteTimeAxisView* tv;
446 vector<ustring> paths;
451 if (convert_drop_to_paths (paths, context, x, y, data, info, time)) {
455 /* D-n-D coordinates are window-relative, so convert to "world" coordinates
461 track_canvas->window_to_world (x, y, wx, wy);
462 //wx += horizontal_adjustment.get_value();
463 //wy += vertical_adjustment.get_value();
465 ev.type = GDK_BUTTON_RELEASE;
469 frame = event_frame (&ev, 0, &cy);
473 if ((tvp = trackview_by_y_position (cy)) == 0) {
475 /* drop onto canvas background: create new tracks */
479 if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
480 do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame);
482 do_embed (paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
485 } else if ((tv = dynamic_cast<RouteTimeAxisView*>(tvp)) != 0) {
487 /* check that its an audio track, not a bus */
489 /* check that its an audio track, not a bus */
491 if (tv->get_diskstream()) {
492 /* select the track, then embed */
495 if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
496 do_import (paths, Editing::ImportDistinctFiles, Editing::ImportToTrack, SrcBest, frame);
498 do_embed (paths, Editing::ImportDistinctFiles, ImportToTrack, frame);
504 context->drag_finish (true, false, time);
508 Editor::drop_regions (const RefPtr<Gdk::DragContext>& context,
510 const SelectionData& data,
511 guint info, guint time)
513 const SerializedObjectPointers<boost::shared_ptr<Region> >* sr =
514 reinterpret_cast<const SerializedObjectPointers<boost::shared_ptr<Region> > *> (data.get_data());
516 for (uint32_t i = 0; i < sr->cnt; ++i) {
518 boost::shared_ptr<Region> r = sr->data[i];
520 insert_region_list_drag (r, x, y);
523 context->drag_finish (true, false, time);
527 Editor::drop_routes (const Glib::RefPtr<Gdk::DragContext>& context,
529 const Gtk::SelectionData& data,
530 guint info, guint time) {
531 const SerializedObjectPointers<boost::shared_ptr<Route> >* sr =
532 reinterpret_cast<const SerializedObjectPointers<boost::shared_ptr<Route> > *> (data.get_data());
534 for (uint32_t i = 0; i < sr->cnt; ++i) {
535 boost::shared_ptr<Route> r = sr->data[i];
536 insert_route_list_drag (r, x, y);
539 context->drag_finish (true, false, time);
543 Editor::maybe_autoscroll (GdkEventMotion* event)
545 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
546 nframes64_t frame = drag_info.current_pointer_frame;
547 bool startit = false;
548 double vertical_pos = vertical_adjustment.get_value();
549 double upper = vertical_adjustment.get_upper();
552 adjust the event.y to take account of the bounds
553 of the _trackview_group
556 double vsx1, vsx2, vsy1, vsy2;
557 _trackview_group->get_bounds (vsx1, vsy1, vsx2, vsy2);
562 if ((event->y - vsy1) < vertical_pos) {
567 if ((event->y - vsy1) > (vertical_pos + canvas_height - canvas_timebars_vsize) && vertical_pos <= upper) {
572 if (frame > rightmost_frame) {
574 if (rightmost_frame < max_frames) {
579 } else if (frame < leftmost_frame) {
580 if (leftmost_frame > 0) {
587 if (!allow_vertical_scroll) {
591 if ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0)) {
592 stop_canvas_autoscroll ();
595 if (startit && autoscroll_timeout_tag < 0) {
596 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
599 last_autoscroll_x = autoscroll_x;
600 last_autoscroll_y = autoscroll_y;
604 Editor::maybe_autoscroll_horizontally (GdkEventMotion* event)
606 nframes64_t rightmost_frame = leftmost_frame + current_page_frames();
607 nframes64_t frame = drag_info.current_pointer_frame;
608 bool startit = false;
613 if (frame > rightmost_frame) {
615 if (rightmost_frame < max_frames) {
620 } else if (frame < leftmost_frame) {
621 if (leftmost_frame > 0) {
628 if ((autoscroll_x != last_autoscroll_x) || (autoscroll_y != last_autoscroll_y) || (autoscroll_x == 0 && autoscroll_y == 0)) {
629 stop_canvas_autoscroll ();
632 if (startit && autoscroll_timeout_tag < 0) {
633 start_canvas_autoscroll (autoscroll_x, autoscroll_y);
636 last_autoscroll_x = autoscroll_x;
637 last_autoscroll_y = autoscroll_y;
641 Editor::_autoscroll_canvas (void *arg)
643 return ((Editor *) arg)->autoscroll_canvas ();
647 Editor::autoscroll_canvas ()
649 nframes64_t new_frame;
650 nframes64_t limit = max_frames - current_page_frames();
655 if (autoscroll_x_distance != 0) {
657 if (autoscroll_cnt == 50) { /* 0.5 seconds */
659 /* after about a while, speed up a bit by changing the timeout interval */
661 autoscroll_x_distance = (nframes64_t) floor (current_page_frames()/30.0f);
663 } else if (autoscroll_cnt == 150) { /* 1.0 seconds */
665 autoscroll_x_distance = (nframes64_t) floor (current_page_frames()/20.0f);
667 } else if (autoscroll_cnt == 300) { /* 1.5 seconds */
669 /* after about another while, speed up by increasing the shift per callback */
671 autoscroll_x_distance = (nframes64_t) floor (current_page_frames()/10.0f);
676 if (autoscroll_y_distance != 0) {
678 if (autoscroll_cnt == 50) { /* 0.5 seconds */
680 /* after about a while, speed up a bit by changing the timeout interval */
682 autoscroll_y_distance = 10;
684 } else if (autoscroll_cnt == 150) { /* 1.0 seconds */
686 autoscroll_y_distance = 20;
688 } else if (autoscroll_cnt == 300) { /* 1.5 seconds */
690 /* after about another while, speed up by increasing the shift per callback */
692 autoscroll_y_distance = 40;
696 if (autoscroll_x < 0) {
697 if (leftmost_frame < autoscroll_x_distance) {
700 new_frame = leftmost_frame - autoscroll_x_distance;
702 } else if (autoscroll_x > 0) {
703 if (leftmost_frame > limit - autoscroll_x_distance) {
706 new_frame = leftmost_frame + autoscroll_x_distance;
709 new_frame = leftmost_frame;
712 double vertical_pos = vertical_adjustment.get_value();
714 if (autoscroll_y < 0) {
716 if (vertical_pos < autoscroll_y_distance) {
719 new_pixel = vertical_pos - autoscroll_y_distance;
722 target_pixel = drag_info.current_pointer_y - autoscroll_y_distance;
723 target_pixel = max (target_pixel, 0.0);
725 } else if (autoscroll_y > 0) {
727 double top_of_bottom_of_canvas = full_canvas_height - canvas_height;
729 if (vertical_pos > full_canvas_height - autoscroll_y_distance) {
730 new_pixel = full_canvas_height;
732 new_pixel = vertical_pos + autoscroll_y_distance;
735 new_pixel = min (top_of_bottom_of_canvas, new_pixel);
737 target_pixel = drag_info.current_pointer_y + autoscroll_y_distance;
739 /* don't move to the full canvas height because the item will be invisible
740 (its top edge will line up with the bottom of the visible canvas.
743 target_pixel = min (target_pixel, full_canvas_height - 10);
746 target_pixel = drag_info.current_pointer_y;
747 new_pixel = vertical_pos;
752 if ((new_frame == 0 || new_frame == limit) && (new_pixel == 0 || new_pixel == DBL_MAX)) {
757 if (new_frame != leftmost_frame) {
758 reset_x_origin (new_frame);
761 vertical_adjustment.set_value (new_pixel);
765 Glib::RefPtr<Gdk::Window> canvas_window = const_cast<Editor*>(this)->track_canvas->get_window();
767 Gdk::ModifierType mask;
768 canvas_window->get_pointer (x, y, mask);
769 ev.type = GDK_MOTION_NOTIFY;
770 ev.state &= Gdk::BUTTON1_MASK;
774 motion_handler (drag_info.item, (GdkEvent*) &ev, drag_info.item_type, true);
778 if (autoscroll_cnt == 1) {
780 /* connect the timeout so that we get called repeatedly */
782 autoscroll_timeout_tag = g_idle_add ( _autoscroll_canvas, this);
791 Editor::start_canvas_autoscroll (int dx, int dy)
793 if (!session || autoscroll_active) {
797 stop_canvas_autoscroll ();
799 autoscroll_active = true;
802 autoscroll_x_distance = (nframes64_t) floor (current_page_frames()/50.0);
803 autoscroll_y_distance = fabs (dy * 5); /* pixels */
806 /* do it right now, which will start the repeated callbacks */
808 autoscroll_canvas ();
812 Editor::stop_canvas_autoscroll ()
815 if (autoscroll_timeout_tag >= 0) {
816 g_source_remove (autoscroll_timeout_tag);
817 autoscroll_timeout_tag = -1;
820 autoscroll_active = false;
824 Editor::left_track_canvas (GdkEventCrossing *ev)
826 set_entered_track (0);
827 set_entered_regionview (0);
828 reset_canvas_action_sensitivity (false);
833 Editor::entered_track_canvas (GdkEventCrossing *ev)
835 reset_canvas_action_sensitivity (true);
840 Editor::tie_vertical_scrolling ()
842 scroll_canvas_vertically ();
844 /* this will do an immediate redraw */
846 controls_layout.get_vadjustment()->set_value (vertical_adjustment.get_value());
850 Editor::scroll_canvas_horizontally ()
852 nframes64_t time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
854 if (time_origin != leftmost_frame) {
855 canvas_scroll_to (time_origin);
858 /* horizontal scrolling only */
859 double x1, x2, y1, y2, x_delta;
861 _master_group->get_bounds(x1, y1, x2, y2);
862 x_delta = x1 + horizontal_adjustment.get_value();
864 _master_group->move (-x_delta, 0);
865 timebar_group->move (-x_delta, 0);
866 cursor_group->move (-x_delta, 0);
867 update_fixed_rulers ();
868 redisplay_tempo (true);
872 Editor::scroll_canvas_vertically ()
874 /* vertical scrolling only */
875 double x1, x2, y1, y2, y_delta;
877 _trackview_group->get_bounds(x1, y1, x2, y2);
878 y_delta = y1 + get_trackview_group_vertical_offset ();
880 _trackview_group->move (0, -y_delta);
882 /* required to keep the controls_layout in lock step with the canvas group */
883 track_canvas->update_now ();
887 Editor::canvas_horizontally_scrolled ()
889 nframes64_t time_origin = (nframes64_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
891 if (time_origin != leftmost_frame) {
892 canvas_scroll_to (time_origin);
894 redisplay_tempo (true);
898 Editor::canvas_scroll_to (nframes64_t time_origin)
900 leftmost_frame = time_origin;
901 nframes64_t rightmost_frame = leftmost_frame + current_page_frames ();
903 if (rightmost_frame > last_canvas_frame) {
904 last_canvas_frame = rightmost_frame;
905 //reset_scrolling_region ();
910 Editor::color_handler()
912 playhead_cursor->canvas_item.property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_PlayHead.get();
913 verbose_canvas_cursor->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_VerboseCanvasCursor.get();
915 meter_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MeterBar.get();
916 meter_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
918 tempo_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TempoBar.get();
919 tempo_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
921 marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBar.get();
922 marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
924 cd_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CDMarkerBar.get();
925 cd_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
927 range_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeMarkerBar.get();
928 range_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
930 transport_marker_bar->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportMarkerBar.get();
931 transport_marker_bar->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerBarSeparator.get();
933 cd_marker_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
934 cd_marker_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
936 range_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
937 range_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragBarRect.get();
939 transport_bar_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
940 transport_bar_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportDragRect.get();
942 marker_drag_line->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerDragLine.get();
944 range_marker_drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
945 range_marker_drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
947 transport_loop_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
948 transport_loop_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportLoopRect.get();
950 transport_punch_range_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
951 transport_punch_range_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TransportPunchRect.get();
953 transport_punchin_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
954 transport_punchout_line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_PunchLine.get();
956 zoom_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
957 zoom_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ZoomRect.get();
959 rubberband_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
960 rubberband_rect->property_fill_color_rgba() = (guint32) ARDOUR_UI::config()->canvasvar_RubberBandRect.get();
962 location_marker_color = ARDOUR_UI::config()->canvasvar_LocationMarker.get();
963 location_range_color = ARDOUR_UI::config()->canvasvar_LocationRange.get();
964 location_cd_marker_color = ARDOUR_UI::config()->canvasvar_LocationCDMarker.get();
965 location_loop_color = ARDOUR_UI::config()->canvasvar_LocationLoop.get();
966 location_punch_color = ARDOUR_UI::config()->canvasvar_LocationPunch.get();
968 refresh_location_display ();
969 redisplay_tempo (true);
972 session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
977 Editor::flush_canvas ()
980 track_canvas->update_now ();
981 // gdk_window_process_updates (GTK_LAYOUT(track_canvas->gobj())->bin_window, true);