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)
362 font_size = name_font->get_size() / Pango::SCALE;
363 pb_width = new_name.length() * font_size;
365 Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, pb_width, name_height);
367 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, pb_width, name_height);
368 cairo_t *cr = cairo_create (surface);
369 cairo_text_extents_t te;
370 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
371 cairo_select_font_face (cr, name_font->get_family().c_str(),
372 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
373 cairo_set_font_size (cr, font_size);
374 cairo_text_extents (cr, new_name.c_str(), &te);
376 cairo_move_to (cr, 0.5,
377 0.5 - te.height / 2 - te.y_bearing + name_height / 2);
378 cairo_show_text (cr, new_name.c_str());
380 unsigned char* src = cairo_image_surface_get_data (surface);
381 convert_bgra_to_rgba(src, buf->get_pixels(), pb_width, name_height);
384 name_pixbuf->property_pixbuf() = buf;
386 if (_type == End || _type == LoopEnd || _type == PunchOut) {
387 name_pixbuf->property_x() = -(te.width);
393 Marker::set_position (nframes64_t frame)
395 double new_unit_position = editor.frame_to_unit (frame);
396 new_unit_position -= shift;
397 group->move (new_unit_position - unit_position, 0.0);
398 frame_position = frame;
399 unit_position = new_unit_position;
402 line->property_x1() = unit_position + shift;
403 line->property_x2() = unit_position + shift;
408 Marker::reposition ()
410 set_position (frame_position);
426 Marker::set_color_rgba (uint32_t color)
428 mark->property_fill_color_rgba() = color;
429 mark->property_outline_color_rgba() = color;
432 /***********************************************************************/
434 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
435 ARDOUR::TempoSection& temp)
436 : Marker (editor, parent, rgba, text, Tempo, 0, false),
439 set_position (_tempo.frame());
440 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
443 TempoMarker::~TempoMarker ()
447 /***********************************************************************/
449 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
450 ARDOUR::MeterSection& m)
451 : Marker (editor, parent, rgba, text, Meter, 0, false),
454 set_position (_meter.frame());
455 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
458 MeterMarker::~MeterMarker ()