1 #include "ardour/session.h"
2 #include "time_axis_view.h"
3 #include "streamview.h"
4 #include "editor_summary.h"
5 #include "gui_thread.h"
7 #include "region_view.h"
11 using namespace ARDOUR;
13 /** Construct an EditorSummary.
14 * @param e Editor to represent.
16 EditorSummary::EditorSummary (Editor* e)
20 _regions_dirty (true),
23 _pixels_per_frame (1),
36 EditorSummary::set_session (Session* s)
40 Region::RegionPropertyChanged.connect (sigc::hide (mem_fun (*this, &EditorSummary::set_dirty)));
42 _session->RegionRemoved.connect (sigc::hide (mem_fun (*this, &EditorSummary::set_dirty)));
43 _session->EndTimeChanged.connect (mem_fun (*this, &EditorSummary::set_dirty));
44 _session->StartTimeChanged.connect (mem_fun (*this, &EditorSummary::set_dirty));
50 EditorSummary::~EditorSummary ()
53 gdk_pixmap_unref (_pixmap);
57 /** Handle an expose event.
58 * @param event Event from GTK.
61 EditorSummary::on_expose_event (GdkEventExpose* event)
63 /* Render the regions pixmap */
65 Gdk::Rectangle const exposure (
66 event->area.x, event->area.y, event->area.width, event->area.height
69 Gdk::Rectangle r = exposure;
70 Gdk::Rectangle content (0, 0, _width, _height);
72 r.intersect (content, intersects);
76 GdkPixmap* p = get_pixmap (get_window()->gobj ());
80 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
91 /* Render the view rectangle */
93 pair<double, double> x;
94 pair<double, double> y;
97 cairo_t* cr = gdk_cairo_create (get_window()->gobj());
99 cairo_set_source_rgba (cr, 0, 1, 0, 0.5);
101 cairo_move_to (cr, x.first, y.first);
102 cairo_line_to (cr, x.second, y.first);
103 cairo_line_to (cr, x.second, y.second);
104 cairo_line_to (cr, x.first, y.second);
105 cairo_line_to (cr, x.first, y.first);
113 /** @param drawable GDK drawable.
114 * @return pixmap for the regions.
117 EditorSummary::get_pixmap (GdkDrawable* drawable)
119 if (_regions_dirty) {
122 gdk_pixmap_unref (_pixmap);
124 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
126 cairo_t* cr = gdk_cairo_create (_pixmap);
130 _regions_dirty = false;
136 /** Render the required regions to a cairo context.
140 EditorSummary::render (cairo_t* cr)
148 cairo_set_source_rgb (cr, 0, 0, 0);
149 cairo_rectangle (cr, 0, 0, _width, _height);
152 /* compute total height of all tracks */
155 for (PublicEditor::TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
156 h += (*i)->effective_height ();
159 nframes_t const start = _session->current_start_frame ();
160 _pixels_per_frame = static_cast<double> (_width) / (_session->current_end_frame() - start);
161 _vertical_scale = static_cast<double> (_height) / h;
167 for (PublicEditor::TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
168 StreamView* s = (*i)->view ();
171 double const h = (*i)->effective_height () * _vertical_scale;
172 cairo_set_line_width (cr, h);
174 double const v = ((n % 2) == 0) ? 1 : 0.5;
175 cairo_set_source_rgb (cr, v, v, v);
177 s->foreach_regionview (bind (
178 mem_fun (*this, &EditorSummary::render_region),
190 /** Render a region for the summary.
191 * @param r Region view.
192 * @param cr Cairo context.
193 * @param start Frame offset that the summary starts at.
194 * @param y y coordinate to render at.
197 EditorSummary::render_region (RegionView* r, cairo_t* cr, nframes_t start, double y) const
199 cairo_move_to (cr, (r->region()->position() - start) * _pixels_per_frame, y);
200 cairo_line_to (cr, ((r->region()->position() - start + r->region()->length())) * _pixels_per_frame, y);
204 /** Set the summary so that the whole thing will be re-rendered next time it is required */
206 EditorSummary::set_dirty ()
208 ENSURE_GUI_THREAD (mem_fun (*this, &EditorSummary::set_dirty));
210 _regions_dirty = true;
214 /** Set the summary so that just the view boundary markers will be re-rendered */
216 EditorSummary::set_bounds_dirty ()
218 ENSURE_GUI_THREAD (mem_fun (*this, &EditorSummary::set_bounds_dirty));
222 /** Handle a size request.
223 * @param req GTK requisition
226 EditorSummary::on_size_request (Gtk::Requisition *req)
228 /* Use a dummy, small width and the actual height that we want */
233 /** Handle a size allocation.
234 * @param alloc GTK allocation.
237 EditorSummary::on_size_allocate (Gtk::Allocation& alloc)
239 Gtk::EventBox::on_size_allocate (alloc);
241 _width = alloc.get_width ();
242 _height = alloc.get_height ();
248 EditorSummary::centre_on_click (GdkEventButton* ev)
250 nframes_t x = (ev->x / _pixels_per_frame) + _session->current_start_frame();
251 nframes_t const xh = _editor->current_page_frames () / 2;
258 _editor->reset_x_origin (x);
260 double y = ev->y / _vertical_scale;
261 double const yh = _editor->canvas_height () / 2;
268 _editor->reset_y_origin (y);
271 /** Handle a button press.
272 * @param ev GTK event.
275 EditorSummary::on_button_press_event (GdkEventButton* ev)
277 if (ev->button == 1) {
279 pair<double, double> xr;
280 pair<double, double> yr;
281 editor_view (&xr, &yr);
283 if (xr.first <= ev->x && ev->x <= xr.second && yr.first <= ev->y && ev->y <= yr.second) {
285 /* click inside the view rectangle: drag it */
288 _x_offset = ev->x - xr.first;
289 _y_offset = ev->y - yr.first;
290 _editor->_dragging_playhead = true;
294 /* click outside the view rectangle: centre the view around the mouse click */
295 centre_on_click (ev);
303 EditorSummary::editor_view (pair<double, double>* x, pair<double, double>* y) const
305 x->first = (_editor->leftmost_position () - _session->current_start_frame ()) * _pixels_per_frame;
306 x->second = x->first + _editor->current_page_frames() * _pixels_per_frame;
308 y->first = _editor->get_trackview_group_vertical_offset () * _vertical_scale;
309 y->second = y->first + _editor->canvas_height () * _vertical_scale;
313 EditorSummary::on_motion_notify_event (GdkEventMotion* ev)
321 _editor->reset_x_origin (((ev->x - _x_offset) / _pixels_per_frame) + _session->current_start_frame ());
322 _editor->reset_y_origin ((ev->y - _y_offset) / _vertical_scale);
328 EditorSummary::on_button_release_event (GdkEventButton* ev)
330 if (_dragging && !_moved) {
331 centre_on_click (ev);
335 _editor->_dragging_playhead = false;