...towards unique track numbers.
[ardour.git] / libs / ardour / session.cc
index 3a2f035e738d1ce737a6fef103bd90dbe1a34e63..e7dde4d2256b318044ec7d29a92213618c5bfd9a 100644 (file)
@@ -119,6 +119,7 @@ PBD::Signal1<int,boost::shared_ptr<Playlist> > Session::AskAboutPlaylistDeletion
 PBD::Signal0<void> Session::Quit;
 PBD::Signal0<void> Session::FeedbackDetected;
 PBD::Signal0<void> Session::SuccessfulGraphSort;
+PBD::Signal2<void,std::string,std::string> Session::VersionMismatch;
 
 static void clean_up_session_event (SessionEvent* ev) { delete ev; }
 const SessionEvent::RTeventCallback Session::rt_cleanup (clean_up_session_event);
@@ -132,12 +133,15 @@ Session::Session (AudioEngine &eng,
        : _engine (eng)
        , _target_transport_speed (0.0)
        , _requested_return_frame (-1)
+       , _under_nsm_control (false)
+       , _unique_track_number (0)
        , _session_dir (new SessionDirectory(fullpath))
        , state_tree (0)
        , _state_of_the_state (Clean)
        , _butler (new Butler (*this))
        , _post_transport_work (0)
        , _send_timecode_update (false)
+       , ltc_enc_buf(0)
        , _all_route_group (new RouteGroup (*this, "all"))
        , routes (new RouteList)
        , _total_free_4k_blocks (0)
@@ -1596,7 +1600,7 @@ Session::find_route_name (string const & base, uint32_t& id, char* name, size_t
                }
 
                ++id;
-
+               
        } while (id < (UINT_MAX-1));
 
        return false;
@@ -1613,7 +1617,7 @@ Session::count_existing_track_channels (ChanCount& in, ChanCount& out)
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
                 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
