2 Copyright (C) 2001 Paul Davis
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.
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.
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.
21 #include <ardour/tempo.h>
24 #include "public_editor.h"
25 #include "canvas-simpleline.h"
30 Marker::Marker (PublicEditor& ed, GtkCanvasGroup *parent, guint32 rgba, const string& annotation,
31 Type type, gint (*callback)(GtkCanvasItem *, GdkEvent *, gpointer), jack_nframes_t frame)
33 : editor (ed), _type(type)
35 double label_offset = 0;
125 points = gtk_canvas_points_new (6);
127 points->coords[0] = 0.0;
128 points->coords[1] = 0.0;
130 points->coords[2] = 6.0;
131 points->coords[3] = 0.0;
133 points->coords[4] = 6.0;
134 points->coords[5] = 5.0;
136 points->coords[6] = 3.0;
137 points->coords[7] = 10.0;
139 points->coords[8] = 0.0;
140 points->coords[9] = 5.0;
142 points->coords[10] = 0.0;
143 points->coords[11] = 0.0;
151 points = gtk_canvas_points_new (6);
153 points->coords[0] = 3.0;
154 points->coords[1] = 0.0;
156 points->coords[2] = 6.0;
157 points->coords[3] = 5.0;
159 points->coords[4] = 6.0;
160 points->coords[5] = 10.0;
162 points->coords[6] = 0.0;
163 points->coords[7] = 10.0;
165 points->coords[8] = 0.0;
166 points->coords[9] = 5.0;
168 points->coords[10] = 3.0;
169 points->coords[11] = 0.0;
176 points = gtk_canvas_points_new (6);
178 points->coords[0] = 0.0;
179 points->coords[1] = 0.0;
181 points->coords[2] = 5.0;
182 points->coords[3] = 0.0;
184 points->coords[4] = 10.0;
185 points->coords[5] = 5.0;
187 points->coords[6] = 5.0;
188 points->coords[7] = 10.0;
190 points->coords[8] = 0.0;
191 points->coords[9] = 10.0;
193 points->coords[10] = 0.0;
194 points->coords[11] = 0.0;
201 points = gtk_canvas_points_new (6);
203 points->coords[0] = 5.0;
204 points->coords[1] = 0.0;
206 points->coords[2] = 10.0;
207 points->coords[3] = 0.0;
209 points->coords[4] = 10.0;
210 points->coords[5] = 10.0;
212 points->coords[6] = 5.0;
213 points->coords[7] = 10.0;
215 points->coords[8] = 0.0;
216 points->coords[9] = 5.0;
218 points->coords[10] = 5.0;
219 points->coords[11] = 0.0;
226 points = gtk_canvas_points_new (7);
228 points->coords[0] = 0.0;
229 points->coords[1] = 0.0;
231 points->coords[2] = 4.0;
232 points->coords[3] = 0.0;
234 points->coords[4] = 4.0;
235 points->coords[5] = 8.0;
237 points->coords[6] = 8.0;
238 points->coords[7] = 8.0;
240 points->coords[8] = 8.0;
241 points->coords[9] = 11.0;
243 points->coords[10] = 0.0;
244 points->coords[11] = 11.0;
246 points->coords[12] = 0.0;
247 points->coords[13] = 0.0;
254 points = gtk_canvas_points_new (7);
256 points->coords[0] = 8.0;
257 points->coords[1] = 0.0;
259 points->coords[2] = 8.0;
260 points->coords[3] = 11.0;
262 points->coords[4] = 0.0;
263 points->coords[5] = 11.0;
265 points->coords[6] = 0.0;
266 points->coords[7] = 8.0;
268 points->coords[8] = 4.0;
269 points->coords[9] = 8.0;
271 points->coords[10] = 4.0;
272 points->coords[11] = 0.0;
274 points->coords[12] = 8.0;
275 points->coords[13] = 0.0;
282 points = gtk_canvas_points_new (6);
284 points->coords[0] = 0.0;
285 points->coords[1] = 0.0;
287 points->coords[2] = 8.0;
288 points->coords[3] = 0.0;
290 points->coords[4] = 4.0;
291 points->coords[5] = 4.0;
293 points->coords[6] = 4.0;
294 points->coords[7] = 11.0;
296 points->coords[8] = 0.0;
297 points->coords[9] = 11.0;
299 points->coords[10] = 0.0;
300 points->coords[11] = 0.0;
307 points = gtk_canvas_points_new (6);
309 points->coords[0] = 0.0;
310 points->coords[1] = 0.0;
312 points->coords[2] = 8.0;
313 points->coords[3] = 0.0;
315 points->coords[4] = 8.0;
316 points->coords[5] = 11.0;
318 points->coords[6] = 4.0;
319 points->coords[7] = 11.0;
321 points->coords[8] = 4.0;
322 points->coords[9] = 4.0;
324 points->coords[10] = 0.0;
325 points->coords[11] = 0.0;
333 frame_position = frame;
334 unit_position = editor.frame_to_unit (frame);
336 /* adjust to properly locate the tip */
338 unit_position -= shift;
340 group = gtk_canvas_item_new (parent,
341 gtk_canvas_group_get_type(),
346 // cerr << "set mark al points, nc = " << points->num_points << endl;
347 mark = gtk_canvas_item_new (GTK_CANVAS_GROUP(group),
348 gtk_canvas_polygon_get_type(),
350 "fill_color_rgba", rgba,
351 "outline_color", "black",
354 string fontname = get_font_for_style (N_("MarkerText"));
356 text = gtk_canvas_item_new (GTK_CANVAS_GROUP(group),
357 gtk_canvas_text_get_type (),
358 "text", annotation.c_str(),
361 "font", fontname.c_str(),
362 "anchor", GTK_ANCHOR_NW,
363 "fill_color", "black",
366 gtk_object_set_data (GTK_OBJECT(group), "marker", this);
367 gtk_signal_connect (GTK_OBJECT(group), "event", (GtkSignalFunc) callback, &editor);
369 editor.ZoomChanged.connect (slot (*this, &Marker::reposition));
374 /* destroying the group destroys its contents */
375 gtk_object_destroy (GTK_OBJECT(group));
376 gtk_canvas_points_unref (points);
380 Marker::set_name (const string& name)
382 gtk_canvas_item_set (text, "text", name.c_str(), NULL);
386 Marker::set_position (jack_nframes_t frame)
388 double new_unit_position = editor.frame_to_unit (frame);
389 new_unit_position -= shift;
390 gtk_canvas_item_move (group, new_unit_position - unit_position, 0.0);
391 frame_position = frame;
392 unit_position = new_unit_position;
396 Marker::reposition ()
398 set_position (frame_position);
404 gtk_canvas_item_show (group);
410 gtk_canvas_item_hide (group);
414 Marker::set_color_rgba (uint32_t color)
416 gtk_canvas_item_set (mark, "fill_color_rgba", color, NULL);
419 /***********************************************************************/
421 TempoMarker::TempoMarker (PublicEditor& editor, GtkCanvasGroup *parent, guint32 rgba, const string& text,
422 ARDOUR::TempoSection& temp,
423 gint (*callback)(GtkCanvasItem *, GdkEvent *, gpointer))
424 : Marker (editor, parent, rgba, text, Tempo, callback, 0),
427 set_position (_tempo.frame());
428 gtk_object_set_data (GTK_OBJECT(group), "tempo_marker", this);
431 TempoMarker::~TempoMarker ()
435 /***********************************************************************/
437 MeterMarker::MeterMarker (PublicEditor& editor, GtkCanvasGroup *parent, guint32 rgba, const string& text,
438 ARDOUR::MeterSection& m,
439 gint (*callback)(GtkCanvasItem *, GdkEvent *, gpointer))
440 : Marker (editor, parent, rgba, text, Meter, callback, 0),
443 set_position (_meter.frame());
444 gtk_object_set_data (GTK_OBJECT(group), "meter_marker", this);
447 MeterMarker::~MeterMarker ()