Can't call the wrong function when there's only one of them: remove ARDOUR::Parameter...
[ardour.git] / libs / ardour / session_state.cc
index c4448640fd438f827d4eb2499b6934976036c855..3d5e7fb24e37da9442284c228289cb3ec152e7e0 100644 (file)
@@ -64,6 +64,7 @@
 #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>
@@ -77,7 +78,6 @@
 #include <ardour/midi_source.h>
 #include <ardour/sndfile_helpers.h>
 #include <ardour/auditioner.h>
-#include <ardour/export.h>
 #include <ardour/io_processor.h>
 #include <ardour/send.h>
 #include <ardour/processor.h>
@@ -168,7 +168,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        pending_locate_frame = 0;
        pending_locate_roll = false;
        pending_locate_flush = false;
-       dstream_buffer_size = 0;
+       audio_dstream_buffer_size = 0;
+       midi_dstream_buffer_size = 0;
        state_tree = 0;
        state_was_pending = false;
        set_next_event ();
@@ -199,6 +200,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _play_range = false;
        waiting_to_start = false;
        _exporting = false;
+       _exporting_realtime = false;
        _gain_automation_buffer = 0;
        _pan_automation_buffer = 0;
        _npan_buffers = 0;
@@ -296,9 +298,9 @@ Session::second_stage_init (bool new_session)
                return -1;
        }
 
-       /*if (start_midi_thread ()) {
+       if (start_midi_thread ()) {
                return -1;
-       }*/
+       }
 
        // set_state() will call setup_raid_path(), but if it's a new session we need
        // to call setup_raid_path() here.
@@ -352,7 +354,7 @@ Session::second_stage_init (bool new_session)
 
        BootMessage (_("Reset Remote Controls"));
 
-       //send_full_time_code ();
+       send_full_time_code (0);
        _engine.transport_locate (0);
        deliver_mmc (MIDI::MachineControl::cmdMmcReset, 0);
        deliver_mmc (MIDI::MachineControl::cmdLocate, 0);
@@ -431,8 +433,9 @@ Session::setup_raid_path (string path)
        AudioFileSource::set_search_path (sound_search_path.to_string ());
        SMFSource::set_search_path (midi_search_path.to_string ());
 
+
        // reset the round-robin soundfile path thingie
-       
+
        last_rr_session_dir = session_dirs.begin();
 }
 
@@ -535,6 +538,10 @@ Session::create (bool& new_session, const string& mix_template, nframes_t initia
                }
 
        }
+       
+       /* Instantiate metadata */
+       
+       _metadata = new SessionMetadata ();
 
        /* set initial start + end point */
 
@@ -975,6 +982,8 @@ Session::state(bool full_state)
 
        node->add_child_nocopy (get_options());
 
+       node->add_child_nocopy (_metadata->get_state());
+
        child = node->add_child ("Sources");
 
        if (full_state) {
@@ -1200,6 +1209,7 @@ Session::set_state (const XMLNode& node)
        Path
        extra
        Options/Config
+       Metadata
        Locations
        Sources
        AudioRegions
@@ -1227,6 +1237,12 @@ Session::set_state (const XMLNode& node)
                error << _("Session: XML state has no options section") << endmsg;
        }
 
+       if ((child = find_named_node (node, "Metadata")) == 0) {
+               warning << _("Session: XML state has no metadata section (2.0 session?)") << endmsg;
+       } else if (_metadata->set_state (*child)) {
+               goto out;
+       }
+
        if ((child = find_named_node (node, "Locations")) == 0) {
                error << _("Session: XML state has no locations section") << endmsg;
                goto out;
@@ -1741,7 +1757,8 @@ Session::XMLSourceFactory (const XMLNode& node)
        }
 
        try {
-               return SourceFactory::create (*this, node);
+               /* note: do peak building in another thread when loading session state */
+               return SourceFactory::create (*this, node, true);
        }
 
        catch (failed_constructor& err) {
@@ -1792,6 +1809,43 @@ Session::save_template (string template_name)
        return 0;
 }
 
+int
+Session::rename_template (string old_name, string new_name) 
+{
+       sys::path old_path (user_template_directory());
+       old_path /= old_name + template_suffix;
+
+       sys::path new_path(user_template_directory());
+       new_path /= new_name + template_suffix;
+
+       if (sys::exists (new_path)) {
+               warning << string_compose(_("Template \"%1\" already exists - template not renamed"),
+                                         new_path.to_string()) << endmsg;
+               return -1;
+       }
+
+       try {
+               sys::rename (old_path, new_path);
+               return 0;
+       } catch (...) {
+               return -1;
+       }
+}
+
+int
+Session::delete_template (string name) 
+{
+       sys::path path = user_template_directory();
+       path /= name + template_suffix;
+
+       try {
+               sys::remove (path);
+               return 0;
+       } catch (...) {
+               return -1;
+       }
+}
+
 void
 Session::refresh_disk_space ()
 {
@@ -2007,17 +2061,13 @@ Session::XMLNamedSelectionFactory (const XMLNode& node)
 string
 Session::automation_dir () const
 {
-       string res = _path;
-       res += "automation/";
-       return res;
+       return Glib::build_filename (_path, "automation");
 }
 
 string
 Session::analysis_dir () const
 {
-       string res = _path;
-       res += "analysis/";
-       return res;
+       return Glib::build_filename (_path, "analysis");
 }
 
 int
@@ -2859,10 +2909,12 @@ Session::controllable_by_id (const PBD::ID& id)
 }
 
 void 
-Session::add_instant_xml (XMLNode& node)
+Session::add_instant_xml (XMLNode& node, bool write_to_config)
 {
        Stateful::add_instant_xml (node, _path);
-       Config->add_instant_xml (node);
+       if (write_to_config) {
+               Config->add_instant_xml (node);
+       }
 }
 
 XMLNode*
@@ -2988,8 +3040,16 @@ Session::restore_history (string snapshot_name)
                                    ut->add_command (c);
                            }
                            
+                   } else if (n->name() == "DeltaCommand") {
+                        PBD::ID  id(n->property("midi_source")->value());
+                        boost::shared_ptr<MidiSource> midi_source = 
+                                boost::dynamic_pointer_cast<MidiSource, Source>(source_by_id(id));
+                        if(midi_source) {
+                                ut->add_command(new MidiModel::DeltaCommand(midi_source->model(), *n));                                 
+                        } else {
+                                error << "FIXME: Failed to downcast MidiSource for DeltaCommand" << endmsg;
+                        }
                    } else {
-
                            error << string_compose(_("Couldn't figure out how to make a Command out of a %1 XMLNode."), n->name()) << endmsg;
                    }
            }