track templates, backported from 2.X
[ardour.git] / libs / ardour / ardour / session.h
index b6d8f1510145304ce1ca655d27920714e214b888..082e05a9bdf26584f1699479a64f797ef25ac430 100644 (file)
 #ifndef __ardour_session_h__
 #define __ardour_session_h__
 
-#include <string>
 #include <list>
 #include <map>
-#include <vector>
 #include <set>
 #include <stack>
+#include <string>
+#include <vector>
+#include <stdint.h>
 
+#include <boost/dynamic_bitset.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/weak_ptr.hpp>
-#include <boost/dynamic_bitset.hpp>
-
-#include <stdint.h>
+#include <boost/utility.hpp>
 
 #include <sndfile.h>
 
 #include <glibmm/thread.h>
 
-#include <pbd/error.h>
-#include <pbd/undo.h>
-#include <pbd/pool.h>
-#include <pbd/rcu.h>
-#include <pbd/statefuldestructible.h>
+#include "pbd/error.h"
+#include "pbd/pool.h"
+#include "pbd/rcu.h"
+#include "pbd/statefuldestructible.h"
+#include "pbd/undo.h"
 
-#include <midi++/types.h>
-#include <midi++/mmc.h>
+#include "midi++/mmc.h"
+#include "midi++/types.h"
 
-#include <pbd/stateful.h>
-#include <pbd/destructible.h>
+#include "pbd/destructible.h"
+#include "pbd/stateful.h"
 
-#include <ardour/ardour.h>
-#include <ardour/configuration.h>
-#include <ardour/export_status.h>
-#include <ardour/location.h>
-#include <ardour/gain.h>
-#include <ardour/io.h>
-
-#include <ardour/smpte.h>
+#include "ardour/ardour.h"
+#include "ardour/chan_count.h"
+#include "ardour/configuration.h"
+#include "ardour/location.h"
+#include "ardour/smpte.h"
 
 class XMLTree;
 class XMLNode;
@@ -70,56 +67,57 @@ namespace PBD {
        class Controllable;
 }
 
