the BIG CONFIG patch
[ardour.git] / libs / ardour / ardour / session.h
index dbcd830a044add00e709dae1ab57cdc26ab4e700..36a8393ccdffcf0c4ee58a08c7c87c944b2cd42e 100644 (file)
 #ifndef __ardour_session_h__
 #define __ardour_session_h__
 
+
 #include <string>
 #include <list>
 #include <map>
 #include <vector>
 #include <set>
 #include <stack>
+
+#include <boost/weak_ptr.hpp>
+
 #include <stdint.h>
 
 #include <sndfile.h>
 #include <pbd/undo.h>
 #include <pbd/pool.h>
 #include <pbd/rcu.h>
+#include <pbd/statefuldestructible.h>
 
 #include <midi++/types.h>
 #include <midi++/mmc.h>
 
 #include <pbd/stateful.h> 
+#include <pbd/destructible.h> 
 
 #include <ardour/ardour.h>
 #include <ardour/configuration.h>
@@ -66,6 +72,7 @@ namespace ARDOUR {
 class Port;
 class AudioEngine;
 class Slave;
+class Diskstream;      
 class AudioDiskstream; 
 class Route;
 class AuxInput;
@@ -93,11 +100,10 @@ struct RouteGroup;
 
 using std::vector;
 using std::string;
-using std::list;
 using std::map;
 using std::set;
 
-class Session : public sigc::trackable, public Stateful
+class Session : public sigc::trackable, public PBD::StatefulDestructible
 
 {
   private:
@@ -113,17 +119,6 @@ class Session : public sigc::trackable, public Stateful
                Recording = 2
        };
 
-       enum SlaveSource {
-               None = 0,
-               MTC,
-               JACK
-       };
-       
-       enum AutoConnectOption {
-               AutoConnectPhysical = 0x1,
-               AutoConnectMaster = 0x2
-       };
-
        struct Event {
            enum Type {
                    SetTransportSpeed,
@@ -157,19 +152,21 @@ class Session : public sigc::trackable, public Stateful
                    Clear
            };
 
-           Type                type;
-           Action              action;
-           jack_nframes_t      action_frame;
-           jack_nframes_t      target_frame;
-           float               speed;
+           Type           type;
+           Action         action;
+           jack_nframes_t action_frame;
+           jack_nframes_t target_frame;
+           float          speed;
 
            union {
-               void*                ptr;
-               bool                 yes_or_no;
-               Session::SlaveSource slave;
-               Route*               route;
+                       void*                ptr;
+                       bool                 yes_or_no;
+                       SlaveSource slave;
+                       Route*               route;
            };
 
+           boost::shared_ptr<Region>   region;
+
            list<AudioRange>     audio_range;
            list<MusicRange>     music_range;
 
@@ -239,6 +236,7 @@ class Session : public sigc::trackable, public Stateful
        string path() const { return _path; }
        string name() const { return _name; }
        string snap_name() const { return _current_snapshot_name; }
+       string raid_path () const;
 
        void set_snap_name ();
 
@@ -247,12 +245,13 @@ class Session : public sigc::trackable, public Stateful
        bool dirty() const { return _state_of_the_state & Dirty; }
        sigc::signal<void> DirtyChanged;
 
-       std::string sound_dir () const;
-       std::string tape_dir () const;
+       std::string sound_dir (bool with_path = true) const;
        std::string peak_dir () const;
        std::string dead_sound_dir () const;
        std::string automation_dir () const;
 
+       string peak_path_from_audio_path (string) const;
+
        static string suffixed_search_path (std::string suffix, bool data);
        static string control_protocol_path ();
        static string template_path ();
@@ -260,7 +259,6 @@ class Session : public sigc::trackable, public Stateful
        static void get_template_list (list<string>&);
        
        static string change_audio_path_by_name (string oldpath, string oldname, string newname, bool destructive);
-       static string peak_path_from_audio_path (string);
        string audio_path_from_name (string, uint32_t nchans, uint32_t chan, bool destructive);
 
        void process (jack_nframes_t nframes);
@@ -269,32 +267,20 @@ class Session : public sigc::trackable, public Stateful
        vector<Sample*>& get_silent_buffers (uint32_t howmany);
        vector<Sample*>& get_send_buffers () { return _send_buffers; }
 
-       AudioDiskstream    *diskstream_by_id (const PBD::ID& id);
-       AudioDiskstream    *diskstream_by_name (string name);
+       void add_diskstream (boost::shared_ptr<Diskstream>);
+       boost::shared_ptr<Diskstream> diskstream_by_id (const PBD::ID& id);
+       boost::shared_ptr<Diskstream> diskstream_by_name (string name);
 
        bool have_captured() const { return _have_captured; }
 
        void refill_all_diskstream_buffers ();
        uint32_t diskstream_buffer_size() const { return dstream_buffer_size; }
        
-       /* XXX fix required here when we get new diskstream types *, but
-          not sure of the direction to take this in until then.
-       */
-
-       uint32_t get_next_diskstream_id() const { return n_audio_diskstreams(); }
-       uint32_t n_audio_diskstreams() const;
+       uint32_t get_next_diskstream_id() const { return n_diskstreams(); }
+       uint32_t n_diskstreams() const;
        
-       typedef list<AudioDiskstream *> AudioDiskstreamList;
-
-       Session::AudioDiskstreamList audio_disk_streams() const {
-               Glib::RWLock::ReaderLock lm (diskstream_lock);
-               return audio_diskstreams; /* XXX yes, force a copy */
-       }
-
-       void foreach_audio_diskstream (void (AudioDiskstream::*func)(void));
-       template<class T> void foreach_audio_diskstream (T *obj, void (T::*func)(AudioDiskstream&));
-
-       typedef std::list<boost::shared_ptr<Route> > RouteList; 
+       typedef std::list<boost::shared_ptr<Diskstream> > DiskstreamList;
+       typedef std::list<boost::shared_ptr<Route> >      RouteList; 
 
        boost::shared_ptr<RouteList> get_routes() const {
                return routes.reader ();
@@ -313,6 +299,7 @@ class Session : public sigc::trackable, public Stateful
        template<class T, class A> void foreach_route (T *obj, void (T::*func)(Route&, A), A arg);
 
        boost::shared_ptr<Route> route_by_name (string);
+       boost::shared_ptr<Route> route_by_id (PBD::ID);
        boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
 
        bool route_name_unique (string) const;
@@ -334,11 +321,9 @@ class Session : public sigc::trackable, public Stateful
        void disable_record (bool rt_context, bool force = false);
        void step_back_from_record ();
        
-       sigc::signal<void> going_away;
-
        /* Proxy signal for region hidden changes */
 
-       sigc::signal<void,Region*> RegionHiddenChange;
+       sigc::signal<void,boost::shared_ptr<Region> > RegionHiddenChange;
 
        /* Emitted when all i/o connections are complete */
        
@@ -355,37 +340,38 @@ class Session : public sigc::trackable, public Stateful
        sigc::signal<void> DurationChanged;
        sigc::signal<void> HaltOnXrun;
 
-       sigc::signal<void,boost::shared_ptr<Route> > RouteAdded;
-       sigc::signal<void,AudioDiskstream*> AudioDiskstreamAdded;
+       sigc::signal<void,RouteList&> RouteAdded;
 
        void request_roll ();
        void request_bounded_roll (jack_nframes_t start, jack_nframes_t end);
        void request_stop (bool abort = false);
        void request_locate (jack_nframes_t frame, bool with_roll = false);
-       void request_auto_loop (bool yn);
+       void request_play_loop (bool yn);
        jack_nframes_t  last_transport_start() const { return _last_roll_location; }
        void goto_end ()   { request_locate (end_location->start(), false);}
        void goto_start () { request_locate (start_location->start(), false); }
+       void set_session_start (jack_nframes_t start) { start_location->set_start(start); }
+       void set_session_end (jack_nframes_t end) { end_location->set_start(end); _end_location_is_free = false; }
        void use_rf_shuttle_speed ();
        void request_transport_speed (float speed);
-       void request_overwrite_buffer (AudioDiskstream*);
-       void request_diskstream_speed (AudioDiskstream&, float speed);
+       void request_overwrite_buffer (Diskstream*);
+       void request_diskstream_speed (Diskstream&, float speed);
        void request_input_change_handling ();
 
        bool locate_pending() const { return static_cast<bool>(post_transport_work&PostTransportLocate); }
        bool transport_locked () const;
 
        int wipe ();
-       int wipe_diskstream (AudioDiskstream *);
 
-       int remove_region_from_region_list (Region&);
+       int remove_region_from_region_list (boost::shared_ptr<Region>);
 
        jack_nframes_t get_maximum_extent () const;
        jack_nframes_t current_end_frame() const { return end_location->start(); }
        jack_nframes_t current_start_frame() const { return start_location->start(); }
        jack_nframes_t frame_rate() const   { return _current_frame_rate; }
-       double frames_per_smpte_frame() const { return _frames_per_smpte_frame; }
        jack_nframes_t frames_per_hour() const { return _frames_per_hour; }
+
+       double frames_per_smpte_frame() const { return _frames_per_smpte_frame; }
        jack_nframes_t smpte_frames_per_hour() const { return _smpte_frames_per_hour; }
 
        /* Locations */
@@ -399,83 +385,7 @@ class Session : public sigc::trackable, public Stateful
        void set_auto_punch_location (Location *);
        void set_auto_loop_location (Location *);
 
-
-       enum ControlType {
-               AutoPlay,
-               AutoLoop,
-               AutoReturn,
-               AutoInput,
-               PunchIn,
-               PunchOut,
-               SendMTC,
-               MMCControl,
-               SoloLatch,
-               SoloingModel,
-               RecordingPlugins,
-               CrossFadesActive,
-               SendMMC,
-               SlaveType,
-               Clicking,
-               EditingMode,
-               PlayRange,
-               LayeringModel,
-               CrossfadingModel,
-               SeamlessLoop,
-               MidiFeedback,
-               MidiControl,
-               TranzportControl,
-               Feedback
-       };
-
-       sigc::signal<void,ControlType> ControlChanged;
-
-       void set_auto_play (bool yn);
-       void set_auto_return (bool yn);
-       void set_auto_input (bool yn);
        void reset_input_monitor_state ();
-       void set_input_auto_connect (bool yn);
-       void set_output_auto_connect (AutoConnectOption);
-       void set_punch_in (bool yn);
-       void set_punch_out (bool yn);
-       void set_send_mtc (bool yn);
-       void set_send_mmc (bool yn);
-       void set_mmc_control (bool yn);
-       void set_midi_feedback (bool yn);
-       void set_midi_control (bool yn);
-       void set_do_not_record_plugins (bool yn);
-       void set_crossfades_active (bool yn);
-       void set_seamless_loop (bool yn);
-
-       bool get_auto_play () const { return auto_play; }
-       bool get_auto_input () const { return auto_input; }
-       bool get_auto_loop () const { return auto_loop; }
-       bool get_seamless_loop () const { return seamless_loop; }
-       bool get_punch_in () const { return punch_in; }
-       bool get_punch_out () const { return punch_out; }
-       bool get_all_safe () const { return all_safe; }
-       bool get_auto_return () const { return auto_return; }
-       bool get_send_mtc () const;
-       bool get_send_mmc () const;
-       bool get_mmc_control () const;
-       bool get_midi_feedback () const;
-       bool get_midi_control () const;
-       bool get_do_not_record_plugins () const { return do_not_record_plugins; }
-       bool get_crossfades_active () const { return crossfades_active; }
-
-       bool get_input_auto_connect () const;
-       AutoConnectOption get_output_auto_connect () const { return output_auto_connect; }
-
-       enum LayerModel {
-               LaterHigher,
-               MoveAddHigher,
-               AddHigher
-       };
-
-       void set_layer_model (LayerModel);
-       LayerModel get_layer_model () const { return layer_model; }
-
-       void set_xfade_model (CrossfadeModel);
-       CrossfadeModel get_xfade_model () const { return xfade_model; }
 
        void add_event (jack_nframes_t action_frame, Event::Type type, jack_nframes_t target_frame = 0);
        void remove_event (jack_nframes_t frame, Event::Type type);
@@ -489,6 +399,8 @@ class Session : public sigc::trackable, public Stateful
        int save_state (string snapshot_name, bool pending = false);
        int restore_state (string snapshot_name);
        int save_template (string template_name);
+        int save_history (string snapshot_name = "");
+        int restore_history (string snapshot_name);
 
        static int rename_template (string old_name, string new_name);
 
@@ -501,7 +413,7 @@ class Session : public sigc::trackable, public Stateful
        static vector<string*>* possible_states(string path);
 
        XMLNode& get_state();
-       int      set_state(const XMLNode& node);
+       int      set_state(const XMLNode& node); // not idempotent
        XMLNode& get_template();
 
        void add_instant_xml (XMLNode&, const std::string& dir);
@@ -546,55 +458,53 @@ class Session : public sigc::trackable, public Stateful
 
        /* fundamental operations. duh. */
 
-       boost::shared_ptr<AudioTrack> new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal);
-       boost::shared_ptr<Route>      new_audio_route (int input_channels, int output_channels);
+       std::list<boost::shared_ptr<AudioTrack> > new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal, uint32_t how_many = 1);
+       RouteList new_audio_route (int input_channels, int output_channels, uint32_t how_many);
 
        void   remove_route (boost::shared_ptr<Route>);
 
        void   resort_routes ();
        void   resort_routes_using (boost::shared_ptr<RouteList>);
-       void   resort_routes_proxy (void* src) {
-               resort_routes ();
-       }
 
        AudioEngine &engine() { return _engine; };
 
-       /* configuration. there should really be accessors/mutators
-          for these 
-       */
-
-       float   meter_hold () { return _meter_hold; }
-       void    set_meter_hold (float);
-       sigc::signal<void> MeterHoldChanged;
-
-       float   meter_falloff () { return _meter_falloff; }
-       void    set_meter_falloff (float);
-       sigc::signal<void> MeterFalloffChanged;
-       
        int32_t  max_level;
        int32_t  min_level;
-       string  click_emphasis_sound;
-       string  click_sound;
-       bool    click_requested;
-       jack_nframes_t over_length_short;
-       jack_nframes_t over_length_long;
-       bool    send_midi_timecode;
-       bool    send_midi_machine_control;
-       float   shuttle_speed_factor;
-       float   shuttle_speed_threshold;
-       float   rf_speed;
-       float   smpte_frames_per_second;
-       bool    smpte_drop_frames;
-       AnyTime preroll;
-       AnyTime postroll;
-       
+
        /* Time */
 
        jack_nframes_t transport_frame () const {return _transport_frame; }
        jack_nframes_t audible_frame () const;
 
+       enum SmpteFormat {
+               smpte_23976,
+               smpte_24,
+               smpte_24976,
+               smpte_25,
+               smpte_2997,
+               smpte_2997drop,
+               smpte_30,
+               smpte_30drop,
+               smpte_5994,
+               smpte_60,
+       };
+
+       enum PullupFormat {
+               pullup_Plus4Plus1,
+               pullup_Plus4,
+               pullup_Plus4Minus1,
+               pullup_Plus1,
+               pullup_None,
+               pullup_Minus1,
+               pullup_Minus4Plus1,
+               pullup_Minus4,
+               pullup_Minus4Minus1,
+       };
+
        int  set_smpte_type (float fps, bool drop_frames);
 
+       void sync_time_vars();
+
        void bbt_time (jack_nframes_t when, BBT_Time&);
        void smpte_to_sample( SMPTE::Time& smpte, jack_nframes_t& sample, bool use_offset, bool use_subframes ) const;
        void sample_to_smpte( jack_nframes_t sample, SMPTE::Time& smpte, bool use_offset, bool use_subframes ) const;
@@ -612,12 +522,13 @@ class Session : public sigc::trackable, public Stateful
 
        jack_nframes_t convert_to_frames_at (jack_nframes_t position, AnyTime&);
 
+       static sigc::signal<void> StartTimeChanged;
+       static sigc::signal<void> EndTimeChanged;
        static sigc::signal<void> SMPTEOffsetChanged;
-       sigc::signal<void> SMPTETypeChanged;
 
-       void        request_slave_source (SlaveSource, jack_nframes_t pos = 0);
-       SlaveSource slave_source() const { return _slave_type; }
-       bool        synced_to_jack() const { return _slave_type == JACK; }
+       void        request_slave_source (SlaveSource);
+       bool        synced_to_jack() const { return Config->get_slave_source() == JACK; }
+
        float       transport_speed() const { return _transport_speed; }
        bool        transport_stopped() const { return _transport_speed == 0.0f; }
        bool        transport_rolling() const { return _transport_speed != 0.0f; }
@@ -628,19 +539,19 @@ class Session : public sigc::trackable, public Stateful
        
        /* region info  */
 
-       sigc::signal<void,AudioRegion *> AudioRegionAdded;
-       sigc::signal<void,AudioRegion *> AudioRegionRemoved;
+       sigc::signal<void,boost::shared_ptr<AudioRegion> > AudioRegionAdded;
+       sigc::signal<void,boost::shared_ptr<AudioRegion> > AudioRegionRemoved;
 
        int region_name (string& result, string base = string(""), bool newlevel = false) const;
        string new_region_name (string);
        string path_from_region_name (string name, string identifier);
 
-       AudioRegion* find_whole_file_parent (AudioRegion&);
-       void find_equivalent_playlist_regions (AudioRegion&, std::vector<AudioRegion*>& result);
+       boost::shared_ptr<AudioRegion> find_whole_file_parent (boost::shared_ptr<AudioRegion>);
+       void find_equivalent_playlist_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >& result);
 
