Update GPL boilerplate and (C)
[ardour.git] / gtk2_ardour / mini_timeline.h
1 /*
2  * Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2016-2018 Ben Loftis <ben@harrisonconsoles.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef __gtkardour_mini_timeline_h__
21 #define __gtkardour_mini_timeline_h__
22
23 #include <list>
24 #include <pangomm.h>
25
26 #include "pbd/signals.h"
27
28 #include "ardour/ardour.h"
29 #include "ardour/types.h"
30 #include "ardour/session_handle.h"
31
32 #include "gtkmm2ext/cairo_widget.h"
33 #include "gtkmm2ext/utils.h"
34
35 #include "audio_clock.h"
36
37 namespace ARDOUR {
38         class Session;
39 }
40
41 namespace Gtk {
42         class Menu;
43 }
44
45 class MiniTimeline : public CairoWidget, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList
46 {
47
48 public:
49         MiniTimeline ();
50         ~MiniTimeline ();
51
52         void set_session (ARDOUR::Session *);
53
54 private:
55         void session_going_away ();
56         void super_rapid_update ();
57
58         void on_size_request (Gtk::Requisition*);
59         void on_size_allocate (Gtk::Allocation&);
60         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
61         void on_name_changed ();
62         void set_colors ();
63         void parameter_changed (std::string const &);
64
65         void calculate_time_width ();
66         void calculate_time_spacing ();
67         void update_minitimeline ();
68         void draw_dots (cairo_t*, int left, int right, int y, Gtkmm2ext::Color);
69         int  draw_mark (cairo_t*, int x0, int x1, const std::string&, bool& prelight);
70         int  draw_edge (cairo_t*, int x0, int x1, bool left, const std::string&, bool& prelight);
71
72         void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
73         void format_time (samplepos_t when);
74
75         bool on_button_press_event (GdkEventButton*);
76         bool on_button_release_event (GdkEventButton*);
77         bool on_scroll_event (GdkEventScroll*);
78         bool on_motion_notify_event (GdkEventMotion*);
79         bool on_leave_notify_event (GdkEventCrossing*);
80
81         void build_minitl_context_menu ();
82         void set_span (ARDOUR::samplecnt_t);
83
84         Glib::RefPtr<Pango::Layout> _layout;
85         sigc::connection super_rapid_connection;
86         PBD::ScopedConnectionList marker_connection;
87         PBD::ScopedConnectionList session_connection;
88
89         samplepos_t _last_update_sample;
90         AudioClock::Mode _clock_mode;
91         int _time_width;
92         int _time_height;
93
94         int _n_labels;
95         double _px_per_sample;
96         ARDOUR::samplecnt_t _time_granularity;
97         ARDOUR::samplecnt_t _time_span_samples;
98         int _marker_height;
99
100         int _pointer_x;
101         int _pointer_y;
102
103         Gtk::Menu* _minitl_context_menu;
104
105         uint32_t _phead_color;
106
107         struct JumpRange {
108                 JumpRange (int l, int r, samplepos_t t, bool p = false)
109                         : left (l), right (r), to (t), prelight (p) {}
110                 int left;
111                 int right;
112                 samplepos_t to;
113                 bool prelight;
114         };
115
116         typedef std::list <JumpRange> JumpList;
117         JumpList _jumplist;
118 };
119
120 #endif