improved (?) Session::audible_frame()
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 21 Oct 2008 15:03:50 +0000 (15:03 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 21 Oct 2008 15:03:50 +0000 (15:03 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3990 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_mixer.cc
libs/ardour/ardour/session.h
libs/ardour/session.cc
libs/ardour/session_state.cc
libs/ardour/session_transport.cc

index 58a2d55a0c399ef14c75dd08ef9eb2d86b7fe28c..d58a202e1a87ea5a72df30474eff8497f9e2ca7b 100644 (file)
@@ -176,7 +176,6 @@ Editor::set_selected_mixer_strip (TimeAxisView& view)
 }
 
 double current = 0.0;
-bool currentInitialized = 0;
 
 void
 Editor::update_current_screen ()
index 35b8c5489d5e1371094efd37db81d8cf9cec8486..c967310dc77ee6a99e56600b9241496632988b50 100644 (file)
@@ -1755,8 +1755,7 @@ class Session : public PBD::StatefulDestructible
 
        /* used in ::audible_frame() */
 
-       mutable float af_last_transport_speed;
-       mutable nframes64_t af_last_frame;
+       mutable bool have_looped;
 };
 
 } // namespace ARDOUR
index 0a58a7da25834edf7f1dffc4333e3539f1fe86f4..a6a322739e235070d1516440d625b487baba905c 100644 (file)
@@ -1377,6 +1377,10 @@ Session::audible_frame () const
        nframes_t ret;
        nframes_t offset;
        nframes_t tf;
+       
+       if (_transport_speed == 0.0f) {
+               return last_stop_frame;
+       }
 
        /* the first of these two possible settings for "offset"
           mean that the audible frame is stationary until 
@@ -1407,56 +1411,43 @@ Session::audible_frame () const
                tf = _transport_frame;
        }
 
-       if (_transport_speed == 0) {
-               ret = tf;
-               goto block_retrograde;
-       }
-
-       if (tf < offset) {
-               ret = 0;
-               goto block_retrograde;
-       }
-
        ret = tf;
 
        if (!non_realtime_work_pending()) {
 
                /* MOVING */
 
-               /* take latency into account */
-               
-               if (_transport_speed > 0.0) {
-                       /* forwards */
-                       ret -= offset;
-               } else {
-                       /* backwards */
-                       ret += offset;
-               }
+               /* check to see if we have passed the first guaranteed
+                  audible frame past our last stopping position. if not,
+                  the return that last stopping point because in terms
+                  of audible frames, we have not moved yet.
+               */
 
-       }
+               if (_transport_speed > 0.0f) {
 
-       /* do not allow retrograde motion near startup or a direction change
-          caused by latency correction. we detect this by the asking if the present
-          and previously-noted transport speed (and thus direction) are the same.
-       */
+                       if (!play_loop || !have_looped) {
+                               if (tf < last_stop_frame + offset) {
+                                       return last_stop_frame;
+                                       
+                               }
+                       } 
+                       
 
-  block_retrograde:
-       if ((af_last_transport_speed >= 0.0) == (_transport_speed >= 0.0)) {
+                       /* forwards */
+                       ret -= offset;
 
-               if (_transport_speed > 0.0) {
-                       if (ret < af_last_frame) {
-                               ret = af_last_frame;
-                       }
+               } else if (_transport_speed < 0.0f) {
 
-               } else if (_transport_speed < 0.0) {
-                       if (ret > af_last_frame) {
-                               ret = af_last_frame;
+                       /* XXX wot? no backward looping? */
+
+                       if (tf > last_stop_frame - offset) {
+                               return last_stop_frame;
+                       } else {
+                               /* backwards */
+                               ret += offset;
                        }
-               } 
-       } 
-               
-       af_last_frame = ret;
-       af_last_transport_speed = _transport_speed;
+               }
+       }
 
        return ret;
 }
index 469914c97159902d398d9b09723411a0925e78be..3b68f8fb44a274af49843552a18caf801da358b0 100644 (file)
@@ -148,6 +148,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        g_atomic_int_set (&_record_status, Disabled);
        loop_changing = false;
        play_loop = false;
+       have_looped = false;
        _last_roll_location = 0;
        _last_record_location = 0;
        pending_locate_frame = 0;
@@ -228,8 +229,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _smpte_offset = 0;
        _smpte_offset_negative = true;
        last_smpte_valid = false;
-       af_last_transport_speed = 0.0;
-       af_last_frame = 0.0;
 
        sync_time_vars ();
 
index 1baf6cae291c47f8954ce9247599ea7b19c3ff55..83bac047ac8af5b27c98012c18aa5e9a934a7f1f 100644 (file)
@@ -437,6 +437,8 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
                _requested_return_frame = -1;
        }
 
+        have_looped = false; 
+
         send_full_time_code ();
        deliver_mmc (MIDI::MachineControl::cmdStop, 0);
        deliver_mmc (MIDI::MachineControl::cmdLocate, _transport_frame);
@@ -766,7 +768,7 @@ Session::locate (nframes_t target_frame, bool with_roll, bool with_flush, bool w
                                        }
                                }
                        }
-
+                       have_looped = true;
                        TransportLooped(); // EMIT SIGNAL
                }
        }
@@ -926,6 +928,7 @@ void
 Session::start_transport ()
 {
        _last_roll_location = _transport_frame;
+       have_looped = false;
 
        /* if record status is Enabled, move it to Recording. if its
           already Recording, move it to Disabled.