+namespace Evoral {
+       class Curve;
+}
+
 namespace ARDOUR {
 
-class Port;
+class AudioDiskstream;
 class AudioEngine;
-class Slave;
-class Diskstream;
-class Route;
-class AuxInput;
-class Source;
+class AudioFileSource;
+class AudioRegion;
 class AudioSource;
+class AudioTrack;
+class Auditioner;
+class AutomationList;
+class AuxInput;
 class BufferSet;
-
+class Bundle;
+class ControlProtocolInfo;
 class Diskstream;
-class AudioDiskstream;
+class ExportHandler;
+class ExportStatus;
+class IO;
+class IOProcessor;
 class MidiDiskstream;
-class AudioFileSource;
+class MidiRegion;
 class MidiSource;
-class Auditioner;
-class Processor;
-class Send;
-class IOProcessor;
-class PortInsert;
-class PluginInsert;
-class Bundle;
-class TempoMap;
-class AudioTrack;
+class MidiTrack;
 class NamedSelection;
-class AudioRegion;
-
-class Region;
 class Playlist;
-class VSTPlugin;
-class ControlProtocolInfo;
-
-class MidiTrack;
-class MidiRegion;
+class PluginInsert;
+class Port;
+class PortInsert;
+class Processor;
+class Region;
+class Route;
+class RouteGroup;
 class SMFSource;
-
+class Send;
 class SessionDirectory;
 class SessionMetadata;
-class ExportHandler;
-
-struct RouteGroup;
+class Slave;
+class Source;
+class TempoMap;
+class VSTPlugin;
 
 using std::vector;
 using std::string;
 using std::map;
 using std::set;
 
-class Session : public PBD::StatefulDestructible
+class Session : public PBD::StatefulDestructible, public boost::noncopyable
 {
   private:
        typedef std::pair<boost::weak_ptr<Route>,bool> RouteBooleanState;
@@ -135,115 +133,114 @@ class Session : public PBD::StatefulDestructible
        };
 
        struct Event {
-           enum Type {
-                   SetTransportSpeed,
-                   SetDiskstreamSpeed,
-                   Locate,
-                   LocateRoll,
-                   LocateRollLocate,
-                   SetLoop,
-                   PunchIn,
-                   PunchOut,
-                   RangeStop,
-                   RangeLocate,
-                   Overwrite,
-                   SetSlaveSource,
-                   Audition,
-                   InputConfigurationChange,
-                   SetAudioRange,
-                   SetPlayRange,
-
-                   /* only one of each of these events
-                      can be queued at any one time
-                   */
-
-                   StopOnce,
-                   AutoLoop
-           };
-
-           enum Action {
-                   Add,
-                   Remove,
-                   Replace,
-                   Clear
-           };
-
-               Type           type;
-           Action         action;
-           nframes_t action_frame;
-           nframes_t target_frame;
-           float          speed;
-
-           union {
-                       void*                ptr;
-                       bool                 yes_or_no;
-                       nframes_t            target2_frame;
-                       SlaveSource slave;
-                       Route*               route;
-           };
-
-           boost::shared_ptr<Region>     region;
-
-           list<AudioRange>     audio_range;
-           list<MusicRange>     music_range;
-
-           Event(Type t, Action a, nframes_t when, nframes_t where, float spd, bool yn = false)
-                   : type (t),
-                     action (a),
-                     action_frame (when),
-                     target_frame (where),
-                     speed (spd),
-                     yes_or_no (yn) {}
-
-           void set_ptr (void* p) {
-                   ptr = p;
-           }
-
-           bool before (const Event& other) const {
-                   return action_frame < other.action_frame;
-           }
-
-           bool after (const Event& other) const {
-                   return action_frame > other.action_frame;
-           }
-
-           static bool compare (const Event *e1, const Event *e2) {
-                   return e1->before (*e2);
-           }
-
-           void *operator new (size_t ignored) {
-                   return pool.alloc ();
-           }
-
-           void operator delete(void *ptr, size_t size) {
-                   pool.release (ptr);
-           }
-
-           static const nframes_t Immediate = 0;
-
-        private:
-           static MultiAllocSingleReleasePool pool;
+               enum Type {
+                       SetTransportSpeed,
+                       SetDiskstreamSpeed,
+                       Locate,
+                       LocateRoll,
+                       LocateRollLocate,
+                       SetLoop,
+                       PunchIn,
+                       PunchOut,
+                       RangeStop,
+                       RangeLocate,
+                       Overwrite,
+                       SetSlaveSource,
+                       Audition,
+                       InputConfigurationChange,
+                       SetAudioRange,
+                       SetPlayRange,
+
+                       /* only one of each of these events can be queued at any one time */
+
+                       StopOnce,
+                       AutoLoop
+               };
+
+               enum Action {
+                       Add,
+                       Remove,
+                       Replace,
+                       Clear
+               };
+
+               Type             type;
+               Action           action;
+               nframes_t        action_frame;
+               nframes_t        target_frame;
+               double           speed;
+
+               union {
+                       void*        ptr;
+                       bool         yes_or_no;
+                       nframes_t    target2_frame;
+                       SlaveSource  slave;
+                       Route*       route;
+               };
+
+               list<AudioRange> audio_range;
+               list<MusicRange> music_range;
+               
+               boost::shared_ptr<Region> region;
+
+               Event(Type t, Action a, nframes_t when, nframes_t where, double spd, bool yn = false)
+                       : type (t)
+                       , action (a)
+                       , action_frame (when)
+                       , target_frame (where)
+                       , speed (spd)
+                       , yes_or_no (yn)
+               {}
+
+               void set_ptr (void* p) {
+                       ptr = p;
+               }
+
+               bool before (const Event& other) const {
+                       return action_frame < other.action_frame;
+               }
+
+               bool after (const Event& other) const {
+                       return action_frame > other.action_frame;
+               }
+
+               static bool compare (const Event *e1, const Event *e2) {
+                       return e1->before (*e2);
+               }
+
+               void *operator new (size_t ignored) {
+                       return pool.alloc ();
+               }
+
+               void operator delete(void *ptr, size_t size) {
+                       pool.release (ptr);
+               }
+
+               static const nframes_t Immediate = 0;
+
+               private:
+               static MultiAllocSingleReleasePool pool;
        };
 
        /* creating from an XML file */
 
        Session (AudioEngine&,
-                const string& fullpath,
-                const string& snapshot_name,
-                string mix_template = "");
+                       const string& fullpath,
+                       const string& snapshot_name,
+                       string mix_template = "");
 
        /* creating a new Session */
 
        Session (AudioEngine&,
-                string fullpath,
-                string snapshot_name,
-                AutoConnectOption input_auto_connect,
-                AutoConnectOption output_auto_connect,
-                uint32_t control_out_channels,
-                uint32_t master_out_channels,
-                uint32_t n_physical_in,
-                uint32_t n_physical_out,
-                nframes_t initial_length);
+                       string fullpath,
+                       string snapshot_name,
+                       AutoConnectOption input_auto_connect,
+                       AutoConnectOption output_auto_connect,
+                       uint32_t control_out_channels,
+                       uint32_t master_out_channels,
+                       uint32_t n_physical_in,
+                       uint32_t n_physical_out,
+                       nframes_t initial_length);
 
        virtual ~Session ();
 
