Automation -use editor_add in gui, record straight lines with fewer points.
authornick_m <mainsbridge@gmail.com>
Mon, 15 Jun 2015 06:35:19 +0000 (16:35 +1000)
committernick_m <mainsbridge@gmail.com>
Tue, 16 Jun 2015 23:54:22 +0000 (09:54 +1000)
- don't keep setting/unsetting write pass when transport frame
  remains the same (think larger jack buffer sizes)
- insert guards are now 64 frames after when.
- refactor previous approach.

gtk2_ardour/automation_controller.cc
gtk2_ardour/automation_region_view.cc
gtk2_ardour/automation_time_axis.cc
gtk2_ardour/editor_drag.cc
libs/ardour/automation_watch.cc
libs/evoral/evoral/ControlList.hpp
libs/evoral/src/ControlList.cpp

index f57f2a737a81314f20ec9524f5f26d2875d86751..44c03159a4f2a84f0d4bb0bc5c02a55f4172b2bd 100644 (file)
@@ -204,7 +204,7 @@ AutomationController::toggled ()
                                _controllable->set_automation_state(Write);
                        }
                        if (_controllable->list()) {
-                               _controllable->list()->set_in_write_pass(true, false, _controllable->session().audible_frame());
+                               _controllable->list()->set_in_write_pass(true, true, _controllable->session().audible_frame());
                        }
                }
                const bool was_active = _controllable->get_value() >= 0.5;
index 7e330949de8b877d9b7a16867ad21f19b6a6fde8..b418d096f22e1e2c7726740b7af66b5efe54761b 100644 (file)
@@ -190,7 +190,7 @@ AutomationRegionView::add_automation_event (GdkEvent *, framepos_t when, double
        view->editor().begin_reversible_command (_("add automation event"));
        XMLNode& before = _line->the_list()->get_state();
 
-       _line->the_list()->add (when_d, y, with_guard_points, false);
+       _line->the_list()->editor_add (when_d, y, with_guard_points);
 
        XMLNode& after = _line->the_list()->get_state();
 
index 6d3a506cfa9b73561c5ad8bab9f7023468adf547..d5276e0cc511fd2acdd07a6d7f6e365dcef76bd7 100644 (file)
@@ -644,10 +644,10 @@ AutomationTimeAxisView::add_automation_event (GdkEvent* event, framepos_t when,
        _editor.begin_reversible_command (_("add automation event"));
        XMLNode& before = list->get_state();
 
-       list->add (when, y, with_guard_points);
+       list->editor_add (when, y, with_guard_points);
 
        XMLNode& after = list->get_state();
-       _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list, &before, &after));
+       _session->add_command (new MementoCommand<ARDOUR::AutomationList> (*list.get (), &before, &after));
        _editor.commit_reversible_command ();
        _session->set_dirty ();
 }
index b079972a1b32f64493692f96360bafb6a08de3ac..229b1ae1a0fdab78d149ba3f77273a852ecd3c65 100644 (file)
@@ -5521,8 +5521,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
 
-                               the_list->editor_add (p, value (the_list, p));
-                               the_list->editor_add (q, value (the_list, q));
+                               the_list->editor_add (p, value (the_list, p), false);
+                               the_list->editor_add (q, value (the_list, q), false);
                        }
 
                        /* same thing for the end */
@@ -5547,8 +5547,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
 
-                               the_list->editor_add (p, value (the_list, p));
-                               the_list->editor_add (q, value (the_list, q));
+                               the_list->editor_add (p, value (the_list, p), false);
+                               the_list->editor_add (q, value (the_list, q), false);
                        }
                }
 
index 4e833fceb5cd2cae57e87cee5dbd31142f9432e4..3714f1750214b8caf338a67e170416ec55781d13 100644 (file)
@@ -128,7 +128,7 @@ AutomationWatch::timer ()
                                        (*aw)->list()->add (time, (*aw)->user_double(), true);
                                }
                        }