-       AudioRegion *XMLRegionFactory (const XMLNode&, bool full);
+       boost::shared_ptr<AudioRegion> XMLRegionFactory (const XMLNode&, bool full);
 
-       template<class T> void foreach_audio_region (T *obj, void (T::*func)(AudioRegion *));
+       template<class T> void foreach_audio_region (T *obj, void (T::*func)(boost::shared_ptr<AudioRegion>));
 
        /* source management */
 
@@ -654,7 +565,7 @@ class Session : public sigc::trackable, public Stateful
            string pathname;
            
            /* result */
-           std::vector<AudioRegion*> new_regions;
+           std::vector<boost::shared_ptr<AudioRegion> > new_regions;
            
        };
 
@@ -662,15 +573,15 @@ class Session : public sigc::trackable, public Stateful
        bool sample_rate_convert (import_status&, string infile, string& outfile);
        string build_tmp_convert_name (string file);
 
-       Session::SlaveSource post_export_slave;
+       SlaveSource post_export_slave;
        jack_nframes_t post_export_position;
 
        int start_audio_export (ARDOUR::AudioExportSpecification&);
        int stop_audio_export (ARDOUR::AudioExportSpecification&);
        
-       void add_audio_source (AudioSource *);
-       void remove_source (Source *);
-       int  cleanup_audio_file_source (AudioFileSource&);
+       void add_source (boost::shared_ptr<Source>);
+       void remove_source (boost::weak_ptr<Source>);
+       int  cleanup_audio_file_source (boost::shared_ptr<AudioFileSource>);
 
        struct cleanup_report {
            vector<string> paths;
@@ -680,8 +591,8 @@ class Session : public sigc::trackable, public Stateful
        int  cleanup_sources (cleanup_report&);
        int  cleanup_trash_sources (cleanup_report&);
 
-       int destroy_region (Region*);
-       int destroy_regions (list<Region*>);
+       int destroy_region (boost::shared_ptr<Region>);
+       int destroy_regions (std::list<boost::shared_ptr<Region> >);
 
        int remove_last_capture ();
 
@@ -699,12 +610,12 @@ class Session : public sigc::trackable, public Stateful
 
        static sigc::signal<int> AskAboutPendingState;
        
-       sigc::signal<void,Source *> SourceAdded;
-       sigc::signal<void,Source *> SourceRemoved;
+       sigc::signal<void,boost::shared_ptr<Source> > SourceAdded;
+       sigc::signal<void,boost::shared_ptr<Source> > SourceRemoved;
 
-       AudioFileSource *create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive);
+       boost::shared_ptr<AudioFileSource> create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive);
 
