most of libardour now actually compiles
[ardour.git] / libs / ardour / ardour / session.h
index 1d37f8583a04282b40db4c79de82d1a04a383c0a..a782680082ac5f800807d5dfe630eac392fb7f84 100644 (file)
 #include <boost/weak_ptr.hpp>
 #include <boost/utility.hpp>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 
 #include "pbd/error.h"
+#include "pbd/event_loop.h"
 #include "pbd/rcu.h"
 #include "pbd/statefuldestructible.h"
 #include "pbd/signals.h"
 #include "pbd/undo.h"
 
+#include "evoral/types.hpp"
+
 #include "midi++/types.h"
 
 #include "timecode/time.h"
+#include "ltc/ltc.h"
 
 #include "ardour/ardour.h"
-#include "ardour/click.h"
 #include "ardour/chan_count.h"
+#include "ardour/delivery.h"
+#include "ardour/interthread_info.h"
 #include "ardour/rc_configuration.h"
 #include "ardour/session_configuration.h"
 #include "ardour/session_event.h"
 #include "ardour/location.h"
 #include "ardour/interpolation.h"
-#include "ardour/speakers.h"
+#include "ardour/route_graph.h"
 
 #ifdef HAVE_JACK_SESSION
 #include <jack/session.h>
 #endif
 
+
 class XMLTree;
 class XMLNode;
