Unconditionally save instant.xml on session-close
[ardour.git] / gtk2_ardour / marker.h
1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
7  * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __gtk_ardour_marker_h__
25 #define __gtk_ardour_marker_h__
26
27 #include <string>
28 #include <glib.h>
29
30 #include <sigc++/signal.h>
31
32 #include "ardour/ardour.h"
33 #include "pbd/signals.h"
34
35 #include "canvas/fwd.h"
36 #include "canvas/types.h"
37
38 namespace ARDOUR {
39         class TempoSection;
40         class MeterSection;
41 }
42
43 class PublicEditor;
44
45 /** Location Marker
46  *
47  * Editor ruler representation of a location marker or range on the timeline.
48  */
49 class ArdourMarker : public sigc::trackable
50 {
51 public:
52         enum Type {
53                 Mark,
54                 Tempo,
55                 Meter,
56                 SessionStart, ///< session start
57                 SessionEnd,   ///< session end
58                 RangeStart,
59                 RangeEnd,
60                 LoopStart,
61                 LoopEnd,
62                 PunchIn,
63                 PunchOut
64         };
65
66
67         ArdourMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, Type,
68                       samplepos_t sample = 0, bool handle_events = true);
69
70         virtual ~ArdourMarker ();
71
72         static PBD::Signal1<void,ArdourMarker*> CatchDeletion;
73
74         static void setup_sizes (const double timebar_height);
75
76         ArdourCanvas::Item& the_item() const;
77
78         void set_selected (bool);
79         void set_show_line (bool);
80         void canvas_height_set (double);
81
82         void set_position (samplepos_t);
83         void set_name (const std::string&);
84         void set_points_color (uint32_t rgba);
85         void set_color_rgba (uint32_t rgba);
86         void setup_line ();
87
88         samplepos_t position() const { return sample_position; }
89
90         ArdourCanvas::Container * get_parent() { return _parent; }
91         void reparent (ArdourCanvas::Container & parent);
92
93         void hide ();
94         void show ();
95
96         Type type () { return _type; }
97
98         void set_left_label_limit (double);
99         void set_right_label_limit (double);
100
101         std::string name () const {
102                 return _name;
103         }
104
105         bool label_on_left () const;
106
107 protected:
108         PublicEditor& editor;
109
110         Pango::FontDescription name_font;
111
112         ArdourCanvas::Container* _parent;
113         ArdourCanvas::Container *group;
114         ArdourCanvas::Polygon *mark;
115         ArdourCanvas::Text *_name_item;
116         ArdourCanvas::Points *points;
117         ArdourCanvas::Line* _track_canvas_line;
118         ArdourCanvas::Rectangle* _name_background;
119
120         std::string  _name;
121         double        unit_position;
122         samplepos_t    sample_position;
123         double       _shift;
124         Type         _type;
125         int           name_height;
126         bool         _selected;
127         bool         _shown;
128         bool         _line_shown;
129         double       _canvas_height;
130         uint32_t     _color;
131         uint32_t     _points_color;
132         double       _left_label_limit; ///< the number of pixels available to the left of this marker for a label
133         double       _right_label_limit; ///< the number of pixels available to the right of this marker for a label
134         double       _label_offset;
135
136         void reposition ();
137         void setup_line_x ();
138         void setup_name_display ();
139
140 private:
141         /* disallow copy construction */
142         ArdourMarker (ArdourMarker const &);
143         ArdourMarker & operator= (ArdourMarker const &);
144 };
145
146 class TempoMarker : public ArdourMarker
147 {
148   public:
149         TempoMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, ARDOUR::TempoSection&);
150         ~TempoMarker ();
151
152         ARDOUR::TempoSection& tempo() const { return _tempo; }
153
154         void update_height_mark (const double ratio);
155   private:
156         ARDOUR::TempoSection& _tempo;
157 };
158
159 class MeterMarker : public ArdourMarker
160 {
161   public:
162         MeterMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, ARDOUR::MeterSection&);
163         ~MeterMarker ();
164
165         ARDOUR::MeterSection& meter() const { return _meter; }
166
167   private:
168         ARDOUR::MeterSection& _meter;
169 };
170
171 #endif /* __gtk_ardour_marker_h__ */