2 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2007-2011 David Robillard <d@drobilla.net>
5 * Copyright (C) 2007 Doug McLain <doug@nostar.net>
6 * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
8 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
9 * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
10 * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sigc++/bind.h>
28 #include "ardour/tempo.h"
30 #include "canvas/rectangle.h"
31 #include "canvas/container.h"
32 #include "canvas/line.h"
33 #include "canvas/polygon.h"
34 #include "canvas/text.h"
35 #include "canvas/canvas.h"
36 #include "canvas/scroll_group.h"
37 #include "canvas/debug.h"
39 #include "ui_config.h"
41 * ardour_ui.h include was moved to the top of the list
42 * due to a conflicting definition of 'Rect' between
43 * Apple's MacTypes.h and GTK.
45 * Now that we are including ui_config.h and not ardour_ui.h
46 * the above comment may no longer apply and this comment
47 * can be removed and ui_config.h inclusion moved.
51 #include "public_editor.h"
53 #include "rgb_macros.h"
55 #include <gtkmm2ext/utils.h>
60 using namespace ARDOUR;
61 using namespace ARDOUR_UI_UTILS;
62 using namespace Gtkmm2ext;
64 PBD::Signal1<void,ArdourMarker*> ArdourMarker::CatchDeletion;
66 static double marker_height = 13.0;
68 void ArdourMarker::setup_sizes(const double timebar_height)
70 marker_height = floor (timebar_height) - 2;
73 ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, const string& annotation,
74 Type type, samplepos_t sample, bool handle_events)
78 , _track_canvas_line (0)
84 , _points_color (rgba)
85 , _left_label_limit (DBL_MAX)
86 , _right_label_limit (DBL_MAX)
91 const double MH = marker_height - .5;
92 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
93 const double M6 = std::max(2.f, rintf(6.f * UIConfiguration::instance().get_ui_scale()));
102 * (0,MH*.4) (6,MH*.4)
112 * (0,MH*.6) (6,MH.*.6)
142 * 0,0 ------> marker_height,0
168 points = new ArdourCanvas::Points ();
170 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
171 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
172 points->push_back (ArdourCanvas::Duple ( M6, MH * .4));
173 points->push_back (ArdourCanvas::Duple ( M3, MH));
174 points->push_back (ArdourCanvas::Duple (0.0, MH * .4));
175 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
178 _label_offset = 10.0;
183 points = new ArdourCanvas::Points ();
184 points->push_back (ArdourCanvas::Duple ( M3, 0.0));
185 points->push_back (ArdourCanvas::Duple ( M6, MH * .6));
186 points->push_back (ArdourCanvas::Duple ( M6, MH));
187 points->push_back (ArdourCanvas::Duple (0.0, MH));
188 points->push_back (ArdourCanvas::Duple (0.0, MH * .6));
189 points->push_back (ArdourCanvas::Duple ( M3, 0.0));
197 points = new ArdourCanvas::Points ();
198 points->push_back (ArdourCanvas::Duple ( 0.0, 0.0));
199 points->push_back (ArdourCanvas::Duple (M6 + .5, MH * .5));
200 points->push_back (ArdourCanvas::Duple ( 0.0, MH));
201 points->push_back (ArdourCanvas::Duple ( 0.0, 0.0));
209 points = new ArdourCanvas::Points (); // leaks
210 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
211 points->push_back (ArdourCanvas::Duple ( M6, MH));
212 points->push_back (ArdourCanvas::Duple (0.0, MH * .5));
213 points->push_back (ArdourCanvas::Duple ( M6, 0.0));
220 points = new ArdourCanvas::Points ();
221 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
222 points->push_back (ArdourCanvas::Duple (MH, MH));
223 points->push_back (ArdourCanvas::Duple (0.0, MH));
224 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
231 points = new ArdourCanvas::Points ();
232 points->push_back (ArdourCanvas::Duple (MH, 0.0));
233 points->push_back (ArdourCanvas::Duple (MH, MH));
234 points->push_back (ArdourCanvas::Duple (0.0, MH));
235 points->push_back (ArdourCanvas::Duple (MH, 0.0));
242 points = new ArdourCanvas::Points ();
243 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
244 points->push_back (ArdourCanvas::Duple (MH, 0.0));
245 points->push_back (ArdourCanvas::Duple (0.0, MH));
246 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
253 points = new ArdourCanvas::Points ();
254 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
255 points->push_back (ArdourCanvas::Duple (MH, 0.0));
256 points->push_back (ArdourCanvas::Duple (MH, MH));
257 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
265 sample_position = sample;
266 unit_position = editor.sample_to_pixel (sample);
267 unit_position -= _shift;
269 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 1));
271 group->name = string_compose ("Marker::group for %1", annotation);
274 _name_background = new ArdourCanvas::Rectangle (group);
276 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
279 /* adjust to properly locate the tip */
281 mark = new ArdourCanvas::Polygon (group);
282 CANVAS_DEBUG_NAME (mark, string_compose ("Marker::mark for %1", annotation));
285 set_color_rgba (rgba);
287 /* setup name pixbuf sizes */
288 name_font = get_font_for_style (N_("MarkerText"));
292 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
295 layout->set_font_description (name_font);
296 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
298 _name_item = new ArdourCanvas::Text (group);
299 CANVAS_DEBUG_NAME (_name_item, string_compose ("ArdourMarker::_name_item for %1", annotation));
300 _name_item->set_font_description (name_font);
301 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
302 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height - name_height - 1) * .5 ));
304 set_name (annotation.c_str());
306 editor.ZoomChanged.connect (sigc::mem_fun (*this, &ArdourMarker::reposition));
308 /* events will be handled by both the group and the mark itself, so
309 * make sure they can both be used to lookup this object.
312 group->set_data ("marker", this);
313 mark->set_data ("marker", this);
316 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
320 ArdourMarker::~ArdourMarker ()
322 CatchDeletion (this); /* EMIT SIGNAL */
324 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
326 delete _track_canvas_line;
330 void ArdourMarker::reparent(ArdourCanvas::Container & parent)
332 group->reparent (&parent);
337 ArdourMarker::set_selected (bool s)
342 mark->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
343 mark->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
347 ArdourMarker::set_show_line (bool s)
354 ArdourMarker::setup_line ()
356 if (_shown && (_selected || _line_shown)) {
358 if (_track_canvas_line == 0) {
360 _track_canvas_line = new ArdourCanvas::Line (editor.get_hscroll_group());
361 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
364 ArdourCanvas::Duple g = group->canvas_origin();
365 ArdourCanvas::Duple d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
367 _track_canvas_line->set_x0 (d.x);
368 _track_canvas_line->set_x1 (d.x);
369 _track_canvas_line->set_y0 (d.y);
370 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
371 _track_canvas_line->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
372 _track_canvas_line->raise_to_top ();
373 _track_canvas_line->show ();
376 if (_track_canvas_line) {
377 _track_canvas_line->hide ();
383 ArdourMarker::canvas_height_set (double h)
390 ArdourMarker::the_item() const
396 ArdourMarker::set_name (const string& new_name)
400 mark->set_tooltip(new_name);
401 _name_background->set_tooltip(new_name);
402 _name_item->set_tooltip(new_name);
404 setup_name_display ();
407 /** @return true if our label is on the left of the mark, otherwise false */
409 ArdourMarker::label_on_left () const
411 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
415 ArdourMarker::setup_name_display ()
417 double limit = DBL_MAX;
419 if (label_on_left ()) {
420 limit = _left_label_limit;
422 limit = _right_label_limit;
425 const float padding = std::max(2.f, rintf(2.f * UIConfiguration::instance().get_ui_scale()));
426 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
428 /* Work out how wide the name can be */
429 int name_width = min ((double) pixel_width (_name, name_font) + padding, limit);
431 if (name_width == 0) {
436 if (label_on_left ()) {
437 _name_item->set_x_position (-name_width);
440 _name_item->clamp_width (name_width);
441 _name_item->set (_name);
443 if (label_on_left ()) {
444 /* adjust right edge of background to fit text */
445 _name_background->set_x0 (_name_item->position().x - padding);
446 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
448 /* right edge remains at zero (group-relative). Add
449 * arbitrary 2 pixels of extra padding at the end
454 // tip's x-pos is at "M3", box is 2x marker's
455 _name_background->set_x0 (-M3);
456 _name_background->set_x1 (3 * M3);
460 _name_background->set_x0 (M3);
461 _name_background->set_x1 (_name_item->position().x + name_width + padding);
464 _name_background->set_x0 (0);
465 _name_background->set_x1 (_name_item->position().x + name_width + padding);
471 _name_background->set_y0 (0);
472 _name_background->set_y1 (marker_height + 1);
476 ArdourMarker::set_position (samplepos_t sample)
478 unit_position = editor.sample_to_pixel (sample) - _shift;
479 group->set_x_position (unit_position);
481 sample_position = sample;
485 ArdourMarker::reposition ()
487 set_position (sample_position);
491 ArdourMarker::show ()
500 ArdourMarker::hide ()
509 ArdourMarker::set_points_color (uint32_t c)
512 mark->set_fill_color (_points_color);
513 mark->set_outline_color (_points_color);
517 ArdourMarker::set_color_rgba (uint32_t c)
521 mark->set_fill_color (_selected ? UIConfiguration::instance().color ("entered marker") : _color);
522 mark->set_outline_color ( _selected ? UIConfiguration::instance().color ("entered marker") : _color );
524 if (_track_canvas_line && !_selected) {
525 _track_canvas_line->set_outline_color (_color);
528 _name_background->set_fill (true);
529 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
530 _name_background->set_outline (false);
533 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
535 ArdourMarker::set_left_label_limit (double p)
537 /* Account for the size of the marker */
538 _left_label_limit = p - marker_height;
539 if (_left_label_limit < 0) {
540 _left_label_limit = 0;
543 if (label_on_left ()) {
544 setup_name_display ();
548 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
550 ArdourMarker::set_right_label_limit (double p)
552 /* Account for the size of the marker */
553 _right_label_limit = p - marker_height;
554 if (_right_label_limit < 0) {
555 _right_label_limit = 0;
558 if (!label_on_left ()) {
559 setup_name_display ();
563 /***********************************************************************/
565 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
566 ARDOUR::TempoSection& temp)
567 : ArdourMarker (editor, parent, rgba, text, Tempo, temp.sample(), false),
570 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
573 TempoMarker::~TempoMarker ()
578 TempoMarker::update_height_mark (const double ratio)
580 const double MH = marker_height - .5;
581 const double top = MH * (1 - ratio);
582 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
583 const double M6 = std::max(2.f, rintf(6.f * UIConfiguration::instance().get_ui_scale()));
586 points = new ArdourCanvas::Points ();
587 points->push_back (ArdourCanvas::Duple ( M3, top));
588 points->push_back (ArdourCanvas::Duple ( M6, min (top + (MH * .6), MH)));
589 points->push_back (ArdourCanvas::Duple ( M6, MH));
590 points->push_back (ArdourCanvas::Duple (0.0, MH));
591 points->push_back (ArdourCanvas::Duple (0.0, min (top + (MH * .6), MH)));
592 points->push_back (ArdourCanvas::Duple ( M3, top));
597 /***********************************************************************/
599 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
600 ARDOUR::MeterSection& m)
601 : ArdourMarker (editor, parent, rgba, text, Meter, m.sample(), false),
604 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
607 MeterMarker::~MeterMarker ()