1 #include <sigc++/bind.h>
2 #include "ardour/tempo.h"
4 #include "canvas/rectangle.h"
5 #include "canvas/container.h"
6 #include "canvas/curve.h"
7 #include "canvas/canvas.h"
8 #include "canvas/debug.h"
10 #include "ui_config.h"
12 #include "tempo_curve.h"
13 #include "public_editor.h"
15 #include "rgb_macros.h"
17 #include <gtkmm2ext/utils.h>
21 PBD::Signal1<void,TempoCurve*> TempoCurve::CatchDeletion;
23 static double curve_height = 13.0;
25 void TempoCurve::setup_sizes(const double timebar_height)
27 curve_height = floor (timebar_height) - 2.5;
29 /* ignores Tempo note type - only note_types_per_minute is potentially curved */
30 TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, framepos_t frame, bool handle_events)
37 , _min_tempo (temp.note_types_per_minute())
38 , _max_tempo (temp.note_types_per_minute())
42 frame_position = frame;
43 unit_position = editor.sample_to_pixel (frame);
45 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 1));
47 group->name = string_compose ("TempoCurve::group for %1", _tempo.note_types_per_minute());
50 _curve = new ArdourCanvas::FramedCurve (group);
52 _curve->name = string_compose ("TempoCurve::curve for %1", _tempo.note_types_per_minute());
54 _curve->set_points_per_segment (3);
55 points = new ArdourCanvas::Points ();
56 _curve->set (*points);
58 set_color_rgba (rgba);
60 editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
62 /* events will be handled by both the group and the mark itself, so
63 * make sure they can both be used to lookup this object.
66 _curve->set_data ("tempo curve", this);
69 //group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
72 _curve->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this));
76 TempoCurve::~TempoCurve ()
78 CatchDeletion (this); /* EMIT SIGNAL */
80 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
84 void TempoCurve::reparent(ArdourCanvas::Container & parent)
86 group->reparent (&parent);
91 TempoCurve::canvas_height_set (double h)
97 TempoCurve::the_item() const
103 TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
105 unit_position = editor.sample_to_pixel (frame);
106 group->set_x_position (unit_position);
107 frame_position = frame;
108 _end_frame = end_frame;
111 points = new ArdourCanvas::Points ();
113 points->push_back (ArdourCanvas::Duple (0.0, curve_height));
115 if (frame >= end_frame) {
116 /* shouldn't happen but ..*/
117 const double tempo_at = _tempo.note_types_per_minute();
118 const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height);
120 points->push_back (ArdourCanvas::Duple (0.0, y_pos));
121 points->push_back (ArdourCanvas::Duple (1.0, y_pos));
123 } else if (_tempo.type() == ARDOUR::TempoSection::Constant || _tempo.c() == 0.0) {
124 const double tempo_at = _tempo.note_types_per_minute();
125 const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height);
127 points->push_back (ArdourCanvas::Duple (0.0, y_pos));
128 points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (end_frame - frame), y_pos));
131 const framepos_t frame_step = max ((end_frame - frame) / 5, (framepos_t) 1);
132 framepos_t current_frame = frame;
134 while (current_frame < end_frame) {
135 const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_frame (current_frame)).note_types_per_minute();
136 const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
138 points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), min (y_pos, curve_height)));
140 current_frame += frame_step;
143 const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_frame (end_frame)).note_types_per_minute();
144 const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
146 points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (end_frame - frame), min (y_pos, curve_height)));
149 _curve->set (*points);
153 TempoCurve::reposition ()
155 set_position (frame_position, _end_frame);
175 TempoCurve::set_color_rgba (uint32_t c)
178 _curve->set_fill_color (UIConfiguration::instance().color_mod ("tempo curve", "selection rect"));
179 _curve->set_outline_color (_color);