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"
30 #include "ardour_ui.h"
32 * ardour_ui.h include was moved to the top of the list
33 * due to a conflicting definition of 'Rect' between
34 * Apple's MacTypes.h and GTK.
38 #include "public_editor.h"
40 #include "rgb_macros.h"
42 #include <gtkmm2ext/utils.h>
47 using namespace ARDOUR;
48 using namespace Gtkmm2ext;
50 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
52 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
53 Type type, framepos_t frame, bool handle_events)
58 , _track_canvas_line (0)
64 , _left_label_limit (DBL_MAX)
65 , _right_label_limit (DBL_MAX)
139 points = new ArdourCanvas::Points ();
141 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
142 points->push_back (ArdourCanvas::Duple (6.0, 0.0));
143 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
144 points->push_back (ArdourCanvas::Duple (3.0, 13.0));
145 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
146 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
155 points = new ArdourCanvas::Points ();
156 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
157 points->push_back (ArdourCanvas::Duple (6.0, 5.0));
158 points->push_back (ArdourCanvas::Duple (6.0, 10.0));
159 points->push_back (ArdourCanvas::Duple (0.0, 10.0));
160 points->push_back (ArdourCanvas::Duple (0.0, 5.0));
161 points->push_back (ArdourCanvas::Duple (3.0, 0.0));
170 points = new ArdourCanvas::Points ();
171 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
172 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
173 points->push_back (ArdourCanvas::Duple (0.0, 13.0));
174 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
177 _label_offset = 13.0;
182 points = new ArdourCanvas::Points ();
183 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
184 points->push_back (ArdourCanvas::Duple (13.0, 0.0));
185 points->push_back (ArdourCanvas::Duple (13.0, 13.0));
186 points->push_back (ArdourCanvas::Duple (6.5, 6.5));
193 points = new ArdourCanvas::Points ();
194 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
195 points->push_back (ArdourCanvas::Duple (13.0, 13.0));
196 points->push_back (ArdourCanvas::Duple (0.0, 13.0));
197 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
200 _label_offset = 12.0;
204 points = new ArdourCanvas::Points ();
205 points->push_back (ArdourCanvas::Duple (13.0, 0.0));
206 points->push_back (ArdourCanvas::Duple (13.0, 13.0));
207 points->push_back (ArdourCanvas::Duple (0.0, 13.0));
208 points->push_back (ArdourCanvas::Duple (13.0, 0.0));
215 points = new ArdourCanvas::Points ();
216 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
217 points->push_back (ArdourCanvas::Duple (13.0, 0.0));
218 points->push_back (ArdourCanvas::Duple (0.0, 13.0));
219 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
222 _label_offset = 13.0;
226 points = new ArdourCanvas::Points ();
227 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
228 points->push_back (ArdourCanvas::Duple (12.0, 0.0));
229 points->push_back (ArdourCanvas::Duple (12.0, 12.0));
230 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
238 frame_position = frame;
239 unit_position = editor.sample_to_pixel (frame);
240 unit_position -= _shift;
242 group = new ArdourCanvas::Group (&parent, ArdourCanvas::Duple (unit_position, 0));
244 group->name = string_compose ("Marker::group for %1", annotation);
247 _name_background = new ArdourCanvas::Rectangle (group);
249 _name_background->name = string_compose ("Marker::_name_background for %1", annotation);
252 /* adjust to properly locate the tip */
254 mark = new ArdourCanvas::Polygon (group);
256 mark->name = string_compose ("Marker::mark for %1", annotation);
259 set_color_rgba (rgba);
261 /* setup name pixbuf sizes */
262 name_font = get_font_for_style (N_("MarkerText"));
266 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
269 layout->set_font_description (name_font);
270 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
272 _name_item = new ArdourCanvas::Text (group);
273 _name_item->set_font_description (name_font);
274 _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
277 _name_item->name = string_compose ("Marker::_name_item for %1", annotation);
279 _name_item->set_position (ArdourCanvas::Duple (_label_offset, (13.0 / 2.0) - (name_height / 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));
300 CatchDeletion (this); /* EMIT SIGNAL */
302 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
304 delete _time_bars_line;
305 delete _track_canvas_line;
308 void Marker::reparent(ArdourCanvas::Group & parent)
310 group->reparent (&parent);
315 Marker::set_selected (bool s)
322 Marker::set_show_line (bool s)
329 Marker::setup_line ()
331 if (_shown && (_selected || _line_shown)) {
333 if (_time_bars_line == 0) {
335 _time_bars_line = new ArdourCanvas::Line (editor.get_time_bars_group());
336 _time_bars_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
337 _time_bars_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
339 _track_canvas_line = new ArdourCanvas::Line (editor.get_track_canvas_group());
340 _track_canvas_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
341 _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
344 ArdourCanvas::Duple g = group->item_to_canvas (ArdourCanvas::Duple (0, 0));
345 ArdourCanvas::Duple d = _time_bars_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
347 _time_bars_line->set_x0 (d.x);
348 _time_bars_line->set_x1 (d.x);
349 _time_bars_line->set_y0 (d.y);
350 _time_bars_line->set_y1 (ArdourCanvas::COORD_MAX);
351 _time_bars_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
352 _time_bars_line->raise_to_top ();
353 _time_bars_line->show ();
355 d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
356 _track_canvas_line->set_x0 (d.x);
357 _track_canvas_line->set_x1 (d.x);
358 _track_canvas_line->set_y0 (d.y);
359 _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
360 _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
361 _track_canvas_line->raise_to_top ();
362 _track_canvas_line->show ();
365 if (_time_bars_line) {
366 _time_bars_line->hide ();
367 _track_canvas_line->hide ();
373 Marker::canvas_height_set (double h)
380 Marker::the_item() const
386 Marker::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 Marker::label_on_left () const
397 return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut);
401 Marker::setup_name_display ()
403 double limit = DBL_MAX;
405 if (label_on_left ()) {
406 limit = _left_label_limit;
408 limit = _right_label_limit;
411 /* Work out how wide the name can be */
412 int name_width = min ((double) pixel_width (_name, name_font) + 2, limit);
414 if (name_width == 0) {
418 if (label_on_left ()) {
419 _name_item->set_x_position (-name_width);
422 _name_item->set (_name);
425 // need to "clip" name to name_width and name_height
427 if (label_on_left ()) {
428 _name_background->set_x0 (_name_item->position().x - 2);
429 _name_background->set_x1 (_name_item->position().x + name_width + _shift);
431 _name_background->set_x0 (_name_item->position().x - _label_offset + 2);
432 _name_background->set_x1 (_name_item->position().x + name_width);
435 _name_background->set_y0 (0);
436 _name_background->set_y1 (13);
440 Marker::set_position (framepos_t frame)
442 unit_position = editor.sample_to_pixel (frame) - _shift;
443 group->set_x_position (unit_position);
445 frame_position = frame;
449 Marker::reposition ()
451 set_position (frame_position);
473 Marker::set_color_rgba (uint32_t c)
476 mark->set_fill_color (_color);
477 mark->set_outline_color (_color);
479 if (_time_bars_line && !_selected) {
480 _time_bars_line->set_outline_color (_color);
481 _track_canvas_line->set_outline_color (_color);
484 _name_background->set_fill (true);
485 _name_background->set_fill_color (UINT_RGBA_CHANGE_A (_color, 0x70));
486 _name_background->set_outline_color (_color);
489 /** Set the number of pixels that are available for a label to the left of the centre of this marker */
491 Marker::set_left_label_limit (double p)
493 /* Account for the size of the marker */
494 _left_label_limit = p - 13;
495 if (_left_label_limit < 0) {
496 _left_label_limit = 0;
499 if (label_on_left ()) {
500 setup_name_display ();
504 /** Set the number of pixels that are available for a label to the right of the centre of this marker */
506 Marker::set_right_label_limit (double p)
508 /* Account for the size of the marker */
509 _right_label_limit = p - 13;
510 if (_right_label_limit < 0) {
511 _right_label_limit = 0;
514 if (!label_on_left ()) {
515 setup_name_display ();
519 /***********************************************************************/
521 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
522 ARDOUR::TempoSection& temp)
523 : Marker (editor, parent, rgba, text, Tempo, 0, false),
526 set_position (_tempo.frame());
527 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), group, this));
530 TempoMarker::~TempoMarker ()
534 /***********************************************************************/
536 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
537 ARDOUR::MeterSection& m)
538 : Marker (editor, parent, rgba, text, Meter, 0, false),
541 set_position (_meter.frame());
542 group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), group, this));
545 MeterMarker::~MeterMarker ()