replace fixed-point linear interpolation with double-based version, thereby removing...
[ardour.git] / libs / ardour / session_state.cc
index 0f1d9720351a3c21f5f24aa1f3ce21fd2a115d1f..0946acfadedf33d2d30c85e483230c161812d6c7 100644 (file)
     
 */
 
+
+#ifdef WAF_BUILD
+#include "libardour-config.h"
+#endif
+
 #define __STDC_FORMAT_MACROS 1
 #include <stdint.h>
 
 #include <glibmm.h>
 #include <glibmm/thread.h>
 
-#include <midi++/mmc.h>
-#include <midi++/port.h>
-
-#include <pbd/error.h>
-#include <pbd/pathscanner.h>
-#include <pbd/pthread_utils.h>
-#include <pbd/search_path.h>
-#include <pbd/stacktrace.h>
-
-#include <ardour/audioengine.h>
-#include <ardour/configuration.h>
-#include <ardour/session.h>
-#include <ardour/session_directory.h>
-#include <ardour/session_utils.h>
-#include <ardour/session_state_utils.h>
-#include <ardour/session_metadata.h>
-#include <ardour/buffer.h>
-#include <ardour/audio_diskstream.h>
-#include <ardour/midi_diskstream.h>
-#include <ardour/utils.h>
-#include <ardour/audioplaylist.h>
-#include <ardour/midi_playlist.h>
-#include <ardour/smf_source.h>
-#include <ardour/audiofilesource.h>
-#include <ardour/silentfilesource.h>
-#include <ardour/sndfilesource.h>
-#include <ardour/midi_source.h>
-#include <ardour/sndfile_helpers.h>
-#include <ardour/auditioner.h>
-#include <ardour/io_processor.h>
-#include <ardour/send.h>
-#include <ardour/processor.h>
-#include <ardour/user_bundle.h>
-#include <ardour/slave.h>
-#include <ardour/tempo.h>
-#include <ardour/audio_track.h>
-#include <ardour/midi_track.h>
-#include <ardour/midi_patch_manager.h>
-#include <ardour/cycle_timer.h>
-#include <ardour/utils.h>
-#include <ardour/named_selection.h>
-#include <ardour/version.h>
-#include <ardour/location.h>
-#include <ardour/audioregion.h>
-#include <ardour/midi_region.h>
-#include <ardour/crossfade.h>
-#include <ardour/control_protocol_manager.h>
-#include <ardour/region_factory.h>
-#include <ardour/source_factory.h>
-#include <ardour/playlist_factory.h>
-#include <ardour/filename_extensions.h>
-#include <ardour/directory_names.h>
-#include <ardour/template_utils.h>
-#include <ardour/ticker.h>
-#include <ardour/route_group.h>
-
-#include <control_protocol/control_protocol.h>
+#include "midi++/mmc.h"
+#include "midi++/port.h"
+
+#include "pbd/error.h"
+#include "pbd/pathscanner.h"
+#include "pbd/pthread_utils.h"
+#include "pbd/search_path.h"
+#include "pbd/stacktrace.h"
+
+#include "ardour/audioengine.h"
+#include "ardour/configuration.h"
+#include "ardour/session.h"
+#include "ardour/session_directory.h"
+#include "ardour/session_utils.h"
+#include "ardour/session_state_utils.h"
+#include "ardour/session_metadata.h"
+#include "ardour/buffer.h"
+#include "ardour/audio_diskstream.h"
+#include "ardour/midi_diskstream.h"
+#include "ardour/utils.h"
+#include "ardour/audioplaylist.h"
+#include "ardour/midi_playlist.h"
+#include "ardour/smf_source.h"
+#include "ardour/audiofilesource.h"
+#include "ardour/silentfilesource.h"
+#include "ardour/sndfilesource.h"
+#include "ardour/midi_source.h"
+#include "ardour/sndfile_helpers.h"
+#include "ardour/auditioner.h"
+#include "ardour/io_processor.h"
+#include "ardour/send.h"
+#include "ardour/processor.h"
+#include "ardour/user_bundle.h"
+#include "ardour/slave.h"
+#include "ardour/tempo.h"
+#include "ardour/audio_track.h"
+#include "ardour/midi_track.h"
+#include "ardour/midi_patch_manager.h"
+#include "ardour/cycle_timer.h"
+#include "ardour/utils.h"
+#include "ardour/named_selection.h"
+#include "ardour/version.h"
+#include "ardour/location.h"
+#include "ardour/audioregion.h"
+#include "ardour/midi_region.h"
+#include "ardour/crossfade.h"
+#include "ardour/control_protocol_manager.h"
+#include "ardour/region_factory.h"
+#include "ardour/source_factory.h"
+#include "ardour/playlist_factory.h"
+#include "ardour/filename_extensions.h"
+#include "ardour/directory_names.h"
+#include "ardour/template_utils.h"
+#include "ardour/ticker.h"
+#include "ardour/route_group.h"
+
+#include "control_protocol/control_protocol.h"
 
 #include "i18n.h"
 #include <locale.h>
