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 "ardour_ui.h"
25 * ardour_ui.h include was moved to the top of the list
26 * due to a conflicting definition of 'Rect' between
27 * Apple's MacTypes.h and GTK.
31 #include "public_editor.h"
33 #include "canvas_impl.h"
34 #include "simpleline.h"
36 #include <gtkmm2ext/utils.h>
41 using namespace ARDOUR;
42 using namespace Gtkmm2ext;
44 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
46 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& annotation,
47 Type type, nframes_t frame, bool handle_events)
51 , _line_parent (&line_parent)
60 double label_offset = 0;
132 points = new ArdourCanvas::Points ();
134 points->push_back (Gnome::Art::Point (0.0, 0.0));
135 points->push_back (Gnome::Art::Point (6.0, 0.0));
136 points->push_back (Gnome::Art::Point (6.0, 5.0));
137 points->push_back (Gnome::Art::Point (3.0, 10.0));
138 points->push_back (Gnome::Art::Point (0.0, 5.0));
139 points->push_back (Gnome::Art::Point (0.0, 0.0));
148 points = new ArdourCanvas::Points ();
149 points->push_back (Gnome::Art::Point (3.0, 0.0));
150 points->push_back (Gnome::Art::Point (6.0, 5.0));
151 points->push_back (Gnome::Art::Point (6.0, 10.0));
152 points->push_back (Gnome::Art::Point (0.0, 10.0));
153 points->push_back (Gnome::Art::Point (0.0, 5.0));
154 points->push_back (Gnome::Art::Point (3.0, 0.0));
161 points = new ArdourCanvas::Points ();
162 points->push_back (Gnome::Art::Point (0.0, 0.0));
163 points->push_back (Gnome::Art::Point (6.5, 6.5));
164 points->push_back (Gnome::Art::Point (0.0, 13.0));
165 points->push_back (Gnome::Art::Point (0.0, 0.0));
172 points = new ArdourCanvas::Points ();
173 points->push_back (Gnome::Art::Point (6.5, 6.5));
174 points->push_back (Gnome::Art::Point (13.0, 0.0));
175 points->push_back (Gnome::Art::Point (13.0, 13.0));
176 points->push_back (Gnome::Art::Point (6.5, 6.5));
183 points = new ArdourCanvas::Points ();
184 points->push_back (Gnome::Art::Point (0.0, 0.0));
185 points->push_back (Gnome::Art::Point (13.0, 13.0));
186 points->push_back (Gnome::Art::Point (0.0, 13.0));
187 points->push_back (Gnome::Art::Point (0.0, 0.0));
194 points = new ArdourCanvas::Points ();
195 points->push_back (Gnome::Art::Point (13.0, 0.0));
196 points->push_back (Gnome::Art::Point (13.0, 13.0));
197 points->push_back (Gnome::Art::Point (0.0, 13.0));
198 points->push_back (Gnome::Art::Point (13.0, 0.0));
205 points = new ArdourCanvas::Points ();
206 points->push_back (Gnome::Art::Point (0.0, 0.0));
207 points->push_back (Gnome::Art::Point (13.0, 0.0));
208 points->push_back (Gnome::Art::Point (0.0, 13.0));
209 points->push_back (Gnome::Art::Point (0.0, 0.0));
216 points = new ArdourCanvas::Points ();
217 points->push_back (Gnome::Art::Point (0.0, 0.0));
218 points->push_back (Gnome::Art::Point (12.0, 0.0));
219 points->push_back (Gnome::Art::Point (12.0, 12.0));
220 points->push_back (Gnome::Art::Point (0.0, 0.0));
228 frame_position = frame;
229 unit_position = editor.frame_to_unit (frame);
231 /* adjust to properly locate the tip */
233 unit_position -= _shift;
235 group = new Group (parent, unit_position, 1.0);
237 mark = new Polygon (*group);
238 mark->property_points() = *points;
239 set_color_rgba (rgba);
240 mark->property_width_pixels() = 1;
242 /* setup name pixbuf sizes */
243 name_font = get_font_for_style (N_("MarkerText"));
247 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
250 layout->set_font_description (*name_font);
251 Gtkmm2ext::get_ink_pixel_size (layout, width, name_height);
253 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
254 name_pixbuf->property_x() = label_offset;
255 name_pixbuf->property_y() = (13/2) - (name_height/2);
257 set_name (annotation.c_str());
259 editor.ZoomChanged.connect (sigc::mem_fun (*this, &Marker::reposition));
261 mark->set_data ("marker", this);
264 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
272 CatchDeletion (this); /* EMIT SIGNAL */
274 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
282 void Marker::reparent(ArdourCanvas::Group & parent)
284 group->reparent(parent);
289 Marker::set_selected (bool s)
296 Marker::set_show_line (bool s)
303 Marker::setup_line ()
305 if (_shown && (_selected || _line_shown)) {
309 _line = new ArdourCanvas::SimpleLine (*_line_parent);
310 _line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint.get();
314 _line->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
319 /* work out where to start the line from so that it extends only as far as the mark */
321 _parent->i2w (x, yo);
322 _line_parent->w2i (x, yo);
325 _line->property_y1() = yo + 10;
326 _line->property_y2() = yo + 10 + _canvas_height;
328 _line->property_color_rgba() = _selected ? ARDOUR_UI::config()->canvasvar_EditPoint.get() : _color;
329 _line->raise_to_top ();
340 Marker::canvas_height_set (double h)
347 Marker::the_item() const
353 Marker::set_name (const string& new_name)
355 int name_width = pixel_width (new_name, *name_font) + 2;
357 name_pixbuf->property_pixbuf() = pixbuf_from_string(new_name, name_font, name_width, name_height, Gdk::Color ("#000000"));
359 if (_type == End || _type == LoopEnd || _type == PunchOut) {
360 name_pixbuf->property_x() = - (name_width);
365 Marker::setup_line_x ()
368 _line->property_x1() = unit_position + _shift - 0.5;
369 _line->property_x2() = unit_position + _shift - 0.5;
374 Marker::set_position (framepos_t frame)
376 double new_unit_position = editor.frame_to_unit (frame);
377 new_unit_position -= _shift;
378 group->move (new_unit_position - unit_position, 0.0);
379 frame_position = frame;
380 unit_position = new_unit_position;
386 Marker::reposition ()
388 set_position (frame_position);
410 Marker::set_color_rgba (uint32_t c)
413 mark->property_fill_color_rgba() = _color;
414 mark->property_outline_color_rgba() = _color;
415 if (_line && !_selected) {
416 _line->property_color_rgba() = _color;
420 /***********************************************************************/
422 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& text,
423 ARDOUR::TempoSection& temp)
424 : Marker (editor, parent, line_parent, rgba, text, Tempo, 0, false),
427 set_position (_tempo.frame());
428 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
431 TempoMarker::~TempoMarker ()
435 /***********************************************************************/
437 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& text,
438 ARDOUR::MeterSection& m)
439 : Marker (editor, parent, line_parent, rgba, text, Meter, 0, false),
442 set_position (_meter.frame());
443 group->signal_event().connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
446 MeterMarker::~MeterMarker ()