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>
34 Marker::Marker (PublicEditor
& ed
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& annotation
,
35 Type type
, nframes_t frame
, bool handle_events
)
37 : editor (ed
), _parent(&parent
), _type(type
)
39 double label_offset
= 0;
133 points
= new ArdourCanvas::Points ();
135 points
->push_back (Gnome::Art::Point (0.0, 0.0));
136 points
->push_back (Gnome::Art::Point (6.0, 0.0));
137 points
->push_back (Gnome::Art::Point (6.0, 5.0));
138 points
->push_back (Gnome::Art::Point (3.0, 10.0));
139 points
->push_back (Gnome::Art::Point (0.0, 5.0));
140 points
->push_back (Gnome::Art::Point (0.0, 0.0));
149 points
= new ArdourCanvas::Points ();
150 points
->push_back (Gnome::Art::Point (3.0, 0.0));
151 points
->push_back (Gnome::Art::Point (6.0, 5.0));
152 points
->push_back (Gnome::Art::Point (6.0, 10.0));
153 points
->push_back (Gnome::Art::Point (0.0, 10.0));
154 points
->push_back (Gnome::Art::Point (0.0, 5.0));
155 points
->push_back (Gnome::Art::Point (3.0, 0.0));
162 points
= new ArdourCanvas::Points ();
163 points
->push_back (Gnome::Art::Point (0.0, 0.0));
164 points
->push_back (Gnome::Art::Point (6.5, 6.5));
165 points
->push_back (Gnome::Art::Point (0.0, 13.0));
166 points
->push_back (Gnome::Art::Point (0.0, 0.0));
173 points
= new ArdourCanvas::Points ();
174 points
->push_back (Gnome::Art::Point (6.5, 6.5));
175 points
->push_back (Gnome::Art::Point (13.0, 0.0));
176 points
->push_back (Gnome::Art::Point (13.0, 13.0));
177 points
->push_back (Gnome::Art::Point (6.5, 6.5));
184 points
= new ArdourCanvas::Points ();
185 points
->push_back (Gnome::Art::Point (0.0, 0.0));
186 points
->push_back (Gnome::Art::Point (13.0, 13.0));
187 points
->push_back (Gnome::Art::Point (0.0, 13.0));
188 points
->push_back (Gnome::Art::Point (0.0, 0.0));
195 points
= new ArdourCanvas::Points ();
196 points
->push_back (Gnome::Art::Point (13.0, 0.0));
197 points
->push_back (Gnome::Art::Point (13.0, 13.0));
198 points
->push_back (Gnome::Art::Point (0.0, 13.0));
199 points
->push_back (Gnome::Art::Point (13.0, 0.0));
206 points
= new ArdourCanvas::Points ();
207 points
->push_back (Gnome::Art::Point (0.0, 0.0));
208 points
->push_back (Gnome::Art::Point (13.0, 0.0));
209 points
->push_back (Gnome::Art::Point (0.0, 13.0));
210 points
->push_back (Gnome::Art::Point (0.0, 0.0));
217 points
= new ArdourCanvas::Points ();
218 points
->push_back (Gnome::Art::Point (0.0, 0.0));
219 points
->push_back (Gnome::Art::Point (12.0, 0.0));
220 points
->push_back (Gnome::Art::Point (12.0, 12.0));
221 points
->push_back (Gnome::Art::Point (0.0, 0.0));
229 frame_position
= frame
;
230 unit_position
= editor
.frame_to_unit (frame
);
232 /* adjust to properly locate the tip */
234 unit_position
-= shift
;
236 group
= new Group (parent
, unit_position
, 1.0);
238 mark
= new Polygon (*group
);
239 mark
->property_points() = *points
;
240 mark
->property_fill_color_rgba() = rgba
;
241 mark
->property_outline_color_rgba() = rgba
;
242 mark
->property_width_pixels() = 1;
244 /* setup name pixbuf sizes */
245 name_font
= get_font_for_style (N_("MarkerText"));
248 Glib::RefPtr
<Pango::Layout
> layout
= foo
.create_pango_layout (X_("Hg")); /* ascender + descender */
251 layout
->set_font_description (*name_font
);
252 Gtkmm2ext::get_ink_pixel_size (layout
, width
, name_height
);
254 name_pixbuf
= new ArdourCanvas::Pixbuf(*group
);
255 name_pixbuf
->property_x() = label_offset
;
256 name_pixbuf
->property_y() = (13 / 2) - (name_height
/ 2);
258 set_name (annotation
.c_str());
260 editor
.ZoomChanged
.connect (mem_fun (*this, &Marker::reposition
));
262 mark
->set_data ("marker", this);
265 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_marker_event
), mark
, this));
277 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
288 void Marker::reparent(ArdourCanvas::Group
& parent
)
290 group
->reparent(parent
);
296 Marker::set_line_vpos (double pos
, double height
)
299 line
->property_y1() = pos
;
300 line
->property_y2() = pos
+ height
;
305 Marker::add_line (ArdourCanvas::Group
* group
, double y_origin
, double initial_height
)
309 line
= new ArdourCanvas::SimpleLine (*group
);
310 line
->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint
.get();
311 line
->property_x1() = unit_position
+ shift
;
312 line
->property_y1() = y_origin
;
313 line
->property_x2() = unit_position
+ shift
;
314 line
->property_y2() = y_origin
+ initial_height
;
316 line
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_marker_event
), mark
, this));
326 line
->raise_to_top();
340 Marker::the_item() const
346 Marker::set_name (const string
& new_name
)
348 int name_width
= pixel_width (new_name
, *name_font
) + 2;
350 name_pixbuf
->property_pixbuf() = pixbuf_from_ustring(new_name
, name_font
, name_width
, name_height
);
352 if (_type
== End
|| _type
== LoopEnd
|| _type
== PunchOut
) {
353 name_pixbuf
->property_x() = - (name_width
);
358 Marker::set_position (nframes_t frame
)
360 double new_unit_position
= editor
.frame_to_unit (frame
);
361 new_unit_position
-= shift
;
362 group
->move (new_unit_position
- unit_position
, 0.0);
363 frame_position
= frame
;
364 unit_position
= new_unit_position
;
367 line
->property_x1() = unit_position
+ shift
;
368 line
->property_x2() = unit_position
+ shift
;
373 Marker::reposition ()
375 set_position (frame_position
);
391 Marker::set_color_rgba (uint32_t color
)
393 mark
->property_fill_color_rgba() = color
;
394 mark
->property_outline_color_rgba() = color
;
397 /***********************************************************************/
399 TempoMarker::TempoMarker (PublicEditor
& editor
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& text
,
400 ARDOUR::TempoSection
& temp
)
401 : Marker (editor
, parent
, rgba
, text
, Tempo
, 0, false),
404 set_position (_tempo
.frame());
405 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_tempo_marker_event
), mark
, this));
408 TempoMarker::~TempoMarker ()
412 /***********************************************************************/
414 MeterMarker::MeterMarker (PublicEditor
& editor
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& text
,
415 ARDOUR::MeterSection
& m
)
416 : Marker (editor
, parent
, rgba
, text
, Meter
, 0, false),
419 set_position (_meter
.frame());
420 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_meter_marker_event
), mark
, this));
423 MeterMarker::~MeterMarker ()