-class AEffect;
+struct _AEffect;
+typedef struct _AEffect AEffect;
 
 namespace MIDI {
        class Port;
@@ -81,6 +88,7 @@ namespace Evoral {
 
 namespace ARDOUR {
 
+class Amp;
 class AudioEngine;
 class AudioFileSource;
 class AudioRegion;
@@ -92,19 +100,22 @@ class AuxInput;
 class BufferSet;
 class Bundle;
 class Butler;
+class Click;
 class Diskstream;
 class ExportHandler;
 class ExportStatus;
+class Graph;
 class IO;
 class IOProcessor;
 class ImportStatus;
+class MidiClockTicker;
+class MidiControlUI;
 class MidiRegion;
 class MidiSource;
 class MidiTrack;
-class MidiControlUI;
-class NamedSelection;
 class Playlist;
 class PluginInsert;
+class PluginInfo;
 class Port;
 class PortInsert;
 class ProcessThread;
@@ -122,9 +133,8 @@ class Slave;
 class Source;
 class Speakers;
 class TempoMap;
-class VSTPlugin;
-class Graph;
 class Track;
+class WindowsVSTPlugin;
 
 extern void setup_enum_writer ();
 
@@ -168,20 +178,15 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        const SessionDirectory& session_directory () const { return *(_session_dir.get()); }
 
-       static PBD::Signal0<void> AutoBindingOn;
-       static PBD::Signal0<void> AutoBindingOff;
-
        static PBD::Signal1<void,std::string> Dialog;
 
-       std::string sound_dir (bool with_path = true) const;
-       std::string peak_dir () const;
-       std::string dead_dir () const;
-       std::string automation_dir () const;
-       std::string analysis_dir() const;
-       std::string plugins_dir() const;
-       
        int ensure_subdirs ();
 
+       std::string automation_dir () const;  ///< Automation data
+       std::string analysis_dir () const;    ///< Analysis data
+       std::string plugins_dir () const;     ///< Plugin state
+       std::string externals_dir () const;   ///< Links to external files
+
        std::string peak_path (std::string) const;
 
        std::string change_source_path_by_name (std::string oldpath, std::string oldname, std::string newname, bool destructive);
@@ -190,7 +195,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string new_audio_source_name (const std::string&, uint32_t nchans, uint32_t chan, bool destructive);
        std::string new_midi_source_name (const std::string&);
        std::string new_source_path_from_name (DataType type, const std::string&);
-       RouteList new_route_from_template (uint32_t how_many, const std::string& template_path);
+        RouteList new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name);
 
        void process (pframes_t nframes);
 
@@ -209,7 +214,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void refresh_disk_space ();
 
        int load_diskstreams_2X (XMLNode const &, int);
-       
+
        int load_routes (const XMLNode&, int);
        boost::shared_ptr<RouteList> get_routes() const {
                return routes.reader ();
@@ -231,16 +236,20 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                bool operator() (boost::shared_ptr<Route>, boost::shared_ptr<Route> b);
        };
 
-       void sync_order_keys (std::string const &);
+        void notify_remote_id_change ();
+        void sync_order_keys (RouteSortOrderKey);
 
        template<class T> void foreach_route (T *obj, void (T::*func)(Route&));
        template<class T> void foreach_route (T *obj, void (T::*func)(boost::shared_ptr<Route>));
        template<class T, class A> void foreach_route (T *obj, void (T::*func)(Route&, A), A arg);
 
+       static char session_name_is_legal (const std::string&);
        bool io_name_is_legal (const std::string&);
        boost::shared_ptr<Route> route_by_name (std::string);
        boost::shared_ptr<Route> route_by_id (PBD::ID);
        boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
+       boost::shared_ptr<Track> track_by_diskstream_id (PBD::ID);
+        void routes_using_input_from (const std::string& str, RouteList& rl);
 
        bool route_name_unique (std::string) const;
        bool route_name_internal (std::string) const;
@@ -282,7 +291,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
         *  - engine halted
        */
        PBD::Signal0<void> TransportStateChange;
-       
+
        PBD::Signal1<void,framepos_t> PositionChanged; /* sent after any non-sequential motion */
        PBD::Signal1<void,framepos_t> Xrun;
        PBD::Signal0<void> TransportLooped;
@@ -291,8 +300,18 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        PBD::Signal0<void> Located;
 
        PBD::Signal1<void,RouteList&> RouteAdded;
-       /** Emitted when anything about any of our route groups changes */
-       PBD::Signal0<void> RouteGroupChanged;
+       /** Emitted when a property of one of our route groups changes.
+        *  The parameter is the RouteGroup that has changed.
+        */
+       PBD::Signal1<void, RouteGroup *> RouteGroupPropertyChanged;
+       /** Emitted when a route is added to one of our route groups.
+        *  First parameter is the RouteGroup, second is the route.
+        */
+       PBD::Signal2<void, RouteGroup *, boost::weak_ptr<Route> > RouteAddedToRouteGroup;
+       /** Emitted when a route is removed from one of our route groups.
+        *  First parameter is the RouteGroup, second is the route.
+        */
+       PBD::Signal2<void, RouteGroup *, boost::weak_ptr<Route> > RouteRemovedFromRouteGroup;
 
        /* Step Editing status changed */
        PBD::Signal1<void,bool> StepEditStatusChange;
@@ -312,8 +331,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void goto_start ();
        void use_rf_shuttle_speed ();
        void allow_auto_play (bool yn);
-       void request_transport_speed (double speed);
-       void request_transport_speed_nonzero (double);
+        void request_transport_speed (double speed, bool as_default = false);
+        void request_transport_speed_nonzero (double, bool as_default = false);
        void request_overwrite_buffer (Track *);
        void adjust_playback_buffering();
        void adjust_capture_buffering();
@@ -340,7 +359,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                return mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
        }
 
-       float timecode_frames_per_second() const;
+       double timecode_frames_per_second() const;
        bool timecode_drop_frames() const;
 
        /* Locations */
@@ -355,15 +374,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void set_auto_loop_location (Location *);
        int location_name(std::string& result, std::string base = std::string(""));
 
-       void reset_input_monitor_state ();
-
        pframes_t get_block_size()        const { return current_block_size; }
        framecnt_t worst_output_latency () const { return _worst_output_latency; }
        framecnt_t worst_input_latency ()  const { return _worst_input_latency; }
        framecnt_t worst_track_latency ()  const { return _worst_track_latency; }
        framecnt_t worst_playback_latency () const { return _worst_output_latency + _worst_track_latency; }
 
-#ifdef HAVE_JACK_SESSION 
+#ifdef HAVE_JACK_SESSION
        void jack_session_event (jack_session_event_t* event);
 #endif
        int save_state (std::string snapshot_name, bool pending = false, bool switch_to_snapshot = false);
@@ -374,12 +391,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void remove_state (std::string snapshot_name);
        void rename_state (std::string old_name, std::string new_name);
        void remove_pending_capture_state ();
-
-       static int rename_template (std::string old_name, std::string new_name);
-       static int delete_template (std::string name);
+       int rename (const std::string&);
+       bool get_nsm_state () const { return _under_nsm_control; }
+       void set_nsm_state (bool state) { _under_nsm_control = state; }
 
        PBD::Signal1<void,std::string> StateSaved;
        PBD::Signal0<void> StateReady;
+       PBD::Signal0<void> SaveSession;
 
        std::vector<std::string*>* possible_states() const;
        static std::vector<std::string*>* possible_states (std::string path);
@@ -441,15 +459,16 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                );
 
        std::list<boost::shared_ptr<MidiTrack> > new_midi_track (
-               TrackMode mode = Normal, RouteGroup* route_group = 0, uint32_t how_many = 1, std::string name_template = ""
+               const ChanCount& input, const ChanCount& output,
+               boost::shared_ptr<PluginInfo> instrument = boost::shared_ptr<PluginInfo>(),
+               TrackMode mode = Normal, 
+               RouteGroup* route_group = 0, uint32_t how_many = 1, std::string name_template = ""
                );
 
        void   remove_route (boost::shared_ptr<Route>);
        void   resort_routes ();
        void   resort_routes_using (boost::shared_ptr<RouteList>);
 
-       void   set_remote_control_ids();
-
        AudioEngine & engine() { return _engine; }
        AudioEngine const & engine () const { return _engine; }
 
@@ -484,14 +503,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void timecode_duration_string (char *, framecnt_t) const;
 
        framecnt_t convert_to_frames (AnyTime const & position);
-        framecnt_t any_duration_to_frames (framepos_t position, AnyTime const & duration);
+       framecnt_t any_duration_to_frames (framepos_t position, AnyTime const & duration);
 
        static PBD::Signal1<void, framepos_t> StartTimeChanged;
        static PBD::Signal1<void, framepos_t> EndTimeChanged;
 
-       std::vector<SyncSource> get_available_sync_options() const;
        void   request_sync_source (Slave*);
-       bool   synced_to_jack() const { return config.get_external_sync() && config.get_sync_source() == JACK; }
+       bool   synced_to_jack() const { return config.get_external_sync() && Config->get_sync_source() == JACK; }
 
        double transport_speed() const { return _transport_speed; }
        bool   transport_stopped() const { return _transport_speed == 0.0f; }