-       Source *source_by_id (const PBD::ID&);
+       boost::shared_ptr<Source> source_by_id (const PBD::ID&);
 
        /* playlist management */
 
@@ -713,8 +624,6 @@ class Session : public sigc::trackable, public Stateful
        sigc::signal<void,Playlist*> PlaylistAdded;
        sigc::signal<void,Playlist*> PlaylistRemoved;
 
-       Playlist *get_playlist (string name);
-
        uint32_t n_playlists() const;
 
        template<class T> void foreach_playlist (T *obj, void (T::*func)(Playlist *));
@@ -729,6 +638,10 @@ class Session : public sigc::trackable, public Stateful
        sigc::signal<void> NamedSelectionAdded;
        sigc::signal<void> NamedSelectionRemoved;
 
+        /* Curves and AutomationLists (TODO when they go away) */
+        void add_curve(Curve*);
+        void add_automation_list(AutomationList*);
+
        /* fade curves */
 
        float get_default_fade_length () const { return default_fade_msecs; }
@@ -739,7 +652,7 @@ class Session : public sigc::trackable, public Stateful
 
        boost::shared_ptr<Auditioner> the_auditioner() { return auditioner; }
        void audition_playlist ();
-       void audition_region (AudioRegion&);
+       void audition_region (boost::shared_ptr<Region>);
        void cancel_audition ();
        bool is_auditioning () const;
        
