make ARDOUR2_UI_RC work again
[ardour.git] / gtk2_ardour / marker.cc
1 /*
2     Copyright (C) 2001 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <sigc++/bind.h>
21 #include <ardour/tempo.h>
22
23 #include "marker.h"
24 #include "public_editor.h"
25 #include "utils.h"
26 #include "canvas_impl.h"
27
28 #include "i18n.h"
29
30 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation, 
31                 Type type, nframes_t frame, bool handle_events)
32
33         : editor (ed), _type(type)
34 {
35         double label_offset = 0;
36         bool annotate_left = false;
37
38         /* Shapes we use:
39
40           Mark:
41
42            (0,0) -> (6,0)
43              ^        |
44              |        V
45            (0,5)    (6,5)
46                \    / 
47                (3,10)
48
49
50            TempoMark:
51            MeterMark:
52
53                (3,0)
54               /      \
55            (0,5) -> (6,5)
56              ^        |
57              |        V
58            (0,10)<-(6,10)
59
60
61            Start:
62
63            0,0\ 
64             |  \        
65             |   \ 6,6
66             |   /
67             |  /
68            0,12 
69
70            End:
71
72                /12,0
73               /     | 
74              /      |
75            6,6      |
76              \      |
77               \     |
78                \    |
79                12,12
80
81              
82            TransportStart:
83
84              0,0
85               | \ 
86               |  \ 
87               |   \ 
88               |    \
89               |     \  
90              0,13 --- 13,13
91
92            TransportEnd:
93
94                     /13,0
95                    /   |
96                   /    |
97                  /     |
98                 /      |
99                /       |
100              0,13 ------ 13,13
101              
102
103              PunchIn:
104
105              0,0 ------> 13,0
106               |       /
107               |      /
108               |     /
109               |    / 
110               |   / 
111               |  / 
112              0,13
113
114              PunchOut
115
116            0,0 -->-13,0
117             \       | 
118              \      |
119               \     |
120                \    |
121                 \   |
122                  \  |
123                  13,13
124              
125            
126         */
127
128         switch (type) {
129         case Mark:
130                 points = new ArdourCanvas::Points ();
131
132                 points->push_back (Gnome::Art::Point (0.0, 0.0));
133                 points->push_back (Gnome::Art::Point (6.0, 0.0));
134                 points->push_back (Gnome::Art::Point (6.0, 5.0));
135                 points->push_back (Gnome::Art::Point (3.0, 10.0));              
136                 points->push_back (Gnome::Art::Point (0.0, 5.0));               
137                 points->push_back (Gnome::Art::Point (0.0, 0.0));               
138                 
139                 shift = 3;
140                 label_offset = 8.0;
141                 break;
142
143         case Tempo:
144         case Meter:
145
146                 points = new ArdourCanvas::Points ();
147                 points->push_back (Gnome::Art::Point (3.0, 0.0));
148                 points->push_back (Gnome::Art::Point (6.0, 5.0));               
149                 points->push_back (Gnome::Art::Point (6.0, 10.0));              
150                 points->push_back (Gnome::Art::Point (0.0, 10.0));              
151                 points->push_back (Gnome::Art::Point (0.0, 5.0));               
152                 points->push_back (Gnome::Art::Point (3.0, 0.0));               
153
154                 shift = 3;
155                 label_offset = 8.0;
156                 break;
157
158         case Start:
159                 points = new ArdourCanvas::Points ();
160                 points->push_back (Gnome::Art::Point (0.0, 0.0));               
161                 points->push_back (Gnome::Art::Point (6.5, 6.5));               
162                 points->push_back (Gnome::Art::Point (0.0, 13.0));              
163                 points->push_back (Gnome::Art::Point (0.0, 0.0));       
164
165                 shift = 0;
166                 label_offset = 13.0;
167                 break;
168
169         case End:
170                 points = new ArdourCanvas::Points ();
171                 points->push_back (Gnome::Art::Point (6.5, 6.5));
172                 points->push_back (Gnome::Art::Point (13.0, 0.0));              
173                 points->push_back (Gnome::Art::Point (13.0, 13.0));                     
174                 points->push_back (Gnome::Art::Point (6.5, 6.5));               
175                 
176                 shift = 13;
177                 label_offset = 6.0;
178                 annotate_left = true;
179                 break;
180
181         case LoopStart:
182                 points = new ArdourCanvas::Points ();
183                 points->push_back (Gnome::Art::Point (0.0, 0.0));       
184                 points->push_back (Gnome::Art::Point (13.0, 13.0));             
185                 points->push_back (Gnome::Art::Point (0.0, 13.0));              
186                 points->push_back (Gnome::Art::Point (0.0, 0.0));               
187                 
188                 shift = 0;
189                 label_offset = 12.0;
190                 break;
191
192         case LoopEnd:
193                 points = new ArdourCanvas::Points ();
194                 points->push_back (Gnome::Art::Point (13.0,  0.0));
195                 points->push_back (Gnome::Art::Point (13.0, 13.0));     
196                 points->push_back (Gnome::Art::Point (0.0, 13.0));              
197                 points->push_back (Gnome::Art::Point (13.0, 0.0));
198                 
199                 shift = 13;
200                 label_offset = 0.0;
201                 annotate_left = true;
202                 break;
203
204         case  PunchIn:
205                 points = new ArdourCanvas::Points ();
206                 points->push_back (Gnome::Art::Point (0.0, 0.0));
207                 points->push_back (Gnome::Art::Point (13.0, 0.0));              
208                 points->push_back (Gnome::Art::Point (0.0, 13.0));      
209                 points->push_back (Gnome::Art::Point (0.0, 0.0));       
210
211                 shift = 0;
212                 label_offset = 13.0;
213                 break;
214                 
215         case  PunchOut:
216                 points = new ArdourCanvas::Points ();
217                 points->push_back (Gnome::Art::Point (0.0, 0.0));
218                 points->push_back (Gnome::Art::Point (12.0, 0.0));                      
219                 points->push_back (Gnome::Art::Point (12.0, 12.0));             
220                 points->push_back (Gnome::Art::Point (0.0, 0.0));               
221
222                 shift = 13;
223                 label_offset = 0.0;
224                 annotate_left = true;
225                 break;
226                 
227         }
228
229         frame_position = frame;
230         unit_position = editor.frame_to_unit (frame);
231
232         /* adjust to properly locate the tip */
233
234         unit_position -= shift;
235
236         group = new Group (parent, unit_position, 1.0);
237
238         mark = new Polygon (*group);
239         mark->property_points() = *points;
240         mark->property_fill_color_rgba() = rgba;
241         mark->property_outline_color_rgba() = rgba;
242         mark->property_width_pixels() = 1;
243         Pango::FontDescription font = get_font_for_style (N_("MarkerText"));
244         
245         text = new Text (*group);
246         text->property_text() = annotation.c_str();
247         text->property_font_desc() = font;
248         if (annotate_left) {
249           text->property_x() = -(text->property_text_width());
250         } else {
251           text->property_x() = label_offset;
252         }
253         text->property_y() = 0.0;
254         text->property_anchor() = Gtk::ANCHOR_NW;
255         text->property_fill_color() = "black";
256
257         editor.ZoomChanged.connect (mem_fun (*this, &Marker::reposition));
258
259         mark->set_data ("marker", this);
260
261         if (handle_events) {
262                 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
263         }
264
265 }
266
267 Marker::~Marker ()
268 {
269         /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
270         delete text;
271         delete mark;
272         delete points;
273 }
274
275 ArdourCanvas::Item&
276 Marker::the_item() const
277 {
278         return *mark;
279 }
280
281 void
282 Marker::set_name (const string& name)
283 {
284         text->property_text() = name.c_str();
285         if (_type == End) {
286           text->property_x() = -(text->property_text_width());
287         }
288 }
289
290 void
291 Marker::set_position (nframes_t frame)
292 {
293         double new_unit_position = editor.frame_to_unit (frame);
294         new_unit_position -= shift;
295         group->move (new_unit_position - unit_position, 0.0);
296         frame_position = frame;
297         unit_position = new_unit_position;
298 }
299
300 void
301 Marker::reposition ()
302 {
303         set_position (frame_position);
304 }       
305
306 void
307 Marker::show ()
308 {
309         group->show();
310 }
311
312 void
313 Marker::hide ()
314 {
315         group->hide();
316 }
317
318 void
319 Marker::set_color_rgba (uint32_t color)
320 {
321         mark->property_fill_color_rgba() = color;
322 }
323
324 /***********************************************************************/
325
326 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text, 
327                           ARDOUR::TempoSection& temp)
328         : Marker (editor, parent, rgba, text, Tempo, 0, false),
329           _tempo (temp)
330 {
331         set_position (_tempo.frame());
332         group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
333 }
334
335 TempoMarker::~TempoMarker ()
336 {
337 }
338
339 /***********************************************************************/
340
341 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text, 
342                           ARDOUR::MeterSection& m) 
343         : Marker (editor, parent, rgba, text, Meter, 0, false),
344           _meter (m)
345 {
346         set_position (_meter.frame());
347         group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
348 }
349
350 MeterMarker::~MeterMarker ()
351 {
352 }
353