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 "ardour_ui.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.
40 #include "public_editor.h"
42 #include "rgb_macros.h"
44 #include <gtkmm2ext/utils.h>
49 using namespace ARDOUR;
50 using namespace ARDOUR_UI_UTILS;
51 using namespace Gtkmm2ext;
53 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
55 static double marker_height = 13.0;
57 void Marker::setup_sizes(const double timebar_height)
59 marker_height = floor (timebar_height) - 2;
62 Marker::Marker (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, const string& annotation,
63 Type type, framepos_t frame, bool handle_events)
67 , _track_canvas_line (0)
73 , _left_label_limit (DBL_MAX)
74 , _right_label_limit (DBL_MAX)
79 const double MH = marker_height - 1;
97 * (0,MH*.6) (6,MH.*.6)
127 * 0,0 ------> marker_height,0
139 * 0,0 ------> marker_height,0
147 * marker_height,marker_height
153 points = new ArdourCanvas::Points ();
155 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
156 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
157 points->push_back (ArdourCanvas::Duple (6.0, MH * .4));
158 points->push_back (ArdourCanvas::Duple (3.0, MH));
159 points->push_back (ArdourCanvas::Duple (0.0, MH * .4));
160 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
163 _label_offset = 10.0;
168 points = new ArdourCanvas::Points ();
169 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
170 points->push_back (ArdourCanvas::Duple (6.0, MH * .6));
171 points->push_back (ArdourCanvas::Duple (6.0, MH));
172 points->push_back (ArdourCanvas::Duple (0.0, MH));
173 points->push_back (ArdourCanvas::Duple (0.0, MH * .6));
174 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
182 points = new ArdourCanvas::Points ();
183 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
184 points->push_back (ArdourCanvas::Duple (6.5, MH * .5));
185 points->push_back (ArdourCanvas::Duple (0.0, MH));
186 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
194 points = new ArdourCanvas::Points ();
195 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
196 points->push_back (ArdourCanvas::Duple (6.0, MH));
197 points->push_back (ArdourCanvas::Duple (0.0, MH * .5));
198 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
205 points = new ArdourCanvas::Points ();
206 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
207 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
208 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
209 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
212 _label_offset = marker_height;
216 points = new ArdourCanvas::Points ();
217 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
218 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
219 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
220 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
222 _shift = marker_height;
227 points = new ArdourCanvas::Points ();
228 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
229 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
230 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
231 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
234 _label_offset = marker_height;
238 points = new ArdourCanvas::Points ();
239 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
240 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
241 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
242 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
244 _shift = marker_height;
250 frame_position = frame;
251 unit_position = editor.sample_to_pixel (frame);
252 unit_position -= _shift;
254 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
256 group->name = string_compose ("Marker::group for %1", annotation);
259 _name_background = new ArdourCanvas::Rectangle (group);
261 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
264 /* adjust to properly locate the tip */
266 mark = new ArdourCanvas::Polygon (group);
267 CANVAS_DEBUG_NAME (mark, string_compose ("Marker::mark for %1", annotation));
270 set_color_rgba (rgba);
272 /* setup name pixbuf sizes */
273 name_font = get_font_for_style (N_("MarkerText"));
277 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
280 layout->set_font_description (name_font);
281 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
283 _name_item = new ArdourCanvas::Text (group);
284 CANVAS_DEBUG_NAME (_name_item, string_compose ("Marker::_name_item for %1", annotation));
285 _name_item->set_font_description (name_font);
286 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
287 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height - name_height - 1) * .5 ));
289 set_name (annotation.c_str());
291 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
293 /* events will be handled by both the group and the mark itself, so
294 * make sure they can both be used to lookup this object.
297 group->set_data ("marker", this);
298 mark->set_data ("marker", this);
301 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
307 CatchDeletion (this); /* EMIT SIGNAL */
309 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
311 delete _track_canvas_line;
314 void Marker::reparent(ArdourCanvas::Container & parent)
316 group->reparent (&parent);
321 Marker::set_selected (bool s)
328 Marker::set_show_line (bool s)
335 Marker::setup_line ()
337 if (_shown && (_selected || _line_shown)) {
339 if (_track_canvas_line == 0) {
341 _track_canvas_line = new ArdourCanvas::Line (editor.get_hscroll_group());
342 _track_canvas_line->set_outline_color (ARDOUR_UI::config()->color ("edit point"));
343 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
346 ArdourCanvas::Duple g = group->canvas_origin();
347 ArdourCanvas::Duple d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
349 _track_canvas_line->set_x0 (d.x);
350 _track_canvas_line->set_x1 (d.x);
351 _track_canvas_line->set_y0 (d.y);
352 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
353 _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->color ("edit point") : _color);
354 _track_canvas_line->raise_to_top ();
355 _track_canvas_line->show ();
358 if (_track_canvas_line) {
359 _track_canvas_line->hide ();
365 Marker::canvas_height_set (double h)
372 Marker::the_item() const
378 Marker::set_name (const string& new_name)
382 setup_name_display ();
385 /** @return true if our label is on the left of the mark, otherwise false */
387 Marker::label_on_left () const
389 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
393 Marker::setup_name_display ()
395 double limit = DBL_MAX;
397 if (label_on_left ()) {
398 limit = _left_label_limit;
400 limit = _right_label_limit;
403 /* Work out how wide the name can be */
404 int name_width = min ((double) pixel_width (_name, name_font) + 2, limit);
406 if (name_width == 0) {
411 if (label_on_left ()) {
412 _name_item->set_x_position (-name_width);
415 _name_item->clamp_width (name_width);
416 _name_item->set (_name);
418 if (label_on_left ()) {
419 /* adjust right edge of background to fit text */
420 _name_background->set_x0 (_name_item->position().x - 2);
421 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
423 /* right edge remains at zero (group-relative). Add
424 * arbitrary 2 pixels of extra padding at the end
426 _name_background->set_x1 (_name_item->position().x + name_width + 2.0);
430 _name_background->set_y0 (0);
431 /* unfortunate hard coding - this has to * match the marker bars height */
432 _name_background->set_y1 (marker_height + 1.0);
436 Marker::set_position (framepos_t frame)
438 unit_position = editor.sample_to_pixel (frame) - _shift;
439 group->set_x_position (unit_position);
441 frame_position = frame;
445 Marker::reposition ()
447 set_position (frame_position);
469 Marker::set_color_rgba (uint32_t c)
472 mark->set_fill_color (_color);
473 mark->set_outline_color (_color);
475 if (_track_canvas_line && !_selected) {
476 _track_canvas_line->set_outline_color (_color);
479 _name_background->set_fill (true);
480 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
481 _name_background->set_outline_color (_color);
484 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
486 Marker::set_left_label_limit (double p)
488 /* Account for the size of the marker */
489 _left_label_limit = p - marker_height;
490 if (_left_label_limit < 0) {
491 _left_label_limit = 0;
494 if (label_on_left ()) {
495 setup_name_display ();
499 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
501 Marker::set_right_label_limit (double p)
503 /* Account for the size of the marker */
504 _right_label_limit = p - marker_height;
505 if (_right_label_limit < 0) {
506 _right_label_limit = 0;
509 if (!label_on_left ()) {
510 setup_name_display ();
514 /***********************************************************************/
516 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
517 ARDOUR::TempoSection& temp)
518 : Marker (editor, parent, rgba, text, Tempo, 0, false),
521 set_position (_tempo.frame());
522 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
525 TempoMarker::~TempoMarker ()
529 /***********************************************************************/
531 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
532 ARDOUR::MeterSection& m)
533 : Marker (editor, parent, rgba, text, Meter, 0, false),
536 set_position (_meter.frame());
537 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
540 MeterMarker::~MeterMarker ()