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.
20 #include <sigc++/bind.h>
21 #include "ardour/tempo.h"
23 #include "ardour_ui.h"
25 * ardour_ui.h include was moved to the top of the list
26 * due to a conflicting definition of 'Rect' between
27 * Apple's MacTypes.h and GTK.
31 #include "public_editor.h"
33 #include "canvas_impl.h"
34 #include "simpleline.h"
35 #include "simplerect.h"
36 #include "rgb_macros.h"
38 #include <gtkmm2ext/utils.h>
43 using namespace ARDOUR;
44 using namespace Gtkmm2ext;
46 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
48 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
49 Type type, framepos_t frame, bool handle_events)
60 , _left_label_limit (DBL_MAX)
61 , _right_label_limit (DBL_MAX)
135 points = new ArdourCanvas::Points ();
137 points->push_back (Gnome::Art::Point (0.0, 0.0));
138 points->push_back (Gnome::Art::Point (6.0, 0.0));
139 points->push_back (Gnome::Art::Point (6.0, 5.0));
140 points->push_back (Gnome::Art::Point (3.0, 13.0));
141 points->push_back (Gnome::Art::Point (0.0, 5.0));
142 points->push_back (Gnome::Art::Point (0.0, 0.0));
151 points = new ArdourCanvas::Points ();
152 points->push_back (Gnome::Art::Point (3.0, 0.0));
153 points->push_back (Gnome::Art::Point (6.0, 5.0));
154 points->push_back (Gnome::Art::Point (6.0, 10.0));
155 points->push_back (Gnome::Art::Point (0.0, 10.0));
156 points->push_back (Gnome::Art::Point (0.0, 5.0));
157 points->push_back (Gnome::Art::Point (3.0, 0.0));
166 points = new ArdourCanvas::Points ();
167 points->push_back (Gnome::Art::Point (0.0, 0.0));
168 points->push_back (Gnome::Art::Point (6.5, 6.5));
169 points->push_back (Gnome::Art::Point (0.0, 13.0));
170 points->push_back (Gnome::Art::Point (0.0, 0.0));
173 _label_offset = 13.0;
178 points = new ArdourCanvas::Points ();
179 points->push_back (Gnome::Art::Point (6.5, 6.5));
180 points->push_back (Gnome::Art::Point (13.0, 0.0));
181 points->push_back (Gnome::Art::Point (13.0, 13.0));
182 points->push_back (Gnome::Art::Point (6.5, 6.5));
189 points = new ArdourCanvas::Points ();
190 points->push_back (Gnome::Art::Point (0.0, 0.0));
191 points->push_back (Gnome::Art::Point (13.0, 13.0));
192 points->push_back (Gnome::Art::Point (0.0, 13.0));
193 points->push_back (Gnome::Art::Point (0.0, 0.0));
196 _label_offset = 12.0;
200 points = new ArdourCanvas::Points ();
201 points->push_back (Gnome::Art::Point (13.0, 0.0));
202 points->push_back (Gnome::Art::Point (13.0, 13.0));
203 points->push_back (Gnome::Art::Point (0.0, 13.0));
204 points->push_back (Gnome::Art::Point (13.0, 0.0));
211 points = new ArdourCanvas::Points ();
212 points->push_back (Gnome::Art::Point (0.0, 0.0));
213 points->push_back (Gnome::Art::Point (13.0, 0.0));
214 points->push_back (Gnome::Art::Point (0.0, 13.0));
215 points->push_back (Gnome::Art::Point (0.0, 0.0));
218 _label_offset = 13.0;
222 points = new ArdourCanvas::Points ();
223 points->push_back (Gnome::Art::Point (0.0, 0.0));
224 points->push_back (Gnome::Art::Point (12.0, 0.0));
225 points->push_back (Gnome::Art::Point (12.0, 12.0));
226 points->push_back (Gnome::Art::Point (0.0, 0.0));
234 frame_position = frame;
235 unit_position = editor.frame_to_unit (frame);
236 unit_position -= _shift;
238 group = new Group (parent, unit_position, 1.0);
240 _name_background = new ArdourCanvas::SimpleRect (*group);
241 _name_background->property_outline_pixels() = 1;
243 /* adjust to properly locate the tip */
245 mark = new Polygon (*group);
246 mark->property_points() = *points;
247 set_color_rgba (rgba);
248 mark->property_width_pixels() = 1;
250 /* setup name pixbuf sizes */
251 name_font = get_font_for_style (N_("MarkerText"));
255 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
258 layout->set_font_description (*name_font);
259 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
261 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
262 name_pixbuf->property_x() = _label_offset;
263 name_pixbuf->property_y() = (13/2) - (name_height/2);
265 set_name (annotation.c_str());
267 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
269 mark->set_data ("marker", this);
270 _name_background->set_data ("marker", this);
273 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
281 CatchDeletion (this); /* EMIT SIGNAL */
283 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
288 void Marker::reparent(ArdourCanvas::Group & parent)
290 group->reparent (parent);
295 Marker::set_selected (bool s)
302 Marker::set_show_line (bool s)
309 Marker::setup_line ()
311 if (_shown && (_selected || _line_shown)) {
315 _line = new ArdourCanvas::SimpleLine (*group);
316 _line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint.get();
318 _line->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
321 /* work out where to start the line from so that it extends from the top of the canvas */
327 _line->property_x1() = _shift;
328 _line->property_x2() = _shift;
329 _line->property_y1() = -yo; // zero in world coordinates, negative in item/parent coordinate space
330 _line->property_y2() = -yo + _canvas_height;
332 _line->property_color_rgba() = _selected ? ARDOUR_UI::config()->canvasvar_EditPoint.get() : _color;
333 _line->raise_to_top ();
344 Marker::canvas_height_set (double h)
351 Marker::the_item() const
357 Marker::set_name (const string& new_name)
361 setup_name_display ();
364 /** @return true if our label is on the left of the mark, otherwise false */
366 Marker::label_on_left () const
368 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
372 Marker::setup_name_display ()
374 double limit = DBL_MAX;
376 if (label_on_left ()) {
377 limit = _left_label_limit;
379 limit = _right_label_limit;
382 /* Work out how wide the name can be */
383 int name_width = min ((double) pixel_width (_name, *name_font) + 2, limit);
384 if (name_width == 0) {
388 if (label_on_left ()) {
389 name_pixbuf->property_x() = -name_width;
392 name_pixbuf->property_pixbuf() = pixbuf_from_string (_name, name_font, name_width, name_height, Gdk::Color ("#000000"));
394 if (label_on_left ()) {
395 _name_background->property_x1() = name_pixbuf->property_x() - 2;
396 _name_background->property_x2() = name_pixbuf->property_x() + name_width + _shift;
398 _name_background->property_x1() = name_pixbuf->property_x() - _label_offset + 2;
399 _name_background->property_x2() = name_pixbuf->property_x() + name_width;
402 _name_background->property_y1() = 0;
403 _name_background->property_y2() = 13;
407 Marker::set_position (framepos_t frame)
409 double new_unit_position = editor.frame_to_unit (frame);
410 new_unit_position -= _shift;
411 group->move (new_unit_position - unit_position, 0.0);
412 frame_position = frame;
413 unit_position = new_unit_position;
417 Marker::reposition ()
419 set_position (frame_position);
441 Marker::set_color_rgba (uint32_t c)
444 mark->property_fill_color_rgba() = _color;
445 mark->property_outline_color_rgba() = _color;
447 if (_line && !_selected) {
448 _line->property_color_rgba() = _color;
451 _name_background->property_fill() = true;
452 _name_background->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (_color, 0x70);
453 _name_background->property_outline_color_rgba() = _color;
456 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
458 Marker::set_left_label_limit (double p)
460 /* Account for the size of the marker */
461 _left_label_limit = p - 13;
462 if (_left_label_limit < 0) {
463 _left_label_limit = 0;
466 if (label_on_left ()) {
467 setup_name_display ();
471 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
473 Marker::set_right_label_limit (double p)
475 /* Account for the size of the marker */
476 _right_label_limit = p - 13;
477 if (_right_label_limit < 0) {
478 _right_label_limit = 0;
481 if (!label_on_left ()) {
482 setup_name_display ();
486 /***********************************************************************/
488 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
489 ARDOUR::TempoSection& temp)
490 : Marker (editor, parent, rgba, text, Tempo, 0, false),
493 set_position (_tempo.frame());
494 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
497 TempoMarker::~TempoMarker ()
501 /***********************************************************************/
503 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
504 ARDOUR::MeterSection& m)
505 : Marker (editor, parent, rgba, text, Meter, 0, false),
508 set_position (_meter.frame());
509 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
512 MeterMarker::~MeterMarker ()