consolidate mini-timeline code, latch expose
[ardour.git] / gtk2_ardour / mini_timeline.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
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.
13  *
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef __gtkardour_mini_timeline_h__
20 #define __gtkardour_mini_timeline_h__
21
22 #include <list>
23 #include <pangomm.h>
24
25 #include "pbd/signals.h"
26
27 #include "ardour/ardour.h"
28 #include "ardour/session_handle.h"
29
30 #include "gtkmm2ext/cairo_widget.h"
31 #include "gtkmm2ext/utils.h"
32
33 #include "audio_clock.h"
34
35 namespace ARDOUR {
36         class Session;
37 }
38
39 class MiniTimeline : public CairoWidget, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList
40 {
41
42 public:
43         MiniTimeline ();
44         ~MiniTimeline ();
45
46         void set_session (ARDOUR::Session *);
47
48 private:
49         void session_going_away ();
50         void super_rapid_update ();
51
52         void on_size_request (Gtk::Requisition*);
53         void on_size_allocate (Gtk::Allocation&);
54         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
55         void on_name_changed ();
56         void set_colors ();
57         void parameter_changed (std::string const &);
58
59         void calculate_time_width ();
60         void calculate_time_spacing ();
61         void update_minitimeline ();
62         void draw_dots (cairo_t*, int left, int right, int y, ArdourCanvas::Color);
63         int  draw_mark (cairo_t*, int x0, int x1, int h, const std::string&);
64
65         void render (cairo_t*, cairo_rectangle_t*);
66         void format_time (framepos_t when);
67
68         bool on_button_release_event (GdkEventButton *ev);
69         bool on_scroll_event (GdkEventScroll*);
70
71         Glib::RefPtr<Pango::Layout> _layout;
72         sigc::connection super_rapid_connection;
73         PBD::ScopedConnectionList marker_connection;
74         PBD::ScopedConnectionList session_connection;
75
76         framepos_t _last_update_frame;
77         AudioClock::Mode _clock_mode;
78         int _time_width;
79         int _time_height;
80
81         int _n_labels;
82         double _px_per_sample;
83         framepos_t _time_granularity;
84         framepos_t _time_span_samples;
85
86         struct JumpRange {
87                 JumpRange (int l, int r, framepos_t t)
88                         : left (l), right (r), to (t) {}
89                 int left;
90                 int right;
91                 framepos_t to;
92         };
93
94         typedef std::list <JumpRange> JumpList;
95         JumpList _jumplist;
96 };
97
98 #endif