fix visual focus indication in IOSelector; import pays attention to audio file embedd...
[ardour.git] / libs / ardour / session.cc
index 99fad0d0130759d63b85f567510b5a4d2e0aec1f..a4def58bb43c973a01a9d2d60a8f083ac20ceb61 100644 (file)
@@ -278,7 +278,7 @@ Session::Session (AudioEngine &eng,
        
        new_session = !g_file_test (_path.c_str(), GFileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
        if (new_session) {
-               if (create (new_session, mix_template, _engine.frame_rate() * 60 * 5)) {
+               if (create (new_session, mix_template, compute_initial_length())) {
                        cerr << "create failed\n";
                        throw failed_constructor ();
                }
@@ -328,8 +328,16 @@ Session::Session (AudioEngine &eng,
 
        cerr << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (2)" << endl;
 
-       n_physical_outputs = max (requested_physical_out, _engine.n_physical_outputs());
-       n_physical_inputs = max (requested_physical_in, _engine.n_physical_inputs());
+       n_physical_outputs = _engine.n_physical_outputs();
+       n_physical_inputs = _engine.n_physical_inputs();
+
+       if (n_physical_inputs) {
+               n_physical_inputs = max (requested_physical_in, n_physical_inputs);
+       }
+
+       if (n_physical_outputs) {
+               n_physical_outputs = max (requested_physical_out, n_physical_outputs);
+       }
 
        first_stage_init (fullpath, snapshot_name);
 
@@ -1325,7 +1333,7 @@ Session::set_frame_rate (nframes_t frames_per_second)
        Route::set_automation_interval ((jack_nframes_t) ceil ((double) frames_per_second * 0.25));
 
        // XXX we need some equivalent to this, somehow
-       // DestructiveFileSource::setup_standard_crossfades (frames_per_second);
+       // SndFileSource::setup_standard_crossfades (frames_per_second);
 
        set_dirty();
 
@@ -1771,12 +1779,12 @@ Session::new_audio_route (int input_channels, int output_channels, uint32_t how_
                                      << endmsg;
                        }
                        
-                       for (uint32_t x = 0; x < bus->n_inputs(); ++x) {
+                       for (uint32_t x = 0; n_physical_inputs && x < bus->n_inputs(); ++x) {
                                
                                port = "";
-                               
+
                                if (Config->get_input_auto_connect() & AutoConnectPhysical) {
-                                       port = physinputs[((n+x)%n_physical_inputs)];
+                                               port = physinputs[((n+x)%n_physical_inputs)];
                                } 
                                
                                if (port.length() && bus->connect_input (bus->input (x), port, this)) {
@@ -1784,7 +1792,7 @@ Session::new_audio_route (int input_channels, int output_channels, uint32_t how_
                                }
                        }
                        
-                       for (uint32_t x = 0; x < bus->n_outputs(); ++x) {
+                       for (uint32_t x = 0; n_physical_outputs && x < bus->n_outputs(); ++x) {
                                
                                port = "";
                                
@@ -1897,8 +1905,9 @@ Session::remove_route (shared_ptr<Route> route)
        {       
                RCUWriter<RouteList> writer (routes);
                shared_ptr<RouteList> rs = writer.get_copy ();
-               rs->remove (route);
                
+               rs->remove (route);
+
                /* deleting the master out seems like a dumb
                   idea, but its more of a UI policy issue
                   than our concern.
@@ -2526,7 +2535,7 @@ Session::remove_region (boost::weak_ptr<Region> weak_region)
        set_dirty();
 
        if (removed) {
-                AudioRegionRemoved(ar); /* EMIT SIGNAL */
+               AudioRegionRemoved (ar); /* EMIT SIGNAL */
        }
 }
 
@@ -2562,32 +2571,38 @@ Session::find_equivalent_playlist_regions (boost::shared_ptr<Region> region, vec
 int
 Session::destroy_region (boost::shared_ptr<Region> region)
 {
-       boost::shared_ptr<AudioRegion> aregion;
-
-       if ((aregion = boost::dynamic_pointer_cast<AudioRegion> (region)) == 0) {
-               return 0;
-       }
-       
-       if (aregion->playlist()) {
-               aregion->playlist()->destroy_region (region);
-       }
-
        vector<boost::shared_ptr<Source> > srcs;
-       
-       for (uint32_t n = 0; n < aregion->n_channels(); ++n) {
-               srcs.push_back (aregion->source (n));
+               
+       {
+               boost::shared_ptr<AudioRegion> aregion;
+               
+               if ((aregion = boost::dynamic_pointer_cast<AudioRegion> (region)) == 0) {
+                       return 0;
+               }
+               
+               if (aregion->playlist()) {
+                       aregion->playlist()->destroy_region (region);
+               }
+               
+               for (uint32_t n = 0; n < aregion->n_channels(); ++n) {
+                       srcs.push_back (aregion->source (n));
+               }
        }
 
+       region->drop_references ();
+
        for (vector<boost::shared_ptr<Source> >::iterator i = srcs.begin(); i != srcs.end(); ++i) {
-               
-               if ((*i).use_count() == 1) {
-                       boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*i);
 
+               if (!(*i)->used()) {
+                       boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*i);
+                       
                        if (afs) {
                                (afs)->mark_for_remove ();
                        }
                        
                        (*i)->drop_references ();
+                       
+                       cerr << "source was not used by any playlist\n";
                }
        }
 
@@ -2979,6 +2994,20 @@ Session::add_playlist (Playlist* playlist)
        PlaylistAdded (playlist); /* EMIT SIGNAL */
 }
 
+void
+Session::get_playlists (vector<Playlist*>& s)
+{
+       { 
+               Glib::Mutex::Lock lm (playlist_lock);
+               for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+                       s.push_back (*i);
+               }
+               for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+                       s.push_back (*i);
+               }
+       }
+}
+
 void
 Session::track_playlist (Playlist* pl, bool inuse)
 {
@@ -3768,3 +3797,10 @@ Session::add_automation_list(AutomationList *al)
 {
        automation_lists[al->id()] = al;
 }
+
+nframes_t
+Session::compute_initial_length ()
+{
+       return _engine.frame_rate() * 60 * 5;
+}
+