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/polygon.h"
8 #include "canvas/canvas.h"
9 #include "canvas/debug.h"
11 #include "ui_config.h"
13 #include "tempo_curve.h"
14 #include "public_editor.h"
16 #include "rgb_macros.h"
18 #include <gtkmm2ext/utils.h>
22 PBD::Signal1<void,TempoCurve*> TempoCurve::CatchDeletion;
24 TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, framepos_t frame, bool handle_events)
31 , _max_tempo (temp.beats_per_minute())
36 const double MH = 12.0;
37 const double M3 = std::max(1.f, rintf(3.f * UIConfiguration::instance().get_ui_scale()));
38 const double M6 = std::max(2.f, rintf(6.f * UIConfiguration::instance().get_ui_scale()));
40 points = new ArdourCanvas::Points ();
41 points->push_back (ArdourCanvas::Duple (0.0, 0.0));
42 points->push_back (ArdourCanvas::Duple (1.0, 0.0));
43 points->push_back (ArdourCanvas::Duple (1.0, MH));
44 points->push_back (ArdourCanvas::Duple (0.0, MH));
46 frame_position = frame;
47 unit_position = editor.sample_to_pixel (frame);
49 group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
51 group->name = string_compose ("Marker::group for %1", _tempo.beats_per_minute());
54 _background = new ArdourCanvas::Rectangle (group);
56 _background->name = string_compose ("Marker::_background for %1", _tempo.beats_per_minute());
58 _background->set_x0 (0.0);
59 _background->set_x1 (ArdourCanvas::COORD_MAX);
60 _background->set_outline_what (ArdourCanvas::Rectangle::What(0));
61 _curve = new ArdourCanvas::Curve (group);
63 _curve->name = string_compose ("Marker::_background for %1", _tempo.beats_per_minute());
65 _curve->set_fill_mode (ArdourCanvas::Curve::Inside);
66 _curve->set_points_per_segment (32);
67 _curve->set (*points);
69 set_color_rgba (rgba);
71 editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
73 /* events will be handled by both the group and the mark itself, so
74 * make sure they can both be used to lookup this object.
77 group->set_data ("marker", this);
80 //group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
82 set_position (_tempo.frame(), UINT32_MAX);
83 _curve->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), group, this));
84 _background->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), group, this));
88 TempoCurve::~TempoCurve ()
90 CatchDeletion (this); /* EMIT SIGNAL */
92 /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
96 void TempoCurve::reparent(ArdourCanvas::Container & parent)
98 group->reparent (&parent);
103 TempoCurve::canvas_height_set (double h)
109 TempoCurve::the_item() const
115 TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
117 const double height = 12.0;
119 unit_position = editor.sample_to_pixel (frame);
120 group->set_x_position (unit_position);
121 frame_position = frame;
122 _end_frame = end_frame;
123 _background->set_x0 (0.0);
124 _background->set_x1 (editor.sample_to_pixel (end_frame - frame));
125 const double tempo_delta = max (10.0, _max_tempo - _min_tempo);
127 points = new ArdourCanvas::Points ();
128 if (end_frame == UINT32_MAX) {
129 _curve->set_fill_mode (ArdourCanvas::Curve::None);
130 const double tempo_at = _tempo.tempo_at_frame (frame, editor.session()->frame_rate()) * _tempo.note_type();
131 const double y2_pos = (height + 2.0) - (((tempo_at - _min_tempo) / (tempo_delta)) * height);
133 points->push_back (ArdourCanvas::Duple (0.0, y2_pos));
134 points->push_back (ArdourCanvas::Duple (ArdourCanvas::COORD_MAX - 5.0, y2_pos));
137 _curve->set_fill_mode (ArdourCanvas::Curve::Inside);
138 const framepos_t frame_step = (end_frame - frame) / 32;
139 framepos_t current_frame = frame;
140 while (current_frame < end_frame) {
141 const double tempo_at = _tempo.tempo_at_frame (current_frame, editor.session()->frame_rate()) * _tempo.note_type();
142 const double y2_pos = (height + 2.0) - (((tempo_at - _min_tempo) / (tempo_delta)) * height);
144 points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), y2_pos));
145 max_y = max (y2_pos, max_y);
146 current_frame += frame_step;
150 /* the background fills the gap between the bottom of the curve and the time bar */
151 _background->set_y0 (max_y + 1.0);
152 _background->set_y1 (height + 2.0);
154 if (max_y == height + 2.0) {
160 _curve->set (*points);
164 TempoCurve::reposition ()
166 set_position (frame_position, _end_frame);
186 TempoCurve::set_color_rgba (uint32_t c)
189 _curve->set_fill_color (UIConfiguration::instance().color_mod ("selection rect", "selection rect"));
190 _curve->set_outline_color (_color);
192 _background->set_fill (true);
193 _background->set_fill_color (UIConfiguration::instance().color_mod ("selection rect", "selection rect"));