@@ -151,20 +156,17 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _tempo_map->StateChanged.connect (mem_fun (*this, &Session::tempo_map_changed));
 
 
-
+       _non_soloed_outs_muted = false;
+       _listen_cnt = 0;
        g_atomic_int_set (&processing_prohibited, 0);
-       insert_cnt = 0;
        _transport_speed = 0;
        _last_transport_speed = 0;
-       phi = (uint64_t) (0x1000000);
-       target_phi = phi;
+       _target_transport_speed = 0;
        auto_play_legal = false;
        transport_sub_state = 0;
        _transport_frame = 0;
-       last_stop_frame = 0;
        end_location = new Location (0, 0, _("end"), Location::Flags ((Location::IsMark|Location::IsEnd)));
        start_location = new Location (0, 0, _("start"), Location::Flags ((Location::IsMark|Location::IsStart)));
-       _end_location_is_free = true;
        g_atomic_int_set (&_record_status, Disabled);
        loop_changing = false;
        play_loop = false;
@@ -182,7 +184,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        next_quarter_frame_to_send = -1;
        current_block_size = 0;
        solo_update_disabled = false;
-       currently_soloing = false;
        _have_captured = false;
        _worst_output_latency = 0;
        _worst_input_latency = 0;
@@ -206,7 +207,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _npan_buffers = 0;
        pending_abort = false;
        destructive_index = 0;
-       current_trans = 0;
        first_file_data_format_reset = true;
        first_file_header_format_reset = true;
        butler_thread = (pthread_t) 0;
@@ -216,8 +216,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
        /* default short fade = 15ms */
 
-       Crossfade::set_short_xfade_length ((nframes_t) floor (Config->get_short_xfade_seconds() * frame_rate()));
-       SndFileSource::setup_standard_crossfades (frame_rate());
+       Crossfade::set_short_xfade_length ((nframes_t) floor (config.get_short_xfade_seconds() * frame_rate()));
+       SndFileSource::setup_standard_crossfades (*this, frame_rate());
 
        last_mmc_step.tv_sec = 0;
        last_mmc_step.tv_usec = 0;
@@ -233,7 +233,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
        process_function = &Session::process_with_events;
 
