Fix thinko in 9581cb26 - scratch-buffer can't be used recursively.
authorRobin Gareus <robin@gareus.org>
Sat, 10 Jun 2017 23:57:28 +0000 (01:57 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 11 Jun 2017 00:16:35 +0000 (02:16 +0200)
libs/ardour/gain_control.cc
libs/ardour/slavable_automation_control.cc

index cbafc75ad4139b403fb419af4c00c2626966838f..f5162460670ca2f8d1ea71f221dc1a8d40cc9a6e 100644 (file)
@@ -105,5 +105,11 @@ GainControl::inc_gain (gain_t factor)
 bool
 GainControl::get_masters_curve_locked (framepos_t start, framepos_t end, float* vec, framecnt_t veclen) const
 {
+       if (_masters.empty()) {
+               return list()->curve().rt_safe_get_vector (start, end, vec, veclen);
+       }
+       for (framecnt_t i = 0; i < veclen; ++i) {
+               vec[i] = 1.f;
+       }
        return SlavableAutomationControl::masters_curve_multiply (start, end, vec, veclen);
 }
index 8a7a8ba00f79b9d28fe2c1fd8d9322ea817a1597..5ab968f69cee011b271d1495a2ef7a1857f4f746 100644 (file)
@@ -27,6 +27,7 @@
 #include "evoral/Curve.hpp"
 
 #include "ardour/audioengine.h"
+#include "ardour/runtime_functions.h"
 #include "ardour/slavable_automation_control.h"
 #include "ardour/session.h"
 
@@ -127,40 +128,24 @@ SlavableAutomationControl::get_masters_curve_locked (framepos_t, framepos_t, flo
 bool
 SlavableAutomationControl::masters_curve_multiply (framepos_t start, framepos_t end, float* vec, framecnt_t veclen) const
 {
-       bool rv = list()->curve().rt_safe_get_vector (start, end, vec, veclen);
+       gain_t* scratch = _session.scratch_automation_buffer ();
+       bool rv = list()->curve().rt_safe_get_vector (start, end, scratch, veclen);
+       if (rv) {
+               for (framecnt_t i = 0; i < veclen; ++i) {
+                       vec[i] *= scratch[i];
+               }
+       } else {
+               apply_gain_to_buffer (vec, veclen, Control::get_double ());
+       }
        if (_masters.empty()) {
                return rv;
        }
-       gain_t* scratch = _session.scratch_automation_buffer ();
-       for (Masters::const_iterator mr = _masters.begin(); mr != _masters.end(); ++mr) {
-               boost::shared_ptr<AutomationControl> ac (mr->second.master());
-               bool got_curve;
 
+       for (Masters::const_iterator mr = _masters.begin(); mr != _masters.end(); ++mr) {
                boost::shared_ptr<SlavableAutomationControl> sc
-                       = boost::dynamic_pointer_cast<SlavableAutomationControl>(ac);
-               if (sc) {
-                       got_curve = sc->get_masters_curve_locked (start, end, scratch, veclen);
-               } else {
-                       got_curve = ac->list()->curve().rt_safe_get_vector (start, end, scratch, veclen);
-               }
-               if (got_curve) {
-                       // TODO use SSE/AVX methods, e.g. ARDOUR::apply_gain_to_buffer, mix_buffers_no_gain
-                       // which works as long as automation _types_ gain_t == ARDOUR::Sample type == float
-                       if (!rv) {
-                               // TODO optimize this, in case rv is false, direcly use "vec" above.
-                               rv = true;
-                               memcpy (vec, scratch, sizeof (float) * veclen);
-                       } else {
-                               for (framecnt_t i = 0; i < veclen; ++i) {
-                                       vec[i] *= scratch[i];
-                               }
-                       }
-               } else if (rv) {
-                       const float v = get_masters_value ();
-                       for (framecnt_t i = 0; i < veclen; ++i) {
-                               vec[i] *= v;
-                       }
-               }
+                       = boost::dynamic_pointer_cast<SlavableAutomationControl>(mr->second.master());
+               assert (sc);
+               rv |= sc->masters_curve_multiply (start, end, vec, veclen);
        }
        return rv;
 }