replace fixed-point linear interpolation with double-based version, thereby removing...
[ardour.git] / libs / ardour / session_state.cc
index 955da881d19fc52cbb0daee7d9a85d94e3e4ca77..0946acfadedf33d2d30c85e483230c161812d6c7 100644 (file)
     
 */
 
+
+#ifdef WAF_BUILD
+#include "libardour-config.h"
+#endif
+
 #define __STDC_FORMAT_MACROS 1
 #include <stdint.h>
 
@@ -152,8 +157,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 
 
        _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;
        _target_transport_speed = 0;
@@ -588,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
        {
@@ -612,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;
@@ -642,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
@@ -685,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 */
 
@@ -697,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;
 
@@ -760,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)) {
 
@@ -773,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)) {
@@ -819,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)) {
@@ -1036,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());
        }
 
@@ -1167,7 +1167,7 @@ Session::set_state (const XMLNode& node)
        AudioDiskstreams
        Connections
        Routes
-       EditGroups
+       RouteGroups
        MixGroups
        Click
        ControlProtocols
@@ -1277,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;
        }
 
@@ -1506,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) {
                        
@@ -1541,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);
@@ -2043,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);
                }
        }
        
@@ -2134,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;
                }
@@ -2364,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;
                }
@@ -2372,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;
@@ -2407,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) {
@@ -2868,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;
@@ -2921,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."),
@@ -3212,8 +3158,13 @@ Session::config_changed (std::string p, bool ours)
                }
        } 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 ();
 }