@@ -747,25 +660,14 @@ class Session : public sigc::trackable, public Stateful
 
        /* flattening stuff */
 
-       int write_one_audio_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt, bool overwrite, vector<AudioSource*>&,
+       int write_one_audio_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt, bool overwrite, vector<boost::shared_ptr<AudioSource> >&,
                                   InterThreadInfo& wot);
        int freeze (InterThreadInfo&);
 
        /* session-wide solo/mute/rec-enable */
-
-       enum SoloModel {
-               InverseMute,
-               SoloBus
-       };
        
        bool soloing() const { return currently_soloing; }
 
-       SoloModel solo_model() const { return _solo_model; }
-       void set_solo_model (SoloModel);
-
-       bool solo_latched() const { return _solo_latched; }
-       void set_solo_latched (bool yn);
-       
        void set_all_solo (bool);
        void set_all_mute (bool);
 
@@ -803,7 +705,7 @@ class Session : public sigc::trackable, public Stateful
        sigc::signal<void,Connection *> ConnectionRemoved;
 
        /* MIDI */
-       
+
        int set_mtc_port (string port_tag);
        int set_mmc_port (string port_tag);
        int set_midi_port (string port_tag);
@@ -847,55 +749,89 @@ class Session : public sigc::trackable, public Stateful
        string next_undo() const { return history.next_undo(); }
        string next_redo() const { return history.next_redo(); }
 