-       if (Config->get_use_video_sync()) {
+       if (config.get_use_video_sync()) {
                waiting_for_sync_offset = true;
        } else {
                waiting_for_sync_offset = false;
@@ -275,8 +275,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
        /* stop IO objects from doing stuff until we're ready for them */
 
-       IO::disable_panners ();
-       IO::disable_ports ();
+       Delivery::disable_panners ();
        IO::disable_connecting ();
 }
 
@@ -341,8 +340,7 @@ Session::second_stage_init (bool new_session)
        /* handle this one in a different way than all others, so that its clear what happened */
        
        catch (AudioEngine::PortRegistrationFailure& err) {
-               error << _("Unable to create all required ports")
-                     << endmsg;
+               error << err.what() << endmsg;
                return -1;
        }
 
@@ -366,11 +364,7 @@ Session::second_stage_init (bool new_session)
 
        ControlProtocolManager::instance().set_session (*this);
 
-       if (new_session) {
-               _end_location_is_free = true;
-       } else {
-               _end_location_is_free = false;
-       }
+       config.set_end_marker_is_free (new_session);
 
        _state_of_the_state = Clean;
        
@@ -415,12 +409,7 @@ Session::setup_raid_path (string path)
        SearchPath sound_search_path;
        SearchPath midi_search_path;
 
-       for (
-                       SearchPath::const_iterator i = search_path.begin();
-                       i != search_path.end();
-                       ++i
-               )
-       {
+       for (SearchPath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) {
                sp.path = (*i).to_string ();
                sp.blocks = 0; // not needed
                session_dirs.push_back (sp);
@@ -431,14 +420,11 @@ Session::setup_raid_path (string path)
                midi_search_path += sdir.midi_path ();
        }
 
-       // set the AudioFileSource and SMFSource search path
-
-       AudioFileSource::set_search_path (sound_search_path.to_string ());
-       SMFSource::set_search_path (midi_search_path.to_string ());
-
+       // set the search path for each data type
+       FileSource::set_search_path (DataType::AUDIO, sound_search_path.to_string ());
+       SMFSource::set_search_path (DataType::MIDI, midi_search_path.to_string ());
 
        // reset the round-robin soundfile path thingie
-
        last_rr_session_dir = session_dirs.begin();
 }
 
@@ -607,7 +593,7 @@ Session::remove_pending_capture_state ()
 {
        sys::path pending_state_file_path(_session_dir->root_path());
        
-       pending_state_file_path /= _current_snapshot_name + pending_suffix;
+       pending_state_file_path /= legalize_for_path (_current_snapshot_name) + pending_suffix;
 
        try
        {
@@ -631,8 +617,8 @@ Session::rename_state (string old_name, string new_name)
                return;
        }
 
-       const string old_xml_filename = old_name + statefile_suffix;
-       const string new_xml_filename = new_name + statefile_suffix;
+       const string old_xml_filename = legalize_for_path (old_name) + statefile_suffix;
+       const string new_xml_filename = legalize_for_path (new_name) + statefile_suffix;
 
        const sys::path old_xml_path = _session_dir->root_path() / old_xml_filename;
        const sys::path new_xml_path = _session_dir->root_path() / new_xml_filename;
@@ -661,7 +647,7 @@ Session::remove_state (string snapshot_name)
 
        sys::path xml_path(_session_dir->root_path());
 
-       xml_path /= snapshot_name + statefile_suffix;
+       xml_path /= legalize_for_path (snapshot_name) + statefile_suffix;
 
        if (!create_backup_file (xml_path)) {
                // don't remove it if a backup can't be made
@@ -704,7 +690,7 @@ Session::save_state (string snapshot_name, bool pending)
 
                /* proper save: use statefile_suffix (.ardour in English) */
                
-               xml_path /= snapshot_name + statefile_suffix;
+               xml_path /= legalize_for_path (snapshot_name) + statefile_suffix;
 
                /* make a backup copy of the old file */
 
@@ -716,12 +702,12 @@ Session::save_state (string snapshot_name, bool pending)
        } else {
 
                /* pending save: use pending_suffix (.pending in English) */
-               xml_path /= snapshot_name + pending_suffix;
+               xml_path /= legalize_for_path (snapshot_name) + pending_suffix;
        }
 
        sys::path tmp_path(_session_dir->root_path());
 
-       tmp_path /= snapshot_name + temp_suffix;
+       tmp_path /= legalize_for_path (snapshot_name) + temp_suffix;
 
        // cerr << "actually writing state to " << xml_path.to_string() << endl;
 
@@ -779,7 +765,7 @@ Session::load_state (string snapshot_name)
        /* check for leftover pending state from a crashed capture attempt */
 
        sys::path xmlpath(_session_dir->root_path());
-       xmlpath /= snapshot_name + pending_suffix;
+       xmlpath /= legalize_for_path (snapshot_name) + pending_suffix;
 
        if (sys::exists (xmlpath)) {
 
@@ -792,7 +778,7 @@ Session::load_state (string snapshot_name)
 
        if (!state_was_pending) {
                xmlpath = _session_dir->root_path();
-               xmlpath /= snapshot_name + statefile_suffix;
+               xmlpath /= legalize_for_path (snapshot_name) + statefile_suffix;
        }
        
        if (!sys::exists (xmlpath)) {
@@ -838,7 +824,7 @@ Session::load_state (string snapshot_name)
 
                sys::path backup_path(_session_dir->root_path());
 
-               backup_path /= snapshot_name + "-1" + statefile_suffix;
+               backup_path /= legalize_for_path (snapshot_name) + "-1" + statefile_suffix;
 
                // only create a backup once
                if (sys::exists (backup_path)) {
@@ -868,11 +854,9 @@ Session::load_state (string snapshot_name)
 int
 Session::load_options (const XMLNode& node)
 {
-       XMLNode* child;
-       XMLProperty* prop;
        LocaleGuard lg (X_("POSIX"));
 
-       Config->set_variables (node, ConfigVariableBase::Session);
+       config.set_variables (node);
 
        /* now reset MIDI ports because the session can have its own 
           MIDI configuration.
@@ -880,38 +864,9 @@ Session::load_options (const XMLNode& node)
 
        setup_midi ();
 
-       if ((child = find_named_node (node, "end-marker-is-free")) != 0) {
-               if ((prop = child->property ("val")) != 0) {
-                       _end_location_is_free = (prop->value() == "yes");
-               }
-       }
-
        return 0;
 }
 
-bool
-Session::save_config_options_predicate (ConfigVariableBase::Owner owner) const
-{
-       const ConfigVariableBase::Owner modified_by_session_or_user = (ConfigVariableBase::Owner)
-               (ConfigVariableBase::Session|ConfigVariableBase::Interface);
-
-       return owner & modified_by_session_or_user;
-}
-
-XMLNode&
-Session::get_options () const
-{
-       XMLNode* child;
-       LocaleGuard lg (X_("POSIX"));
-
-       XMLNode& option_root = Config->get_variables (mem_fun (*this, &Session::save_config_options_predicate));
-
-       child = option_root.add_child ("end-marker-is-free");
-       child->add_property ("val", _end_location_is_free ? "yes" : "no");
-
-       return option_root;
-}
-
 XMLNode&
 Session::get_state()
 {
@@ -987,7 +942,7 @@ Session::state(bool full_state)
 
        /* various options */
 
-       node->add_child_nocopy (get_options());
+       node->add_child_nocopy (config.get_variables ());
 
        node->add_child_nocopy (_metadata->get_state());
 
@@ -998,18 +953,13 @@ Session::state(bool full_state)
 
                for (SourceMap::iterator siter = sources.begin(); siter != sources.end(); ++siter) {
                        
-                       /* Don't save information about AudioFileSources that are empty */
+                       /* Don't save information about non-destructive file sources that are empty */
+                       /* FIXME: MIDI breaks if this is made FileSource like it should be... */
                        
                        boost::shared_ptr<AudioFileSource> fs;
-
                        if ((fs = boost::dynamic_pointer_cast<AudioFileSource> (siter->second)) != 0) {
-
-                               /* Don't save sources that are empty, unless they're destructive (which are OK
-                                  if they are empty, because we will re-use them every time.)
-                               */
-
                                if (!fs->destructive()) {
-                                       if (fs->length() == 0) {
+                                       if (fs->length(fs->timeline_position()) == 0) {
                                                continue;
                                        }
                                }
@@ -1091,13 +1041,8 @@ Session::state(bool full_state)
        }
 
        
-       child = node->add_child ("EditGroups");
-       for (list<RouteGroup *>::iterator i = edit_groups.begin(); i != edit_groups.end(); ++i) {
-               child->add_child_nocopy ((*i)->get_state());
-       }
-
-       child = node->add_child ("MixGroups");
-       for (list<RouteGroup *>::iterator i = mix_groups.begin(); i != mix_groups.end(); ++i) {
+       child = node->add_child ("RouteGroups");
+       for (list<RouteGroup *>::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) {
                child->add_child_nocopy ((*i)->get_state());
        }
 
@@ -1207,13 +1152,12 @@ Session::set_state (const XMLNode& node)
        }
 
        
-       IO::disable_ports ();
        IO::disable_connecting ();
 
        /* Object loading order:
 
        Path
-       extra
+       Extra
        Options/Config
        MIDI Control // relies on data from Options/Config
        Metadata
@@ -1223,13 +1167,13 @@ Session::set_state (const XMLNode& node)
        AudioDiskstreams
        Connections
        Routes
-       EditGroups
+       RouteGroups
        MixGroups
        Click
        ControlProtocols
        */
 
-       if ((child = find_named_node (node, "extra")) != 0) {
+       if ((child = find_named_node (node, "Extra")) != 0) {
                _extra_xml = new XMLNode (*child);
        }
 
@@ -1333,17 +1277,10 @@ Session::set_state (const XMLNode& node)
                _bundle_xml_node = new XMLNode (*child);
        }
        
-       if ((child = find_named_node (node, "EditGroups")) == 0) {
-               error << _("Session: XML state has no edit groups section") << endmsg;
-               goto out;
-       } else if (load_edit_groups (*child)) {
-               goto out;
-       }
-
-       if ((child = find_named_node (node, "MixGroups")) == 0) {
-               error << _("Session: XML state has no mix groups section") << endmsg;
+       if ((child = find_named_node (node, "RouteGroups")) == 0) {
+               error << _("Session: XML state has no route groups section") << endmsg;
                goto out;
-       } else if (load_mix_groups (*child)) {
+       } else if (load_route_groups (*child)) {
                goto out;
        }
 
@@ -1422,8 +1359,10 @@ Session::XMLRouteFactory (const XMLNode& node)
        
        DataType type = DataType::AUDIO;
        const XMLProperty* prop = node.property("default-type");
-       if (prop)
+
+       if (prop) {
                type = DataType(prop->value());
+       } 
        
        assert(type != DataType::NIL);
 
@@ -1560,7 +1499,7 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full)
                }
        }
 
-       for (uint32_t n=1; n < nchans; ++n) {
+       for (uint32_t n = 0; n < nchans; ++n) {
                snprintf (buf, sizeof(buf), X_("master-source-%d"), n);
                if ((prop = node.property (buf)) != 0) {
                        
@@ -1595,7 +1534,7 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full)
                }
 
                if (!master_sources.empty()) {
-                       if (master_sources.size() == nchans) {
+                       if (master_sources.size() != nchans) {
                                error << _("Session: XMLNode describing an AudioRegion is missing some master sources; ignored") << endmsg;
                        } else {
                                region->set_master_sources (master_sources);
@@ -1740,14 +1679,11 @@ Session::load_sources (const XMLNode& node)
        set_dirty();
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-
                try {
                        if ((source = XMLSourceFactory (**niter)) == 0) {
                                error << _("Session: cannot create Source from XML description.") << endmsg;
                        }
-               }
-
-               catch (non_existent_source& err) {
+               } catch (MissingSource& err) {
                        warning << _("A sound file is missing. It will be replaced by silence.") << endmsg;
                        source = SourceFactory::createSilent (*this, **niter, max_frames, _current_frame_rate);
                }
@@ -2100,35 +2036,18 @@ Session::load_bundles (XMLNode const & node)
 }                              
 
 int
-Session::load_edit_groups (const XMLNode& node)
-{
-       return load_route_groups (node, true);
-}
-
-int
-Session::load_mix_groups (const XMLNode& node)
-{
-       return load_route_groups (node, false);
-}
-
-int
-Session::load_route_groups (const XMLNode& node, bool edit)
+Session::load_route_groups (const XMLNode& node)
 {
        XMLNodeList nlist = node.children();
        XMLNodeConstIterator niter;
-       RouteGroup* rg;
 
-       set_dirty();
+       set_dirty ();
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                if ((*niter)->name() == "RouteGroup") {
-                       if (edit) {
-                               rg = add_edit_group ("");
-                               rg->set_state (**niter);
-                       } else {
-                               rg = add_mix_group ("");
-                               rg->set_state (**niter);
-                       }
+                       RouteGroup* rg = new RouteGroup (*this, "");
+                       add_route_group (rg);
+                       rg->set_state (**niter);
                }
        }
        
@@ -2191,73 +2110,35 @@ Session::possible_states () const
        return possible_states(_path);
 }
 
-RouteGroup *
-Session::add_edit_group (string name)
-{
-       RouteGroup* rg = new RouteGroup (*this, name);
-       edit_groups.push_back (rg);
-       edit_group_added (rg); /* EMIT SIGNAL */
-       set_dirty();
-       return rg;
-}
-
-RouteGroup *
-Session::add_mix_group (string name)
-{
-       RouteGroup* rg = new RouteGroup (*this, name, RouteGroup::Relative);
-       mix_groups.push_back (rg);
-       mix_group_added (rg); /* EMIT SIGNAL */
-       set_dirty();
-       return rg;
-}
-
 void
-Session::remove_edit_group (RouteGroup& rg)
+Session::add_route_group (RouteGroup* g)
 {
-       list<RouteGroup*>::iterator i;
-
-       if ((i = find (edit_groups.begin(), edit_groups.end(), &rg)) != edit_groups.end()) {
-               (*i)->apply (&Route::drop_edit_group, this);
-               edit_groups.erase (i);
-               edit_group_removed (); /* EMIT SIGNAL */
-       }
-
-       delete &rg;
+       _route_groups.push_back (g);
+       route_group_added (g); /* EMIT SIGNAL */
+       set_dirty ();
 }
 
 void
-Session::remove_mix_group (RouteGroup& rg)
+Session::remove_route_group (RouteGroup& rg)
 {
        list<RouteGroup*>::iterator i;
 
-       if ((i = find (mix_groups.begin(), mix_groups.end(), &rg)) != mix_groups.end()) {
-               (*i)->apply (&Route::drop_mix_group, this);
-               mix_groups.erase (i);
-               mix_group_removed (); /* EMIT SIGNAL */
+       if ((i = find (_route_groups.begin(), _route_groups.end(), &rg)) != _route_groups.end()) {
+               (*i)->apply (&Route::drop_route_group, this);
+               _route_groups.erase (i);
+               route_group_removed (); /* EMIT SIGNAL */
        }
 
        delete &rg;
 }
 
-RouteGroup *
-Session::mix_group_by_name (string name)
-{
-       list<RouteGroup *>::iterator i;
-
-       for (i = mix_groups.begin(); i != mix_groups.end(); ++i) {
-               if ((*i)->name() == name) {
-                       return* i;
-               }
-       }
-       return 0;
-}
 
 RouteGroup *
-Session::edit_group_by_name (string name)
+Session::route_group_by_name (string name)
 {
        list<RouteGroup *>::iterator i;
 
-       for (i = edit_groups.begin(); i != edit_groups.end(); ++i) {
+       for (i = _route_groups.begin(); i != _route_groups.end(); ++i) {
                if ((*i)->name() == name) {
                        return* i;
                }
@@ -2266,29 +2147,36 @@ Session::edit_group_by_name (string name)
 }
 
 void
-Session::begin_reversible_command (const string& name)
+Session::begin_reversible_command(const string& name)
 {
-       current_trans = new UndoTransaction;
-       current_trans->set_name (name);
+       UndoTransaction* trans = new UndoTransaction();
+       trans->set_name(name);
+       if (!_current_trans.empty()) {
+               _current_trans.top()->add_command(trans);
+       }
+       _current_trans.push(trans);
 }
 
 void
-Session::commit_reversible_command (Command *cmd)
+Session::commit_reversible_command(Command *cmd)
 {
+       assert(!_current_trans.empty());
        struct timeval now;
 
        if (cmd) {
-               current_trans->add_command (cmd);
+               _current_trans.top()->add_command(cmd);
        }
 
-       if (current_trans->empty()) {
+       if (_current_trans.top()->empty()) {
+               _current_trans.pop();
                return;
        }
 
-       gettimeofday (&now, 0);
-       current_trans->set_timestamp (now);
+       gettimeofday(&now, 0);
+       _current_trans.top()->set_timestamp(now);
 
-       _history.add (current_trans);
+       _history.add(_current_trans.top());
+       _current_trans.pop();
 }
 
 Session::GlobalRouteBooleanState 
@@ -2377,32 +2265,6 @@ Session::set_global_record_enable (GlobalRouteBooleanState s, void* src)
        set_global_route_boolean (s, &Route::set_record_enable, src);
 }
 
-#if 0
-UndoAction
-Session::global_mute_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_mute), get_global_route_boolean (&Route::muted), src);
-}
-
-UndoAction
-Session::global_metering_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_route_metering), get_global_route_metering (), src);
-}
-
-UndoAction
-Session::global_solo_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_solo), get_global_route_boolean (&Route::soloed), src);
-}
-
-UndoAction
-Session::global_record_enable_memento (void* src)
-{
-       return sigc::bind (mem_fun (*this, &Session::set_global_record_enable), get_global_route_boolean (&Route::record_enabled), src);
-}
-#endif
-
 static bool
 accept_all_non_peak_files (const string& path, void *arg)
 {
@@ -2440,6 +2302,12 @@ Session::find_all_sources (string path, set<string>& result)
                
                XMLProperty* prop;
 
+               if ((prop = (*niter)->property (X_("type"))) == 0) {
+                       continue;
+               }
+
+               DataType type (prop->value());
+
                if ((prop = (*niter)->property (X_("name"))) == 0) {
                        continue;
                }
@@ -2448,12 +2316,14 @@ Session::find_all_sources (string path, set<string>& result)
                        /* external file, ignore */
                        continue;
                }
+               
+               Glib::ustring found_path;
+               bool is_new;
+               uint16_t chan;
 
-               sys::path source_path = _session_dir->sound_path ();
-
-               source_path /= prop->value ();
-
-               result.insert (source_path.to_string ());
+               if (FileSource::find (type, prop->value(), true, is_new, chan, found_path)) {
+                       result.insert (found_path);
+               }
        }
 
        return 0;
@@ -2483,7 +2353,7 @@ Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_th
        }
 
        this_snapshot_path = _path;
