Fix auto capture alignment when bouncing metronome
[ardour.git] / libs / ardour / track.cc
index 045f8297a0630a9761f800f2893e24a1636e7830..e80026742a8908fb02f6556f615775120e674e2e 100644 (file)
@@ -1,20 +1,25 @@
 /*
-    Copyright (C) 2006 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2019 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #include "pbd/error.h"
 
 #include "ardour/amp.h"
@@ -103,7 +108,13 @@ Track::init ()
 
        set_align_choice_from_io ();
 
-       use_new_playlist (data_type());
+       if (!name().empty()) {
+               /* an empty name means that we are being constructed via
+                  serialized state (XML). Don't create a playlist, because one
+                  will be created or discovered during ::set_state().
+               */
+               use_new_playlist (data_type());
+       }
 
        boost::shared_ptr<Route> rp (boost::dynamic_pointer_cast<Route> (shared_from_this()));
        boost::shared_ptr<Track> rt = boost::dynamic_pointer_cast<Track> (rp);
@@ -181,11 +192,11 @@ Track::set_state (const XMLNode& node, int version)
                                        set_align_choice (ac, true);
                                }
 
-                               if (boost::shared_ptr<AudioPlaylist> pl = boost::dynamic_pointer_cast<AudioPlaylist> (_session.playlists->by_name (name))) {
+                               if (boost::shared_ptr<AudioPlaylist> pl = boost::dynamic_pointer_cast<AudioPlaylist> (_session.playlists()->by_name (name))) {
                                        use_playlist (DataType::AUDIO, pl);
                                }
 
-                               if (boost::shared_ptr<MidiPlaylist> pl = boost::dynamic_pointer_cast<MidiPlaylist> (_session.playlists->by_name (name))) {
+                               if (boost::shared_ptr<MidiPlaylist> pl = boost::dynamic_pointer_cast<MidiPlaylist> (_session.playlists()->by_name (name))) {
                                        use_playlist (DataType::MIDI, pl);
                                }
                        }
@@ -390,7 +401,7 @@ Track::set_name (const string& str)
 
        boost::shared_ptr<Track> me = boost::dynamic_pointer_cast<Track> (shared_from_this ());
 
-       if (_playlists[data_type()]->all_regions_empty () && _session.playlists->playlists_for_track (me).size() == 1) {
+       if (_playlists[data_type()]->all_regions_empty () && _session.playlists()->playlists_for_track (me).size() == 1) {
                /* Only rename the diskstream (and therefore the playlist) if
                   a) the playlist has never had a region added to it and
                   b) there is only one playlist for this track.
@@ -608,7 +619,7 @@ Track::find_and_use_playlist (DataType dt, PBD::ID const & id)
 {
        boost::shared_ptr<Playlist> playlist;
 
-       if ((playlist = _session.playlists->by_id (id)) == 0) {
+       if ((playlist = _session.playlists()->by_id (id)) == 0) {
                return -1;
        }
 
@@ -620,6 +631,13 @@ Track::find_and_use_playlist (DataType dt, PBD::ID const & id)
        return use_playlist (dt, playlist);
 }
 
+void
+update_region_visibility(boost::shared_ptr<Region> r)
+{
+       Region::RegionPropertyChanged(r, Properties::hidden);
+}
+
+
 int
 Track::use_playlist (DataType dt, boost::shared_ptr<Playlist> p)
 {
@@ -631,9 +649,15 @@ Track::use_playlist (DataType dt, boost::shared_ptr<Playlist> p)
                }
        }
 
+       boost::shared_ptr<Playlist> old = _playlists[dt];
+
        if (ret == 0) {
                _playlists[dt] = p;
        }
+       
+       //allow all regions of prior and new playlists to update their visibility?
+       if (old)  old->foreach_region(update_region_visibility);
+       if (p)    p->foreach_region(update_region_visibility);
 
        _session.set_dirty ();
        PlaylistChanged (); /* EMIT SIGNAL */
@@ -736,8 +760,20 @@ Track::set_align_choice_from_io ()
 
                        connections.clear ();
                }
+
+               /* Special case bounding the Metronome.
+                * Click-out is aligned to output and hence
+                * equivalent to a physical round-trip alike
+                * ExistingMaterial.
+                */
+               if (!have_physical && _session.click_io ()) {
+                       if (_session.click_io ()->connected_to (_input)) {
+                               have_physical = true;
+                       }
+               }
        }
 
+
 #ifdef MIXBUS
        // compensate for latency when bouncing from master or mixbus.
        // we need to use "ExistingMaterial" to pick up the master bus' latency