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;
30 TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, framepos_t frame, bool handle_events)
37 , _min_tempo (temp.beats_per_minute())
38 , _max_tempo (temp.beats_per_minute())
44 points = new ArdourCanvas::Points ();
45 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
46 points->push_back (ArdourCanvas::Duple (1.0, 0.0));
47 points->push_back (ArdourCanvas::Duple (1.0, curve_height));
48 points->push_back (ArdourCanvas::Duple (0.0, curve_height));
50 frame_position = frame;
51 unit_position = editor.sample_to_pixel (frame);
53 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
55 group->name = string_compose ("Marker::group for %1", _tempo.beats_per_minute());
58 _background = new ArdourCanvas::Rectangle (group);
60 _background->name = string_compose ("TempoCurve::_background for %1", _tempo.beats_per_minute());
62 _background->set_x0 (0.0);
63 _background->set_x1 (ArdourCanvas::COORD_MAX);
64 _background->set_outline_what (ArdourCanvas::Rectangle::What(0));
65 _curve = new ArdourCanvas::Curve (group);
67 _curve->name = string_compose ("TempoCurve::_curve for %1", _tempo.beats_per_minute());
69 _curve->set_fill_mode (ArdourCanvas::Curve::Inside);
70 _curve->set_points_per_segment (32);
71 _curve->set (*points);
73 set_color_rgba (rgba);
75 editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
77 /* events will be handled by both the group and the mark itself, so
78 * make sure they can both be used to lookup this object.
81 _curve->set_data ("tempo curve", this);
82 _background->set_data ("tempo curve", this);
85 //group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
88 set_position (_tempo.frame(), UINT32_MAX);
89 _curve->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this));
90 _background->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _background, this));
94 TempoCurve::~TempoCurve ()
96 CatchDeletion (this); /* EMIT SIGNAL */
98 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
102 void TempoCurve::reparent(ArdourCanvas::Container & parent)
104 group->reparent (&parent);
109 TempoCurve::canvas_height_set (double h)
115 TempoCurve::the_item() const
121 TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
124 unit_position = editor.sample_to_pixel (frame);
125 group->set_x_position (unit_position);
126 frame_position = frame;
127 _end_frame = end_frame;
129 const double tempo_delta = max (10.0, _max_tempo - _min_tempo);
131 points = new ArdourCanvas::Points ();
133 if (end_frame == UINT32_MAX) {
134 _curve->set_fill_mode (ArdourCanvas::Curve::None);
135 const double tempo_at = _tempo.tempo_at_frame (frame, editor.session()->frame_rate()) * _tempo.note_type();
136 const double y2_pos = (curve_height + 2.0) - (((tempo_at - _min_tempo) / (tempo_delta)) * curve_height);
138 points->push_back (ArdourCanvas::Duple (0.0, y2_pos));
139 points->push_back (ArdourCanvas::Duple (ArdourCanvas::COORD_MAX - 5.0, y2_pos));
142 _curve->set_fill_mode (ArdourCanvas::Curve::Inside);
143 const framepos_t frame_step = (end_frame - frame) / 32;
144 framepos_t current_frame = frame;
145 while (current_frame < end_frame) {
146 const double tempo_at = _tempo.tempo_at_frame (current_frame, editor.session()->frame_rate()) * _tempo.note_type();
147 const double y2_pos = (curve_height + 2.0) - (((tempo_at - _min_tempo) / (tempo_delta)) * curve_height);
149 points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), y2_pos));
150 max_y = max (y2_pos, max_y);
151 current_frame += frame_step;
155 /* the background fills the gap between the bottom of the curve and the time bar */
156 _background->set_x0 (0.0);
157 _background->set_x1 (editor.sample_to_pixel (end_frame - frame));
158 _background->set_y0 (max_y + 1.0);
159 _background->set_y1 (curve_height + 2.0);
161 if (max_y == curve_height + 2.0) {
167 _curve->set (*points);
171 TempoCurve::reposition ()
173 set_position (frame_position, _end_frame);
193 TempoCurve::set_color_rgba (uint32_t c)
196 _curve->set_fill_color (UIConfiguration::instance().color_mod ("selection rect", "selection rect"));
197 _curve->set_outline_color (_color);
199 _background->set_fill (true);
200 _background->set_fill_color (UIConfiguration::instance().color_mod ("selection rect", "selection rect"));