-       this_snapshot_path += _current_snapshot_name;
+       this_snapshot_path += legalize_for_path (_current_snapshot_name);
        this_snapshot_path += statefile_suffix;
 
        for (vector<string*>::iterator i = state_files->begin(); i != state_files->end(); ++i) {
@@ -2577,7 +2447,7 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                   capture files.
                */
 
-               if (!i->second->used() && i->second->length() > 0) {
+               if (!i->second->used() && i->second->length(i->second->timeline_position()) > 0) {
                        dead_sources.push_back (i->second);
                        i->second->GoingAway();
                } 
@@ -2623,9 +2493,9 @@ Session::cleanup_sources (Session::cleanup_report& rep)
         */
        
        for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
-               boost::shared_ptr<AudioFileSource> fs;
+               boost::shared_ptr<FileSource> fs;
                
-               if ((fs = boost::dynamic_pointer_cast<AudioFileSource> (i->second)) != 0) {
+               if ((fs = boost::dynamic_pointer_cast<FileSource> (i->second)) != 0) {
                        all_sources.insert (fs->path());
                } 
        }
@@ -2866,7 +2736,12 @@ void
 Session::set_deletion_in_progress ()
 {
        _state_of_the_state = StateOfTheState (_state_of_the_state | Deletion);
+}
 
+void
+Session::clear_deletion_in_progress ()
+{
+       _state_of_the_state = StateOfTheState (_state_of_the_state & (~Deletion));
 }
 
 void
@@ -2939,7 +2814,7 @@ Session::save_history (string snapshot_name)
                snapshot_name = _current_snapshot_name;
        }
   
-       const string history_filename = snapshot_name + history_suffix;
+       const string history_filename = legalize_for_path (snapshot_name) + history_suffix;
        const string backup_filename = history_filename + backup_suffix;
        const sys::path xml_path = _session_dir->root_path() / history_filename;
        const sys::path backup_path = _session_dir->root_path() / backup_filename;
@@ -2992,11 +2867,11 @@ Session::restore_history (string snapshot_name)
        if (snapshot_name.empty()) {
                snapshot_name = _current_snapshot_name;
        }
-
-       const string xml_filename = snapshot_name + history_suffix;
+       
+       const string xml_filename = legalize_for_path (snapshot_name) + history_suffix;
        const sys::path xml_path = _session_dir->root_path() / xml_filename;
-
-    cerr << "Loading history from " << xml_path.to_string() << endmsg;
+       
+       cerr << "Loading history from " << xml_path.to_string() << endmsg;
 
        if (!sys::exists (xml_path)) {
                info << string_compose (_("%1: no history file \"%2\" for this session."),
@@ -3067,18 +2942,20 @@ Session::restore_history (string snapshot_name)
 }
 
 void
-Session::config_changed (const char* parameter_name)
+Session::config_changed (std::string p, bool ours)
 {
-#define PARAM_IS(x) (!strcmp (parameter_name, (x)))
-
-       if (PARAM_IS ("seamless-loop")) {
+       if (ours) {
+               set_dirty ();
+       }
+       
+       if (p == "seamless-loop") {
                
-       } else if (PARAM_IS ("rf-speed")) {
+       } else if (p == "rf-speed") {
                
-       } else if (PARAM_IS ("auto-loop")) {
+       } else if (p == "auto-loop") {
+               
+       } else if (p == "auto-input") {
                
-       } else if (PARAM_IS ("auto-input")) {
-
                if (Config->get_monitoring_model() == HardwareMonitoring && transport_rolling()) {
                        /* auto-input only makes a difference if we're rolling */
                        
@@ -3086,38 +2963,38 @@ Session::config_changed (const char* parameter_name)
                        
                        for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
                                if ((*i)->record_enabled ()) {
-                                       (*i)->monitor_input (!Config->get_auto_input());
+                                       (*i)->monitor_input (!config.get_auto_input());
                                }
                        }
                }
 
-       } else if (PARAM_IS ("punch-in")) {
+       } else if (p == "punch-in") {
 
                Location* location;
                
                if ((location = _locations.auto_punch_location()) != 0) {
                        
-                       if (Config->get_punch_in ()) {
+                       if (config.get_punch_in ()) {
                                replace_event (Event::PunchIn, location->start());
                        } else {
                                remove_event (location->start(), Event::PunchIn);
                        }
                }
                
-       } else if (PARAM_IS ("punch-out")) {
+       } else if (p == "punch-out") {
 
                Location* location;
                
                if ((location = _locations.auto_punch_location()) != 0) {
                        
-                       if (Config->get_punch_out()) {
+                       if (config.get_punch_out()) {
                                replace_event (Event::PunchOut, location->end());
                        } else {
                                clear_events (Event::PunchOut);
                        }
                }
 
-       } else if (PARAM_IS ("edit-mode")) {
+       } else if (p == "edit-mode") {
 
                Glib::Mutex::Lock lm (playlist_lock);
                
@@ -3125,63 +3002,63 @@ Session::config_changed (const char* parameter_name)
                        (*i)->set_edit_mode (Config->get_edit_mode ());
                }
 
-       } else if (PARAM_IS ("use-video-sync")) {
+       } else if (p == "use-video-sync") {
 
-               waiting_for_sync_offset = Config->get_use_video_sync();
+               waiting_for_sync_offset = config.get_use_video_sync();
 
-       } else if (PARAM_IS ("mmc-control")) {
+       } else if (p == "mmc-control") {
 
                //poke_midi_thread ();
 
-       } else if (PARAM_IS ("mmc-device-id") || PARAM_IS ("mmc-receive-id")) {
+       } else if (p == "mmc-device-id" || p == "mmc-receive-id") {
 
                if (mmc) {
                        mmc->set_receive_device_id (Config->get_mmc_receive_device_id());
                }
 
-       } else if (PARAM_IS ("mmc-send-id")) {
+       } else if (p == "mmc-send-id") {
 
                if (mmc) {
                        mmc->set_send_device_id (Config->get_mmc_send_device_id());
                }
 
-       } else if (PARAM_IS ("midi-control")) {
+       } else if (p == "midi-control") {
                
                //poke_midi_thread ();
 
-       } else if (PARAM_IS ("raid-path")) {
+       } else if (p == "raid-path") {
 
-               setup_raid_path (Config->get_raid_path());
+               setup_raid_path (config.get_raid_path());
 
-       } else if (PARAM_IS ("smpte-format")) {
+       } else if (p == "smpte-format") {
 
                sync_time_vars ();
 
-       } else if (PARAM_IS ("video-pullup")) {
+       } else if (p == "video-pullup") {
 
                sync_time_vars ();
 
-       } else if (PARAM_IS ("seamless-loop")) {
+       } else if (p == "seamless-loop") {
 
                if (play_loop && transport_rolling()) {
                        // to reset diskstreams etc
                        request_play_loop (true);
                }
 
-       } else if (PARAM_IS ("rf-speed")) {
+       } else if (p == "rf-speed") {
 
                cumulative_rf_motion = 0;
                reset_rf_scale (0);
 
-       } else if (PARAM_IS ("click-sound")) {
+       } else if (p == "click-sound") {
 
                setup_click_sounds (1);
 
-       } else if (PARAM_IS ("click-emphasis-sound")) {
+       } else if (p == "click-emphasis-sound") {
 
                setup_click_sounds (-1);
 
-       } else if (PARAM_IS ("clicking")) {
+       } else if (p == "clicking") {
 
                if (Config->get_clicking()) {
                        if (_click_io && click_data) { // don't require emphasis data
@@ -3191,7 +3068,7 @@ Session::config_changed (const char* parameter_name)
                        _clicking = false;
                }
 
-       } else if (PARAM_IS ("send-mtc")) {
+       } else if (p == "send-mtc") {
                
                /* only set the internal flag if we have
                   a port.
@@ -3207,7 +3084,7 @@ Session::config_changed (const char* parameter_name)
                        session_send_mtc = false;
                }
 
-       } else if (PARAM_IS ("send-mmc")) {
+       } else if (p == "send-mmc") {
                
                /* only set the internal flag if we have
                   a port.
@@ -3220,7 +3097,7 @@ Session::config_changed (const char* parameter_name)
                        session_send_mmc = false; 
                }
 
-       } else if (PARAM_IS ("midi-feedback")) {
+       } else if (p == "midi-feedback") {
                
                /* only set the internal flag if we have
                   a port.
@@ -3230,11 +3107,11 @@ Session::config_changed (const char* parameter_name)
                        session_midi_feedback = Config->get_midi_feedback();
                }
 
-       } else if (PARAM_IS ("jack-time-master")) {
+       } else if (p == "jack-time-master") {
 
                engine().reset_timebase ();
 
-       } else if (PARAM_IS ("native-file-header-format")) {
+       } else if (p == "native-file-header-format") {
 
                if (!first_file_header_format_reset) {
                        reset_native_file_format ();
@@ -3242,7 +3119,7 @@ Session::config_changed (const char* parameter_name)
 
                first_file_header_format_reset = false;
 
-       } else if (PARAM_IS ("native-file-data-format")) {
+       } else if (p == "native-file-data-format") {
 
                if (!first_file_data_format_reset) {
                        reset_native_file_format ();
@@ -3250,17 +3127,17 @@ Session::config_changed (const char* parameter_name)
 
                first_file_data_format_reset = false;
 
-       } else if (PARAM_IS ("slave-source")) {
-               set_slave_source (Config->get_slave_source());
-       } else if (PARAM_IS ("remote-model")) {
+       } else if (p == "slave-source") {
+                               set_slave_source (Config->get_slave_source());
+       } else if (p == "remote-model") {
                set_remote_control_ids ();
-       }  else if (PARAM_IS ("denormal-model")) {
+       }  else if (p == "denormal-model") {
                setup_fpu ();
-       } else if (PARAM_IS ("history-depth")) {
+       } else if (p == "history-depth") {
                set_history_depth (Config->get_history_depth());
-       } else if (PARAM_IS ("sync-all-route-ordering")) {
+       } else if (p == "sync-all-route-ordering") {
                sync_order_keys ("session");
-       } else if (PARAM_IS ("initial-program-change")) {
+       } else if (p == "initial-program-change") {
 
                if (_mmc_port && Config->get_initial_program_change() >= 0) {
                        MIDI::byte buf[2];
@@ -3270,7 +3147,7 @@ Session::config_changed (const char* parameter_name)
 
                        _mmc_port->midimsg (buf, sizeof (buf), 0);
                }
-       } else if (PARAM_IS ("initial-program-change")) {
+       } else if (p == "initial-program-change") {
 
                if (_mmc_port && Config->get_initial_program_change() >= 0) {
                        MIDI::byte* buf = new MIDI::byte[2];
@@ -3279,14 +3156,16 @@ Session::config_changed (const char* parameter_name)
                        buf[1] = (Config->get_initial_program_change() & 0x7f);
                        // deliver_midi (_mmc_port, buf, 2);
                }
-       } else if (PARAM_IS ("solo-mute-override")) {
-               catch_up_on_solo_mute_override ();
+       } else if (p == "solo-mute-override") {
+               // catch_up_on_solo_mute_override ();
+       } else if (p == "listen-position") {
+               listen_position_changed ();
+       } else if (p == "solo-control-is-listen-control") {
+               solo_control_mode_changed ();
        }
 
-       set_dirty ();
-                  
-#undef PARAM_IS
 
+       set_dirty ();
 }
 
 void