Don't strip suffixes twice from peakfile names, otherwise source names like fred...
[ardour.git] / libs / ardour / session.cc
index f68da4adb20ae5e230dbf842cd8d55aaaa307682..2392d45ca1f59f8cd2778ccb3295073323ca045f 100644 (file)
@@ -17,7 +17,6 @@
 
 */
 
-#define __STDC_LIMIT_MACROS
 #include <stdint.h>
 
 #include <algorithm>
@@ -120,12 +119,13 @@ PBD::Signal2<int,nframes_t,nframes_t> Session::AskAboutSampleRateMismatch;
 PBD::Signal0<void> Session::SendFeedback;
 
 PBD::Signal0<void> Session::TimecodeOffsetChanged;
-PBD::Signal0<void> Session::StartTimeChanged;
-PBD::Signal0<void> Session::EndTimeChanged;
+PBD::Signal1<void, framepos_t> Session::StartTimeChanged;
+PBD::Signal1<void, framepos_t> Session::EndTimeChanged;
 PBD::Signal0<void> Session::AutoBindingOn;
 PBD::Signal0<void> Session::AutoBindingOff;
 PBD::Signal2<void,std::string, std::string> Session::Exported;
 PBD::Signal1<int,boost::shared_ptr<Playlist> > Session::AskAboutPlaylistDeletion;
+PBD::Signal0<void> Session::Quit;
 
 static void clean_up_session_event (SessionEvent* ev) { delete ev; }
 const SessionEvent::RTeventCallback Session::rt_cleanup (clean_up_session_event);
@@ -203,6 +203,9 @@ Session::Session (AudioEngine &eng,
                DirtyChanged (); /* EMIT SIGNAL */
        }
 
+       StartTimeChanged.connect_same_thread (*this, boost::bind (&Session::start_time_changed, this, _1));
+       EndTimeChanged.connect_same_thread (*this, boost::bind (&Session::end_time_changed, this, _1));
+
         _is_new = false;
 }
 
@@ -1096,12 +1099,14 @@ Session::maybe_enable_record ()
 
        g_atomic_int_set (&_record_status, Enabled);
 
-       /* this function is currently called from somewhere other than an RT thread.
-          this save_state() call therefore doesn't impact anything.
+       /* This function is currently called from somewhere other than an RT thread.
+          This save_state() call therefore doesn't impact anything.  Doing it here
+          means that we save pending state of which sources the next record will use,
+          which gives us some chance of recovering from a crash during the record.
        */
-
+       
        save_state ("", true);
-
+       
        if (_transport_speed) {
                if (!config.get_punch_in()) {
                        enable_record ();
@@ -1114,11 +1119,11 @@ Session::maybe_enable_record ()
        set_dirty();
 }
 
-nframes64_t
+framepos_t
 Session::audible_frame () const
 {
-       nframes64_t ret;
-       nframes64_t tf;
+       framepos_t ret;
+       framepos_t tf;
        nframes_t offset;
 
        /* the first of these two possible settings for "offset"
@@ -2491,11 +2496,11 @@ Session::update_session_range_location_marker ()
                return;
        }
 
-       pair<nframes_t, nframes_t> const ext = get_extent ();
+       pair<framepos_t, framepos_t> const ext = get_extent ();
 
        if (_session_range_location == 0) {
                /* we don't have a session range yet; use this one (provided it is valid) */
-               if (ext.first != max_frames) {
+               if (ext.first != max_framepos) {
                        add_session_range_location (ext.first, ext.second);
                }
        } else {
@@ -2514,12 +2519,12 @@ Session::update_session_range_location_marker ()
 }
 
 /** @return Extent of the session's contents; if the session is empty, the first value of
- *  the pair will equal max_frames.
+ *  the pair will equal max_framepos.
  */
-pair<nframes_t, nframes_t>
+pair<framepos_t, framepos_t>
 Session::get_extent () const
 {
-       pair<nframes_t, nframes_t> ext (max_frames, 0);
+       pair<framepos_t, framepos_t> ext (max_framepos, 0);
        
        boost::shared_ptr<RouteList> rl = routes.reader ();
        for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
@@ -2529,7 +2534,7 @@ Session::get_extent () const
                        continue;
                }
 
-               pair<nframes_t, nframes_t> e = tr->playlist()->get_extent ();
+               pair<framepos_t, framepos_t> e = tr->playlist()->get_extent ();
                if (e.first < ext.first) {
                        ext.first = e.first;
                }
@@ -2869,7 +2874,7 @@ string
 Session::peak_path (string base) const
 {
        sys::path peakfile_path(_session_dir->peak_path());
-       peakfile_path /= basename_nosuffix (base) + peakfile_suffix;
+       peakfile_path /= base + peakfile_suffix;
        return peakfile_path.to_string();
 }
 
@@ -3189,7 +3194,7 @@ Session::graph_reordered ()
        }
 }
 
-nframes_t
+framecnt_t
 Session::available_capture_duration ()
 {
        float sample_bytes_on_disk = 4.0; // keep gcc happy
@@ -3217,11 +3222,11 @@ Session::available_capture_duration ()
 
        double scale = 4096.0 / sample_bytes_on_disk;
 
-       if (_total_free_4k_blocks * scale > (double) max_frames) {
-               return max_frames;
+       if (_total_free_4k_blocks * scale > (double) max_framecnt) {
+               return max_framecnt;
        }
-
-       return (nframes_t) floor (_total_free_4k_blocks * scale);
+        
+       return (framecnt_t) floor (_total_free_4k_blocks * scale);
 }
 
 void
@@ -3930,7 +3935,7 @@ Session::get_available_sync_options () const
 }
 
 boost::shared_ptr<RouteList>
-Session::get_routes_with_regions_at (nframes64_t const p) const
+Session::get_routes_with_regions_at (framepos_t const p) const
 {
        shared_ptr<RouteList> r = routes.reader ();
        shared_ptr<RouteList> rl (new RouteList);
@@ -3974,13 +3979,13 @@ Session::goto_start ()
        }
 }
 
-nframes_t
+framepos_t
 Session::current_start_frame () const
 {
        return _session_range_location ? _session_range_location->start() : 0;
 }
 
-nframes_t
+framepos_t
 Session::current_end_frame () const
 {
        return _session_range_location ? _session_range_location->end() : 0;
@@ -4025,3 +4030,33 @@ Session::step_edit_status_change (bool yn)
         }
 }
 
+        
+void
+Session::start_time_changed (framepos_t old)
+{
+       /* Update the auto loop range to match the session range
+          (unless the auto loop range has been changed by the user)
+       */
+       
+       Location* s = _locations->session_range_location ();
+       Location* l = _locations->auto_loop_location ();
+
+       if (l->start() == old) {
+               l->set_start (s->start(), true);
+       }
+}
+
+void
+Session::end_time_changed (framepos_t old)
+{
+       /* Update the auto loop range to match the session range
+          (unless the auto loop range has been changed by the user)
+       */
+
+       Location* s = _locations->session_range_location ();
+       Location* l = _locations->auto_loop_location ();
+
+       if (l->end() == old) {
+               l->set_end (s->end(), true);
+       }
+}