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 "canvas/rectangle.h"
24 #include "canvas/container.h"
25 #include "canvas/line.h"
26 #include "canvas/polygon.h"
27 #include "canvas/text.h"
28 #include "canvas/canvas.h"
29 #include "canvas/scroll_group.h"
30 #include "canvas/debug.h"
32 #include "ui_config.h"
34 * ardour_ui.h include was moved to the top of the list
35 * due to a conflicting definition of 'Rect' between
36 * Apple's MacTypes.h and GTK.
38 * Now that we are including ui_config.h and not ardour_ui.h
39 * the above comment may no longer apply and this comment
40 * can be removed and ui_config.h inclusion moved.
44 #include "public_editor.h"
46 #include "rgb_macros.h"
48 #include <gtkmm2ext/utils.h>
53 using namespace ARDOUR;
54 using namespace ARDOUR_UI_UTILS;
55 using namespace Gtkmm2ext;
57 PBD::Signal1<void,ArdourMarker*> ArdourMarker::CatchDeletion;
59 static double marker_height = 13.0;
61 void ArdourMarker::setup_sizes(const double timebar_height)
63 marker_height = floor (timebar_height) - 2;
66 ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, const string& annotation,
67 Type type, framepos_t frame, bool handle_events)
71 , _track_canvas_line (0)
77 , _left_label_limit (DBL_MAX)
78 , _right_label_limit (DBL_MAX)
83 const double MH = marker_height - 1;
84 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
85 const double M6 = std::max(2.f, rintf(6.f * UIConfiguration::instance().get_ui_scale()));
104 * (0,MH*.6) (6,MH.*.6)
134 * 0,0 ------> marker_height,0
146 * 0,0 ------> marker_height,0
154 * marker_height,marker_height
160 points = new ArdourCanvas::Points ();
162 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
163 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
164 points->push_back (ArdourCanvas::Duple ( M6, MH * .4));
165 points->push_back (ArdourCanvas::Duple ( M3, MH));
166 points->push_back (ArdourCanvas::Duple (0.0, MH * .4));
167 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
170 _label_offset = 10.0;
175 points = new ArdourCanvas::Points ();
176 points->push_back (ArdourCanvas::Duple ( M3, 0.0));
177 points->push_back (ArdourCanvas::Duple ( M6, MH * .6));
178 points->push_back (ArdourCanvas::Duple ( M6, MH));
179 points->push_back (ArdourCanvas::Duple (0.0, MH));
180 points->push_back (ArdourCanvas::Duple (0.0, MH * .6));
181 points->push_back (ArdourCanvas::Duple ( M3, 0.0));
189 points = new ArdourCanvas::Points ();
190 points->push_back (ArdourCanvas::Duple ( 0.0, 0.0));
191 points->push_back (ArdourCanvas::Duple (M6 + .5, MH * .5));
192 points->push_back (ArdourCanvas::Duple ( 0.0, MH));
193 points->push_back (ArdourCanvas::Duple ( 0.0, 0.0));
201 points = new ArdourCanvas::Points (); // leaks
202 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
203 points->push_back (ArdourCanvas::Duple ( M6, MH));
204 points->push_back (ArdourCanvas::Duple (0.0, MH * .5));
205 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
212 points = new ArdourCanvas::Points ();
213 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
214 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
215 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
216 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
219 _label_offset = marker_height;
223 points = new ArdourCanvas::Points ();
224 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
225 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
226 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
227 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
229 _shift = marker_height;
234 points = new ArdourCanvas::Points ();
235 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
236 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
237 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
238 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
241 _label_offset = marker_height;
245 points = new ArdourCanvas::Points ();
246 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
247 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
248 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
249 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
251 _shift = marker_height;
257 frame_position = frame;
258 unit_position = editor.sample_to_pixel (frame);
259 unit_position -= _shift;
261 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
263 group->name = string_compose ("Marker::group for %1", annotation);
266 _name_background = new ArdourCanvas::Rectangle (group);
268 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
271 /* adjust to properly locate the tip */
273 mark = new ArdourCanvas::Polygon (group);
274 CANVAS_DEBUG_NAME (mark, string_compose ("Marker::mark for %1", annotation));
277 set_color_rgba (rgba);
279 /* setup name pixbuf sizes */
280 name_font = get_font_for_style (N_("MarkerText"));
284 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
287 layout->set_font_description (name_font);
288 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
290 _name_item = new ArdourCanvas::Text (group);
291 CANVAS_DEBUG_NAME (_name_item, string_compose ("ArdourMarker::_name_item for %1", annotation));
292 _name_item->set_font_description (name_font);
293 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
294 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height - name_height - 1) * .5 ));
296 set_name (annotation.c_str());
298 editor.ZoomChanged.connect (sigc::mem_fun (*this, &ArdourMarker::reposition));
300 /* events will be handled by both the group and the mark itself, so
301 * make sure they can both be used to lookup this object.
304 group->set_data ("marker", this);
305 mark->set_data ("marker", this);
308 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
312 ArdourMarker::~ArdourMarker ()
314 CatchDeletion (this); /* EMIT SIGNAL */
316 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
318 delete _track_canvas_line;
322 void ArdourMarker::reparent(ArdourCanvas::Container & parent)
324 group->reparent (&parent);
329 ArdourMarker::set_selected (bool s)
336 ArdourMarker::set_show_line (bool s)
343 ArdourMarker::setup_line ()
345 if (_shown && (_selected || _line_shown)) {
347 if (_track_canvas_line == 0) {
349 _track_canvas_line = new ArdourCanvas::Line (editor.get_hscroll_group());
350 _track_canvas_line->set_outline_color (UIConfiguration::instance().color ("edit point"));
351 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
354 ArdourCanvas::Duple g = group->canvas_origin();
355 ArdourCanvas::Duple d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
357 _track_canvas_line->set_x0 (d.x);
358 _track_canvas_line->set_x1 (d.x);
359 _track_canvas_line->set_y0 (d.y);
360 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
361 _track_canvas_line->set_outline_color (_selected ? UIConfiguration::instance().color ("edit point") : _color);
362 _track_canvas_line->raise_to_top ();
363 _track_canvas_line->show ();
366 if (_track_canvas_line) {
367 _track_canvas_line->hide ();
373 ArdourMarker::canvas_height_set (double h)
380 ArdourMarker::the_item() const
386 ArdourMarker::set_name (const string& new_name)
390 setup_name_display ();
393 /** @return true if our label is on the left of the mark, otherwise false */
395 ArdourMarker::label_on_left () const
397 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
401 ArdourMarker::setup_name_display ()
403 double limit = DBL_MAX;
405 if (label_on_left ()) {
406 limit = _left_label_limit;
408 limit = _right_label_limit;
411 const float padding = std::max(2.f, rintf(2.f * UIConfiguration::instance().get_ui_scale()));
413 /* Work out how wide the name can be */
414 int name_width = min ((double) pixel_width (_name, name_font) + padding, limit);
416 if (name_width == 0) {
421 if (label_on_left ()) {
422 _name_item->set_x_position (-name_width);
425 _name_item->clamp_width (name_width);
426 _name_item->set (_name);
428 if (label_on_left ()) {
429 /* adjust right edge of background to fit text */
430 _name_background->set_x0 (_name_item->position().x - padding);
431 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
433 /* right edge remains at zero (group-relative). Add
434 * arbitrary 2 pixels of extra padding at the end
436 _name_background->set_x1 (_name_item->position().x + name_width + padding);
440 _name_background->set_y0 (0);
441 /* unfortunate hard coding - this has to * match the marker bars height */
442 _name_background->set_y1 (marker_height + 1.0);
446 ArdourMarker::set_position (framepos_t frame)
448 unit_position = editor.sample_to_pixel (frame) - _shift;
449 group->set_x_position (unit_position);
451 frame_position = frame;
455 ArdourMarker::reposition ()
457 set_position (frame_position);
461 ArdourMarker::show ()
470 ArdourMarker::hide ()
479 ArdourMarker::set_color_rgba (uint32_t c)
482 mark->set_fill_color (_color);
483 mark->set_outline_color (_color);
485 if (_track_canvas_line && !_selected) {
486 _track_canvas_line->set_outline_color (_color);
489 _name_background->set_fill (true);
490 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
491 _name_background->set_outline_color (_color);
494 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
496 ArdourMarker::set_left_label_limit (double p)
498 /* Account for the size of the marker */
499 _left_label_limit = p - marker_height;
500 if (_left_label_limit < 0) {
501 _left_label_limit = 0;
504 if (label_on_left ()) {
505 setup_name_display ();
509 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
511 ArdourMarker::set_right_label_limit (double p)
513 /* Account for the size of the marker */
514 _right_label_limit = p - marker_height;
515 if (_right_label_limit < 0) {
516 _right_label_limit = 0;
519 if (!label_on_left ()) {
520 setup_name_display ();
524 /***********************************************************************/
526 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
527 ARDOUR::TempoSection& temp)
528 : ArdourMarker (editor, parent, rgba, text, Tempo, 0, false),
531 set_position (_tempo.frame());
532 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
535 TempoMarker::~TempoMarker ()
540 TempoMarker::update_height_mark (const double& ratio)
542 const double MH = marker_height;
543 const double top = MH * (1 - ratio);
544 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
545 const double M6 = std::max(2.f, rintf(6.f * UIConfiguration::instance().get_ui_scale()));
548 points = new ArdourCanvas::Points ();
549 points->push_back (ArdourCanvas::Duple ( M3, top));
550 points->push_back (ArdourCanvas::Duple ( M6, min (top + (MH * .6), MH)));
551 points->push_back (ArdourCanvas::Duple ( M6, MH));
552 points->push_back (ArdourCanvas::Duple (0.0, MH));
553 points->push_back (ArdourCanvas::Duple (0.0, min (top + (MH * .6), MH)));
554 points->push_back (ArdourCanvas::Duple ( M3, top));
559 /***********************************************************************/
561 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
562 ARDOUR::MeterSection& m)
563 : ArdourMarker (editor, parent, rgba, text, Meter, 0, false),
566 set_position (_meter.frame());
567 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
570 MeterMarker::~MeterMarker ()