Add API to run automation only (emit Changed signal).
[ardour.git] / libs / ardour / session_transport.cc
index 4556dfa7f318cd31d71c3870a041e8590eb0f24f..8eb25bfbd827eb2b22ebb497496f46db79d08533 100644 (file)
@@ -444,12 +444,6 @@ Session::butler_transport_work ()
        }
 
        if (ptw & PostTransportAdjustPlaybackBuffering) {
-               /* non_realtime_locate() calls Automatable::transport_located()
-                * for every route. This eventually calls
-                * ARDOUR::AutomationList::state () which has a LocaleGuard,
-                * and would switch locales forth/back every time.
-                */
-               LocaleGuard lg;
                for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
                        boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
                        if (tr) {
@@ -498,7 +492,6 @@ Session::butler_transport_work ()
                /* don't seek if locate will take care of that in non_realtime_stop() */
 
                if (!(ptw & PostTransportLocate)) {
-                       LocaleGuard lg; // see note for non_realtime_locate() above
                        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
                                (*i)->non_realtime_locate (_transport_frame);
 
@@ -608,7 +601,6 @@ Session::non_realtime_locate ()
 
 
        {
-               LocaleGuard lg; // see note for non_realtime_locate() above
                boost::shared_ptr<RouteList> rl = routes.reader();
                for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
                        (*i)->non_realtime_locate (_transport_frame);
@@ -875,7 +867,6 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
        /* this for() block can be put inside the previous if() and has the effect of ... ??? what */
 
        {
-               LocaleGuard lg; // see note for non_realtime_locate() above
                DEBUG_TRACE (DEBUG::Transport, X_("Butler PTW: locate\n"));
                for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
                        DEBUG_TRACE (DEBUG::Transport, string_compose ("Butler PTW: locate on %1\n", (*i)->name()));
@@ -1367,7 +1358,9 @@ Session::locate (framepos_t target_frame, bool with_roll, bool with_flush, bool
        }
 
        _last_roll_location = _last_roll_or_reversal_location =  _transport_frame;
-       Located (); /* EMIT SIGNAL */
+       if (!synced_to_engine () || _transport_frame == _engine.transport_frame ()) {
+               Located (); /* EMIT SIGNAL */
+       }
 }
 
 /** Set the transport speed.
@@ -1702,19 +1695,20 @@ Session::start_transport ()
                        const Tempo& tempo = _tempo_map->tempo_at_frame (_transport_frame);
                        const Meter& meter = _tempo_map->meter_at_frame (_transport_frame);
 
-                       double div = meter.divisions_per_bar ();
-                       double pulses = _tempo_map->exact_qn_at_frame (_transport_frame, 0) * div / 4.0;
-                       double beats_left = fmod (pulses, div);
+                       const double num = meter.divisions_per_bar ();
+                       const double den = meter.note_divisor ();
+                       const double barbeat = _tempo_map->exact_qn_at_frame (_transport_frame, 0) * den / (4. * num);
+                       const double bar_fract = fmod (barbeat, 1.0); // fraction of bar elapsed.
 
                        _count_in_samples = meter.frames_per_bar (tempo, _current_frame_rate);
 
-                       double dt = _count_in_samples / div;
-                       if (beats_left == 0) {
+                       double dt = _count_in_samples / num;
+                       if (bar_fract == 0) {
                                /* at bar boundary, count-in 2 bars before start. */
                                _count_in_samples *= 2;
                        } else {
                                /* beats left after full bar until roll position */
-                               _count_in_samples += meter.frames_per_grid (tempo, _current_frame_rate) * beats_left;
+                               _count_in_samples *= 1. + bar_fract;
                        }
 
                        int clickbeat = 0;
@@ -1722,7 +1716,7 @@ Session::start_transport ()
                        while (cf < _transport_frame) {
                                add_click (cf - _worst_track_latency, clickbeat == 0);
                                cf += dt;
-                               clickbeat = fmod (clickbeat + 1, div);
+                               clickbeat = fmod (clickbeat + 1, num);
                        }
                }
        }