Committed filthy mess of a working copy solely for moving between machines.
[ardour.git] / libs / ardour / session_state.cc
index 241d54c8b66c03daf45ec9a8df6f9c97f0881a82..602ac943149fc845080a1a36035c40e4112bce43 100644 (file)
@@ -81,6 +81,7 @@
 #include <ardour/location.h>
 #include <ardour/audioregion.h>
 #include <ardour/crossfade.h>
+#include <ardour/control_protocol_manager.h>
 
 #include "i18n.h"
 #include <locale.h>
@@ -149,12 +150,13 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        state_was_pending = false;
        set_next_event ();
        outbound_mtc_smpte_frame = 0;
-       next_quarter_frame_to_send = -1;
+       next_quarter_frame_to_send = 0;
        current_block_size = 0;
        _solo_latched = true;
        _solo_model = InverseMute;
        solo_update_disabled = false;
        currently_soloing = false;
+       _have_captured = false;
        _worst_output_latency = 0;
        _worst_input_latency = 0;
        _worst_track_latency = 0;
@@ -165,7 +167,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        butler_gain_buffer = 0;
        auditioner = 0;
        mmc_control = false;
-       midi_feedback = false;
        midi_control = true;
        mmc = 0;
        post_transport_work = PostTransportWork (0);
@@ -183,7 +184,6 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _master_out = 0;
        input_auto_connect = AutoConnectOption (0);
        output_auto_connect = AutoConnectOption (0);
-       _have_captured = false;
        waiting_to_start = false;
        _exporting = false;
        _gain_automation_buffer = 0;
@@ -192,6 +192,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        pending_abort = false;
        layer_model = MoveAddHigher;
        xfade_model = ShortCrossfade;
+       destructive_index = 0;
 
        /* allocate conversion buffers */
        _conversion_buffers[ButlerContext] = new char[DiskStream::disk_io_frames() * 4];
@@ -296,13 +297,11 @@ Session::second_stage_init (bool new_session)
                return -1;
        }
 
+       /* FIXME
        if (start_midi_thread ()) {
                return -1;
        }
-
-       if (init_feedback ()) {
-               return -1;
-       }
+       */
 
        if (state_tree) {
                if (set_state (*state_tree->root())) {
@@ -339,11 +338,13 @@ Session::second_stage_init (bool new_session)
                first_time_running = _engine.Running.connect (mem_fun (*this, &Session::when_engine_running));
        }
 
-       send_full_time_code ();
+       // FIXME
+       //send_full_time_code ();
        _engine.transport_locate (0);
-       deliver_mmc (MIDI::MachineControl::cmdMmcReset, 0);
-       deliver_mmc (MIDI::MachineControl::cmdLocate, 0);
-       send_all_midi_feedback();
+       //deliver_mmc (MIDI::MachineControl::cmdMmcReset, 0);
+       //deliver_mmc (MIDI::MachineControl::cmdLocate, 0);
+
+       ControlProtocolManager::instance().set_session (*this);
 
        if (new_session) {
                _end_location_is_free = true;
@@ -401,13 +402,32 @@ Session::setup_raid_path (string path)
 
        if (colons == 0) {
 
-               /* no multiple search path, just one directory (common case) */
+               /* no multiple search path, just one location (common case) */
 
                sp.path = path;
                sp.blocks = 0;
                session_dirs.push_back (sp);
+
+               string fspath;
+
+               /* sounds dir */
+
+               fspath += sp.path;
+               if (fspath[fspath.length()-1] != '/') {
+                       fspath += '/';
+               }
+               fspath += sound_dir_name;
+               fspath += ':';
+
+               /* tape dir */
+
+               fspath += sp.path;
+               if (fspath[fspath.length()-1] != '/') {
+                       fspath += '/';
+               }
+               fspath += tape_dir_name;
                
-               FileSource::set_search_path (path + sound_dir_name);
+               FileSource::set_search_path (fspath);
 
                return;
        }
@@ -418,6 +438,9 @@ Session::setup_raid_path (string path)
                
                sp.blocks = 0;
                sp.path = remaining.substr (0, colon);
+               session_dirs.push_back (sp);
+
+               /* add sounds to file search path */
 
                fspath += sp.path;
                if (fspath[fspath.length()-1] != '/') {
@@ -426,7 +449,14 @@ Session::setup_raid_path (string path)
                fspath += sound_dir_name;
                fspath += ':';
 
-               session_dirs.push_back (sp);
+               /* add tape dir to file search path */
+
+               fspath += sp.path;
+               if (fspath[fspath.length()-1] != '/') {
+                       fspath += '/';
+               }
+               fspath += tape_dir_name;
+               fspath += ':';
 
                remaining = remaining.substr (colon+1);
        }
@@ -436,11 +466,19 @@ Session::setup_raid_path (string path)
                sp.blocks = 0;
                sp.path = remaining;
 
+               fspath += ':';
                fspath += sp.path;
                if (fspath[fspath.length()-1] != '/') {
                        fspath += '/';
                }
                fspath += sound_dir_name;
+               fspath += ':';
+
+               fspath += sp.path;
+               if (fspath[fspath.length()-1] != '/') {
+                       fspath += '/';
+               }
+               fspath += tape_dir_name;
 
                session_dirs.push_back (sp);
        }
@@ -681,7 +719,7 @@ Session::save_state (string snapshot_name, bool pending)
        if (!pending) {
 
                bool was_dirty = dirty();
-               
+
                _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty);
                
                if (was_dirty) {
@@ -985,6 +1023,12 @@ Session::load_options (const XMLNode& node)
                }
        }
 
