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 const double marker_height = 13.0;
57 Marker::Marker (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, const string& annotation,
58 Type type, framepos_t frame, bool handle_events)
62 , _track_canvas_line (0)
68 , _left_label_limit (DBL_MAX)
69 , _right_label_limit (DBL_MAX)
118 0,0 ------> marker_height,0
129 0,0 -->-marker_height,0
136 marker_height,marker_height
143 points = new ArdourCanvas::Points ();
145 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
146 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
147 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
148 points->push_back (ArdourCanvas::Duple (3.0, marker_height));
149 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
150 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
159 points = new ArdourCanvas::Points ();
160 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
161 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
162 points->push_back (ArdourCanvas::Duple (6.0, 10.0));
163 points->push_back (ArdourCanvas::Duple (0.0, 10.0));
164 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
165 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
174 points = new ArdourCanvas::Points ();
175 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
176 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
177 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
178 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
181 _label_offset = marker_height;
186 points = new ArdourCanvas::Points ();
187 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
188 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
189 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
190 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
192 _shift = marker_height;
197 points = new ArdourCanvas::Points ();
198 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
199 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
200 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
201 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
204 _label_offset = 12.0;
208 points = new ArdourCanvas::Points ();
209 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
210 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
211 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
212 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
214 _shift = marker_height;
219 points = new ArdourCanvas::Points ();
220 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
221 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
222 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
223 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
226 _label_offset = marker_height;
230 points = new ArdourCanvas::Points ();
231 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
232 points->push_back (ArdourCanvas::Duple (12.0, 0.0));
233 points->push_back (ArdourCanvas::Duple (12.0, 12.0));
234 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
236 _shift = marker_height;
242 frame_position = frame;
243 unit_position = editor.sample_to_pixel (frame);
244 unit_position -= _shift;
246 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
248 group->name = string_compose ("Marker::group for %1", annotation);
251 _name_background = new ArdourCanvas::Rectangle (group);
253 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
256 /* adjust to properly locate the tip */
258 mark = new ArdourCanvas::Polygon (group);
259 CANVAS_DEBUG_NAME (mark, string_compose ("Marker::mark for %1", annotation));
262 set_color_rgba (rgba);
264 /* setup name pixbuf sizes */
265 name_font = get_font_for_style (N_("MarkerText"));
269 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
272 layout->set_font_description (name_font);
273 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
275 _name_item = new ArdourCanvas::Text (group);
276 CANVAS_DEBUG_NAME (_name_item, string_compose ("Marker::_name_item for %1", annotation));
277 _name_item->set_font_description (name_font);
278 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
279 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height / 2.0) - (name_height / 2.0) - 2.0));
281 set_name (annotation.c_str());
283 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
285 /* events will be handled by both the group and the mark itself, so
286 * make sure they can both be used to lookup this object.
289 group->set_data ("marker", this);
290 mark->set_data ("marker", this);
293 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
299 CatchDeletion (this); /* EMIT SIGNAL */
301 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
303 delete _track_canvas_line;
306 void Marker::reparent(ArdourCanvas::Container & parent)
308 group->reparent (&parent);
313 Marker::set_selected (bool s)
320 Marker::set_show_line (bool s)
327 Marker::setup_line ()
329 if (_shown && (_selected || _line_shown)) {
331 if (_track_canvas_line == 0) {
333 _track_canvas_line = new ArdourCanvas::Line (editor.get_hscroll_group());
334 _track_canvas_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
335 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
338 ArdourCanvas::Duple g = group->canvas_origin();
339 ArdourCanvas::Duple d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
341 _track_canvas_line->set_x0 (d.x);
342 _track_canvas_line->set_x1 (d.x);
343 _track_canvas_line->set_y0 (d.y);
344 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
345 _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
346 _track_canvas_line->raise_to_top ();
347 _track_canvas_line->show ();
350 if (_track_canvas_line) {
351 _track_canvas_line->hide ();
357 Marker::canvas_height_set (double h)
364 Marker::the_item() const
370 Marker::set_name (const string& new_name)
374 setup_name_display ();
377 /** @return true if our label is on the left of the mark, otherwise false */
379 Marker::label_on_left () const
381 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
385 Marker::setup_name_display ()
387 double limit = DBL_MAX;
389 if (label_on_left ()) {
390 limit = _left_label_limit;
392 limit = _right_label_limit;
395 /* Work out how wide the name can be */
396 int name_width = min ((double) pixel_width (_name, name_font) + 2, limit);
398 if (name_width == 0) {
403 if (label_on_left ()) {
404 _name_item->set_x_position (-name_width);
407 _name_item->clamp_width (name_width);
408 _name_item->set (_name);
410 if (label_on_left ()) {
411 _name_background->set_x0 (_name_item->position().x - 2);
412 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
414 _name_background->set_x0 (_name_item->position().x - _label_offset + 2);
415 _name_background->set_x1 (_name_item->position().x + name_width);
419 _name_background->set_y0 (0);
420 /* unfortunate hard coding - this has to * match the marker bars height */
421 _name_background->set_y1 (marker_height + 1.0);
425 Marker::set_position (framepos_t frame)
427 unit_position = editor.sample_to_pixel (frame) - _shift;
428 group->set_x_position (unit_position);
430 frame_position = frame;
434 Marker::reposition ()
436 set_position (frame_position);
458 Marker::set_color_rgba (uint32_t c)
461 mark->set_fill_color (_color);
462 mark->set_outline_color (_color);
464 if (_track_canvas_line && !_selected) {
465 _track_canvas_line->set_outline_color (_color);
468 _name_background->set_fill (true);
469 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
470 _name_background->set_outline_color (_color);
473 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
475 Marker::set_left_label_limit (double p)
477 /* Account for the size of the marker */
478 _left_label_limit = p - marker_height;
479 if (_left_label_limit < 0) {
480 _left_label_limit = 0;
483 if (label_on_left ()) {
484 setup_name_display ();
488 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
490 Marker::set_right_label_limit (double p)
492 /* Account for the size of the marker */
493 _right_label_limit = p - marker_height;
494 if (_right_label_limit < 0) {
495 _right_label_limit = 0;
498 if (!label_on_left ()) {
499 setup_name_display ();
503 /***********************************************************************/
505 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
506 ARDOUR::TempoSection& temp)
507 : Marker (editor, parent, rgba, text, Tempo, 0, false),
510 set_position (_tempo.frame());
511 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
514 TempoMarker::~TempoMarker ()
518 /***********************************************************************/
520 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
521 ARDOUR::MeterSection& m)
522 : Marker (editor, parent, rgba, text, Meter, 0, false),
525 set_position (_meter.frame());
526 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
529 MeterMarker::~MeterMarker ()