revisit setting up processors during route construction; remove several more XML...
[ardour.git] / libs / ardour / session.cc
index b2f6f7412fcc96c2ca6e45431e0b573069e51326..2c5c12f6a2ace9f48903d0ba40782ae3e3cf4257 100644 (file)
@@ -125,6 +125,7 @@ const SessionEvent::RTeventCallback Session::rt_cleanup (clean_up_session_event)
 Session::Session (AudioEngine &eng,
                  const string& fullpath,
                  const string& snapshot_name,
+                  BusProfile* bus_profile,
                  string mix_template)
 
        : _engine (eng),
@@ -158,31 +159,27 @@ Session::Session (AudioEngine &eng,
 {
        playlists.reset (new SessionPlaylists);
        
-       bool new_session;
-
        interpolation.add_channel_to (0, 0);
 
        if (!eng.connected()) {
                throw failed_constructor();
        }
 
-       info << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (1)" << endl;
-
        n_physical_outputs = _engine.n_physical_outputs(DataType::AUDIO);
        n_physical_inputs =  _engine.n_physical_inputs(DataType::AUDIO);
 
        first_stage_init (fullpath, snapshot_name);
 
-       new_session = !Glib::file_test (_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
+        _is_new = !Glib::file_test (_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
 
-       if (new_session) {
-               if (create (new_session, mix_template, compute_initial_length())) {
+       if (_is_new) {
+               if (create (mix_template, compute_initial_length(), bus_profile)) {
                        destroy ();
                        throw failed_constructor ();
                }
-       }
+        }
 
-       if (second_stage_init (new_session)) {
+       if (second_stage_init ()) {
                destroy ();
                throw failed_constructor ();
        }
@@ -199,137 +196,8 @@ Session::Session (AudioEngine &eng,
        if (was_dirty) {
                DirtyChanged (); /* EMIT SIGNAL */
        }
-}
-
-Session::Session (AudioEngine &eng,
-                 string fullpath,
-                 string snapshot_name,
-                 AutoConnectOption input_ac,
-                 AutoConnectOption output_ac,
-                 uint32_t master_out_channels,
-                 uint32_t requested_physical_in,
-                 uint32_t requested_physical_out,
-                 nframes_t initial_length)
-
-       : _engine (eng),
-         _target_transport_speed (0.0),
-         _requested_return_frame (-1),
-         _scratch_buffers(new BufferSet()),
-         _silent_buffers(new BufferSet()),
-         _mix_buffers(new BufferSet()),
-         mmc (0),
-         _mmc_port (default_mmc_port),
-         _mtc_port (default_mtc_port),
-         _midi_port (default_midi_port),
-         _midi_clock_port (default_midi_clock_port),
-         _session_dir ( new SessionDirectory(fullpath)),
-         state_tree (0),
-         _butler (new Butler (*this)),
-         _post_transport_work (0),
-         _send_timecode_update (false),
-         diskstreams (new DiskstreamList),
-         routes (new RouteList),
-         _total_free_4k_blocks (0),
-         _bundles (new BundleList),
-         _bundle_xml_node (0),
-         _click_io ((IO *) 0),
-         click_data (0),
-         click_emphasis_data (0),
-         main_outs (0),
-         _metadata (new SessionMetadata()),
-         _have_rec_enabled_diskstream (false)
-{
-       playlists.reset (new SessionPlaylists);
-
-       bool new_session;
-
-       interpolation.add_channel_to (0, 0);
-
-       if (!eng.connected()) {
-               throw failed_constructor();
-       }
-
-       info << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (2)" << endl;
-
-       n_physical_outputs = _engine.n_physical_outputs (DataType::AUDIO);
-       n_physical_inputs = _engine.n_physical_inputs (DataType::AUDIO);
-
-       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);
-
-       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, string(), initial_length)) {
-                       destroy ();
-                       throw failed_constructor ();
-               }
-       }
-
-       {
-               /* set up Master Out and Control Out if necessary */
 
-               RouteList rl;
-               int control_id = 1;
-
-               if (master_out_channels) {
-                       ChanCount count(DataType::AUDIO, master_out_channels);
-                       Route* rt = new Route (*this, _("master"), Route::MasterOut, DataType::AUDIO);
-                       boost_debug_shared_ptr_mark_interesting (rt, "Route");
-                       boost::shared_ptr<Route> r (rt);
-                       r->input()->ensure_io (count, false, this);
-                       r->output()->ensure_io (count, false, this);
-                       r->set_remote_control_id (control_id);
-
-                       rl.push_back (r);
-               } else {
-                       /* prohibit auto-connect to master, because there isn't one */
-                       output_ac = AutoConnectOption (output_ac & ~AutoConnectMaster);
-               }
-
-               if (Config->get_use_monitor_bus()) {
-                       ChanCount count(DataType::AUDIO, master_out_channels);
-                       Route* rt = new Route (*this, _("monitor"), Route::ControlOut, DataType::AUDIO);
-                       boost_debug_shared_ptr_mark_interesting (rt, "Route");
-                       shared_ptr<Route> r (rt);
-                       r->input()->ensure_io (count, false, this);
-                       r->output()->ensure_io (count, false, this);
-                       r->set_remote_control_id (control_id++);
-
-                       rl.push_back (r);
-               }
-
-               if (!rl.empty()) {
-                       add_routes (rl, false);
-               }
-
-       }
-
-       if (no_auto_connect()) {
-               input_ac = AutoConnectOption (0);
-               output_ac = AutoConnectOption (0);
-       }
-
-       Config->set_input_auto_connect (input_ac);
-       Config->set_output_auto_connect (output_ac);
-
-       if (second_stage_init (new_session)) {
-               destroy ();
-               throw failed_constructor ();
-       }
-
-       store_recent_sessions (_name, _path);
-
-       _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty);
-
-       Config->ParameterChanged.connect_same_thread (*this, boost::bind (&Session::config_changed, this, _1, false));
+        _is_new = false;
 }
 
 Session::~Session ()
@@ -406,7 +274,7 @@ Session::destroy ()
 
        auditioner.reset ();
        _master_out.reset ();
-       _control_out.reset ();
+       _monitor_out.reset ();
 
        {
                RCUWriter<RouteList> writer (routes);
@@ -482,7 +350,7 @@ Session::set_worst_io_latencies ()
 }
 
 void
-Session::when_engine_running (bool new_session)
+Session::when_engine_running ()
 {
        string first_physical_output;
 
@@ -643,13 +511,13 @@ Session::when_engine_running (bool new_session)
 
        BootMessage (_("Setup signal flow and plugins"));
 
-       hookup_io (new_session);
+       hookup_io ();
 
-       if (new_session && !no_auto_connect()) {
+       if (_is_new && !no_auto_connect()) {
 
                 /* don't connect the master bus outputs if there is a monitor bus */
 
-               if (_master_out && Config->get_auto_connect_standard_busses() && !_control_out) {
+               if (_master_out && Config->get_auto_connect_standard_busses() && !_monitor_out) {
 
                        /* if requested auto-connect the outputs to the first N physical ports.
                         */
@@ -670,7 +538,7 @@ Session::when_engine_running (bool new_session)
                        }
                }
 
-               if (_control_out) {
+               if (_monitor_out) {
 
                        /* AUDIO ONLY as of june 29th 2009, because listen semantics for anything else
                           are undefined, at best.
@@ -680,16 +548,16 @@ Session::when_engine_running (bool new_session)
                           under some conditions)
                        */
 
-                       uint32_t limit = _control_out->n_inputs().n_audio();
+                       uint32_t limit = _monitor_out->n_inputs().n_audio();
 
                        if (_master_out) {
                                for (uint32_t n = 0; n < limit; ++n) {
-                                       AudioPort* p = _control_out->input()->ports().nth_audio_port (n);
+                                       AudioPort* p = _monitor_out->input()->ports().nth_audio_port (n);
                                        AudioPort* o = _master_out->output()->ports().nth_audio_port (n);
 
                                        if (o) {
                                                string connect_to = o->name();
-                                               if (_control_out->input()->connect (p, connect_to, this)) {
+                                               if (_monitor_out->input()->connect (p, connect_to, this)) {
                                                        error << string_compose (_("cannot connect control input %1 to %2"), n, connect_to)
                                                              << endmsg;
                                                        break;
@@ -701,14 +569,14 @@ Session::when_engine_running (bool new_session)
                        /* if control out is not connected, connect control out to physical outs
                        */
 
-                       if (!_control_out->output()->connected ()) {
+                       if (!_monitor_out->output()->connected ()) {
 
                                if (!Config->get_monitor_bus_preferred_bundle().empty()) {
 
                                        boost::shared_ptr<Bundle> b = bundle_by_name (Config->get_monitor_bus_preferred_bundle());
 
                                        if (b) {
-                                               _control_out->output()->connect_ports_to_bundle (b, this);
+                                               _monitor_out->output()->connect_ports_to_bundle (b, this);
                                        } else {
                                                warning << string_compose (_("The preferred I/O for the monitor bus (%1) cannot be found"),
                                                                           Config->get_monitor_bus_preferred_bundle())
@@ -719,15 +587,15 @@ Session::when_engine_running (bool new_session)
                                         
                                        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                                                uint32_t mod = _engine.n_physical_outputs (*t);
-                                               uint32_t limit = _control_out->n_outputs().get(*t);
+                                               uint32_t limit = _monitor_out->n_outputs().get(*t);
 
                                                for (uint32_t n = 0; n < limit; ++n) {
 
-                                                       Port* p = _control_out->output()->ports().port(*t, n);
+                                                       Port* p = _monitor_out->output()->ports().port(*t, n);
                                                        string connect_to = _engine.get_nth_physical_output (*t, (n % mod));
 
                                                        if (!connect_to.empty()) {
-                                                               if (_control_out->output()->connect (p, connect_to, this)) {
+                                                               if (_monitor_out->output()->connect (p, connect_to, this)) {
                                                                        error << string_compose (
                                                                                        _("cannot connect control output %1 to %2"),
                                                                                        n, connect_to)
@@ -754,7 +622,7 @@ Session::when_engine_running (bool new_session)
 }
 
 void
-Session::hookup_io (bool new_session)
+Session::hookup_io ()
 {
        /* stop graph reordering notifications from
           causing resorts, etc.
@@ -770,7 +638,13 @@ Session::hookup_io (bool new_session)
                */
 
                try {
-                       auditioner.reset (new Auditioner (*this));
+                        Auditioner* a = new Auditioner (*this);
+                        if (a->init()) {
+                                delete a;
+                                throw failed_constructor();
+                        }
+                        a->use_new_diskstream ();
+                       auditioner.reset (a);
                }
 
                catch (failed_constructor& err) {
@@ -799,11 +673,11 @@ Session::hookup_io (bool new_session)
            they connect to the control out specifically.
          */
 
-        if (_control_out) {
+        if (_monitor_out) {
                boost::shared_ptr<RouteList> r = routes.reader ();
                 for (RouteList::iterator x = r->begin(); x != r->end(); ++x) {
                         
-                        if ((*x)->is_control()) {
+                        if ((*x)->is_monitor()) {
                                 
                                 /* relax */
                                 
@@ -813,7 +687,7 @@ Session::hookup_io (bool new_session)
                                 
                         } else {
                                 
-                                (*x)->listen_via (_control_out,
+                                (*x)->listen_via (_monitor_out,
                                                   (Config->get_listen_position() == AfterFaderListen ? PostFader : PreFader),
                                                   false, false);
                         }
@@ -1586,6 +1460,14 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m
 
                try {
                        MidiTrack* mt = new MidiTrack (*this, track_name, Route::Flag (0), mode);
+
+                        if (mt->init ()) {
+                                delete mt;
+                                goto failed;
+                        }
+
+                        mt->use_new_diskstream();
+
                        boost_debug_shared_ptr_mark_interesting (mt, "Track");
                        track = boost::shared_ptr<MidiTrack>(mt);
 
@@ -1762,6 +1644,14 @@ Session::new_audio_track (int input_channels, int output_channels, TrackMode mod
 
                try {
                        AudioTrack* at = new AudioTrack (*this, track_name, Route::Flag (0), mode);
+
+                        if (at->init ()) {
+                                delete at;
+                                goto failed;
+                        }
+
+                        at->use_new_diskstream();
+
                        boost_debug_shared_ptr_mark_interesting (at, "Track");
                        track = boost::shared_ptr<AudioTrack>(at);
 
@@ -1894,6 +1784,12 @@ Session::new_audio_route (bool aux, int input_channels, int output_channels, Rou
 
                try {
                        Route* rt = new Route (*this, bus_name, Route::Flag(0), DataType::AUDIO);
+
+                        if (rt->init ()) {
+                                delete rt;
+                                goto failure;
+                        }
+
                        boost_debug_shared_ptr_mark_interesting (rt, "Route");
                        shared_ptr<Route> bus (rt);
 
@@ -2043,7 +1939,7 @@ Session::add_routes (RouteList& new_routes, bool save)
                   we will resort when done.
                */
 
-               if (!_control_out && IO::connecting_legal) {
+               if (!_monitor_out && IO::connecting_legal) {
                        resort_routes_using (r);
                }
        }
@@ -2064,20 +1960,20 @@ Session::add_routes (RouteList& new_routes, bool save)
                        _master_out = r;
                }
 
-               if (r->is_control()) {
-                       _control_out = r;
+               if (r->is_monitor()) {
+                       _monitor_out = r;
                }
        }
 
-       if (_control_out && IO::connecting_legal) {
+       if (_monitor_out && IO::connecting_legal) {
 
                for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) {
-                       if ((*x)->is_control()) {
+                       if ((*x)->is_monitor()) {
                                 /* relax */
                         } else if ((*x)->is_master()) {
                                 /* relax */
                        } else {
-                                (*x)->listen_via (_control_out,
+                                (*x)->listen_via (_monitor_out,
                                                   (Config->get_listen_position() == AfterFaderListen ? PostFader : PreFader),
                                                   false, false);
                         }
@@ -2167,7 +2063,7 @@ Session::globally_add_internal_sends (boost::shared_ptr<Route> dest, Placement p
 void
 Session::add_internal_sends (boost::shared_ptr<Route> dest, Placement p, boost::shared_ptr<RouteList> senders)
 {
-       if (dest->is_control() || dest->is_master()) {
+       if (dest->is_monitor() || dest->is_master()) {
                return;
        }
 
@@ -2177,7 +2073,7 @@ Session::add_internal_sends (boost::shared_ptr<Route> dest, Placement p, boost::
 
        for (RouteList::iterator i = senders->begin(); i != senders->end(); ++i) {
 
-               if ((*i)->is_control() || (*i)->is_master() || (*i) == dest) {
+               if ((*i)->is_monitor() || (*i)->is_master() || (*i) == dest) {
                        continue;
                }
 
@@ -2207,9 +2103,6 @@ Session::add_diskstream (boost::shared_ptr<Diskstream> dstream)
        diskstream_playlist_changed (boost::weak_ptr<Diskstream> (dstream));
 
        dstream->RecordEnableChanged.connect_same_thread (*this, boost::bind (&Session::update_have_rec_enabled_diskstream, this));
-
-       dstream->prepare ();
-
 }
 
 void
@@ -2230,15 +2123,15 @@ Session::remove_route (shared_ptr<Route> route)
                        _master_out = shared_ptr<Route> ();
                }
 
-               if (route == _control_out) {
+               if (route == _monitor_out) {
 
                        /* cancel control outs for all routes */
 
                        for (RouteList::iterator r = rs->begin(); r != rs->end(); ++r) {
-                               (*r)->drop_listen (_control_out);
+                               (*r)->drop_listen (_monitor_out);
                        }
 
-                       _control_out.reset ();
+                       _monitor_out.reset ();
                }
 
                update_route_solo_state ();
@@ -2361,7 +2254,7 @@ Session::route_solo_changed (void* /*src*/, boost::weak_ptr<Route> wpr)
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
                bool via_sends_only;
 
-               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_control() || (*i)->is_hidden()) {
+               if ((*i) == route || (*i)->solo_isolated() || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
                        continue;
                } else if ((*i)->feeds (route, &via_sends_only)) {
                        if (!via_sends_only) {
@@ -2378,8 +2271,8 @@ Session::route_solo_changed (void* /*src*/, boost::weak_ptr<Route> wpr)
  
        /* ditto for control outs make sure master is never muted by solo */
 
-       if (_control_out && route != _control_out && _control_out && _control_out->soloed_by_others() == 0) {
-               _control_out->mod_solo_by_others (1);
+       if (_monitor_out && route != _monitor_out && _monitor_out && _monitor_out->soloed_by_others() == 0) {
+               _monitor_out->mod_solo_by_others (1);
        }
 
        solo_update_disabled = false;
@@ -2401,7 +2294,7 @@ 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_control() && !(*i)->is_hidden() && (*i)->self_soloed()) {
+               if (!(*i)->is_master() && !(*i)->is_monitor() && !(*i)->is_hidden() && (*i)->self_soloed()) {
                        something_soloed = true;
                        break;
                }
@@ -2543,194 +2436,6 @@ Session::diskstream_by_id (const PBD::ID& id)
 
 /* Region management */
 
-string
-Session::new_region_name (string old)
-{
-       string::size_type last_period;
-       uint32_t number;
-       string::size_type len = old.length() + 64;
-       char buf[len];
-
-       if ((last_period = old.find_last_of ('.')) == string::npos) {
-
-               /* no period present - add one explicitly */
-
-               old += '.';
-               last_period = old.length() - 1;
-               number = 0;
-
-       } else {
-
-               number = atoi (old.substr (last_period+1).c_str());
-
-       }
-
-       while (number < (UINT_MAX-1)) {
-
-                const RegionFactory::RegionMap& regions (RegionFactory::regions());
-               RegionFactory::RegionMap::const_iterator i;
-               string sbuf;
-
-               number++;
-
-               snprintf (buf, len, "%s%" PRIu32, old.substr (0, last_period + 1).c_str(), number);
-               sbuf = buf;
-
-               for (i = regions.begin(); i != regions.end(); ++i) {
-                       if (i->second->name() == sbuf) {
-                               break;
-                       }
-               }
-
-               if (i == regions.end()) {
-                       break;
-               }
-       }
-
-       if (number != (UINT_MAX-1)) {
-               return buf;
-       }
-
-       error << string_compose (_("cannot create new name for region \"%1\""), old) << endmsg;
-       return old;
-}
-
-int
-Session::region_name (string& result, string base, bool newlevel)
-{
-       char buf[16];
-       string subbase;
-
-       if (base.find("/") != string::npos) {
-               base = base.substr(base.find_last_of("/") + 1);
-       }
-
-       if (base == "") {
-
-               snprintf (buf, sizeof (buf), "%d", RegionFactory::nregions() + 1);
-               result = "region.";
-               result += buf;
-
-       } else {
-
-               if (newlevel) {
-                       subbase = base;
-               } else {
-                       string::size_type pos;
-
-                       pos = base.find_last_of ('.');
-
-                       /* pos may be npos, but then we just use entire base */
-
-                       subbase = base.substr (0, pos);
-
-               }
-
-               {
-                       Glib::Mutex::Lock lm (region_lock);
-
-                       map<string,uint32_t>::iterator x;
-
-                       result = subbase;
-
-                       if ((x = region_name_map.find (subbase)) == region_name_map.end()) {
-                               result += ".1";
-                               region_name_map[subbase] = 1;
-                       } else {
-                               x->second++;
-                               snprintf (buf, sizeof (buf), ".%d", x->second);
-
-                               result += buf;
-                       }
-               }
-       }
-
-       return 0;
-}
-
-void
-Session::add_region (boost::shared_ptr<Region> region)
-{
-       vector<boost::shared_ptr<Region> > v;
-       v.push_back (region);
-       add_regions (v);
-}
-
-void
-Session::add_regions (vector<boost::shared_ptr<Region> >& new_regions)
-{
-       /* mark dirty because something has changed
-       */
-
-       set_dirty ();
-        
-        for (vector<boost::shared_ptr<Region> >::iterator ii = new_regions.begin(); ii != new_regions.end(); ++ii) {
-                
-                boost::shared_ptr<Region> region = *ii;
-                assert (region);
-                
-                region->PropertyChanged.connect_same_thread (*this, boost::bind (&Session::region_changed, this, _1, boost::weak_ptr<Region>(region)));
-                update_region_name_map (region);
-        }
-        
-        if (!new_regions.empty()) {
-                RegionsAdded (new_regions); /* EMIT SIGNAL */
-        }
-}
-
-void
-Session::update_region_name_map (boost::shared_ptr<Region> region)
-{
-       string::size_type last_period = region->name().find_last_of ('.');
-
-       if (last_period != string::npos && last_period < region->name().length() - 1) {
-
-               string base = region->name().substr (0, last_period);
-               string number = region->name().substr (last_period+1);
-               map<string,uint32_t>::iterator x;
-
-               /* note that if there is no number, we get zero from atoi,
-                  which is just fine
-               */
-
-               region_name_map[base] = atoi (number);
-       }
-}
-
-void
-Session::region_changed (const PropertyChange& what_changed, boost::weak_ptr<Region> weak_region)
-{
-       boost::shared_ptr<Region> region (weak_region.lock ());
-
-       if (!region) {
-               return;
-       }
-
-       if (what_changed.contains (Properties::hidden)) {
-               /* relay hidden changes */
-               RegionHiddenChange (region);
-       }
-
-       if (what_changed.contains (Properties::name)) {
-               update_region_name_map (region);
-       }
-}
-
-void
-Session::remove_region (boost::weak_ptr<Region> weak_region)
-{
-       boost::shared_ptr<Region> region (weak_region.lock ());
-
-       if (!region) {
-               return;
-       }
-
-        RegionFactory::map_remove (region);
-       set_dirty();
-
-        RegionRemoved(region); /* EMIT SIGNAL */
-}
-
 boost::shared_ptr<Region>
 Session::find_whole_file_parent (boost::shared_ptr<Region const> child) const
 {
@@ -3286,7 +2991,7 @@ Session::audition_region (boost::shared_ptr<Region> r)
 void
 Session::cancel_audition ()
 {
-       if (auditioner->active()) {
+       if (auditioner->auditioning()) {
                auditioner->cancel_audition ();
                AuditionActive (false); /* EMIT SIGNAL */
        }
@@ -3295,10 +3000,10 @@ Session::cancel_audition ()
 bool
 Session::RoutePublicOrderSorter::operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b)
 {
-        if (a->is_control()) { 
+        if (a->is_monitor()) { 
                 return true;
         }
-        if (b->is_control()) {
+        if (b->is_monitor()) {
                 return false;
         }
        return a->order_key(N_("signal")) < b->order_key(N_("signal"));
@@ -3345,7 +3050,7 @@ Session::is_auditioning () const
 {
        /* can be called before we have an auditioner object */
        if (auditioner) {
-               return auditioner->active();
+               return auditioner->auditioning();
        } else {
                return false;
        }
@@ -3396,35 +3101,6 @@ Session::graph_reordered ()
        }
 }
 
-void
-Session::add_processor (Processor* processor)
-{
-       /* Session does not own Processors (they belong to a Route) but we do want to track
-          the arrival and departure of port inserts, sends and returns for naming
-          purposes.
-       */
-       processor->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_processor, this, processor));
-       set_dirty();
-}
-
-void
-Session::remove_processor (Processor* processor)
-{
-       Send* send;
-       Return* retrn;
-       PortInsert* port_insert;
-
-       if ((port_insert = dynamic_cast<PortInsert *> (processor)) != 0) {
-               insert_bitset[port_insert->bit_slot()] = false;
-       } else if ((send = dynamic_cast<Send *> (processor)) != 0) {
-               send_bitset[send->bit_slot()] = false;
-       } else if ((retrn = dynamic_cast<Return *> (processor)) != 0) {
-               return_bitset[retrn->bit_slot()] = false;
-       }
-
-       set_dirty();
-}
-
 nframes_t
 Session::available_capture_duration ()
 {
@@ -3612,6 +3288,8 @@ Session::next_return_id ()
 void
 Session::mark_send_id (uint32_t id)
 {
+        cerr << "Marking send ID " << id << " in use\n";
+
        if (id >= send_bitset.size()) {
                send_bitset.resize (id+16, false);
        }
@@ -3645,6 +3323,31 @@ Session::mark_insert_id (uint32_t id)
        insert_bitset[id] = true;
 }
 
+void
+Session::unmark_send_id (uint32_t id)
+{
+       if (id < send_bitset.size()) {
+                send_bitset[id] = false;
+        }
+}
+
+void
+Session::unmark_return_id (uint32_t id)
+{
+       if (id < return_bitset.size()) {
+                return_bitset[id] = false;
+        }
+}
+
+void
+Session::unmark_insert_id (uint32_t id)
+{
+       if (id < insert_bitset.size()) {
+                insert_bitset[id] = false;
+        }
+}
+
+
 /* Named Selection management */
 
 boost::shared_ptr<NamedSelection>
@@ -4089,7 +3792,7 @@ Session::listen_position_changed ()
        boost::shared_ptr<RouteList> r = routes.reader ();
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-               (*i)->put_control_outs_at (p);
+               (*i)->put_monitor_send_at (p);
        }
 }