-               if (tr && !tr->is_hidden()) {
+               if (tr && !tr->is_auditioner()) {
                        in  += tr->n_inputs();
                        out += tr->n_outputs();
                }
@@ -1646,6 +1650,7 @@ Session::new_midi_track (const ChanCount& input, const ChanCount& output, boost:
 
                try {
                        track.reset (new MidiTrack (*this, track_name, Route::Flag (0), mode));
+                       track->set_unique_id(++_unique_track_number);
 
                        if (track->init ()) {
                                goto failed;
@@ -1881,6 +1886,7 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod
 
                try {
                        track.reset (new AudioTrack (*this, track_name, Route::Flag (0), mode));
+                       track->set_unique_id(++_unique_track_number);
 
                        if (track->init ()) {
                                goto failed;
@@ -2035,12 +2041,13 @@ Session::new_audio_route (int input_channels, int output_channels, RouteGroup* r
 }
 
 RouteList
-Session::new_route_from_template (uint32_t how_many, const std::string& template_path)
+Session::new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name_base)
 {
        RouteList ret;
        uint32_t control_id;
        XMLTree tree;
        uint32_t number = 0;
+       const uint32_t being_added = how_many;
 
        if (!tree.read (template_path.c_str())) {
                return ret;
@@ -2060,13 +2067,29 @@ Session::new_route_from_template (uint32_t how_many, const std::string& template
                node_copy.remove_property_recursively (X_("id"));
 
                try {
-                       string const route_name = node_copy.property(X_("name"))->value ();
-                       
-                       /* generate a new name by adding a number to the end of the template name */
                        char name[32];
-                       if (!find_route_name (route_name.c_str(), ++number, name, sizeof(name), true)) {
-                               fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
-                               /*NOTREACHED*/
+
+                       if (!name_base.empty()) {
+
+                               /* if we're adding more than one routes, force
+                                * all the names of the new routes to be
+                                * numbered, via the final parameter.
+                                */
+
+                               if (!find_route_name (name_base.c_str(), ++number, name, sizeof(name), (being_added > 1))) {
+                                       fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
+                                       /*NOTREACHDE*/
+                               }
+
+                       } else {
+
+                               string const route_name  = node_copy.property(X_("name"))->value ();
+                       
+                               /* generate a new name by adding a number to the end of the template name */
+                               if (!find_route_name (route_name.c_str(), ++number, name, sizeof(name), true)) {
+                                       fatal << _("Session: UINT_MAX routes? impossible!") << endmsg;
+                                       /*NOTREACHED*/
+                               }
                        }
 
                        /* set this name in the XML description that we are about to use */
@@ -2227,7 +2250,7 @@ Session::add_routes_inner (RouteList& new_routes, bool input_auto_connect, bool
                */
 
                if (!r->has_order_key (EditorSort)) {
-                       if (r->is_hidden()) {
+                       if (r->is_auditioner()) {
                                /* use an arbitrarily high value */
                                r->set_order_key (EditorSort, UINT_MAX);
                                r->set_order_key (MixerSort, UINT_MAX);
@@ -2452,7 +2475,7 @@ Session::route_listen_changed (void* /*src*/, boost::weak_ptr<Route> wpr)
                        /* new listen: disable all other listen */
                        boost::shared_ptr<RouteList> r = routes.reader ();
                        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-                               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
+                               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
                                        continue;
                                }
                                (*i)->set_listen (false, this);
@@ -2534,7 +2557,7 @@ Session::route_solo_changed (bool self_solo_change, void* /*src*/, boost::weak_p
                /* new solo: disable all other solos, but not the group if its solo-enabled */
 
                for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-                       if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden() ||
+                       if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner() ||
                            (leave_group_alone && ((*i)->route_group() == rg))) {
                                continue;
                        }
@@ -2554,7 +2577,7 @@ Session::route_solo_changed (bool self_solo_change, void* /*src*/, boost::weak_p
                bool via_sends_only;
                bool in_signal_flow;
 
-               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden() ||
+               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner() ||
                    (leave_group_alone && ((*i)->route_group() == rg))) {
                        continue;
                }
@@ -2643,11 +2666,11 @@ Session::update_route_solo_state (boost::shared_ptr<RouteList> r)
        }
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_hidden() && (*i)->self_soloed()) {
+               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_auditioner() && (*i)->self_soloed()) {
                        something_soloed = true;
                }
 
-               if (!(*i)->is_hidden() && (*i)->listening_via_monitor()) {
+               if (!(*i)->is_auditioner() && (*i)->listening_via_monitor()) {
                        if (Config->get_solo_control_is_listen_control()) {
                                listeners++;
                        } else {
@@ -3380,7 +3403,7 @@ Session::create_audio_source_for_session (size_t n_chans, string const & n, uint
        const string path    = new_source_path_from_name(DataType::AUDIO, name);
 
        return boost::dynamic_pointer_cast<AudioFileSource> (
-               SourceFactory::createWritable (DataType::AUDIO, *this, path, string(), destructive, frame_rate()));
+               SourceFactory::createWritable (DataType::AUDIO, *this, path, destructive, frame_rate()));
 }
 
 /** Return a unique name based on \a base for a new internal MIDI source */
@@ -3456,7 +3479,7 @@ Session::create_midi_source_for_session (Track* track, string const & n)
 
        return boost::dynamic_pointer_cast<SMFSource> (
                SourceFactory::createWritable (
-                       DataType::MIDI, *this, path, string(), false, frame_rate()));
+                       DataType::MIDI, *this, path, false, frame_rate()));
 }
 
 
@@ -4008,7 +4031,7 @@ Session::write_one_track (AudioTrack& track, framepos_t start, framepos_t end,
 
                try {
                        fsource = boost::dynamic_pointer_cast<AudioFileSource> (
-                               SourceFactory::createWritable (DataType::AUDIO, *this, buf, string(), false, frame_rate()));
+                               SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate()));
                }
 
                catch (failed_constructor& err) {
@@ -4201,7 +4224,7 @@ Session::add_automation_list(AutomationList *al)
 bool
 Session::have_rec_enabled_track () const
 {
-       return g_atomic_int_get (&_have_rec_enabled_track) == 1;
+       return g_atomic_int_get (const_cast<gint*>(&_have_rec_enabled_track)) == 1;
 }
 
 /** Update the state of our rec-enabled tracks flag */
@@ -4602,7 +4625,7 @@ Session::post_playback_latency ()
        boost::shared_ptr<RouteList> r = routes.reader ();
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-               if (!(*i)->is_hidden() && ((*i)->active())) {
+               if (!(*i)->is_auditioner() && ((*i)->active())) {
                        _worst_track_latency = max (_worst_track_latency, (*i)->update_signal_latency ());
                }
        }
@@ -4708,7 +4731,7 @@ Session::update_latency_compensation (bool force_whole_graph)
        boost::shared_ptr<RouteList> r = routes.reader ();
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-               if (!(*i)->is_hidden() && ((*i)->active())) {
+               if (!(*i)->is_auditioner() && ((*i)->active())) {
                        framecnt_t tl;
                        if ((*i)->signal_latency () != (tl = (*i)->update_signal_latency ())) {
                                some_track_latency_changed = true;