-               } else {  //transport stopped or reversed.  stop the automation pass and start a new one (for bonus points, someday store the previous pass in an undo record)
+               } else if (time != _last_time) {  //transport stopped or reversed.  stop the automation pass and start a new one (for bonus points, someday store the previous pass in an undo record)
                        for (AutomationWatches::iterator aw = automation_watches.begin(); aw != automation_watches.end(); ++aw) {
                                DEBUG_TRACE (DEBUG::Automation, string_compose ("%1: transport in rewind, speed %2, in write pass ? %3 writing ? %4\n", 
                                                                                (*aw)->name(), _session->transport_speed(), _session->transport_rolling(),
index d2be604e5e037b1f44720e3e3898e1cd06cfd0c3..82868cd24c40b52294cd1c222a1ce2823adb753f 100644 (file)
@@ -125,7 +125,7 @@ public:
        void shift (double before, double distance);
 
        virtual void add (double when, double value, bool with_guards=true, bool with_initial=true);
-       virtual void editor_add (double when, double value);
+       virtual void editor_add (double when, double value, bool with_guard);
        
        void fast_simple_add (double when, double value);
 
index 2f1d8f424386fe60288d368f78485ccc4cb343cf..d592be349157e5cc30d26186beddd7f08a766c36 100644 (file)
@@ -452,7 +452,7 @@ ControlList::in_write_pass () const
 }
 
 void
-ControlList::editor_add (double when, double value)
+ControlList::editor_add (double when, double value, bool with_guard)
 {
        /* this is for making changes from a graphical line editor
        */
@@ -464,8 +464,8 @@ ControlList::editor_add (double when, double value)
                 */
 
                if (when >= 1) {
-                       _events.insert (_events.end(), new ControlEvent (0, _default_value));
-                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+                       _events.insert (_events.end(), new ControlEvent (0, value));
+                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added value %2 at zero\n", this, value));
                }
        }
 
@@ -473,6 +473,9 @@ ControlList::editor_add (double when, double value)
        iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
        DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
        _events.insert (i, new ControlEvent (when, value));
+       if (with_guard) {
+               add_guard_point (when);
+       }
 
        mark_dirty ();
 
@@ -491,9 +494,9 @@ ControlList::maybe_add_insert_guard (double when)
                           new control point so that our insert will happen correctly. */
                        most_recent_insert_iterator = _events.insert (
                                most_recent_insert_iterator,
-                               new ControlEvent (when + 1, (*most_recent_insert_iterator)->value));
+                               new ControlEvent (when + 64, (*most_recent_insert_iterator)->value));
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added insert guard point @ %2 = %3\n",
-                                                                        this, when+1,
+                                                                        this, when + 64,
                                                                         (*most_recent_insert_iterator)->value));
                }
        }
@@ -632,15 +635,6 @@ ControlList::add (double when, double value, bool with_guards, bool with_initial
                                 * before it if needed then reset the value of the point.
                                 */
 
-                               if ((when > 0) && most_recent_insert_iterator != _events.begin ()) {
-                                       --most_recent_insert_iterator;
-                                       double last_when =  (*most_recent_insert_iterator)->when;
-                                       ++most_recent_insert_iterator;
-                                       if (when - last_when > 64) {
-                                               add_guard_point (when - 64);
-                                       }
-                               }
-
                                (*most_recent_insert_iterator)->value = value;
 
                                /* if we modified the final value, then its as
@@ -658,10 +652,35 @@ ControlList::add (double when, double value, bool with_guards, bool with_initial
 
                } else {
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert new point at %2 at iterator at %3\n", this, when, (*most_recent_insert_iterator)->when));
-                       
-                       const bool done = maybe_insert_straight_line (when, value);
+                       bool done = false;
+                       /* check for possible straight line here until maybe_insert_straight_line () handles the insert iterator properly*/
+                       if (most_recent_insert_iterator != _events.begin ()) {
+                               bool have_point2 = false;
+                               --most_recent_insert_iterator;
+                               const bool have_point1 = (*most_recent_insert_iterator)->value == value;
+
+                               if (most_recent_insert_iterator != _events.begin ()) {
+                                       --most_recent_insert_iterator;
+                                       have_point2 = (*most_recent_insert_iterator)->value == value;
+                                       ++most_recent_insert_iterator;
+                               }
+
+                               if (have_point1 && have_point2) {
+                                       (*most_recent_insert_iterator)->when = when;
+                                       done = true;
+                               } else {
+                                       ++most_recent_insert_iterator;
+                               }
+                       }
+                       //done = maybe_insert_straight_line (when, value) || done;
+                       /* if the transport is stopped, add guard points (?) */
+                       if (!done && !_in_write_pass && when > 64) {
+                               add_guard_point (when - 64);
+                               maybe_add_insert_guard (when);
+                       }
+
                        if (with_guards) {
-                               maybe_add_insert_guard(when);
+                               maybe_add_insert_guard (when);
                        }
 
                        if (!done) {