-       void begin_reversible_command (string cmd_name, UndoAction *private_undo = 0);
-       void commit_reversible_command (UndoAction* private_redo = 0);
+       void begin_reversible_command (string cmd_name);
+       void commit_reversible_command (Command* cmd = 0);
 
-       void add_undo (const UndoAction& ua) {
-               current_cmd.add_undo (ua);
-       }
-       void add_redo (const UndoAction& ua) {
-               current_cmd.add_redo (ua);
-       }
-       void add_redo_no_execute (const UndoAction& ua) {
-               current_cmd.add_redo_no_execute (ua);
+       void add_command (Command *const cmd) {
+               current_trans->add_command (cmd);
        }
 
-       UndoAction global_solo_memento (void *src);
-       UndoAction global_mute_memento (void *src);
-       UndoAction global_record_enable_memento (void *src);
-       UndoAction global_metering_memento (void *src);
-
-       /* edit mode */
-
-       void set_edit_mode (EditMode);
-       EditMode get_edit_mode () const { return _edit_mode; }
+       std::map<PBD::ID, PBD::StatefulDestructible*> registry;
+
+        // these commands are implemented in libs/ardour/session_command.cc
+       Command *memento_command_factory(XMLNode *n);
+        void register_with_memento_command_factory(PBD::ID, PBD::StatefulDestructible *);
+
+        class GlobalSoloStateCommand : public Command
+        {
+            GlobalRouteBooleanState before, after;
+            Session &sess;
+            void *src;
+        public:
+            GlobalSoloStateCommand(Session &, void *src);
+            void operator()();
+            void undo();
+            XMLNode &get_state();
+            void mark();
+        };
+
+        class GlobalMuteStateCommand : public Command
+        {
+            GlobalRouteBooleanState before, after;
+            Session &sess;
+            void *src;
+        public:
+            GlobalMuteStateCommand(Session &, void *src);
+            void operator()();
+            void undo();
+            XMLNode &get_state();
+            void mark();
+        };
+
+        class GlobalRecordEnableStateCommand : public Command
+        {
+            GlobalRouteBooleanState before, after;
+            Session &sess;
+            void *src;
+        public:
+            GlobalRecordEnableStateCommand(Session &, void *src);
+            void operator()();
+            void undo();
+            XMLNode &get_state();
+            void mark();
+        };
+
+        class GlobalMeteringStateCommand : public Command
+        {
+            GlobalRouteMeterState before, after;
+            Session &sess;
+            void *src;
+        public:
+            GlobalMeteringStateCommand(Session &, void *src);
+            void operator()();
+            void undo();
+            XMLNode &get_state();
+            void mark();
+        };
 
        /* clicking */
 
        boost::shared_ptr<IO>  click_io() { return _click_io; }
-       void set_clicking (bool yn);
-       bool get_clicking() const;
-
-       void set_click_sound (string path);
-       void set_click_emphasis_sound (string path);
                
        /* tempo FX */
 
        struct TimeStretchRequest {
-           ARDOUR::AudioRegion* region;
+           boost::shared_ptr<ARDOUR::AudioRegion> region;
            float                fraction; /* session: read ; GUI: write */
            float                progress; /* session: write ; GUI: read */
            bool                 running;  /* read/write */
            bool                 quick_seek; /* GUI: write */
            bool                 antialias;  /* GUI: write */
 
-           TimeStretchRequest () : region (0) {}
+           TimeStretchRequest () {} 
        };
 
-       AudioRegion* tempoize_region (TimeStretchRequest&);
-
-       string raid_path() const;
-       void   set_raid_path(string);
+       boost::shared_ptr<AudioRegion> tempoize_region (TimeStretchRequest&);
 
        /* need to call this whenever we change native file formats */
 
@@ -947,8 +883,6 @@ class Session : public sigc::trackable, public Stateful
                ExportContext
        };
        
