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"
24 #include "public_editor.h"
26 #include "canvas_impl.h"
27 #include "ardour_ui.h"
28 #include "simpleline.h"
30 #include <gtkmm2ext/utils.h>
35 using namespace ARDOUR;
37 Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
38 Type type, nframes_t frame, bool handle_events)
40 : editor (ed), _parent(&parent), _type(type)
42 double label_offset = 0;
136 points = new ArdourCanvas::Points ();
138 points->push_back (Gnome::Art::Point (0.0, 0.0));
139 points->push_back (Gnome::Art::Point (6.0, 0.0));
140 points->push_back (Gnome::Art::Point (6.0, 5.0));
141 points->push_back (Gnome::Art::Point (3.0, 10.0));
142 points->push_back (Gnome::Art::Point (0.0, 5.0));
143 points->push_back (Gnome::Art::Point (0.0, 0.0));
152 points = new ArdourCanvas::Points ();
153 points->push_back (Gnome::Art::Point (3.0, 0.0));
154 points->push_back (Gnome::Art::Point (6.0, 5.0));
155 points->push_back (Gnome::Art::Point (6.0, 10.0));
156 points->push_back (Gnome::Art::Point (0.0, 10.0));
157 points->push_back (Gnome::Art::Point (0.0, 5.0));
158 points->push_back (Gnome::Art::Point (3.0, 0.0));
165 points = new ArdourCanvas::Points ();
166 points->push_back (Gnome::Art::Point (0.0, 0.0));
167 points->push_back (Gnome::Art::Point (6.5, 6.5));
168 points->push_back (Gnome::Art::Point (0.0, 13.0));
169 points->push_back (Gnome::Art::Point (0.0, 0.0));
176 points = new ArdourCanvas::Points ();
177 points->push_back (Gnome::Art::Point (6.5, 6.5));
178 points->push_back (Gnome::Art::Point (13.0, 0.0));
179 points->push_back (Gnome::Art::Point (13.0, 13.0));
180 points->push_back (Gnome::Art::Point (6.5, 6.5));
187 points = new ArdourCanvas::Points ();
188 points->push_back (Gnome::Art::Point (0.0, 0.0));
189 points->push_back (Gnome::Art::Point (13.0, 13.0));
190 points->push_back (Gnome::Art::Point (0.0, 13.0));
191 points->push_back (Gnome::Art::Point (0.0, 0.0));
198 points = new ArdourCanvas::Points ();
199 points->push_back (Gnome::Art::Point (13.0, 0.0));
200 points->push_back (Gnome::Art::Point (13.0, 13.0));
201 points->push_back (Gnome::Art::Point (0.0, 13.0));
202 points->push_back (Gnome::Art::Point (13.0, 0.0));
209 points = new ArdourCanvas::Points ();
210 points->push_back (Gnome::Art::Point (0.0, 0.0));
211 points->push_back (Gnome::Art::Point (13.0, 0.0));
212 points->push_back (Gnome::Art::Point (0.0, 13.0));
213 points->push_back (Gnome::Art::Point (0.0, 0.0));
220 points = new ArdourCanvas::Points ();
221 points->push_back (Gnome::Art::Point (0.0, 0.0));
222 points->push_back (Gnome::Art::Point (12.0, 0.0));
223 points->push_back (Gnome::Art::Point (12.0, 12.0));
224 points->push_back (Gnome::Art::Point (0.0, 0.0));
232 frame_position = frame;
233 unit_position = editor.frame_to_unit (frame);
235 /* adjust to properly locate the tip */
237 unit_position -= shift;
239 group = new Group (parent, unit_position, 1.0);
241 mark = new Polygon (*group);
242 mark->property_points() = *points;
243 mark->property_fill_color_rgba() = rgba;
244 mark->property_outline_color_rgba() = rgba;
245 mark->property_width_pixels() = 1;
247 /* setup name pixbuf sizes */
248 name_font = get_font_for_style (N_("MarkerText"));
254 Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
258 layout->set_font_description (*name_font);
259 Gtkmm2ext::get_ink_pixel_size (layout, width, height);
260 name_height = height + 6;
262 name_pixbuf = new ArdourCanvas::Pixbuf(*group);
263 name_pixbuf->property_x() = label_offset;
265 set_name (annotation.c_str());
267 editor.ZoomChanged.connect (mem_fun (*this, &Marker::reposition));
269 mark->set_data ("marker", this);
272 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
284 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
293 void Marker::reparent(ArdourCanvas::Group & parent)
295 group->reparent(parent);
301 Marker::set_line_vpos (double pos, double height)
304 line->property_y1() = pos;
305 line->property_y2() = pos + height;
310 Marker::add_line (ArdourCanvas::Group* group, double y_origin, double initial_height)
314 line = new ArdourCanvas::SimpleLine (*group);
315 line->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint.get();
316 line->property_x1() = unit_position + shift;
317 line->property_y1() = y_origin;
318 line->property_x2() = unit_position + shift;
319 line->property_y2() = y_origin + initial_height;
321 line->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_marker_event), mark, this));
331 line->raise_to_top();
345 Marker::the_item() const
351 Marker::set_name (const string& new_name)
356 font_size = name_font->get_size() / Pango::SCALE;
357 pb_width = new_name.length() * font_size;
359 Glib::RefPtr<Gdk::Pixbuf> buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, pb_width, name_height);
361 cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, pb_width, name_height);
362 cairo_t *cr = cairo_create (surface);
363 cairo_text_extents_t te;
364 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
365 cairo_select_font_face (cr, name_font->get_family().c_str(),
366 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
367 cairo_set_font_size (cr, font_size);
368 cairo_text_extents (cr, new_name.c_str(), &te);
370 cairo_move_to (cr, 0.5,
371 0.5 - te.height / 2 - te.y_bearing + name_height / 2);
372 cairo_show_text (cr, new_name.c_str());
374 unsigned char* src = cairo_image_surface_get_data (surface);
375 convert_bgra_to_rgba(src, buf->get_pixels(), pb_width, name_height);
378 name_pixbuf->property_pixbuf() = buf;
380 if (_type == End || _type == LoopEnd || _type == PunchOut) {
381 name_pixbuf->property_x() = -(te.width);
387 Marker::set_position (nframes_t frame)
389 double new_unit_position = editor.frame_to_unit (frame);
390 new_unit_position -= shift;
391 group->move (new_unit_position - unit_position, 0.0);
392 frame_position = frame;
393 unit_position = new_unit_position;
396 line->property_x1() = unit_position + shift;
397 line->property_x2() = unit_position + shift;
402 Marker::reposition ()
404 set_position (frame_position);
420 Marker::set_color_rgba (uint32_t color)
422 mark->property_fill_color_rgba() = color;
423 mark->property_outline_color_rgba() = color;
426 /***********************************************************************/
428 TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
429 ARDOUR::TempoSection& temp)
430 : Marker (editor, parent, rgba, text, Tempo, 0, false),
433 set_position (_tempo.frame());
434 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_tempo_marker_event), mark, this));
437 TempoMarker::~TempoMarker ()
441 /***********************************************************************/
443 MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
444 ARDOUR::MeterSection& m)
445 : Marker (editor, parent, rgba, text, Meter, 0, false),
448 set_position (_meter.frame());
449 group->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_meter_marker_event), mark, this));
452 MeterMarker::~MeterMarker ()