@@ -502,9 +520,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        TempoMap& tempo_map() { return *_tempo_map; }
 
-       /// signals the current transport position in frames, bbt and timecode time (in that order)
-       PBD::Signal3<void, const framepos_t &, const Timecode::BBT_Time&, const Timecode::Time&> tick;
-
        /* region info  */
 
        boost::shared_ptr<Region> find_whole_file_parent (boost::shared_ptr<Region const>) const;
@@ -517,14 +532,14 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* source management */
 
-       void import_audiofiles (ImportStatus&);
+       void import_files (ImportStatus&);
        bool sample_rate_convert (ImportStatus&, std::string infile, std::string& outfile);
        std::string build_tmp_convert_name (std::string file);
 
        boost::shared_ptr<ExportHandler> get_export_handler ();
        boost::shared_ptr<ExportStatus> get_export_status ();
 
-       int start_audio_export (framepos_t position, bool realtime);
+       int start_audio_export (framepos_t position);
 
        PBD::Signal1<int, framecnt_t> ProcessExport;
        static PBD::Signal2<void,std::string, std::string> Exported;
@@ -557,7 +572,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        boost::shared_ptr<AudioFileSource> create_audio_source_for_session (
                size_t, std::string const &, uint32_t, bool destructive);
-       
+
        boost::shared_ptr<MidiSource> create_midi_source_for_session (
                Track*, std::string const &);
 
@@ -567,16 +582,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void add_playlist (boost::shared_ptr<Playlist>, bool unused = false);
 
-       /* named selections */
-
-       boost::shared_ptr<NamedSelection> named_selection_by_name (std::string name);
-       void add_named_selection (boost::shared_ptr<NamedSelection>);
-       void remove_named_selection (boost::shared_ptr<NamedSelection>);
-
-       template<class T> void foreach_named_selection (T& obj, void (T::*func)(boost::shared_ptr<NamedSelection>));
-       PBD::Signal0<void> NamedSelectionAdded;
-       PBD::Signal0<void> NamedSelectionRemoved;
-
        /* Curves and AutomationLists (TODO when they go away) */
        void add_automation_list(AutomationList*);
 
@@ -593,8 +598,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /* flattening stuff */
 
        boost::shared_ptr<Region> write_one_track (AudioTrack&, framepos_t start, framepos_t end,
-                       bool overwrite, std::vector<boost::shared_ptr<Source> >&, InterThreadInfo& wot,
-                       bool enable_processing = true);
+                                                  bool overwrite, std::vector<boost::shared_ptr<Source> >&, InterThreadInfo& wot,
+                                                  boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export);
        int freeze_all (InterThreadInfo&);
 
        /* session-wide solo/mute/rec-enable */