+       if ((child = find_named_node (node, "end-marker-is-free")) != 0) {
+               if ((prop = child->property ("val")) != 0) {
+                       _end_location_is_free = (prop->value() == "yes");
+               }
+       }
+
        if ((child = find_named_node (node, "layer-model")) != 0) {
                if ((prop = child->property ("val")) != 0) {
                        if (prop->value() == X_("LaterHigher")) {
@@ -1170,6 +1214,8 @@ Session::get_options () const
        child->add_property ("val", get_crossfades_active () ? "yes" : "no");
        child = opthead->add_child ("audible-click");
        child->add_property ("val", get_clicking () ? "yes" : "no");
+       child = opthead->add_child ("end-marker-is-free");
+       child->add_property ("val", _end_location_is_free ? "yes" : "no");
 
        if (click_sound.length()) {
                child = opthead->add_child ("click-sound");
@@ -1232,7 +1278,7 @@ Session::get_template()
           sources in their state node. 
        */
        
-       disable_record ();
+       disable_record (false);
 
        return state(false);
 }
@@ -1298,10 +1344,18 @@ Session::state(bool full_state)
                        /* Don't save information about FileSources that are empty */
                        
                        FileSource* fs;
-                       
+
                        if ((fs = dynamic_cast<FileSource*> ((*siter).second)) != 0) {
-                               if (fs->length() == 0) {
-                                       continue;
+                               DestructiveFileSource* dfs = dynamic_cast<DestructiveFileSource*> (fs);
+
+                               /* destructive file sources are OK if they are empty, because
+                                  we will re-use them every time.
+                               */
+
+                               if (!dfs) {
+                                       if (fs->length() == 0) {
+                                               continue;
+                                       }
                                }
                        }
                        
@@ -2209,13 +2263,7 @@ Session::sound_dir () const
 string
 Session::tape_dir () const
 {
-       string res = Config->get_tape_dir();
-
-       if (!res.empty()) {
-               return res;
-       }
-
-       res = _path;
+       string res = _path;
        res += tape_dir_name;
        res += '/';
        return res;
@@ -2241,22 +2289,27 @@ Session::automation_dir () const
 string
 Session::template_dir ()
 {
-       string path = Config->get_user_ardour_path();
+       string path = get_user_ardour_path();
        path += "templates/";
 
        return path;
 }
 
 string
-Session::template_path ()
+Session::suffixed_search_path (string suffix, bool data)
 {
        string path;
 
-       path += Config->get_user_ardour_path();
+       path += get_user_ardour_path();
        if (path[path.length()-1] != ':') {
                path += ':';
        }
-       path += Config->get_system_ardour_path();
+
+       if (data) {
+               path += get_system_data_path();
+       } else {
+               path += get_system_module_path();
+       }
 
        vector<string> split_path;
        
@@ -2265,7 +2318,8 @@ Session::template_path ()
 
        for (vector<string>::iterator i = split_path.begin(); i != split_path.end(); ++i) {
                path += *i;
-               path += "templates/";
+               path += suffix;
+               path += '/';
                
                if (distance (i, split_path.end()) != 1) {
                        path += ':';
@@ -2275,6 +2329,18 @@ Session::template_path ()
        return path;
 }
 
+string
+Session::template_path ()
+{
+       return suffixed_search_path (X_("templates"), true);
+}
+
+string
+Session::control_protocol_path ()
+{
+       return suffixed_search_path (X_("surfaces"), false);
+}
+
 int
 Session::load_connections (const XMLNode& node)
 {
@@ -2314,18 +2380,18 @@ Session::load_route_groups (const XMLNode& node, bool edit)
 {
        XMLNodeList nlist = node.children();
        XMLNodeConstIterator niter;
-       RouteGroup* route;
+       RouteGroup* rg;
 
        set_dirty();
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                if ((*niter)->name() == "RouteGroup") {
                        if (edit) {
-                               route = add_edit_group ("");
-                               route->set_state (**niter);
+                               rg = add_edit_group ("");
+                               rg->set_state (**niter);
                        } else {
-                               route = add_mix_group ("");
-                               route->set_state (**niter);
+                               rg = add_mix_group ("");
+                               rg->set_state (**niter);
                        }
                }
        }
@@ -2654,7 +2720,7 @@ Session::get_template_list (list<string> &template_names)
 int
 Session::read_favorite_dirs (FavoriteDirs & favs)
 {
-       string path = Config->get_user_ardour_path();
+       string path = get_user_ardour_path();
        path += "/favorite_dirs";
 
        ifstream fav (path.c_str());
@@ -2689,7 +2755,7 @@ Session::read_favorite_dirs (FavoriteDirs & favs)
 int
 Session::write_favorite_dirs (FavoriteDirs & favs)
 {
-       string path = Config->get_user_ardour_path();
+       string path = get_user_ardour_path();
        path += "/favorite_dirs";
 
        ofstream fav (path.c_str());
@@ -3149,7 +3215,7 @@ void
 Session::set_dirty ()
 {
        bool was_dirty = dirty();
-       
+
        _state_of_the_state = StateOfTheState (_state_of_the_state | Dirty);
 
        if (!was_dirty) {