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;
43 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
44 Type type, nframes_t frame, bool handle_events)
46 : editor (ed), _parent(&parent), _type(type)
48 double label_offset = 0;
142 points = new ArdourCanvas::Points ();
144 points->push_back (Gnome::Art::Point (0.0, 0.0));
145 points->push_back (Gnome::Art::Point (6.0, 0.0));
146 points->push_back (Gnome::Art::Point (6.0, 5.0));
147 points->push_back (Gnome::Art::Point (3.0, 10.0));
148 points->push_back (Gnome::Art::Point (0.0, 5.0));
149 points->push_back (Gnome::Art::Point (0.0, 0.0));
158 points = new ArdourCanvas::Points ();
159 points->push_back (Gnome::Art::Point (3.0, 0.0));
160 points->push_back (Gnome::Art::Point (6.0, 5.0));
161 points->push_back (Gnome::Art::Point (6.0, 10.0));
162 points->push_back (Gnome::Art::Point (0.0, 10.0));
163 points->push_back (Gnome::Art::Point (0.0, 5.0));
164 points->push_back (Gnome::Art::Point (3.0, 0.0));
171 points = new ArdourCanvas::Points ();
172 points->push_back (Gnome::Art::Point (0.0, 0.0));
173 points->push_back (Gnome::Art::Point (6.5, 6.5));
174 points->push_back (Gnome::Art::Point (0.0, 13.0));
175 points->push_back (Gnome::Art::Point (0.0, 0.0));
182 points = new ArdourCanvas::Points ();
183 points->push_back (Gnome::Art::Point (6.5, 6.5));
184 points->push_back (Gnome::Art::Point (13.0, 0.0));
185 points->push_back (Gnome::Art::Point (13.0, 13.0));
186 points->push_back (Gnome::Art::Point (6.5, 6.5));
193 points = new ArdourCanvas::Points ();
194 points->push_back (Gnome::Art::Point (0.0, 0.0));
195 points->push_back (Gnome::Art::Point (13.0, 13.0));
196 points->push_back (Gnome::Art::Point (0.0, 13.0));
197 points->push_back (Gnome::Art::Point (0.0, 0.0));
204 points = new ArdourCanvas::Points ();
205 points->push_back (Gnome::Art::Point (13.0, 0.0));
206 points->push_back (Gnome::Art::Point (13.0, 13.0));
207 points->push_back (Gnome::Art::Point (0.0, 13.0));
208 points->push_back (Gnome::Art::Point (13.0, 0.0));
215 points = new ArdourCanvas::Points ();
216 points->push_back (Gnome::Art::Point (0.0, 0.0));
217 points->push_back (Gnome::Art::Point (13.0, 0.0));
218 points->push_back (Gnome::Art::Point (0.0, 13.0));
219 points->push_back (Gnome::Art::Point (0.0, 0.0));
226 points = new ArdourCanvas::Points ();
227 points->push_back (Gnome::Art::Point (0.0, 0.0));
228 points->push_back (Gnome::Art::Point (12.0, 0.0));
229 points->push_back (Gnome::Art::Point (12.0, 12.0));
230 points->push_back (Gnome::Art::Point (0.0, 0.0));
238 frame_position = frame;
239 unit_position = editor.frame_to_unit (frame);
241 /* adjust to properly locate the tip */
243 unit_position -= shift;
245 group = new Group (parent, unit_position, 1.0);
247 mark = new Polygon (*group);
248 mark->property_points() = *points;
249 mark->property_fill_color_rgba() = rgba;
250 mark->property_outline_color_rgba() = rgba;
251 mark->property_width_pixels() = 1;
253 /* setup name pixbuf sizes */
254 name_font = get_font_for_style (N_("MarkerText"));
260 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
264 layout->set_font_description (*name_font);
265 Gtkmm2ext::get_ink_pixel_size (layout, width, height);
266 name_height = height + 6;
268 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
269 name_pixbuf->property_x() = label_offset;
271 set_name (annotation.c_str());
273 editor.ZoomChanged.connect (mem_fun (*this, &Marker::reposition));
275 mark->set_data ("marker", this);
278 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
290 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
299 void Marker::reparent(ArdourCanvas::Group & parent)
301 group->reparent(parent);
307 Marker::set_line_vpos (double pos, double height)
310 line->property_y1() = pos;
311 line->property_y2() = pos + height;
316 Marker::add_line (ArdourCanvas::Group* group, double y_origin, double initial_height)
320 line = new ArdourCanvas::SimpleLine (*group);
321 line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint.get();
322 line->property_x1() = unit_position + shift;
323 line->property_y1() = y_origin;
324 line->property_x2() = unit_position + shift;
325 line->property_y2() = y_origin + initial_height;
327 line->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
337 line->raise_to_top();
351 Marker::the_item() const
357 Marker::set_name (const string& new_name)
359 int name_width = pixel_width (new_name, *name_font) + 2;
361 name_pixbuf->property_pixbuf() = pixbuf_from_ustring(new_name, name_font, name_width, name_height);
363 if (_type == End || _type == LoopEnd || _type == PunchOut) {
364 name_pixbuf->property_x() = - (name_width);
369 Marker::set_position (nframes64_t frame)
371 double new_unit_position = editor.frame_to_unit (frame);
372 new_unit_position -= shift;
373 group->move (new_unit_position - unit_position, 0.0);
374 frame_position = frame;
375 unit_position = new_unit_position;
378 line->property_x1() = unit_position + shift;
379 line->property_x2() = unit_position + shift;
384 Marker::reposition ()
386 set_position (frame_position);
402 Marker::set_color_rgba (uint32_t color)
404 mark->property_fill_color_rgba() = color;
405 mark->property_outline_color_rgba() = color;
408 /***********************************************************************/
410 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
411 ARDOUR::TempoSection& temp)
412 : Marker (editor, parent, rgba, text, Tempo, 0, false),
415 set_position (_tempo.frame());
416 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
419 TempoMarker::~TempoMarker ()
423 /***********************************************************************/
425 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
426 ARDOUR::MeterSection& m)
427 : Marker (editor, parent, rgba, text, Meter, 0, false),
430 set_position (_meter.frame());
431 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
434 MeterMarker::~MeterMarker ()