@@ -607,16 +612,22 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void set_solo (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_just_one_solo (boost::shared_ptr<Route>, bool, SessionEvent::RTeventCallback after = rt_cleanup);
+       void cancel_solo_after_disconnect (boost::shared_ptr<Route>, bool upstream, SessionEvent::RTeventCallback after = rt_cleanup);
        void set_mute (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_listen (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_record_enabled (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_solo_isolated (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
+       void set_monitoring (boost::shared_ptr<RouteList>, MonitorChoice, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
+        void set_exclusive_input_active (boost::shared_ptr<RouteList> rt, bool onoff, bool flip_others=false);
 
        PBD::Signal1<void,bool> SoloActive;
        PBD::Signal0<void> SoloChanged;
        PBD::Signal0<void> IsolatedChanged;
-       
-       /* control/master out */
+
+       /* monitor/master out */
+
+       void add_monitor_section ();
+       void remove_monitor_section ();
 
        boost::shared_ptr<Route> monitor_out() const { return _monitor_out; }
        boost::shared_ptr<Route> master_out() const { return _master_out; }
@@ -626,6 +637,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void globally_set_send_gains_to_zero (boost::shared_ptr<Route> dest);
        void globally_set_send_gains_to_unity (boost::shared_ptr<Route> dest);
        void add_internal_sends (boost::shared_ptr<Route> dest, Placement p, boost::shared_ptr<RouteList> senders);
+       void add_internal_send (boost::shared_ptr<Route>, int, boost::shared_ptr<Route>);
+       void add_internal_send (boost::shared_ptr<Route>, boost::shared_ptr<Processor>, boost::shared_ptr<Route>);
 
        static void set_disable_all_loaded_plugins (bool yn) {
                _disable_all_loaded_plugins = yn;
@@ -635,18 +648,21 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        }
 
        uint32_t next_send_id();
+       uint32_t next_aux_send_id();
        uint32_t next_return_id();
        uint32_t next_insert_id();
        void mark_send_id (uint32_t);
+       void mark_aux_send_id (uint32_t);
        void mark_return_id (uint32_t);
        void mark_insert_id (uint32_t);
        void unmark_send_id (uint32_t);
+       void unmark_aux_send_id (uint32_t);
        void unmark_return_id (uint32_t);
        void unmark_insert_id (uint32_t);
 
        /* s/w "RAID" management */
 
-       framecnt_t available_capture_duration();
+       boost::optional<framecnt_t> available_capture_duration();
 
        /* I/O bundles */
 
@@ -693,6 +709,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                return _current_trans_quarks;
        }
 
+       bool operation_in_progress (GQuark) const;
+
        void add_commands (std::vector<Command*> const & cmds);
 
        std::map<PBD::ID,PBD::StatefulDestructible*> registry;
@@ -705,6 +723,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /* clicking */
 
        boost::shared_ptr<IO> click_io() { return _click_io; }
+       boost::shared_ptr<Amp> click_gain() { return _click_gain; }
 
        /* disk, buffer loads */
 
@@ -716,27 +735,32 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void request_play_range (std::list<AudioRange>*, bool leave_rolling = false);
        bool get_play_range () const { return _play_range; }
 
+       void maybe_update_session_range (framepos_t, framepos_t);
+
        /* buffers for gain and pan */
 
        gain_t* gain_automation_buffer () const;
+       gain_t* send_gain_automation_buffer () const;
        pan_t** pan_automation_buffer () const;
 
        void ensure_buffer_set (BufferSet& buffers, const ChanCount& howmany);
 
        /* VST support */
 
-       static long vst_callback (AEffect* effect,
-                       long opcode,
-                       long index,
-                       long value,
-                       void* ptr,
-                       float opt);
-
+       static intptr_t vst_callback (
+               AEffect* effect,
+               int32_t opcode,
+               int32_t index,
+               intptr_t value,
+               void* ptr,
+               float opt
+               );
+                       
        static PBD::Signal0<void> SendFeedback;
 
        /* Speakers */
 
-        boost::shared_ptr<Speakers> get_speakers ();
+       boost::shared_ptr<Speakers> get_speakers ();
 
        /* Controllables */
 
@@ -746,9 +770,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void add_controllable (boost::shared_ptr<PBD::Controllable>);
        void remove_controllable (PBD::Controllable*);
 
-        boost::shared_ptr<PBD::Controllable> solo_cut_control() const;
-
-       SessionMetadata & metadata () { return *_metadata; }
+       boost::shared_ptr<PBD::Controllable> solo_cut_control() const;
 
        SessionConfiguration config;
 
@@ -763,23 +785,19 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        enum PostTransportWork {
                PostTransportStop               = 0x1,
-               PostTransportDisableRecord      = 0x2,
-               PostTransportPosition           = 0x8,
-               PostTransportDidRecord          = 0x20,
-               PostTransportDuration           = 0x40,
-               PostTransportLocate             = 0x80,
-               PostTransportRoll               = 0x200,
-               PostTransportAbort              = 0x800,
-               PostTransportOverWrite          = 0x1000,
-               PostTransportSpeed              = 0x2000,
-               PostTransportAudition           = 0x4000,
-               PostTransportScrub              = 0x8000,
-               PostTransportReverse            = 0x10000,
-               PostTransportInputChange        = 0x20000,
-               PostTransportCurveRealloc       = 0x40000,
-               PostTransportClearSubstate      = 0x80000,
-               PostTransportAdjustPlaybackBuffering  = 0x100000,
-               PostTransportAdjustCaptureBuffering   = 0x200000
+               PostTransportDuration           = 0x2,
+               PostTransportLocate             = 0x4,
+               PostTransportRoll               = 0x8,
+               PostTransportAbort              = 0x10,
+               PostTransportOverWrite          = 0x20,
+               PostTransportSpeed              = 0x40,
+               PostTransportAudition           = 0x80,
+               PostTransportReverse            = 0x100,
+               PostTransportInputChange        = 0x200,
+               PostTransportCurveRealloc       = 0x400,
+               PostTransportClearSubstate      = 0x800,
+               PostTransportAdjustPlaybackBuffering  = 0x1000,
+               PostTransportAdjustCaptureBuffering   = 0x2000
        };
 
        enum SlaveState {
@@ -787,16 +805,15 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                Waiting,
                Running
        };
-       
+
        SlaveState slave_state() const { return _slave_state; }
+        Slave* slave() const { return _slave; }
 
        boost::shared_ptr<SessionPlaylists> playlists;
 
        void send_mmc_locate (framepos_t);
        int send_full_time_code (framepos_t);
 
-       PBD::Signal0<void> RouteOrderKeyChanged;
-
        bool step_editing() const { return (_step_editors > 0); }
 
        void request_suspend_timecode_transmission ();
@@ -808,6 +825,17 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        std::list<std::string> unknown_processors () const;
 
+       /** Emitted when a feedback cycle has been detected within Ardour's signal
+           processing path.  Until it is fixed (by the user) some (unspecified)
+           routes will not be run.
+       */
+       static PBD::Signal0<void> FeedbackDetected;
+
+       /** Emitted when a graph sort has successfully completed, which means
+           that it has no feedback cycles.
+       */
+       static PBD::Signal0<void> SuccessfulGraphSort;
+
        /* handlers can return an integer value:
           0: config.set_audio_search_path() or config.set_midi_search_path() was used
           to modify the search path and we should try to find it again.
@@ -822,6 +850,17 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /** Emitted when the session wants Ardour to quit */
        static PBD::Signal0<void> Quit;
 
+        /** Emitted when Ardour is asked to load a session in an older session
+        * format, and makes a backup copy.
+        */
+        static PBD::Signal2<void,std::string,std::string> VersionMismatch;
+
+        boost::shared_ptr<Port> ltc_input_port() const;
+        boost::shared_ptr<Port> ltc_output_port() const;
+
+       boost::shared_ptr<IO> ltc_input_io() { return _ltc_input; }
+       boost::shared_ptr<IO> ltc_output_io() { return _ltc_output; }
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -837,10 +876,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void destroy ();
 
        enum SubState {
-               PendingDeclickIn   = 0x1,
-               PendingDeclickOut  = 0x2,
-               StopPendingCapture = 0x4,
-               PendingLocate      = 0x20,
+               PendingDeclickIn      = 0x1,  ///< pending de-click fade-in for start
+               PendingDeclickOut     = 0x2,  ///< pending de-click fade-out for stop
+               StopPendingCapture    = 0x4,
+               PendingLoopDeclickIn  = 0x8,  ///< pending de-click fade-in at the start of a loop
+               PendingLoopDeclickOut = 0x10, ///< pending de-click fade-out at the end of a loop
+               PendingLocate         = 0x20,
        };
 
        /* stuff used in process() should be close together to
@@ -864,10 +905,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        Slave*                  _slave;
        bool                    _silent;
 
-       void maybe_update_session_range (framepos_t, framepos_t);
-       
        // varispeed playback
        double                  _transport_speed;
+       double                  _default_transport_speed;
        double                  _last_transport_speed;
        double                  _target_transport_speed;
        CubicInterpolation       interpolation;
@@ -888,15 +928,17 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        uint32_t                _solo_isolated_cnt;
        bool                    _writable;
        bool                    _was_seamless;
+       bool                    _under_nsm_control;
 
+       void initialize_latencies ();
        void set_worst_io_latencies ();
        void set_worst_playback_latency ();
        void set_worst_capture_latency ();
        void set_worst_io_latencies_x (IOChange, void *) {
                set_worst_io_latencies ();
        }
-        void post_capture_latency ();
-        void post_playback_latency ();
+       void post_capture_latency ();
+       void post_playback_latency ();
 
        void update_latency_compensation_proxy (void* ignored);
 
@@ -906,16 +948,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void process_without_events (pframes_t);
        void process_with_events    (pframes_t);
        void process_audition       (pframes_t);
-       void process_export         (pframes_t);
+        int  process_export         (pframes_t);
        int  process_export_fw      (pframes_t);
 
        void block_processing() { g_atomic_int_set (&processing_prohibited, 1); }
        void unblock_processing() { g_atomic_int_set (&processing_prohibited, 0); }
        bool processing_blocked() const { return g_atomic_int_get (&processing_prohibited); }
 
-       Glib::Mutex                process_thread_lock;
-       std::list<ProcessThread*>  process_threads;
-
        /* slave tracking */
 
        static const int delta_accumulator_size = 25;
@@ -942,6 +981,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        framepos_t post_export_position;
 
        bool _exporting;
+       bool _export_started;
        bool _export_rolling;
 
        boost::shared_ptr<ExportHandler> export_handler;
@@ -950,6 +990,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int  pre_export ();
        int  stop_audio_export ();
        void finalize_audio_export ();
+       void finalize_export_internal (bool stop_freewheel);
+       bool _pre_export_mmc_enabled;
 
        PBD::ScopedConnection export_freewheel_connection;
 
@@ -957,24 +999,25 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int  process_routes (pframes_t, bool& need_butler);
        int  silent_process_routes (pframes_t, bool& need_butler);
 
-       bool get_rec_monitors_input () {
-               if (actively_recording()) {
-                       return true;
-               } else {
-                       if (config.get_auto_input()) {
-                               return false;
-                       } else {
-                               return true;
-                       }
-               }
-       }
-
+       /** @return 1 if there is a pending declick fade-in,
+                  -1 if there is a pending declick fade-out,
+                   0 if there is no pending declick.
+       */
        int get_transport_declick_required () {
                if (transport_sub_state & PendingDeclickIn) {
                        transport_sub_state &= ~PendingDeclickIn;
                        return 1;
                } else if (transport_sub_state & PendingDeclickOut) {
+                       /* XXX: not entirely sure why we don't clear this */
                        return -1;
+               } else if (transport_sub_state & PendingLoopDeclickOut) {
+                       /* Return the declick out first ... */
+                       transport_sub_state &= ~PendingLoopDeclickOut;
+                       return -1;
+               } else if (transport_sub_state & PendingLoopDeclickIn) {
+                       /* ... then the declick in on the next call */
+                       transport_sub_state &= ~PendingLoopDeclickIn;
+                       return 1;
                } else {
                        return 0;
                }
@@ -1004,6 +1047,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void when_engine_running ();
        void graph_reordered ();
 
+       /** current snapshot name, without the .ardour suffix */
        std::string _current_snapshot_name;
 
        XMLTree*         state_tree;
@@ -1015,6 +1059,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int      load_state (std::string snapshot_name);
 
        framepos_t _last_roll_location;
+       /** the session frame time at which we last rolled, located, or changed transport direction */
        framepos_t _last_roll_or_reversal_location;
        framepos_t _last_record_location;
 
@@ -1026,40 +1071,19 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        Butler* _butler;
 
-#if 0 // these should be here, see comments in their other location above
-       enum PostTransportWork {
-               PostTransportStop               = 0x1,
-               PostTransportDisableRecord      = 0x2,
-               PostTransportPosition           = 0x8,
-               PostTransportDidRecord          = 0x20,
-               PostTransportDuration           = 0x40,
-               PostTransportLocate             = 0x80,
-               PostTransportRoll               = 0x200,
-               PostTransportAbort              = 0x800,
-               PostTransportOverWrite          = 0x1000,
-               PostTransportSpeed              = 0x2000,
-               PostTransportAudition           = 0x4000,
-               PostTransportScrub              = 0x8000,
-               PostTransportReverse            = 0x10000,
-               PostTransportInputChange        = 0x20000,
-               PostTransportCurveRealloc       = 0x40000,
-               PostTransportClearSubstate      = 0x80000
-       };
-#endif
        static const PostTransportWork ProcessCannotProceedMask =
                PostTransportWork (
                                PostTransportInputChange|
                                PostTransportSpeed|
                                PostTransportReverse|
                                PostTransportCurveRealloc|
-                               PostTransportScrub|
                                PostTransportAudition|
                                PostTransportLocate|
                                PostTransportStop|
                                PostTransportClearSubstate);
 
        gint _post_transport_work; /* accessed only atomic ops */
-       PostTransportWork post_transport_work() const        { return (PostTransportWork) g_atomic_int_get (&_post_transport_work); }
+        PostTransportWork post_transport_work() const        { return (PostTransportWork) g_atomic_int_get (const_cast<gint*>(&_post_transport_work)); }
        void set_post_transport_work (PostTransportWork ptw) { g_atomic_int_set (&_post_transport_work, (gint) ptw); }
        void add_post_transport_work (PostTransportWork ptw);
 
@@ -1084,6 +1108,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        PBD::ScopedConnectionList loop_connections;
        void             auto_loop_changed (Location *);
+       void             auto_loop_declick_range (Location *, framepos_t &, framepos_t &);
 
        void first_stage_init (std::string path, std::string snapshot_name);
        int  second_stage_init ();
@@ -1123,9 +1148,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* MIDI Machine Control */
 
-       void spp_start (MIDI::Parser&, framepos_t timestamp);
-       void spp_continue (MIDI::Parser&, framepos_t timestamp);
-       void spp_stop (MIDI::Parser&, framepos_t timestamp);
+       void spp_start ();
+       void spp_continue ();
+       void spp_stop ();
 
        void mmc_deferred_play (MIDI::MachineControl &);
        void mmc_stop (MIDI::MachineControl &);
@@ -1153,7 +1178,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        MIDI::byte mtc_msg[16];
        MIDI::byte mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
        MIDI::byte midi_msg[16];
-       framepos_t outbound_mtc_timecode_frame;
+       double outbound_mtc_timecode_frame;
        Timecode::Time transmitting_timecode_time;
        int next_quarter_frame_to_send;
 
@@ -1171,6 +1196,33 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        int send_midi_time_code_for_cycle (framepos_t, framepos_t, pframes_t nframes);
 
+       LTCEncoder*       ltc_encoder;
+       ltcsnd_sample_t*  ltc_enc_buf;
+
+       Timecode::TimecodeFormat ltc_enc_tcformat;
+       int32_t           ltc_buf_off;
+       int32_t           ltc_buf_len;
+
+       double            ltc_speed;
+       int32_t           ltc_enc_byte;
+       framepos_t        ltc_enc_pos;
+       double            ltc_enc_cnt;
+       framepos_t        ltc_enc_off;
+       bool              restarting;
+
+       framepos_t        ltc_timecode_offset;
+       bool              ltc_timecode_negative_offset;
+
+       LatencyRange      ltc_out_latency;
+
+       void ltc_tx_initialize();
+       void ltc_tx_cleanup();
+       void ltc_tx_reset();
+       void ltc_tx_resync_latency();
+       void ltc_tx_recalculate_position();
+       void ltc_tx_parse_offset();
+       void ltc_tx_send_time_code_for_cycle (framepos_t, framepos_t, double, double, pframes_t nframes);
+
        void reset_record_status ();
 
        int no_roll (pframes_t nframes);
@@ -1182,7 +1234,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        MidiControlUI* midi_control_ui;
 
        int           start_midi_thread ();
-       void          terminate_midi_thread ();
 
        void set_play_loop (bool yn);
        void unset_play_loop ();
@@ -1193,10 +1244,11 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void start_locate (framepos_t, bool with_roll, bool with_flush, bool with_loop=false, bool force=false);
        void force_locate (framepos_t frame, bool with_roll = false);
        void set_track_speed (Track *, double speed);
-       void set_transport_speed (double speed, bool abort = false, bool clear_state = false);
+        void set_transport_speed (double speed, bool abort = false, bool clear_state = false, bool as_default = false);
        void stop_transport (bool abort = false, bool clear_state = false);
        void start_transport ();
        void realtime_stop (bool abort, bool clear_state);
+       void realtime_locate ();
        void non_realtime_start_scrub ();
        void non_realtime_set_speed ();
        void non_realtime_locate ();
@@ -1218,11 +1270,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* routes stuff */
 
-       boost::shared_ptr<Graph> route_graph;
+       boost::shared_ptr<Graph> _process_graph;
 
        SerializedRCUManager<RouteList>  routes;
 
-       void add_routes (RouteList&, bool auto_connect, bool save);
+       void add_routes (RouteList&, bool input_auto_connect, bool output_auto_connect, bool save);
+        void add_routes_inner (RouteList&, bool input_auto_connect, bool output_auto_connect);
+        bool _adding_routes_in_progress;
        uint32_t destructive_index;
 
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&, int);
@@ -1233,9 +1287,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        bool find_route_name (std::string const &, uint32_t& id, char* name, size_t name_len, bool);
        void count_existing_track_channels (ChanCount& in, ChanCount& out);
        void auto_connect_route (boost::shared_ptr<Route> route, ChanCount& existing_inputs, ChanCount& existing_outputs,
-                                 bool with_lock, bool connect_inputs = true, 
-                                 ChanCount input_start = ChanCount (), ChanCount output_start = ChanCount ());
-        void midi_output_change_handler (IOChange change, void* /*src*/, boost::weak_ptr<Route> midi_track);
+                                bool with_lock, bool connect_inputs = true,
+                                ChanCount input_start = ChanCount (), ChanCount output_start = ChanCount ());
+       void midi_output_change_handler (IOChange change, void* /*src*/, boost::weak_ptr<Route> midi_track);
 
        /* mixer stuff */
 
@@ -1252,20 +1306,23 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* REGION MANAGEMENT */
 
-       mutable Glib::Mutex region_lock;
+       mutable Glib::Threads::Mutex region_lock;
 
        int load_regions (const XMLNode& node);
+       int load_compounds (const XMLNode& node);
 
-       void route_group_changed ();
+       void route_added_to_route_group (RouteGroup *, boost::weak_ptr<Route>);
+       void route_removed_from_route_group (RouteGroup *, boost::weak_ptr<Route>);
+       void route_group_property_changed (RouteGroup *);
 
        /* SOURCES */
 
-       mutable Glib::Mutex source_lock;
+       mutable Glib::Threads::Mutex source_lock;
 
-  public:      
+  public:
        typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap;
 
-  private:     
+  private:
        SourceMap sources;
 
   public:
@@ -1285,17 +1342,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void playlist_ranges_moved (std::list<Evoral::RangeMove<framepos_t> > const &);
        void playlist_regions_extended (std::list<Evoral::Range<framepos_t> > const &);
 
-       /* NAMED SELECTIONS */
-
-       mutable Glib::Mutex named_selection_lock;
-       typedef std::set<boost::shared_ptr<NamedSelection> > NamedSelectionList;
-       NamedSelectionList named_selections;
-
-       int load_named_selections (const XMLNode&);
-
-       NamedSelection *named_selection_factory (std::string name);
-       NamedSelection *XMLNamedSelectionFactory (const XMLNode&);
-
        /* CURVES and AUTOMATION LISTS */
        std::map<PBD::ID, AutomationList*> automation_lists;
 
@@ -1320,22 +1366,28 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /* INSERT AND SEND MANAGEMENT */
 
        boost::dynamic_bitset<uint32_t> send_bitset;
+       boost::dynamic_bitset<uint32_t> aux_send_bitset;
        boost::dynamic_bitset<uint32_t> return_bitset;
        boost::dynamic_bitset<uint32_t> insert_bitset;
 
        /* S/W RAID */
 
        struct space_and_path {
-               uint32_t blocks; /* 4kB blocks */
+               uint32_t blocks;     ///< 4kB blocks
+               bool blocks_unknown; ///< true if blocks is unknown
                std::string path;
 
-               space_and_path() {
-                       blocks = 0;
-               }
+               space_and_path ()
+                       : blocks (0)
+                       , blocks_unknown (true)
+               {}
        };
 
        struct space_and_path_ascending_cmp {
                bool operator() (space_and_path a, space_and_path b) {
+                       if (a.blocks_unknown != b.blocks_unknown) {
+                               return !a.blocks_unknown;
+                       }
                        return a.blocks > b.blocks;
                }
        };
@@ -1345,7 +1397,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::vector<space_and_path> session_dirs;
        std::vector<space_and_path>::iterator last_rr_session_dir;
        uint32_t _total_free_4k_blocks;
-       Glib::Mutex space_lock;
+       /** If this is true, _total_free_4k_blocks is not definite,
+           as one or more of the session directories' filesystems
+           could not report free space.
+       */
+       bool _total_free_4k_blocks_uncertain;
+       Glib::Threads::Mutex space_lock;
 
        bool no_questions_about_missing_files;
 
@@ -1360,8 +1417,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        XMLNode* _bundle_xml_node;
        int load_bundles (XMLNode const &);
 
-       void reverse_track_buffers ();
-
        UndoHistory      _history;
        /** current undo transaction, or 0 */
        UndoTransaction* _current_trans;
@@ -1376,20 +1431,21 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void reset_jack_connection (jack_client_t* jack);
        void process_rtop (SessionEvent*);
 
-        void  update_latency (bool playback);
+       void  update_latency (bool playback);
 
        XMLNode& state(bool);
 
        /* click track */
-
-       Clicks                 clicks;
-       bool                  _clicking;
-       boost::shared_ptr<IO> _click_io;
-       Sample*                click_data;
-       Sample*                click_emphasis_data;
-       framecnt_t             click_length;
-       framecnt_t             click_emphasis_length;
-       mutable Glib::RWLock   click_lock;
+       typedef std::list<Click*> Clicks;
+       Clicks                  clicks;
+       bool                   _clicking;
+       boost::shared_ptr<IO>  _click_io;
+       boost::shared_ptr<Amp> _click_gain;
+       Sample*                 click_data;
+       Sample*                 click_emphasis_data;
+       framecnt_t              click_length;
+       framecnt_t              click_emphasis_length;
+       mutable Glib::Threads::RWLock    click_lock;
 
        static const Sample     default_click[];
        static const framecnt_t default_click_length;
@@ -1397,6 +1453,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        static const framecnt_t default_click_emphasis_length;
 
        Click *get_click();
+       framepos_t _clicks_cleared;
        void   setup_click_sounds (int which);
        void   setup_click_sounds (Sample**, Sample const *, framecnt_t*, framecnt_t, std::string const &);
        void   clear_clicks ();
@@ -1417,14 +1474,18 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<Route> _master_out;
        boost::shared_ptr<Route> _monitor_out;
 
-       /* VST support */
+       void auto_connect_master_bus ();
+
+       /* Windows VST support */
 
-       long _vst_callback (VSTPlugin*,
-                       long opcode,
-                       long index,
-                       long value,
-                       void* ptr,
-                       float opt);
+       long _windows_vst_callback (
+               WindowsVSTPlugin*,
+               long opcode,
+               long index,
+               long value,
+               void* ptr,
+               float opt
+               );
 
        /* number of hardware ports we're using,
           based on max (requested,available)
@@ -1437,10 +1498,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int find_all_sources_across_snapshots (std::set<std::string>& result, bool exclude_this_snapshot);
 
        typedef std::set<boost::shared_ptr<PBD::Controllable> > Controllables;
-       Glib::Mutex controllables_lock;
+       Glib::Threads::Mutex controllables_lock;
        Controllables controllables;
 
-        boost::shared_ptr<PBD::Controllable> _solo_cut_control;
+       boost::shared_ptr<PBD::Controllable> _solo_cut_control;
 
        void reset_native_file_format();
        bool first_file_data_format_reset;
@@ -1451,12 +1512,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        XMLNode& get_control_protocol_state ();
 
        void set_history_depth (uint32_t depth);
-       void sync_order_keys ();
 
        static bool _disable_all_loaded_plugins;
 
-       SessionMetadata * _metadata;
-
        mutable bool have_looped; ///< Used in ::audible_frame(*)
 
        void update_have_rec_enabled_track ();
@@ -1465,17 +1523,25 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        static int ask_about_playlist_deletion (boost::shared_ptr<Playlist>);
 
        /* realtime "apply to set of routes" operations */
-       SessionEvent* get_rt_event (
-               boost::shared_ptr<RouteList> rl, bool yn,
-               SessionEvent::RTeventCallback after, bool group_override, 
-               void (Session::*method) (boost::shared_ptr<RouteList>, bool, bool));
+       template<typename T> SessionEvent*
+               get_rt_event (boost::shared_ptr<RouteList> rl, T targ, SessionEvent::RTeventCallback after, bool group_override,
+                             void (Session::*method) (boost::shared_ptr<RouteList>, T, bool)) {
+               SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
+               ev->rt_slot = boost::bind (method, this, rl, targ, group_override);
+               ev->rt_return = after;
+               ev->event_loop = PBD::EventLoop::get_event_loop_for_thread ();
+               
+               return ev;
+       }
 
+       void rt_cancel_solo_after_disconnect (boost::shared_ptr<RouteList>, bool upstream, bool /* ignored*/ );
        void rt_set_solo (boost::shared_ptr<RouteList>, bool yn, bool group_override);
        void rt_set_just_one_solo (boost::shared_ptr<RouteList>, bool yn, bool /* ignored*/ );
        void rt_set_mute (boost::shared_ptr<RouteList>, bool yn, bool group_override);
        void rt_set_listen (boost::shared_ptr<RouteList>, bool yn, bool group_override);
        void rt_set_solo_isolated (boost::shared_ptr<RouteList>, bool yn, bool group_override);
        void rt_set_record_enabled (boost::shared_ptr<RouteList>, bool yn, bool group_override);
+       void rt_set_monitoring (boost::shared_ptr<RouteList>, MonitorChoice, bool group_override);
 
        /** temporary list of Diskstreams used only during load of 2.X sessions */
        std::list<boost::shared_ptr<Diskstream> > _diskstreams_2X;
@@ -1484,8 +1550,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void setup_midi_machine_control ();
 
-       void route_order_key_changed ();
-
        void step_edit_status_change (bool);
        uint32_t _step_editors;
 
@@ -1497,10 +1561,27 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void start_time_changed (framepos_t);
        void end_time_changed (framepos_t);
 
-        void set_track_monitor_input_status (bool);
+       void set_track_monitor_input_status (bool);
        framepos_t compute_stop_limit () const;
 
-        boost::shared_ptr<Speakers> _speakers; 
+       boost::shared_ptr<Speakers> _speakers;
+       void load_nested_sources (const XMLNode& node);
+
+       /** The directed graph of routes that is currently being used for audio processing
+           and solo/mute computations.
+       */
+       GraphEdges _current_route_graph;
+
+       uint32_t next_control_id () const;
+       bool ignore_route_processor_changes;
+
+       MidiClockTicker* midi_clock;
+
+        boost::shared_ptr<IO>   _ltc_input;
+        boost::shared_ptr<IO>   _ltc_output;
+
+        void reconnect_ltc_input ();
+        void reconnect_ltc_output ();
 };
 
 } // namespace ARDOUR