@@ -278,12 +275,13 @@ class Session : public PBD::StatefulDestructible
 
        Glib::ustring peak_path (Glib::ustring) const;
 
-       static string change_audio_path_by_name (string oldpath, string oldname, string newname, bool destructive);
-       static string change_midi_path_by_name (string oldpath, string oldname, string newname, bool destructive);
+       static string change_source_path_by_name (string oldpath, string oldname, string newname, bool destructive);
 
        string peak_path_from_audio_path (string) const;
-       string audio_path_from_name (string, uint32_t nchans, uint32_t chan, bool destructive);
-       string midi_path_from_name (string);
+       string new_audio_source_name (const string&, uint32_t nchans, uint32_t chan, bool destructive);
+       string new_midi_source_name (const string&);
+       string new_source_path_from_name (DataType type, const string&);
+       RouteList new_route_from_template (uint32_t how_many, const std::string& template_path);
 
        void process (nframes_t nframes);
 
@@ -305,8 +303,8 @@ class Session : public PBD::StatefulDestructible
        uint32_t n_diskstreams() const;
 
        typedef std::list<boost::shared_ptr<Diskstream> > DiskstreamList;
-       typedef std::list<boost::shared_ptr<Route> >      RouteList;
 
+       int load_routes (const XMLNode&);
        boost::shared_ptr<RouteList> get_routes() const {
                return routes.reader ();
        }
@@ -315,9 +313,15 @@ class Session : public PBD::StatefulDestructible
        uint32_t ntracks () const;
        uint32_t nbusses () const;
 
+       boost::shared_ptr<BundleList> bundles () {
+               return _bundles.reader ();
+       }
+
        struct RoutePublicOrderSorter {
            bool operator() (boost::shared_ptr<Route>, boost::shared_ptr<Route> b);
        };
+       
+       void sync_order_keys (const char* base);
 
        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>));
@@ -368,6 +372,9 @@ class Session : public PBD::StatefulDestructible
        sigc::signal<void,nframes_t> Xrun;
        sigc::signal<void> TransportLooped;
 
+       /** emitted when a locate has occurred */
+       sigc::signal<void> Located;
+
        sigc::signal<void,RouteList&> RouteAdded;
 
        void request_roll_at_and_return (nframes_t start, nframes_t return_to);
@@ -385,31 +392,34 @@ class Session : public PBD::StatefulDestructible
        void set_session_end (nframes_t end) { end_location->set_start(end); _end_location_is_free = false; }
        void use_rf_shuttle_speed ();
        void allow_auto_play (bool yn);
-       void request_transport_speed (float speed);
+       void request_transport_speed (double speed);
        void request_overwrite_buffer (Diskstream*);