-       char *  conversion_buffer(RunContext context) { return _conversion_buffers[context]; }
-       
        /* VST support */
 
        static long vst_callback (AEffect* effect,
@@ -980,7 +914,7 @@ class Session : public sigc::trackable, public Stateful
        void set_frame_rate (jack_nframes_t nframes);
 
   protected:
-       friend class AudioDiskstream;
+       friend class Diskstream;
        void stop_butler ();
        void wait_till_butler_finished();
 
@@ -1015,14 +949,15 @@ class Session : public sigc::trackable, public Stateful
        mutable gint            processing_prohibited;
        process_function_type    process_function;
        process_function_type    last_process_function;
-       jack_nframes_t          _current_frame_rate;
+       bool                     waiting_for_sync_offset;
+       jack_nframes_t          _base_frame_rate;
+       jack_nframes_t          _current_frame_rate;  //this includes video pullup offset
        int                      transport_sub_state;
        mutable gint           _record_status;
        jack_nframes_t          _transport_frame;
        Location*                end_location;
        Location*                start_location;
        Slave                  *_slave;
-       SlaveSource             _slave_type;
        volatile float          _transport_speed;
        volatile float          _desired_transport_speed;
        float                   _last_transport_speed;
@@ -1032,7 +967,6 @@ class Session : public sigc::trackable, public Stateful
        vector<Sample *>        _passthru_buffers;
        vector<Sample *>        _silent_buffers;
        vector<Sample *>        _send_buffers;
-       map<RunContext,char*>   _conversion_buffers;
        jack_nframes_t           current_block_size;
        jack_nframes_t          _worst_output_latency;
        jack_nframes_t          _worst_input_latency;
@@ -1077,6 +1011,7 @@ class Session : public sigc::trackable, public Stateful
 
        void reset_slave_state ();
        bool follow_slave (jack_nframes_t, jack_nframes_t);
+       void set_slave_source (SlaveSource);
 
        bool _exporting;
        int prepare_to_export (ARDOUR::AudioExportSpecification&);
@@ -1090,7 +1025,7 @@ class Session : public sigc::trackable, public Stateful
                if (actively_recording()) {
                        return true;
                } else {
-                       if (auto_input) {
+                       if (Config->get_auto_input()) {
                                return false;
                        } else {
                                return true;
@@ -1118,6 +1053,8 @@ class Session : public sigc::trackable, public Stateful
                return false;
        }
 
+       bool maybe_sync_start (jack_nframes_t&, jack_nframes_t&);
+
        void check_declick_out ();
 
        MIDI::MachineControl*    mmc;
@@ -1126,26 +1063,12 @@ class Session : public sigc::trackable, public Stateful
        MIDI::Port*             _midi_port;
        string                  _path;
        string                  _name;
-       bool                     do_not_record_plugins;
-
-       /* toggles */
-
-       bool auto_play;
-       bool punch_in;
-       bool punch_out;
-       bool auto_loop;
-       bool seamless_loop;
-       bool loop_changing;
-       jack_nframes_t last_loopend;
-       bool auto_input;
-       bool crossfades_active;
-       bool all_safe;
-       bool auto_return;
-       bool monitor_in;
-       bool send_mtc;
-       bool send_mmc;
-       bool mmc_control;
-       bool midi_control;
+       bool                     session_send_mmc;
+       bool                     session_send_mtc;
+       bool                     session_midi_feedback;
+       bool                     play_loop;
+       bool                     loop_changing;
+       jack_nframes_t           last_loopend;
 
        RingBuffer<Event*> pending_events;
 
@@ -1441,13 +1364,13 @@ class Session : public sigc::trackable, public Stateful
 
        bool waiting_to_start;
 
-       void set_auto_loop (bool yn);
-       void overwrite_some_buffers (AudioDiskstream*);
+       void set_play_loop (bool yn);
+       void overwrite_some_buffers (Diskstream*);
        void flush_all_redirects ();
        void locate (jack_nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void start_locate (jack_nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void force_locate (jack_nframes_t frame, bool with_roll = false);
-       void set_diskstream_speed (AudioDiskstream*, float speed);
+       void set_diskstream_speed (Diskstream*, float speed);
        void set_transport_speed (float speed, bool abort = false);
        void stop_transport (bool abort = false);
        void start_transport ();
@@ -1478,17 +1401,16 @@ class Session : public sigc::trackable, public Stateful
 
        /* disk-streams */
 
-       AudioDiskstreamList  audio_diskstreams; 
-       mutable Glib::RWLock diskstream_lock;
+       SerializedRCUManager<DiskstreamList>  diskstreams; 
+
        uint32_t dstream_buffer_size;
-       void add_diskstream (AudioDiskstream*);
        int  load_diskstreams (const XMLNode&);
 
        /* routes stuff */
 
        SerializedRCUManager<RouteList>  routes;
 
-       void   add_route (boost::shared_ptr<Route>);
+       void   add_routes (RouteList&, bool save = true);
        uint32_t destructive_index;
 
        int load_routes (const XMLNode&);
@@ -1511,27 +1433,27 @@ class Session : public sigc::trackable, public Stateful
        /* REGION MANAGEMENT */
 
        mutable Glib::Mutex region_lock;
-       typedef map<PBD::ID,AudioRegion *> AudioRegionList;
+       typedef map<PBD::ID,boost::shared_ptr<AudioRegion> > AudioRegionList;
        AudioRegionList audio_regions;
        
-       void region_renamed (Region *);
-       void region_changed (Change, Region *);
-       void add_region (Region *);
-       void remove_region (Region *);
+       void region_renamed (boost::shared_ptr<Region>);
+       void region_changed (Change, boost::shared_ptr<Region>);
+       void add_region (boost::shared_ptr<Region>);
+       void remove_region (boost::shared_ptr<Region>);
 
        int load_regions (const XMLNode& node);
 
        /* SOURCES */
        
        mutable Glib::Mutex audio_source_lock;
-       typedef std::map<PBD::ID,AudioSource *> AudioSourceList;
+       typedef std::map<PBD::ID,boost::shared_ptr<AudioSource> > AudioSourceList;
 
        AudioSourceList audio_sources;
 
        int load_sources (const XMLNode& node);
        XMLNode& get_sources_as_xml ();
 
-       Source *XMLSourceFactory (const XMLNode&);
+       boost::shared_ptr<Source> XMLSourceFactory (const XMLNode&);
 
        /* PLAYLISTS */
        
@@ -1549,7 +1471,7 @@ class Session : public sigc::trackable, public Stateful
        Playlist *XMLPlaylistFactory (const XMLNode&);
 
        void playlist_length_changed (Playlist *);
-       void diskstream_playlist_changed (AudioDiskstream *);
+       void diskstream_playlist_changed (boost::shared_ptr<Diskstream>);
 
        /* NAMED SELECTIONS */
 
@@ -1562,6 +1484,10 @@ class Session : public sigc::trackable, public Stateful
        NamedSelection *named_selection_factory (string name);
        NamedSelection *XMLNamedSelectionFactory (const XMLNode&);
 
+        /* CURVES and AUTOMATION LISTS */
+        std::map<PBD::ID, Curve*> curves;
+        std::map<PBD::ID, AutomationList*> automation_lists;
+
        /* DEFAULT FADE CURVES */
 
        float default_fade_steepness;
@@ -1570,9 +1496,9 @@ class Session : public sigc::trackable, public Stateful
        /* AUDITIONING */
 
        boost::shared_ptr<Auditioner> auditioner;
-       void set_audition (AudioRegion*);
+       void set_audition (boost::shared_ptr<Region>);
        void non_realtime_set_audition ();
-       AudioRegion *pending_audition_region;
+       boost::shared_ptr<Region> pending_audition_region;
 
        /* EXPORT */
 
@@ -1615,9 +1541,10 @@ class Session : public sigc::trackable, public Stateful
        uint32_t _total_free_4k_blocks;
        Glib::Mutex space_lock;
 
+       static const char* old_sound_dir_name;
        static const char* sound_dir_name;
-       static const char* tape_dir_name;
        static const char* dead_sound_dir_name;
+       static const char* interchange_dir_name;
        static const char* peak_dir_name;
 
        string discover_best_sound_dir (bool destructive = false);
@@ -1636,12 +1563,10 @@ class Session : public sigc::trackable, public Stateful
        ConnectionList _connections;
        int load_connections (const XMLNode&);
 
-       int set_slave_source (SlaveSource, jack_nframes_t);
-
        void reverse_diskstream_buffers ();
 
        UndoHistory history;
-       UndoCommand current_cmd;
+       UndoTransaction* current_trans;
 
        GlobalRouteBooleanState get_global_route_boolean (bool (Route::*method)(void) const);
        GlobalRouteMeterState get_global_route_metering ();
@@ -1705,7 +1630,6 @@ class Session : public sigc::trackable, public Stateful
 
        vector<Route*> master_outs;
        
-       EditMode _edit_mode;
        EditMode pending_edit_mode;
 
        /* range playback */
@@ -1759,6 +1683,8 @@ class Session : public sigc::trackable, public Stateful
 
        void add_controllable (PBD::Controllable*);
        void remove_controllable (PBD::Controllable*);
+
+       void config_changed (const char*);
 };
 
 } // namespace ARDOUR