track templates, backported from 2.X
[ardour.git] / libs / ardour / ardour / session.h
index 60e6aa724e300feea3dd0fb8fddb2e3605035cda..082e05a9bdf26584f1699479a64f797ef25ac430 100644 (file)
 #include <boost/dynamic_bitset.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/weak_ptr.hpp>
+#include <boost/utility.hpp>
 
 #include <sndfile.h>
 
 #include <glibmm/thread.h>
 
-#include <pbd/error.h>
-#include <pbd/pool.h>
-#include <pbd/rcu.h>
-#include <pbd/statefuldestructible.h>
-#include <pbd/undo.h>
+#include "pbd/error.h"
+#include "pbd/pool.h"
+#include "pbd/rcu.h"
+#include "pbd/statefuldestructible.h"
+#include "pbd/undo.h"
 
-#include <midi++/mmc.h>
-#include <midi++/types.h>
+#include "midi++/mmc.h"
+#include "midi++/types.h"
 
-#include <pbd/destructible.h>
-#include <pbd/stateful.h>
+#include "pbd/destructible.h"
+#include "pbd/stateful.h"
 
-#include <ardour/ardour.h>
-#include <ardour/chan_count.h>
-#include <ardour/configuration.h>
-#include <ardour/location.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;
@@ -116,7 +117,7 @@ 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;
@@ -150,9 +151,7 @@ class Session : public PBD::StatefulDestructible
                        SetAudioRange,
                        SetPlayRange,
 
-                       /* only one of each of these events
-                          can be queued at any one time
-                          */
+                       /* only one of each of these events can be queued at any one time */
 
                        StopOnce,
                        AutoLoop
@@ -165,32 +164,33 @@ class Session : public PBD::StatefulDestructible
                        Clear
                };
 
-               Type           type;
-               Action         action;
-               nframes_t      action_frame;
-               nframes_t      target_frame;
-               double         speed;
+               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;
+                       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;
+               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) {}
+                       : type (t)
+                       , action (a)
+                       , action_frame (when)
+                       , target_frame (where)
+                       , speed (spd)
+                       , yes_or_no (yn)
+               {}
 
                void set_ptr (void* p) {
                        ptr = p;
@@ -275,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);
 
@@ -371,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);
@@ -397,16 +401,15 @@ class Session : public PBD::StatefulDestructible
        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; }
 
@@ -438,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);
@@ -467,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,
@@ -492,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++) {
@@ -509,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 ();
@@ -549,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&);
@@ -559,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; }
 
@@ -610,7 +615,7 @@ class Session : public PBD::StatefulDestructible
 
        /* source management */
 
-       struct import_status : public InterThreadInfo {
+       struct ImportStatus : public InterThreadInfo {
                string doing_what;
 
                /* control info */
@@ -624,8 +629,8 @@ class Session : public PBD::StatefulDestructible
                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);
 
        boost::shared_ptr<ExportHandler> get_export_handler ();
@@ -653,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);
@@ -703,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 */
@@ -777,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);
@@ -914,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 */
 
@@ -1024,7 +1024,6 @@ class Session : public PBD::StatefulDestructible
        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;
@@ -1076,10 +1075,10 @@ class Session : public PBD::StatefulDestructible
        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, 
+                       float     slave_speed, 
                        nframes_t slave_transport_frame, 
                        nframes_t this_delta,
-                       bool starting);
+                       bool      starting);
        void follow_slave_silently(nframes_t nframes, nframes_t offset, float slave_speed);
        
        void set_slave_source (SlaveSource);
@@ -1117,7 +1116,6 @@ class Session : public PBD::StatefulDestructible
        }
 
        int get_transport_declick_required () {
-
                if (transport_sub_state & PendingDeclickIn) {
                        transport_sub_state &= ~PendingDeclickIn;
                        return 1;
@@ -1129,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;
                }
@@ -1192,7 +1191,9 @@ 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 {
@@ -1446,13 +1447,13 @@ 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;
 
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&);
@@ -1496,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 ();
 
@@ -1533,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 */