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),
32 EditorSummary::set_session (Session* s)
36 Region::RegionPropertyChanged.connect (sigc::hide (mem_fun (*this, &EditorSummary::set_dirty)));
38 _session->RegionRemoved.connect (sigc::hide (mem_fun (*this, &EditorSummary::set_dirty)));
39 _session->EndTimeChanged.connect (mem_fun (*this, &EditorSummary::set_dirty));
40 _session->StartTimeChanged.connect (mem_fun (*this, &EditorSummary::set_dirty));
46 EditorSummary::~EditorSummary ()
49 gdk_pixmap_unref (_pixmap);
53 /** Handle an expose event.
54 * @param event Event from GTK.
57 EditorSummary::on_expose_event (GdkEventExpose* event)
59 /* Render the regions pixmap */
61 Gdk::Rectangle const exposure (
62 event->area.x, event->area.y, event->area.width, event->area.height
65 Gdk::Rectangle r = exposure;
66 Gdk::Rectangle content (0, 0, _width, _height);
68 r.intersect (content, intersects);
72 GdkPixmap* p = get_pixmap (get_window()->gobj ());
76 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
87 /* Render the view beginning and end markers */
89 cairo_t* cr = gdk_cairo_create (get_window()->gobj());
91 cairo_set_source_rgb (cr, 0, 1, 0);
92 cairo_set_line_width (cr, 2);
94 double const s = (_editor->leftmost_position () - _session->current_start_frame ()) * _pixels_per_frame;
95 cairo_move_to (cr, s, 0);
96 cairo_line_to (cr, s, _height);
99 double const e = s + _editor->current_page_frames() * _pixels_per_frame;
100 cairo_move_to (cr, e, 0);
101 cairo_line_to (cr, e, _height);
109 /** @param drawable GDK drawable.
110 * @return pixmap for the regions.
113 EditorSummary::get_pixmap (GdkDrawable* drawable)
115 if (_regions_dirty) {
118 gdk_pixmap_unref (_pixmap);
120 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
122 cairo_t* cr = gdk_cairo_create (_pixmap);
126 _regions_dirty = false;
132 /** Render the required regions to a cairo context.
136 EditorSummary::render (cairo_t* cr)
144 cairo_set_source_rgb (cr, 0, 0, 0);
145 cairo_rectangle (cr, 0, 0, _width, _height);
150 /* count tracks to render */
151 for (PublicEditor::TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
157 nframes_t const start = _session->current_start_frame ();
158 _pixels_per_frame = static_cast<double> (_width) / (_session->current_end_frame() - start);
159 double const track_height = static_cast<double> (_height) / N;
161 cairo_set_line_width (cr, track_height);
166 for (PublicEditor::TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
167 StreamView* s = (*i)->view ();
170 double const v = ((n % 2) == 0) ? 1 : 0.5;
171 cairo_set_source_rgb (cr, v, v, v);
173 s->foreach_regionview (bind (
174 mem_fun (*this, &EditorSummary::render_region),
177 track_height * (n + 0.5)
185 /** Render a region for the summary.
186 * @param r Region view.
187 * @param cr Cairo context.
188 * @param start Frame offset that the summary starts at.
189 * @param y y coordinate to render at.
192 EditorSummary::render_region (RegionView* r, cairo_t* cr, nframes_t start, double y) const
194 cairo_move_to (cr, (r->region()->position() - start) * _pixels_per_frame, y);
195 cairo_line_to (cr, (r->region()->position() - start + r->region()->length()) * _pixels_per_frame, y);
199 /** Set the summary so that the whole thing will be re-rendered next time it is required */
201 EditorSummary::set_dirty ()
203 ENSURE_GUI_THREAD (mem_fun (*this, &EditorSummary::set_dirty));
205 _regions_dirty = true;
209 /** Set the summary so that just the view boundary markers will be re-rendered */
211 EditorSummary::set_bounds_dirty ()
213 ENSURE_GUI_THREAD (mem_fun (*this, &EditorSummary::set_bounds_dirty));
217 /** Handle a size request.
218 * @param req GTK requisition
221 EditorSummary::on_size_request (Gtk::Requisition *req)
223 /* Use a dummy, small width and the actual height that we want */
228 /** Handle a size allocation.
229 * @param alloc GTK allocation.
232 EditorSummary::on_size_allocate (Gtk::Allocation& alloc)
234 Gtk::EventBox::on_size_allocate (alloc);
236 _width = alloc.get_width ();
237 _height = alloc.get_height ();
242 /** Handle a button press.
243 * @param ev GTK event.
246 EditorSummary::on_button_press_event (GdkEventButton* ev)
248 if (ev->button == 1) {
250 /* centre the editor view around the mouse click */
252 nframes_t f = (ev->x / _pixels_per_frame) + _session->current_start_frame();
254 nframes_t const h = _editor->current_page_frames () / 2;
261 _editor->reset_x_origin (f);