#include <vector>
#include <pbd/stl_delete.h>
+#include <pbd/memento_command.h>
#include <ardour/automation_event.h>
#include <ardour/curve.h>
using namespace std;
using namespace sigc;
using namespace ARDOUR;
+using namespace PBD;
using namespace Editing;
using namespace Gnome; // for Canvas
ControlPoint::~ControlPoint ()
{
- gtk_object_destroy (GTK_OBJECT(item));
+ delete item;
}
bool
/*****/
-AutomationLine::AutomationLine (string name, TimeAxisView& tv, ArdourCanvas::Group& parent, AutomationList& al)
+AutomationLine::AutomationLine (const string & name, TimeAxisView& tv, ArdourCanvas::Group& parent, AutomationList& al)
: trackview (tv),
_name (name),
alist (al),
line = new ArdourCanvas::Line (*group);
line->property_width_pixels() = (guint)1;
+ line->set_data ("line", this);
line->signal_event().connect (mem_fun (*this, &AutomationLine::event_handler));
alist.StateChanged.connect (mem_fun(*this, &AutomationLine::list_changed));
+
+ trackview.session().register_with_memento_command_factory(alist.id(), this);
+
}
AutomationLine::~AutomationLine ()
{
vector_delete (&control_points);
-
- gtk_object_destroy (GTK_OBJECT(group));
+ delete group;
}
bool
}
}
-void
-AutomationLine::set_point_size (double sz)
-{
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- (*i)->set_size (sz);
- }
-}
-
void
AutomationLine::show ()
{
_visible = false;
}
+double
+AutomationLine::control_point_box_size ()
+{
+ if (_height > TimeAxisView::hLarger) {
+ return 8.0;
+ } else if (_height > (guint32) TimeAxisView::hNormal) {
+ return 6.0;
+ }
+ return 4.0;
+}
+
void
AutomationLine::set_height (guint32 h)
{
if (h != _height) {
_height = h;
- if (_height > (guint32) TimeAxisView::Larger) {
- set_point_size (8.0);
- } else if (_height > (guint32) TimeAxisView::Normal) {
- set_point_size (6.0);
- } else {
- set_point_size (4.0);
+ double bsz = control_point_box_size();
+
+ for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+ (*i)->set_size (bsz);
}
reset ();
line to convert them to something relevant.
*/
- mr.xval = (jack_nframes_t) floor (cp.get_x());
+ mr.xval = (nframes_t) floor (cp.get_x());
mr.yval = 1.0 - (cp.get_y() / _height);
/* if xval has not changed, set it directly from the model to avoid rounding errors */
if (mr.xval == trackview.editor.frame_to_unit((*cp.model)->when)) {
- mr.xval = (jack_nframes_t) (*cp.model)->when;
+ mr.xval = (nframes_t) (*cp.model)->when;
} else {
mr.xval = trackview.editor.unit_to_frame (mr.xval);
}
/* part 2: find out where the model point is now
*/
- mr.xpos = (jack_nframes_t) (*cp.model)->when;
+ mr.xpos = (nframes_t) (*cp.model)->when;
mr.ypos = (*cp.model)->value;
/* part 3: get the position of the visual control
after = nth (cp.view_index + 1);
if (before) {
- mr.xmin = (jack_nframes_t) (*before->model)->when;
+ mr.xmin = (nframes_t) (*before->model)->when;
mr.ymin = (*before->model)->value;
mr.start = before->model;
++mr.start;
uint32_t this_ry = 0;
uint32_t prev_ry = 0;
double* slope;
+ uint32_t box_size;
+ uint32_t cpsize;
/* hide all existing points, and the line */
+
+ cpsize = 0;
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->hide();
+ ++cpsize;
}
line->hide ();
slope[n] = ydelta/xdelta;
}
+ box_size = (uint32_t) control_point_box_size ();
+
/* read all points and decide which ones to show as control points */
view_index = 0;
*/
this_rx = (uint32_t) rint (tx);
- this_ry = (unsigned long) rint (ty);
-
- if (view_index && pi != npoints && (this_rx == prev_rx) && (this_ry == prev_ry)) {
+ this_ry = (uint32_t) rint (ty);
+ if (view_index && pi != npoints && /* not the first, not the last */
+ (((this_rx == prev_rx) && (this_ry == prev_ry)) || /* same point */
+ (((this_rx - prev_rx) < (box_size + 2)) && /* too close horizontally */
+ ((abs ((int)(this_ry - prev_ry)) < (int) (box_size + 2)))))) { /* too close vertically */
continue;
- }
+ }
/* ok, we should display this point */
- if (view_index >= control_points.size()) {
+ if (view_index >= cpsize) {
+
/* make sure we have enough control points */
ControlPoint* ncp = new ControlPoint (*this);
-
- if (_height > (guint32) TimeAxisView::Larger) {
- ncp->set_size (8.0);
- } else if (_height > (guint32) TimeAxisView::Normal) {
- ncp->set_size (6.0);
- } else {
- ncp->set_size (4.0);
- }
+
+ ncp->set_size (box_size);
control_points.push_back (ncp);
+ ++cpsize;
}
ControlPoint::ShapeType shape;
line_points.push_back (Art::Point (0,0));
}
+ while (line_points.size() > npoints) {
+ line_points.pop_back ();
+ }
+
for (view_index = 0; view_index < npoints; ++view_index) {
line_points[view_index].set_x (control_points[view_index]->get_x());
line_points[view_index].set_y (control_points[view_index]->get_y());
}
trackview.editor.current_session()->begin_reversible_command (str);
- trackview.editor.current_session()->add_undo (get_memento());
+ trackview.editor.current_session()->add_command (new MementoCommand<AutomationLine>(*this, &get_state(), 0));
first_drag_fraction = fraction;
last_drag_fraction = fraction;
}
void
-AutomationLine::point_drag (ControlPoint& cp, jack_nframes_t x, float fraction, bool with_push)
+AutomationLine::point_drag (ControlPoint& cp, nframes_t x, float fraction, bool with_push)
{
modify_view (cp, x, fraction, with_push);
drags++;
update_pending = false;
- trackview.editor.current_session()->add_redo_no_execute (get_memento());
+ trackview.editor.current_session()->add_command (new MementoCommand<AutomationLine>(*this, 0, &get_state()));
trackview.editor.current_session()->commit_reversible_command ();
trackview.editor.current_session()->set_dirty ();
}
model_representation (cp, mr);
trackview.editor.current_session()->begin_reversible_command (_("remove control point"));
- trackview.editor.current_session()->add_undo (get_memento());
+ XMLNode &before = get_state();
alist.erase (mr.start, mr.end);
- trackview.editor.current_session()->add_redo_no_execute (get_memento());
+ trackview.editor.current_session()->add_command(new MementoCommand<AutomationLine>(*this, &before, &get_state()));
trackview.editor.current_session()->commit_reversible_command ();
trackview.editor.current_session()->set_dirty ();
}
void
-AutomationLine::get_selectables (jack_nframes_t& start, jack_nframes_t& end,
+AutomationLine::get_selectables (nframes_t& start, nframes_t& end,
double botfrac, double topfrac, list<Selectable*>& results)
{
double top;
double bot;
- jack_nframes_t nstart;
- jack_nframes_t nend;
+ nframes_t nstart;
+ nframes_t nend;
bool collecting = false;
/* Curse X11 and its inverted coordinate system! */
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- jack_nframes_t when = (jack_nframes_t) (*(*i)->model)->when;
+ nframes_t when = (nframes_t) (*(*i)->model)->when;
if (when >= start && when <= end) {
// show_selection ();
}
-
-// This is copied into AudioRegionGainLine
-UndoAction
-AutomationLine::get_memento ()
-{
- return alist.get_memento();
-}
-
void
AutomationLine::list_changed (Change ignored)
{
for (ai = events.const_begin(); ai != events.const_end(); ++ai) {
- double translated_y;
-
- translated_y = (*ai)->value;
+ double translated_y = (*ai)->value;
model_to_view_y (translated_y);
tmp_points.push_back (ALPoint (trackview.editor.frame_to_unit ((*ai)->when),
AutomationLine::clear ()
{
/* parent must create command */
- trackview.editor.current_session()->add_undo (get_memento());
+ XMLNode &before = get_state();
alist.clear();
- trackview.editor.current_session()->add_redo_no_execute (get_memento());
+ trackview.editor.current_session()->add_command (new MementoCommand<AutomationLine>(*this, &before, &get_state()));
trackview.editor.current_session()->commit_reversible_command ();
trackview.editor.current_session()->set_dirty ();
}
void
AutomationLine::change_model (AutomationList::iterator i, double x, double y)
{
- alist.modify (i, (jack_nframes_t) x, y);
+ alist.modify (i, (nframes_t) x, y);
}
void
}
}
}
+
+XMLNode &
+AutomationLine::get_state (void)
+{
+ /* function as a proxy for the model */
+ return alist.get_state();
+}
+
+int
+AutomationLine::set_state (const XMLNode &node)
+{
+ /* function as a proxy for the model */
+ return alist.set_state (node);
+}