display timecode from BWF etc in SF browser; accels for windows now work (misspelling...
[ardour.git] / gtk2_ardour / automation_line.cc
index 5c09ddd49b35e1c90d9d8e7f3dcfe07a81ef2394..b7846dd79a03af3e9c45dd092b40277701a1f0a7 100644 (file)
@@ -244,6 +244,9 @@ AutomationLine::AutomationLine (const string & name, TimeAxisView& tv, ArdourCan
        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 ()
@@ -267,14 +270,6 @@ AutomationLine::queue_reset ()
        }
 }
 
-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 () 
 {
@@ -299,18 +294,27 @@ AutomationLine::hide ()
        _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 ();
@@ -501,14 +505,14 @@ AutomationLine::model_representation (ControlPoint& cp, ModelRepresentation& mr)
           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);
        }
@@ -523,7 +527,7 @@ AutomationLine::model_representation (ControlPoint& cp, ModelRepresentation& mr)
        /* 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
@@ -542,7 +546,7 @@ AutomationLine::model_representation (ControlPoint& cp, ModelRepresentation& mr)
        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;
@@ -667,11 +671,16 @@ AutomationLine::determine_visible_control_points (ALPoints& points)
        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 ();
@@ -692,6 +701,8 @@ AutomationLine::determine_visible_control_points (ALPoints& points)
                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;
@@ -733,29 +744,27 @@ AutomationLine::determine_visible_control_points (ALPoints& points)
                */
 
                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;
@@ -826,6 +835,10 @@ AutomationLine::determine_visible_control_points (ALPoints& points)
                        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());
@@ -888,7 +901,7 @@ AutomationLine::start_drag (ControlPoint* cp, float fraction)
        }
 
        trackview.editor.current_session()->begin_reversible_command (str);
-       trackview.editor.current_session()->add_command (new MementoUndoCommand<AutomationLine>(*this, get_state()));
+       trackview.editor.current_session()->add_command (new MementoCommand<AutomationLine>(*this, &get_state(), 0));
        
        first_drag_fraction = fraction;
        last_drag_fraction = fraction;
@@ -896,7 +909,7 @@ AutomationLine::start_drag (ControlPoint* cp, float 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++;
@@ -937,7 +950,7 @@ AutomationLine::end_drag (ControlPoint* cp)
 
                update_pending = false;
 
-               trackview.editor.current_session()->add_command (new MementoRedoCommand<AutomationLine>(*this, get_state()));
+               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 ();
        }
@@ -1018,20 +1031,20 @@ AutomationLine::remove_point (ControlPoint& cp)
 
        alist.erase (mr.start, mr.end);
 
-       trackview.editor.current_session()->add_command(new MementoCommand<AutomationLine>(*this, before, get_state()));
+       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! */
@@ -1044,7 +1057,7 @@ AutomationLine::get_selectables (jack_nframes_t& start, jack_nframes_t& end,
 
        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) {
                        
@@ -1165,14 +1178,6 @@ AutomationLine::hide_selection ()
 //     show_selection ();
 }
 
-
-// This is copied into AudioRegionGainLine
-UndoAction
-AutomationLine::get_memento ()
-{
-       return alist.get_memento();
-}
-
 void
 AutomationLine::list_changed (Change ignored)
 {
@@ -1198,9 +1203,7 @@ AutomationLine::reset_callback (const AutomationList& events)
 
        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),
@@ -1228,7 +1231,7 @@ AutomationLine::clear ()
        /* parent must create command */
         XMLNode &before = get_state();
        alist.clear();
-       trackview.editor.current_session()->add_command (new MementoCommand<AutomationLine>(*this, before, get_state()));
+       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 ();
 }
@@ -1236,7 +1239,7 @@ AutomationLine::clear ()
 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
@@ -1268,15 +1271,16 @@ AutomationLine::hide_all_but_selected_control_points ()
        }
 }
 
-XMLNode &AutomationLine::get_state(void)
+XMLNode &
+AutomationLine::get_state (void)
 {
-    // TODO
-    return alist.get_state();
+       /* function as a proxy for the model */
+       return alist.get_state();
 }
 
-int AutomationLine::set_state(const XMLNode &node)
+int 
+AutomationLine::set_state (const XMLNode &node)
 {
-    // TODO
-    alist.set_state(node);
-    return 0;
+       /* function as a proxy for the model */
+       return alist.set_state (node);
 }