-       void request_diskstream_speed (Diskstream&, float speed);
+       void request_diskstream_speed (Diskstream&, double 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 (boost::shared_ptr<Region>);
 
        nframes_t get_maximum_extent () const;
        nframes_t current_end_frame() const { return end_location->start(); }
        nframes_t current_start_frame() const { return start_location->start(); }
-       // "actual" sample rate of session, set by current audioengine rate, pullup/down etc.
+       /// "actual" sample rate of session, set by current audioengine rate, pullup/down etc.
        nframes_t frame_rate() const   { return _current_frame_rate; }
-       // "native" sample rate of session, regardless of current audioengine rate, pullup/down etc
+       /// "native" sample rate of session, regardless of current audioengine rate, pullup/down etc
        nframes_t nominal_frame_rate() const   { return _nominal_frame_rate; }
        nframes_t frames_per_hour() const { return _frames_per_hour; }
 
        double frames_per_smpte_frame() const { return _frames_per_smpte_frame; }
        nframes_t smpte_frames_per_hour() const { return _smpte_frames_per_hour; }
 
+       MIDI::byte get_mtc_smpte_bits() const { 
+               return mtc_smpte_bits;   /* encoding of SMTPE type for MTC */
+       }
+
        float smpte_frames_per_second() const;
        bool smpte_drop_frames() const;
 
@@ -431,10 +441,10 @@ class Session : public PBD::StatefulDestructible
        void remove_event (nframes_t frame, Event::Type type);
        void clear_events (Event::Type type);
 
-       nframes_t get_block_size() const { return current_block_size; }
+       nframes_t get_block_size()        const { return current_block_size; }
        nframes_t worst_output_latency () const { return _worst_output_latency; }
-       nframes_t worst_input_latency () const { return _worst_input_latency; }
-       nframes_t worst_track_latency () const { return _worst_track_latency; }
+       nframes_t worst_input_latency ()  const { return _worst_input_latency; }
+       nframes_t worst_track_latency ()  const { return _worst_track_latency; }
 
        int save_state (std::string snapshot_name, bool pending = false);
        int restore_state (std::string snapshot_name);
@@ -460,7 +470,7 @@ class Session : public PBD::StatefulDestructible
 
        /// The instant xml file is written to the session directory
        void add_instant_xml (XMLNode&, bool write_to_config = true);
-       XMLNode * instant_xml (const std::string& str);
+       XMLNode* instant_xml (const std::string& str);
 
        enum StateOfTheState {
                Clean = 0x0,
@@ -485,8 +495,8 @@ class Session : public PBD::StatefulDestructible
 
        sigc::signal<void,RouteGroup*> edit_group_added;
        sigc::signal<void,RouteGroup*> mix_group_added;
-       sigc::signal<void> edit_group_removed;
-       sigc::signal<void> mix_group_removed;
+       sigc::signal<void>             edit_group_removed;
+       sigc::signal<void>             mix_group_removed;
 
        void foreach_edit_group (sigc::slot<void,RouteGroup*> sl) {
                for (list<RouteGroup *>::iterator i = edit_groups.begin(); i != edit_groups.end(); i++) {
@@ -502,11 +512,13 @@ class Session : public PBD::StatefulDestructible
 
        /* fundamental operations. duh. */
 
-       std::list<boost::shared_ptr<AudioTrack> > new_audio_track (int input_channels, int output_channels, TrackMode mode = Normal, uint32_t how_many = 1);
+       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);
 
-       std::list<boost::shared_ptr<MidiTrack> > new_midi_track (TrackMode mode = Normal, uint32_t how_many = 1);
-       //boost::shared_ptr<Route>     new_midi_route (uint32_t how_many = 1);
+       std::list<boost::shared_ptr<MidiTrack> > new_midi_track (
+                       TrackMode mode = Normal, uint32_t how_many = 1);
 
        void   remove_route (boost::shared_ptr<Route>);
        void   resort_routes ();
@@ -542,8 +554,8 @@ class Session : public PBD::StatefulDestructible
        void sync_time_vars();
 
        void bbt_time (nframes_t when, BBT_Time&);
-       void smpte_to_sample( SMPTE::Time& smpte, nframes_t& sample, bool use_offset, bool use_subframes ) const;
-       void sample_to_smpte( nframes_t sample, SMPTE::Time& smpte, bool use_offset, bool use_subframes ) const;
+       void smpte_to_sample(SMPTE::Time& smpte, nframes_t& sample, bool use_offset, bool use_subframes) const;
+       void sample_to_smpte(nframes_t sample, SMPTE::Time& smpte, bool use_offset, bool use_subframes) const;
        void smpte_time (SMPTE::Time &);
        void smpte_time (nframes_t when, SMPTE::Time&);
        void smpte_time_subframes (nframes_t when, SMPTE::Time&);
@@ -552,7 +564,7 @@ class Session : public PBD::StatefulDestructible
        void smpte_duration_string (char *, nframes_t) const;
 
        void           set_smpte_offset (nframes_t);
-       nframes_t smpte_offset () const { return _smpte_offset; }
+       nframes_t      smpte_offset () const { return _smpte_offset; }
        void           set_smpte_offset_negative (bool);
        bool           smpte_offset_negative () const { return _smpte_offset_negative; }
 
@@ -562,12 +574,12 @@ class Session : public PBD::StatefulDestructible
        static sigc::signal<void> EndTimeChanged;
        static sigc::signal<void> SMPTEOffsetChanged;
 
-       void        request_slave_source (SlaveSource);
-       bool        synced_to_jack() const { return Config->get_slave_source() == 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; }
+       double transport_speed() const { return _transport_speed; }
+       bool   transport_stopped() const { return _transport_speed == 0.0f; }
+       bool   transport_rolling() const { return _transport_speed != 0.0f; }
 
        void set_silent (bool yn);
        bool silent () { return _silent; }
@@ -576,6 +588,9 @@ class Session : public PBD::StatefulDestructible
 
        TempoMap& tempo_map() { return *_tempo_map; }
 
+       /// signals the current transport position in frames, bbt and smpte time (in that order)
+       sigc::signal<void, const nframes_t&, const BBT_Time&, const SMPTE::Time&> tick;
+       
        /* region info  */
 
        void add_regions (std::vector<boost::shared_ptr<Region> >&);
@@ -600,45 +615,32 @@ class Session : public PBD::StatefulDestructible
 
        /* source management */
 
-       struct import_status : public InterThreadInfo {
-           string doing_what;
-
-           /* control info */
-           SrcQuality quality;
-           volatile bool freeze;
-           std::vector<Glib::ustring> paths;
-           bool replace_existing_source;
+       struct ImportStatus : public InterThreadInfo {
+               string doing_what;
 
-           /* result */
-           SourceList sources;
+               /* control info */
+               uint32_t total;
+               SrcQuality quality;
+               volatile bool freeze;
+               std::vector<Glib::ustring> paths;
+               bool replace_existing_source;
 
+               /* result */
+               SourceList sources;
        };
 
-       void import_audiofiles (import_status&);
-       bool sample_rate_convert (import_status&, string infile, string& outfile);
+       void import_audiofiles (ImportStatus&);
+       bool sample_rate_convert (ImportStatus&, string infile, string& outfile);
        string build_tmp_convert_name (string file);
 
-       /* Export stuff */
-
-       SlaveSource post_export_slave;
-       nframes_t post_export_position;
-
-       ExportStatus export_status;
-       
        boost::shared_ptr<ExportHandler> get_export_handler ();
-       void release_export_handler ();
+       boost::shared_ptr<ExportStatus> get_export_status ();
 
-       int  pre_export ();
-       int  start_audio_export (nframes_t position, bool realtime);
-       int  stop_audio_export ();
-       void finalize_audio_export ();
-       void abort_audio_export ();
+       int  start_audio_export (nframes_t position, bool realtime);    
 
        sigc::signal<int, nframes_t> ProcessExport;
-       sigc::signal<void> ExportFinished;
+       sigc::signal<void> ExportReadFinished;
        static sigc::signal<void, std::string, std::string> Exported;
-       sigc::connection export_freewheel_connection;
-       sigc::connection export_abort_connection;
 
        void add_source (boost::shared_ptr<Source>);
        void remove_source (boost::weak_ptr<Source>);
@@ -656,23 +658,19 @@ class Session : public PBD::StatefulDestructible
 
        int remove_last_capture ();
 
-       /* handlers should return -1 for "stop cleanup", 0 for
-          "yes, delete this playlist" and 1 for "no, don't delete
-          this playlist.
+       /** handlers should return -1 for "stop cleanup",
+           0 for "yes, delete this playlist",
+           1 for "no, don't delete this playlist".
        */
-
        sigc::signal<int,boost::shared_ptr<ARDOUR::Playlist> > AskAboutPlaylistDeletion;
 
-       /* handlers should return 0 for "ignore the rate mismatch"
-          and !0 for "do not use this session"
+       /** handlers should return 0 for "ignore the rate mismatch",
+           !0 for "do not use this session"
        */
-
        static sigc::signal<int,nframes_t, nframes_t> AskAboutSampleRateMismatch;
 
-       /* handlers should return !0 for use pending state, 0 for
-          ignore it.
+       /** handlers should return !0 for use pending state, 0 for ignore it.
        */
-
        static sigc::signal<int> AskAboutPendingState;
 
        boost::shared_ptr<AudioFileSource> create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive);
@@ -706,7 +704,6 @@ class Session : public PBD::StatefulDestructible
        sigc::signal<void> NamedSelectionRemoved;
 
        /* Curves and AutomationLists (TODO when they go away) */
-       void add_curve(Evoral::Curve*);
        void add_automation_list(AutomationList*);
 
        /* fade curves */
@@ -727,8 +724,8 @@ class Session : public PBD::StatefulDestructible
 
        /* flattening stuff */
 
-       boost::shared_ptr<Region> write_one_track (AudioTrack&, nframes_t start, nframes_t end, bool overwrite, vector<boost::shared_ptr<Source> >&,
-                                                  InterThreadInfo& wot);
+       boost::shared_ptr<Region> write_one_track (AudioTrack&, nframes_t start, nframes_t end,
+                       bool overwrite, vector<boost::shared_ptr<Source> >&, InterThreadInfo& wot);
        int freeze (InterThreadInfo&);
 
        /* session-wide solo/mute/rec-enable */
@@ -773,7 +770,6 @@ class Session : public PBD::StatefulDestructible
 
        /* I/O bundles */
 
-       void foreach_bundle (sigc::slot<void, boost::shared_ptr<Bundle> >);
        void add_bundle (boost::shared_ptr<Bundle>);
        void remove_bundle (boost::shared_ptr<Bundle>);
        boost::shared_ptr<Bundle> bundle_by_name (string) const;
@@ -781,7 +777,7 @@ class Session : public PBD::StatefulDestructible
        sigc::signal<void,boost::shared_ptr<Bundle> > BundleAdded;
        sigc::signal<void,boost::shared_ptr<Bundle> > BundleRemoved;
 
-       /* MIDI */
+       /* MIDI control */
 
        void midi_panic(void);
        int set_mtc_port (string port_tag);
@@ -918,7 +914,7 @@ class Session : public PBD::StatefulDestructible
 
        /* clicking */
 
-       boost::shared_ptr<IO>  click_io() { return _click_io; }
+       boost::shared_ptr<IO> click_io() { return _click_io; }
 
        /* disk, buffer loads */
 
@@ -946,21 +942,14 @@ class Session : public PBD::StatefulDestructible
        gain_t* gain_automation_buffer () const { return _gain_automation_buffer; }
        pan_t** pan_automation_buffer () const  { return _pan_automation_buffer; }
 
-       /* buffers for conversion */
-       enum RunContext {
-               ButlerContext = 0,
-               TransportContext,
-               ExportContext
-       };
-
        /* VST support */
 
        static long vst_callback (AEffect* effect,
-                                 long opcode,
-                                 long index,
-                                 long value,
-                                 void* ptr,
-                                 float opt);
+                       long opcode,
+                       long index,
+                       long value,
+                       void* ptr,
+                       float opt);
 
        static sigc::signal<void> SendFeedback;
 
@@ -971,6 +960,8 @@ class Session : public PBD::StatefulDestructible
        void add_controllable (boost::shared_ptr<PBD::Controllable>);
        void remove_controllable (PBD::Controllable*);
 
+       SessionMetadata & metadata () { return *_metadata; }
+
   protected:
        friend class AudioEngine;
        void set_block_size (nframes_t nframes);
@@ -1022,13 +1013,17 @@ class Session : public PBD::StatefulDestructible
        Location*                start_location;
        Slave*                  _slave;
        bool                    _silent;
-       volatile float          _transport_speed;
-       volatile float          _desired_transport_speed;
-       float                   _last_transport_speed;
+       volatile double         _transport_speed;
+       double                  _last_transport_speed;
+       // fixed point transport speed for varispeed playback
+       uint64_t                phi; 
+       // fixed point target transport speed for varispeed playback when tempo changes
+       uint64_t                target_phi;
+       // fixed point phase for varispeed playback
+       uint64_t                phase;
        bool                     auto_play_legal;
        nframes_t               _last_slave_transport_frame;
        nframes_t                maximum_output_latency;
-       nframes_t                last_stop_frame;
        volatile nframes64_t    _requested_return_frame;
        BufferSet*              _scratch_buffers;
        BufferSet*              _silent_buffers;
@@ -1078,11 +1073,30 @@ class Session : public PBD::StatefulDestructible
 
        void reset_slave_state ();
        bool follow_slave (nframes_t, nframes_t);
+       void calculate_moving_average_of_slave_delta(int dir, nframes_t this_delta);
+       void track_slave_state(
+                       float     slave_speed, 
+                       nframes_t slave_transport_frame, 
+                       nframes_t this_delta,
+                       bool      starting);
+       void follow_slave_silently(nframes_t nframes, nframes_t offset, float slave_speed);
+       
        void set_slave_source (SlaveSource);
 
+       SlaveSource post_export_slave;
+       nframes_t post_export_position;
+
        bool _exporting;
        bool _exporting_realtime;
+       
        boost::shared_ptr<ExportHandler> export_handler;
+       boost::shared_ptr<ExportStatus>  export_status;
+
+       int  pre_export ();
+       int  stop_audio_export ();
+       void finalize_audio_export ();
+       
+       sigc::connection export_freewheel_connection;
 
        void prepare_diskstreams ();
        void commit_diskstreams (nframes_t, bool& session_requires_butler);
@@ -1102,7 +1116,6 @@ class Session : public PBD::StatefulDestructible
        }
 
        int get_transport_declick_required () {
-
                if (transport_sub_state & PendingDeclickIn) {
                        transport_sub_state &= ~PendingDeclickIn;
                        return 1;
@@ -1114,7 +1127,8 @@ class Session : public PBD::StatefulDestructible
        }
 
        bool maybe_stop (nframes_t limit) {
-               if ((_transport_speed > 0.0f && _transport_frame >= limit) || (_transport_speed < 0.0f && _transport_frame == 0)) {
+               if (   (_transport_speed > 0.0f && _transport_frame >= limit)
+                   || (_transport_speed < 0.0f && _transport_frame == 0)    ) {
                        stop_transport ();
                        return true;
                }
@@ -1177,15 +1191,17 @@ class Session : public PBD::StatefulDestructible
        mutable gint      butler_should_do_transport_work;
        int               butler_request_pipe[2];
 
-       inline bool transport_work_requested() const { return g_atomic_int_get(&butler_should_do_transport_work); }
+       inline bool transport_work_requested() const {
+               return g_atomic_int_get(&butler_should_do_transport_work);
+       }
 
        struct ButlerRequest {
-           enum Type {
-                   Wake,
-                   Run,
-                   Pause,
-                   Quit
-           };
+               enum Type {
+                       Wake,
+                       Run,
+                       Pause,
+                       Quit
+               };
        };
 
        enum PostTransportWork {
@@ -1207,14 +1223,15 @@ class Session : public PBD::StatefulDestructible
        };
 
        static const PostTransportWork ProcessCannotProceedMask =
-               PostTransportWork (PostTransportInputChange|
-                                  PostTransportSpeed|
-                                  PostTransportReverse|
-                                  PostTransportCurveRealloc|
-                                  PostTransportScrub|
-                                  PostTransportAudition|
-                                  PostTransportLocate|
-                                  PostTransportStop);
+               PostTransportWork (
+                               PostTransportInputChange|
+                               PostTransportSpeed|
+                               PostTransportReverse|
+                               PostTransportCurveRealloc|
+                               PostTransportScrub|
+                               PostTransportAudition|
+                               PostTransportLocate|
+                               PostTransportStop);
 
        PostTransportWork post_transport_work;
 
@@ -1307,13 +1324,9 @@ class Session : public PBD::StatefulDestructible
 
        void deliver_mmc (MIDI::MachineControl::Command, nframes_t);
 
-       void spp_start (MIDI::Parser&);
-       void spp_continue (MIDI::Parser&);
-       void spp_stop (MIDI::Parser&);
-
-       void midi_clock_start (MIDI::Parser&);
-       void midi_clock_continue (MIDI::Parser&);
-       void midi_clock_stop (MIDI::Parser&);
+       void spp_start (MIDI::Parser&, nframes_t timestamp);
+       void spp_continue (MIDI::Parser&, nframes_t timestamp);
+       void spp_stop (MIDI::Parser&, nframes_t timestamp);
 
        void mmc_deferred_play (MIDI::MachineControl &);
        void mmc_stop (MIDI::MachineControl &);
@@ -1373,15 +1386,11 @@ class Session : public PBD::StatefulDestructible
        bool process_can_proceed() const { return !(post_transport_work & ProcessCannotProceedMask); }
 
        struct MIDIRequest {
-
-           enum Type {
-                   PortChange,
-                   Quit
-           };
-
-           Type type;
-
-           MIDIRequest () {}
+               enum Type {
+                       PortChange,
+                       Quit
+               };
+               Type type;
        };
 
        Glib::Mutex  midi_lock;
@@ -1397,9 +1406,6 @@ class Session : public PBD::StatefulDestructible
        void          change_midi_ports ();
        int           use_config_midi_ports ();
 
-       mutable  gint   butler_active;
-       bool waiting_to_start;
-
        void set_play_loop (bool yn);
        void overwrite_some_buffers (Diskstream*);
        void flush_all_inserts ();
@@ -1407,11 +1413,10 @@ class Session : public PBD::StatefulDestructible
        void locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void start_locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void force_locate (nframes_t frame, bool with_roll = false);
-       void set_diskstream_speed (Diskstream*, float speed);
-       void set_transport_speed (float speed, bool abort = false);
+       void set_diskstream_speed (Diskstream*, double speed);
+       void set_transport_speed (double speed, bool abort = false);
        void stop_transport (bool abort = false);
        void start_transport ();
-       void actually_start_transport ();
        void realtime_stop (bool abort);
        void non_realtime_start_scrub ();
        void non_realtime_set_speed ();
@@ -1442,16 +1447,15 @@ class Session : public PBD::StatefulDestructible
 
        uint32_t audio_dstream_buffer_size;
        uint32_t midi_dstream_buffer_size;
-       int  load_diskstreams (const XMLNode&);
+       int load_diskstreams (const XMLNode&);
 
        /* routes stuff */
 
        SerializedRCUManager<RouteList>  routes;
 
-       void   add_routes (RouteList&, bool save);
+       void add_routes (RouteList&, bool save);
        uint32_t destructive_index;
 
-       int load_routes (const XMLNode&);
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&);
 
        /* mixer stuff */
@@ -1462,6 +1466,7 @@ class Session : public PBD::StatefulDestructible
        void route_mute_changed (void *src);
        void route_solo_changed (void *src, boost::weak_ptr<Route>);
        void catch_up_on_solo ();
+       void catch_up_on_solo_mute_override ();
        void update_route_solo_state ();
        void modify_solo_mute (bool, bool);
        void strip_portname_for_solo (string& portname);
@@ -1492,8 +1497,6 @@ class Session : public PBD::StatefulDestructible
        SourceMap get_sources() { return sources; }
 
   private:
-
-
        int load_sources (const XMLNode& node);
        XMLNode& get_sources_as_xml ();
 
@@ -1529,7 +1532,6 @@ class Session : public PBD::StatefulDestructible
        NamedSelection *XMLNamedSelectionFactory (const XMLNode&);
 
        /* CURVES and AUTOMATION LISTS */
-       std::map<PBD::ID, Evoral::Curve*> curves;
        std::map<PBD::ID, AutomationList*> automation_lists;
 
        /* DEFAULT FADE CURVES */
@@ -1567,18 +1569,18 @@ class Session : public PBD::StatefulDestructible
        /* S/W RAID */
 
        struct space_and_path {
-           uint32_t blocks; /* 4kB blocks */
-           string path;
+               uint32_t blocks; /* 4kB blocks */
+               string path;
 
-           space_and_path() {
-                   blocks = 0;
-           }
+               space_and_path() {
+                       blocks = 0;
+               }
        };
 
        struct space_and_path_ascending_cmp {
-           bool operator() (space_and_path a, space_and_path b) {
-                   return a.blocks > b.blocks;
-           }
+               bool operator() (space_and_path a, space_and_path b) {
+                       return a.blocks > b.blocks;
+               }
        };
 
        void setup_raid_path (string path);
@@ -1598,9 +1600,7 @@ class Session : public PBD::StatefulDestructible
 
        /* I/O bundles */
 
-       typedef list<boost::shared_ptr<Bundle> > BundleList;
-       mutable Glib::Mutex bundle_lock;
-       BundleList _bundles;
+       SerializedRCUManager<BundleList> _bundles;
        XMLNode* _bundle_xml_node;
        int load_bundles (XMLNode const &);
 
@@ -1629,36 +1629,36 @@ class Session : public PBD::StatefulDestructible
        /* click track */
 
        struct Click {
-           nframes_t start;
-           nframes_t duration;
-           nframes_t offset;
-           const Sample *data;
+               nframes_t start;
+               nframes_t duration;
+               nframes_t offset;
+               const Sample *data;
 
-           Click (nframes_t s, nframes_t d, const Sample *b)
-                   : start (s), duration (d), data (b) { offset = 0; }
+               Click (nframes_t s, nframes_t d, const Sample *b)
+                       : start (s), duration (d), data (b) { offset = 0; }
 
-           void *operator new(size_t ignored) {
-                   return pool.alloc ();
-           };
+               void *operator new(size_t ignored) {
+                       return pool.alloc ();
+               };
 
-           void operator delete(void *ptr, size_t size) {
-                   pool.release (ptr);
-           }
+               void operator delete(void *ptr, size_t size) {
+                       pool.release (ptr);
+               }
 
          private:
-           static Pool pool;
+               static Pool pool;
        };
 
        typedef list<Click*> Clicks;
 
-       Clicks          clicks;
-       bool           _clicking;
+       Clicks                 clicks;
+       bool                  _clicking;
        boost::shared_ptr<IO> _click_io;
-       Sample*         click_data;
-       Sample*         click_emphasis_data;
-       nframes_t  click_length;
-       nframes_t  click_emphasis_length;
-       mutable Glib::RWLock click_lock;
+       Sample*                click_data;
+       Sample*                click_emphasis_data;
+       nframes_t              click_length;
+       nframes_t              click_emphasis_length;
+       mutable Glib::RWLock   click_lock;
 
        static const Sample    default_click[];
        static const nframes_t default_click_length;
@@ -1693,11 +1693,11 @@ class Session : public PBD::StatefulDestructible
        /* VST support */
 
        long _vst_callback (VSTPlugin*,
-                           long opcode,
-                           long index,
-                           long value,
-                           void* ptr,
-                           float opt);
+                       long opcode,
+                       long index,
+                       long value,
+                       void* ptr,
+                       float opt);
 
        /* number of hardware ports we're using,
           based on max (requested,available)
@@ -1706,6 +1706,11 @@ class Session : public PBD::StatefulDestructible
        uint32_t n_physical_outputs;
        uint32_t n_physical_inputs;
 
+       uint32_t n_physical_audio_outputs;
+       uint32_t n_physical_audio_inputs;
+
+       uint32_t n_physical_midi_outputs;
+       uint32_t n_physical_midi_inputs;
 
        int find_all_sources (std::string path, std::set<std::string>& result);
        int find_all_sources_across_snapshots (std::set<std::string>& result, bool exclude_this_snapshot);
@@ -1730,11 +1735,9 @@ class Session : public PBD::StatefulDestructible
 
        static bool _disable_all_loaded_plugins;
        
-       /* Metadata */
-
        SessionMetadata * _metadata;
-  public:
-       SessionMetadata & metadata () { return *_metadata; }
+
+       mutable bool have_looped; ///< Used in ::audible_frame(*)
 };
 
 } // namespace ARDOUR