Move preroll duration calc into libardour
authorRobin Gareus <robin@gareus.org>
Thu, 19 Jan 2017 11:39:15 +0000 (12:39 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 19 Jan 2017 12:05:54 +0000 (13:05 +0100)
libs/ardour/ardour/session.h
libs/ardour/session.cc

index 49ee8cbb7d0fac7565e65bbef87b993ac744b9ba..a295f112976f55d6ead16cf0558dfcc4306246c4 100644 (file)
@@ -1001,6 +1001,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void request_preroll_record (framepos_t);
        framepos_t preroll_record_in () const { return _preroll_record_in; }
        bool preroll_record_enabled () const { return _preroll_record_in >= 0; }
+       framecnt_t preroll_samples (framepos_t) const;
 
        /* temporary hacks to allow selection to be pushed from GUI into backend.
           Whenever we move the selection object into libardour, these will go away.
index 27a3e6311268df21912922f7ccfe191236e324a8..086edf2b4572eede897d10ef68633c746f8d2a30 100644 (file)
@@ -2105,6 +2105,22 @@ Session::audible_frame () const
        return std::max ((framepos_t)0, ret);
 }
 
+
+framecnt_t
+Session::preroll_samples (framepos_t pos) const
+{
+       const float pr = Config->get_preroll_seconds();
+       if (pos >= 0 && pr < 0) {
+               const Tempo& tempo = _tempo_map->tempo_at_frame (pos);
+               const Meter& meter = _tempo_map->meter_at_frame (pos);
+               return meter.frames_per_bar (tempo, frame_rate()) * -pr;
+       }
+       if (pr < 0) {
+               return 0;
+       }
+       return pr * frame_rate();
+}
+
 void
 Session::set_frame_rate (framecnt_t frames_per_second)
 {