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"
32 Marker::Marker (PublicEditor
& ed
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& annotation
,
33 Type type
, nframes_t frame
, bool handle_events
)
35 : editor (ed
), _parent(&parent
), _type(type
)
37 double label_offset
= 0;
38 bool annotate_left
= false;
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));
180 annotate_left
= true;
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));
203 annotate_left
= true;
207 points
= new ArdourCanvas::Points ();
208 points
->push_back (Gnome::Art::Point (0.0, 0.0));
209 points
->push_back (Gnome::Art::Point (13.0, 0.0));
210 points
->push_back (Gnome::Art::Point (0.0, 13.0));
211 points
->push_back (Gnome::Art::Point (0.0, 0.0));
218 points
= new ArdourCanvas::Points ();
219 points
->push_back (Gnome::Art::Point (0.0, 0.0));
220 points
->push_back (Gnome::Art::Point (12.0, 0.0));
221 points
->push_back (Gnome::Art::Point (12.0, 12.0));
222 points
->push_back (Gnome::Art::Point (0.0, 0.0));
226 annotate_left
= true;
231 frame_position
= frame
;
232 unit_position
= editor
.frame_to_unit (frame
);
234 /* adjust to properly locate the tip */
236 unit_position
-= shift
;
238 group
= new Group (parent
, unit_position
, 1.0);
240 mark
= new Polygon (*group
);
241 mark
->property_points() = *points
;
242 mark
->property_fill_color_rgba() = rgba
;
243 mark
->property_outline_color_rgba() = rgba
;
244 mark
->property_width_pixels() = 1;
245 Pango::FontDescription
* font
= get_font_for_style (N_("MarkerText"));
246 //cerr << " font->get_size() = " << font->get_size() << " is_absolute = " << pango_font_description_get_size_is_absolute(font->gobj()) << " to_string = " << font->to_string() << endl;
247 text
= new Text (*group
);
248 text
->property_font_desc() = *font
;
249 text
->property_text() = annotation
.c_str();
254 text
->property_x() = -(text
->property_text_width());
256 text
->property_x() = label_offset
;
258 text
->property_y() = 0.0;
259 text
->property_anchor() = Gtk::ANCHOR_NW
;
260 text
->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MarkerLabel
.get();
262 editor
.ZoomChanged
.connect (mem_fun (*this, &Marker::reposition
));
264 mark
->set_data ("marker", this);
267 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_marker_event
), mark
, this));
279 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
290 void Marker::reparent(ArdourCanvas::Group
& parent
)
292 group
->reparent(parent
);
298 Marker::set_line_vpos (double pos
, double height
)
301 line
->property_y1() = pos
;
302 line
->property_y2() = pos
+ height
;
307 Marker::add_line (ArdourCanvas::Group
* group
, double y_origin
, double initial_height
)
311 line
= new ArdourCanvas::SimpleLine (*group
);
312 line
->property_color_rgba() = ARDOUR_UI::config()->canvasvar_EditPoint
.get();
313 line
->property_x1() = unit_position
+ shift
;
314 line
->property_y1() = y_origin
;
315 line
->property_x2() = unit_position
+ shift
;
316 line
->property_y2() = y_origin
+ initial_height
;
318 line
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_marker_event
), mark
, this));
328 line
->raise_to_top();
342 Marker::the_item() const
348 Marker::set_name (const string
& name
)
350 text
->property_text() = name
.c_str();
352 text
->property_x() = -(text
->property_text_width());
357 Marker::set_position (nframes_t frame
)
359 double new_unit_position
= editor
.frame_to_unit (frame
);
360 new_unit_position
-= shift
;
361 group
->move (new_unit_position
- unit_position
, 0.0);
362 frame_position
= frame
;
363 unit_position
= new_unit_position
;
366 line
->property_x1() = unit_position
+ shift
;
367 line
->property_x2() = unit_position
+ shift
;
372 Marker::reposition ()
374 set_position (frame_position
);
390 Marker::set_color_rgba (uint32_t color
)
392 mark
->property_fill_color_rgba() = color
;
393 mark
->property_outline_color_rgba() = color
;
396 /***********************************************************************/
398 TempoMarker::TempoMarker (PublicEditor
& editor
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& text
,
399 ARDOUR::TempoSection
& temp
)
400 : Marker (editor
, parent
, rgba
, text
, Tempo
, 0, false),
403 set_position (_tempo
.frame());
404 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_tempo_marker_event
), mark
, this));
407 TempoMarker::~TempoMarker ()
411 /***********************************************************************/
413 MeterMarker::MeterMarker (PublicEditor
& editor
, ArdourCanvas::Group
& parent
, guint32 rgba
, const string
& text
,
414 ARDOUR::MeterSection
& m
)
415 : Marker (editor
, parent
, rgba
, text
, Meter
, 0, false),
418 set_position (_meter
.frame());
419 group
->signal_event().connect (bind (mem_fun (editor
, &PublicEditor::canvas_meter_marker_event
), mark
, this));
422 MeterMarker::~MeterMarker ()