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, ArdourCanvas::Group& line_parent, guint32 rgba, const string& annotation,
49 Type type, nframes_t frame, bool handle_events)
53 , _line_parent (&line_parent)
61 , _left_label_limit (DBL_MAX)
62 , _right_label_limit (DBL_MAX)
136 points = new ArdourCanvas::Points ();
138 points->push_back (Gnome::Art::Point (0.0, 0.0));
139 points->push_back (Gnome::Art::Point (6.0, 0.0));
140 points->push_back (Gnome::Art::Point (6.0, 5.0));
141 points->push_back (Gnome::Art::Point (3.0, 13.0));
142 points->push_back (Gnome::Art::Point (0.0, 5.0));
143 points->push_back (Gnome::Art::Point (0.0, 0.0));
152 points = new ArdourCanvas::Points ();
153 points->push_back (Gnome::Art::Point (3.0, 0.0));
154 points->push_back (Gnome::Art::Point (6.0, 5.0));
155 points->push_back (Gnome::Art::Point (6.0, 10.0));
156 points->push_back (Gnome::Art::Point (0.0, 10.0));
157 points->push_back (Gnome::Art::Point (0.0, 5.0));
158 points->push_back (Gnome::Art::Point (3.0, 0.0));
167 points = new ArdourCanvas::Points ();
168 points->push_back (Gnome::Art::Point (0.0, 0.0));
169 points->push_back (Gnome::Art::Point (6.5, 6.5));
170 points->push_back (Gnome::Art::Point (0.0, 13.0));
171 points->push_back (Gnome::Art::Point (0.0, 0.0));
174 _label_offset = 13.0;
179 points = new ArdourCanvas::Points ();
180 points->push_back (Gnome::Art::Point (6.5, 6.5));
181 points->push_back (Gnome::Art::Point (13.0, 0.0));
182 points->push_back (Gnome::Art::Point (13.0, 13.0));
183 points->push_back (Gnome::Art::Point (6.5, 6.5));
190 points = new ArdourCanvas::Points ();
191 points->push_back (Gnome::Art::Point (0.0, 0.0));
192 points->push_back (Gnome::Art::Point (13.0, 13.0));
193 points->push_back (Gnome::Art::Point (0.0, 13.0));
194 points->push_back (Gnome::Art::Point (0.0, 0.0));
197 _label_offset = 12.0;
201 points = new ArdourCanvas::Points ();
202 points->push_back (Gnome::Art::Point (13.0, 0.0));
203 points->push_back (Gnome::Art::Point (13.0, 13.0));
204 points->push_back (Gnome::Art::Point (0.0, 13.0));
205 points->push_back (Gnome::Art::Point (13.0, 0.0));
212 points = new ArdourCanvas::Points ();
213 points->push_back (Gnome::Art::Point (0.0, 0.0));
214 points->push_back (Gnome::Art::Point (13.0, 0.0));
215 points->push_back (Gnome::Art::Point (0.0, 13.0));
216 points->push_back (Gnome::Art::Point (0.0, 0.0));
219 _label_offset = 13.0;
223 points = new ArdourCanvas::Points ();
224 points->push_back (Gnome::Art::Point (0.0, 0.0));
225 points->push_back (Gnome::Art::Point (12.0, 0.0));
226 points->push_back (Gnome::Art::Point (12.0, 12.0));
227 points->push_back (Gnome::Art::Point (0.0, 0.0));
235 frame_position = frame;
236 unit_position = editor.frame_to_unit (frame);
237 unit_position -= _shift;
239 group = new Group (parent, unit_position, 1.0);
241 _name_background = new ArdourCanvas::SimpleRect (*group);
242 _name_background->property_outline_pixels() = 1;
244 /* adjust to properly locate the tip */
246 mark = new Polygon (*group);
247 mark->property_points() = *points;
248 set_color_rgba (rgba);
249 mark->property_width_pixels() = 1;
251 /* setup name pixbuf sizes */
252 name_font = get_font_for_style (N_("MarkerText"));
256 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
259 layout->set_font_description (*name_font);
260 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
262 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
263 name_pixbuf->property_x() = _label_offset;
264 name_pixbuf->property_y() = (13/2) - (name_height/2);
266 set_name (annotation.c_str());
268 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
270 mark->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 */
291 void Marker::reparent(ArdourCanvas::Group & parent)
293 group->reparent(parent);
298 Marker::set_selected (bool s)
305 Marker::set_show_line (bool s)
312 Marker::setup_line ()
314 if (_shown && (_selected || _line_shown)) {
318 _line = new ArdourCanvas::SimpleLine (*_line_parent);
319 _line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint.get();
323 _line->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
328 /* work out where to start the line from so that it extends only as far as the mark */
330 _parent->i2w (x, yo);
331 _line_parent->w2i (x, yo);
334 _line->property_y1() = yo + 10;
335 _line->property_y2() = yo + 10 + _canvas_height;
337 _line->property_color_rgba() = _selected ? ARDOUR_UI::config()->canvasvar_EditPoint.get() : _color;
338 _line->raise_to_top ();
349 Marker::canvas_height_set (double h)
356 Marker::the_item() const
362 Marker::set_name (const string& new_name)
366 setup_name_display ();
369 /** @return true if our label is on the left of the mark, otherwise false */
371 Marker::label_on_left () const
373 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
377 Marker::setup_name_display ()
379 double limit = DBL_MAX;
381 if (label_on_left ()) {
382 limit = _left_label_limit;
384 limit = _right_label_limit;
387 /* Work out how wide the name can be */
388 int name_width = min ((double) pixel_width (_name, *name_font) + 2, limit);
389 if (name_width == 0) {
393 if (label_on_left ()) {
394 name_pixbuf->property_x() = -name_width;
397 name_pixbuf->property_pixbuf() = pixbuf_from_string (_name, name_font, name_width, name_height, Gdk::Color ("#000000"));
399 if (label_on_left ()) {
400 _name_background->property_x1() = name_pixbuf->property_x() - 2;
401 _name_background->property_x2() = name_pixbuf->property_x() + name_width + _shift;
403 _name_background->property_x1() = name_pixbuf->property_x() - _label_offset + 2;
404 _name_background->property_x2() = name_pixbuf->property_x() + name_width;
407 _name_background->property_y1() = 0;
408 _name_background->property_y2() = 13;
412 Marker::setup_line_x ()
415 _line->property_x1() = unit_position + _shift - 0.5;
416 _line->property_x2() = unit_position + _shift - 0.5;
421 Marker::set_position (framepos_t frame)
423 double new_unit_position = editor.frame_to_unit (frame);
424 new_unit_position -= _shift;
425 group->move (new_unit_position - unit_position, 0.0);
426 frame_position = frame;
427 unit_position = new_unit_position;
433 Marker::reposition ()
435 set_position (frame_position);
457 Marker::set_color_rgba (uint32_t c)
460 mark->property_fill_color_rgba() = _color;
461 mark->property_outline_color_rgba() = _color;
463 if (_line && !_selected) {
464 _line->property_color_rgba() = _color;
466 /* For reasons unknown this is necessary to ensure that the line colour
473 _name_background->property_fill() = true;
474 _name_background->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (_color, 0x70);
475 _name_background->property_outline_color_rgba() = _color;
478 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
480 Marker::set_left_label_limit (double p)
482 /* Account for the size of the marker */
483 _left_label_limit = p - 13;
484 if (_left_label_limit < 0) {
485 _left_label_limit = 0;
488 if (label_on_left ()) {
489 setup_name_display ();
493 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
495 Marker::set_right_label_limit (double p)
497 /* Account for the size of the marker */
498 _right_label_limit = p - 13;
499 if (_right_label_limit < 0) {
500 _right_label_limit = 0;
503 if (!label_on_left ()) {
504 setup_name_display ();
508 /***********************************************************************/
510 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& text,
511 ARDOUR::TempoSection& temp)
512 : Marker (editor, parent, line_parent, rgba, text, Tempo, 0, false),
515 set_position (_tempo.frame());
516 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
519 TempoMarker::~TempoMarker ()
523 /***********************************************************************/
525 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& text,
526 ARDOUR::MeterSection& m)
527 : Marker (editor, parent, line_parent, rgba, text, Meter, 0, false),
530 set_position (_meter.frame());
531 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
534 MeterMarker::~MeterMarker ()