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/group.h"
25 #include "canvas/line.h"
26 #include "canvas/polygon.h"
27 #include "canvas/text.h"
28 #include "canvas/canvas.h"
29 #include "canvas/debug.h"
31 #include "ardour_ui.h"
33 * ardour_ui.h include was moved to the top of the list
34 * due to a conflicting definition of 'Rect' between
35 * Apple's MacTypes.h and GTK.
39 #include "public_editor.h"
41 #include "rgb_macros.h"
43 #include <gtkmm2ext/utils.h>
48 using namespace ARDOUR;
49 using namespace Gtkmm2ext;
51 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
53 static const double marker_height = 13.0;
55 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
56 Type type, framepos_t frame, bool handle_events)
61 , _track_canvas_line (0)
67 , _left_label_limit (DBL_MAX)
68 , _right_label_limit (DBL_MAX)
117 0,0 ------> marker_height,0
128 0,0 -->-marker_height,0
135 marker_height,marker_height
142 points = new ArdourCanvas::Points ();
144 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
145 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
146 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
147 points->push_back (ArdourCanvas::Duple (3.0, marker_height));
148 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
149 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
158 points = new ArdourCanvas::Points ();
159 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
160 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
161 points->push_back (ArdourCanvas::Duple (6.0, 10.0));
162 points->push_back (ArdourCanvas::Duple (0.0, 10.0));
163 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
164 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
173 points = new ArdourCanvas::Points ();
174 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
175 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
176 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
177 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
180 _label_offset = marker_height;
185 points = new ArdourCanvas::Points ();
186 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
187 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
188 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
189 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
191 _shift = marker_height;
196 points = new ArdourCanvas::Points ();
197 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
198 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
199 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
200 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
203 _label_offset = 12.0;
207 points = new ArdourCanvas::Points ();
208 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
209 points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
210 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
211 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
213 _shift = marker_height;
218 points = new ArdourCanvas::Points ();
219 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
220 points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
221 points->push_back (ArdourCanvas::Duple (0.0, marker_height));
222 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
225 _label_offset = marker_height;
229 points = new ArdourCanvas::Points ();
230 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
231 points->push_back (ArdourCanvas::Duple (12.0, 0.0));
232 points->push_back (ArdourCanvas::Duple (12.0, 12.0));
233 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
235 _shift = marker_height;
241 frame_position = frame;
242 unit_position = editor.sample_to_pixel (frame);
243 unit_position -= _shift;
245 group = new ArdourCanvas::Group (&parent, ArdourCanvas::Duple (unit_position, 0));
247 group->name = string_compose ("Marker::group for %1", annotation);
250 _name_background = new ArdourCanvas::Rectangle (group);
252 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
255 /* adjust to properly locate the tip */
257 mark = new ArdourCanvas::Polygon (group);
258 CANVAS_DEBUG_NAME (mark, string_compose ("Marker::mark for %1", annotation));
261 set_color_rgba (rgba);
263 /* setup name pixbuf sizes */
264 name_font = get_font_for_style (N_("MarkerText"));
268 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
271 layout->set_font_description (name_font);
272 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
274 _name_item = new ArdourCanvas::Text (group);
275 CANVAS_DEBUG_NAME (_name_item, string_compose ("Marker::_name_item for %1", annotation));
276 _name_item->set_font_description (name_font);
277 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
278 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height / 2.0) - (name_height / 2.0) - 2.0));
280 set_name (annotation.c_str());
282 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
284 /* events will be handled by both the group and the mark itself, so
285 * make sure they can both be used to lookup this object.
288 group->set_data ("marker", this);
289 mark->set_data ("marker", this);
292 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
298 CatchDeletion (this); /* EMIT SIGNAL */
300 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
302 delete _time_bars_line;
303 delete _track_canvas_line;
306 void Marker::reparent(ArdourCanvas::Group & 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 (_time_bars_line == 0) {
333 _time_bars_line = new ArdourCanvas::Line (editor.get_time_bars_group());
334 _time_bars_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
335 _time_bars_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
337 _track_canvas_line = new ArdourCanvas::Line (editor.get_track_canvas_group());
338 _track_canvas_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
339 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
342 ArdourCanvas::Duple g = group->item_to_canvas (ArdourCanvas::Duple (0, 0));
343 ArdourCanvas::Duple d = _time_bars_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
345 _time_bars_line->set_x0 (d.x);
346 _time_bars_line->set_x1 (d.x);
347 _time_bars_line->set_y0 (d.y);
348 _time_bars_line->set_y1 (ArdourCanvas::COORD_MAX);
349 _time_bars_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
350 _time_bars_line->raise_to_top ();
351 _time_bars_line->show ();
353 d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
354 _track_canvas_line->set_x0 (d.x);
355 _track_canvas_line->set_x1 (d.x);
356 _track_canvas_line->set_y0 (d.y);
357 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
358 _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
359 _track_canvas_line->raise_to_top ();
360 _track_canvas_line->show ();
363 if (_time_bars_line) {
364 _time_bars_line->hide ();
365 _track_canvas_line->hide ();
371 Marker::canvas_height_set (double h)
378 Marker::the_item() const
384 Marker::set_name (const string& new_name)
388 setup_name_display ();
391 /** @return true if our label is on the left of the mark, otherwise false */
393 Marker::label_on_left () const
395 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
399 Marker::setup_name_display ()
401 double limit = DBL_MAX;
403 if (label_on_left ()) {
404 limit = _left_label_limit;
406 limit = _right_label_limit;
409 /* Work out how wide the name can be */
410 int name_width = min ((double) pixel_width (_name, name_font) + 2, limit);
412 if (name_width == 0) {
417 if (label_on_left ()) {
418 _name_item->set_x_position (-name_width);
421 _name_item->clamp_width (name_width);
422 _name_item->set (_name);
424 if (label_on_left ()) {
425 _name_background->set_x0 (_name_item->position().x - 2);
426 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
428 _name_background->set_x0 (_name_item->position().x - _label_offset + 2);
429 _name_background->set_x1 (_name_item->position().x + name_width);
433 _name_background->set_y0 (0);
434 /* unfortunate hard coding - this has to * match the marker bars height */
435 _name_background->set_y1 (marker_height + 1.0);
439 Marker::set_position (framepos_t frame)
441 unit_position = editor.sample_to_pixel (frame) - _shift;
442 group->set_x_position (unit_position);
444 frame_position = frame;
448 Marker::reposition ()
450 set_position (frame_position);
472 Marker::set_color_rgba (uint32_t c)
475 mark->set_fill_color (_color);
476 mark->set_outline_color (_color);
478 if (_time_bars_line && !_selected) {
479 _time_bars_line->set_outline_color (_color);
480 _track_canvas_line->set_outline_color (_color);
483 _name_background->set_fill (true);
484 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
485 _name_background->set_outline_color (_color);
488 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
490 Marker::set_left_label_limit (double p)
492 /* Account for the size of the marker */
493 _left_label_limit = p - marker_height;
494 if (_left_label_limit < 0) {
495 _left_label_limit = 0;
498 if (label_on_left ()) {
499 setup_name_display ();
503 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
505 Marker::set_right_label_limit (double p)
507 /* Account for the size of the marker */
508 _right_label_limit = p - marker_height;
509 if (_right_label_limit < 0) {
510 _right_label_limit = 0;
513 if (!label_on_left ()) {
514 setup_name_display ();
518 /***********************************************************************/
520 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
521 ARDOUR::TempoSection& temp)
522 : Marker (editor, parent, rgba, text, Tempo, 0, false),
525 set_position (_tempo.frame());
526 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
529 TempoMarker::~TempoMarker ()
533 /***********************************************************************/
535 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
536 ARDOUR::MeterSection& m)
537 : Marker (editor, parent, rgba, text, Meter, 0, false),
540 set_position (_meter.frame());
541 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
544 MeterMarker::~MeterMarker ()