2016-05-07 13:03:12 -04:00
|
|
|
#include <sigc++/bind.h>
|
|
|
|
#include "ardour/tempo.h"
|
|
|
|
|
|
|
|
#include "canvas/rectangle.h"
|
|
|
|
#include "canvas/container.h"
|
|
|
|
#include "canvas/curve.h"
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "tempo_curve.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "rgb_macros.h"
|
|
|
|
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
PBD::Signal1<void,TempoCurve*> TempoCurve::CatchDeletion;
|
|
|
|
|
2016-05-07 13:54:52 -04:00
|
|
|
static double curve_height = 13.0;
|
|
|
|
|
|
|
|
void TempoCurve::setup_sizes(const double timebar_height)
|
|
|
|
{
|
2016-05-17 13:26:18 -04:00
|
|
|
curve_height = floor (timebar_height) - 2.5;
|
2016-05-07 13:54:52 -04:00
|
|
|
}
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, ARDOUR::TempoSection& temp, framepos_t frame, bool handle_events)
|
|
|
|
|
|
|
|
: editor (ed)
|
|
|
|
, _parent (&parent)
|
|
|
|
, _curve (0)
|
2016-05-07 13:54:52 -04:00
|
|
|
, _shown (false)
|
2016-05-07 13:03:12 -04:00
|
|
|
, _color (rgba)
|
2016-05-07 13:54:52 -04:00
|
|
|
, _min_tempo (temp.beats_per_minute())
|
2016-05-07 13:03:12 -04:00
|
|
|
, _max_tempo (temp.beats_per_minute())
|
|
|
|
, _tempo (temp)
|
|
|
|
|
|
|
|
{
|
|
|
|
frame_position = frame;
|
|
|
|
unit_position = editor.sample_to_pixel (frame);
|
|
|
|
|
2016-05-17 13:26:18 -04:00
|
|
|
group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 1));
|
2016-05-07 13:03:12 -04:00
|
|
|
#ifdef CANVAS_DEBUG
|
2016-05-24 14:10:22 -04:00
|
|
|
group->name = string_compose ("TempoCurve::group for %1", _tempo.beats_per_minute());
|
2016-05-07 13:03:12 -04:00
|
|
|
#endif
|
|
|
|
|
2016-05-17 13:26:18 -04:00
|
|
|
_curve = new ArdourCanvas::FramedCurve (group);
|
2016-05-07 13:03:12 -04:00
|
|
|
#ifdef CANVAS_DEBUG
|
2016-05-24 14:10:22 -04:00
|
|
|
_curve->name = string_compose ("TempoCurve::curve for %1", _tempo.beats_per_minute());
|
2016-05-07 13:03:12 -04:00
|
|
|
#endif
|
2016-05-17 13:26:18 -04:00
|
|
|
_curve->set_fill_mode (ArdourCanvas::FramedCurve::Inside);
|
2016-05-24 14:10:22 -04:00
|
|
|
_curve->set_points_per_segment (3);
|
2016-05-17 13:26:18 -04:00
|
|
|
|
|
|
|
points = new ArdourCanvas::Points ();
|
|
|
|
points->push_back (ArdourCanvas::Duple (0.0, 0.0));
|
|
|
|
points->push_back (ArdourCanvas::Duple (1.0, 0.0));
|
|
|
|
points->push_back (ArdourCanvas::Duple (1.0, curve_height));
|
|
|
|
points->push_back (ArdourCanvas::Duple (0.0, curve_height));
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
_curve->set (*points);
|
|
|
|
|
|
|
|
set_color_rgba (rgba);
|
|
|
|
|
|
|
|
editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
|
|
|
|
|
|
|
|
/* events will be handled by both the group and the mark itself, so
|
|
|
|
* make sure they can both be used to lookup this object.
|
|
|
|
*/
|
|
|
|
|
2016-05-09 15:25:53 -04:00
|
|
|
_curve->set_data ("tempo curve", this);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
if (handle_events) {
|
|
|
|
//group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
|
|
|
|
}
|
2016-05-09 15:25:53 -04:00
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
set_position (_tempo.frame(), UINT32_MAX);
|
2016-05-09 15:25:53 -04:00
|
|
|
_curve->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_tempo_curve_event), _curve, this));
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TempoCurve::~TempoCurve ()
|
|
|
|
{
|
|
|
|
CatchDeletion (this); /* EMIT SIGNAL */
|
|
|
|
|
|
|
|
/* destroying the parent group destroys its contents, namely any polygons etc. that we added */
|
|
|
|
delete group;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TempoCurve::reparent(ArdourCanvas::Container & parent)
|
|
|
|
{
|
|
|
|
group->reparent (&parent);
|
|
|
|
_parent = &parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::canvas_height_set (double h)
|
|
|
|
{
|
|
|
|
_canvas_height = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Item&
|
|
|
|
TempoCurve::the_item() const
|
|
|
|
{
|
|
|
|
return *group;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
|
|
|
|
{
|
|
|
|
unit_position = editor.sample_to_pixel (frame);
|
|
|
|
group->set_x_position (unit_position);
|
|
|
|
frame_position = frame;
|
|
|
|
_end_frame = end_frame;
|
2016-05-07 13:54:52 -04:00
|
|
|
|
2016-05-17 13:26:18 -04:00
|
|
|
points->clear();
|
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
points = new ArdourCanvas::Points ();
|
2016-05-17 13:26:18 -04:00
|
|
|
points->push_back (ArdourCanvas::Duple (0.0, curve_height));
|
2016-05-07 13:54:52 -04:00
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
if (end_frame == UINT32_MAX) {
|
2016-09-03 13:18:12 -04:00
|
|
|
const double tempo_at = _tempo.tempo_at_frame (frame, editor.session()->frame_rate()) * 4.0;
|
2016-05-24 14:10:22 -04:00
|
|
|
const double y_pos = (curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height);
|
2016-05-17 13:26:18 -04:00
|
|
|
|
|
|
|
points->push_back (ArdourCanvas::Duple (0.0, y_pos));
|
|
|
|
points->push_back (ArdourCanvas::Duple (ArdourCanvas::COORD_MAX - 5.0, y_pos));
|
2016-05-07 13:03:12 -04:00
|
|
|
|
|
|
|
} else {
|
2016-09-03 13:18:12 -04:00
|
|
|
|
2016-07-10 13:53:36 -04:00
|
|
|
const framepos_t frame_step = max ((end_frame - frame) / 5, (framepos_t) 1);
|
2016-05-07 13:03:12 -04:00
|
|
|
framepos_t current_frame = frame;
|
2016-05-17 13:26:18 -04:00
|
|
|
|
2016-05-18 11:01:08 -04:00
|
|
|
while (current_frame < (end_frame - frame_step)) {
|
2016-09-03 13:18:12 -04:00
|
|
|
const double tempo_at = _tempo.tempo_at_frame (current_frame, editor.session()->frame_rate()) * 4.0;
|
2016-06-03 17:24:04 -04:00
|
|
|
const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
2016-06-03 17:24:04 -04:00
|
|
|
points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), min (y_pos, curve_height)));
|
2016-05-17 13:26:18 -04:00
|
|
|
|
2016-05-07 13:03:12 -04:00
|
|
|
current_frame += frame_step;
|
|
|
|
}
|
2016-05-23 16:49:52 -04:00
|
|
|
|
2016-09-03 13:18:12 -04:00
|
|
|
const double tempo_at = _tempo.tempo_at_frame (end_frame, editor.session()->frame_rate()) * 4.0;
|
2016-06-03 17:24:04 -04:00
|
|
|
const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
|
2016-05-07 13:03:12 -04:00
|
|
|
|
2016-06-03 17:24:04 -04:00
|
|
|
points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel ((end_frame - 1) - frame), min (y_pos, curve_height)));
|
2016-05-07 13:03:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_curve->set (*points);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::reposition ()
|
|
|
|
{
|
|
|
|
set_position (frame_position, _end_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::show ()
|
|
|
|
{
|
|
|
|
_shown = true;
|
|
|
|
|
|
|
|
group->show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::hide ()
|
|
|
|
{
|
|
|
|
_shown = false;
|
|
|
|
|
|
|
|
group->hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TempoCurve::set_color_rgba (uint32_t c)
|
|
|
|
{
|
|
|
|
_color = c;
|
2016-06-15 12:06:40 -04:00
|
|
|
_curve->set_fill_color (UIConfiguration::instance().color_mod ("tempo curve", "selection rect"));
|
2016-05-07 13:03:12 -04:00
|
|
|
_curve->set_outline_color (_color);
|
|
|
|
|
|
|
|
}
|