Fix broken whitespace. I'd apologize for the compile times if it was my fault :D
[ardour.git] / libs / ardour / ardour / session.h
index 7abeabd647c5591f383013429b3144128eedd4a4..e1e693510ad64b5896b7417f2f9880bcdf72c0f4 100644 (file)
 #ifndef __ardour_session_h__
 #define __ardour_session_h__
 
+#include "libardour-config.h"
+
 #include <list>
 #include <map>
 #include <set>
-#include <stack>
 #include <string>
 #include <vector>
 #include <stdint.h>
@@ -172,14 +173,11 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        static PBD::Signal1<void,std::string> Dialog;
 
-       std::string sound_dir (bool with_path = true) const;
-       std::string peak_dir () const;
-       std::string dead_sound_dir () const;
+       int ensure_subdirs ();
+
        std::string automation_dir () const;
        std::string analysis_dir() const;
        std::string plugins_dir() const;
-       
-       int ensure_subdirs ();
 
        std::string peak_path (std::string) const;
 
@@ -188,7 +186,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string peak_path_from_audio_path (std::string) const;
        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&, bool as_stub = false);
+       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);
 
        void process (pframes_t nframes);
@@ -208,7 +206,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 ();
@@ -252,7 +250,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                return (RecordState) g_atomic_int_get (&_record_status);
        }
 
-       bool actively_recording () {
+       bool actively_recording () const {
                return record_status() == Recording;
        }
 
@@ -273,7 +271,15 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* Transport mechanism signals */
 
-       PBD::Signal0<void> TransportStateChange; /* generic */
+       /** Emitted on the following changes in transport state:
+        *  - stop (from the butler thread)
+        *  - change in whether or not we are looping (from the process thread)
+        *  - change in the play range (from the process thread)
+        *  - start (from the process thread)
+        *  - 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;
@@ -304,6 +310,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        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_overwrite_buffer (Track *);
        void adjust_playback_buffering();
        void adjust_capture_buffering();
@@ -315,7 +322,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        int wipe ();
 
-       std::pair<framepos_t, framepos_t> get_extent () const;
        framepos_t current_end_frame () const;
        framepos_t current_start_frame () const;
        /** "actual" sample rate of session, set by current audioengine rate, pullup/down etc. */
@@ -352,8 +358,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        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);
@@ -396,12 +403,14 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void add_route_group (RouteGroup *);
        void remove_route_group (RouteGroup&);
+       void reorder_route_groups (std::list<RouteGroup*>);
 
        RouteGroup* route_group_by_name (std::string);
        RouteGroup& all_route_group() const;
 
        PBD::Signal1<void,RouteGroup*> route_group_added;
        PBD::Signal0<void>             route_group_removed;
+       PBD::Signal0<void>             route_groups_reordered;
 
        void foreach_route_group (boost::function<void(RouteGroup*)> f) {
                for (std::list<RouteGroup *>::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) {
@@ -409,16 +418,27 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                }
        }
 
+       std::list<RouteGroup*> const & route_groups () const {
+               return _route_groups;
+       }
+
        /* fundamental operations. duh. */
 
        std::list<boost::shared_ptr<AudioTrack> > new_audio_track (
-               int input_channels, int output_channels, TrackMode mode = Normal, RouteGroup* route_group = 0, uint32_t how_many = 1
+               int input_channels,
+               int output_channels,
+               TrackMode mode = Normal,
+               RouteGroup* route_group = 0,
+               uint32_t how_many = 1,
+               std::string name_template = ""
                );
 
-       RouteList new_audio_route (bool aux, int input_channels, int output_channels, RouteGroup* route_group, uint32_t how_many);
+       RouteList new_audio_route (
+               int input_channels, int output_channels, RouteGroup* route_group, uint32_t how_many, std::string name_template = ""
+               );
 
        std::list<boost::shared_ptr<MidiTrack> > new_midi_track (
-               TrackMode mode = Normal, RouteGroup* route_group = 0, uint32_t how_many = 1
+               TrackMode mode = Normal, RouteGroup* route_group = 0, uint32_t how_many = 1, std::string name_template = ""
                );
 
        void   remove_route (boost::shared_ptr<Route>);
@@ -461,7 +481,7 @@ 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;
@@ -509,6 +529,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void add_source (boost::shared_ptr<Source>);
        void remove_source (boost::weak_ptr<Source>);
 
+       void  cleanup_regions();
        int  cleanup_sources (CleanupReport&);
        int  cleanup_trash_sources (CleanupReport&);
 
@@ -532,10 +553,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        static PBD::Signal0<int> AskAboutPendingState;
 
        boost::shared_ptr<AudioFileSource> create_audio_source_for_session (
-               size_t, std::string const &, uint32_t, bool destructive, bool as_stub = false);
-       
+               size_t, std::string const &, uint32_t, bool destructive);
+
        boost::shared_ptr<MidiSource> create_midi_source_for_session (
-               Track*, std::string const &, bool as_stub = false);
+               Track*, std::string const &);
 
        boost::shared_ptr<Source> source_by_id (const PBD::ID&);
        boost::shared_ptr<Source> source_by_path_and_channel (const std::string&, uint16_t);
@@ -556,12 +577,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /* Curves and AutomationLists (TODO when they go away) */
        void add_automation_list(AutomationList*);
 
-       /* fade curves */
-
-       float get_default_fade_length () const { return default_fade_msecs; }
-       float get_default_fade_steepness () const { return default_fade_steepness; }
-       void set_default_fade (float steepness, float msecs);
-
        /* auditioning */
 
        boost::shared_ptr<Auditioner> the_auditioner() { return auditioner; }
@@ -597,7 +612,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        PBD::Signal1<void,bool> SoloActive;
        PBD::Signal0<void> SoloChanged;
        PBD::Signal0<void> IsolatedChanged;
-       
+
        /* control/master out */
 
        boost::shared_ptr<Route> monitor_out() const { return _monitor_out; }
@@ -662,14 +677,17 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string next_redo() const { return _history.next_redo(); }
 
        void begin_reversible_command (const std::string& cmd_name);
+       void begin_reversible_command (GQuark);
        void commit_reversible_command (Command* cmd = 0);
 
-       UndoTransaction* start_reversible_command (const std::string& cmd_name);
-       void finish_reversible_command (UndoTransaction&);
-
        void add_command (Command *const cmd) {
-               assert(!_current_trans.empty ());
-               _current_trans.top()->add_command (cmd);
+               assert (_current_trans);
+               _current_trans->add_command (cmd);
+       }
+
+       /** @return The list of operations that are currently in progress */
+       std::list<GQuark> const & current_operations () {
+               return _current_trans_quarks;
        }
 
        void add_commands (std::vector<Command*> const & cmds);
@@ -715,7 +733,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* Speakers */
 
-       Speakers& get_speakers ();
+       boost::shared_ptr<Speakers> get_speakers ();
 
        /* Controllables */
 
@@ -725,6 +743,8 @@ 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; }
 
        SessionConfiguration config;
@@ -764,7 +784,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                Waiting,
                Running
        };
-       
+
        SlaveState slave_state() const { return _slave_state; }
 
        boost::shared_ptr<SessionPlaylists> playlists;
@@ -807,7 +827,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
   protected:
        friend class Route;
        void schedule_curve_reallocation ();
-       void update_latency_compensation (bool, bool);
+       void update_latency_compensation (bool force = false);
 
   private:
        int  create (const std::string& mix_template, BusProfile*);
@@ -840,7 +860,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        Location*               _session_range_location; ///< session range, or 0 if there is nothing in the session yet
        Slave*                  _slave;
        bool                    _silent;
-       
+
+       void maybe_update_session_range (framepos_t, framepos_t);
+
        // varispeed playback
        double                  _transport_speed;
        double                  _last_transport_speed;
@@ -865,9 +887,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        bool                    _was_seamless;
 
        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 update_latency_compensation_proxy (void* ignored);
 
@@ -959,7 +985,11 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string             _path;
        std::string             _name;
        bool                    _is_new;
-       bool                     session_send_mtc;
+       bool                    _send_qf_mtc;
+       /** Number of process frames since the last MTC output (when sending MTC); used to
+        *  know when to send full MTC messages every so often.
+        */
+       pframes_t               _pframes_since_last_mtc;
        bool                     session_midi_feedback;
        bool                     play_loop;
        bool                     loop_changing;
@@ -971,6 +1001,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;
@@ -1054,7 +1085,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void first_stage_init (std::string path, std::string snapshot_name);
        int  second_stage_init ();
-       void update_session_range_location_marker ();
        void remove_empty_sounds ();
 
        void setup_midi_control ();
@@ -1137,7 +1167,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        bool _send_timecode_update; ///< Flag to send a full frame (Timecode) MTC message this cycle
 
-       int send_midi_time_code_for_cycle (pframes_t nframes);
+       int send_midi_time_code_for_cycle (framepos_t, framepos_t, pframes_t nframes);
 
        void reset_record_status ();
 
@@ -1165,6 +1195,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        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 ();
@@ -1190,7 +1221,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        SerializedRCUManager<RouteList>  routes;
 
-       void add_routes (RouteList&, bool save);
+       void add_routes (RouteList&, bool auto_connect, bool save);
        uint32_t destructive_index;
 
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&, int);
@@ -1198,16 +1229,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void route_processors_changed (RouteProcessorChange);
 
-       bool find_route_name (const char* base, uint32_t& id, char* name, size_t name_len);
-       void count_existing_route_channels (ChanCount& in, ChanCount& out);
-       void auto_connect_route (
-               Route* route,
-               ChanCount& existing_inputs,
-               ChanCount& existing_outputs,
-               bool connect_inputs = true,
-               ChanCount input_start = ChanCount (),
-               ChanCount output_start = ChanCount ()
-               );
+       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);
 
        /* mixer stuff */
 
@@ -1227,6 +1254,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        mutable Glib::Mutex region_lock;
 
        int load_regions (const XMLNode& node);
+       int load_compounds (const XMLNode& node);
 
        void route_group_changed ();
 
@@ -1234,10 +1262,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        mutable Glib::Mutex source_lock;
 
-  public:      
+  public:
        typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap;
 
-  private:     
+  private:
        SourceMap sources;
 
   public:
@@ -1253,6 +1281,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void remove_playlist (boost::weak_ptr<Playlist>);
        void track_playlist_changed (boost::weak_ptr<Track>);
+       void playlist_region_added (boost::weak_ptr<Region>);
+       void playlist_ranges_moved (std::list<Evoral::RangeMove<framepos_t> > const &);
+       void playlist_regions_extended (std::list<Evoral::Range<framepos_t> > const &);
 
        /* NAMED SELECTIONS */
 
@@ -1331,14 +1362,22 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        void reverse_track_buffers ();
 
-       UndoHistory                  _history;
-       std::stack<UndoTransaction*> _current_trans;
+       UndoHistory      _history;
+       /** current undo transaction, or 0 */
+       UndoTransaction* _current_trans;
+       /** GQuarks to describe the reversible commands that are currently in progress.
+        *  These may be nested, in which case more recently-started commands are toward
+        *  the front of the list.
+        */
+       std::list<GQuark> _current_trans_quarks;
 
        void jack_timebase_callback (jack_transport_state_t, pframes_t, jack_position_t*, int);
        int  jack_sync_callback (jack_transport_state_t, jack_position_t*);
        void reset_jack_connection (jack_client_t* jack);
        void process_rtop (SessionEvent*);
 
+       void  update_latency (bool playback);
+
        XMLNode& state(bool);
 
        /* click track */
@@ -1359,6 +1398,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        Click *get_click();
        void   setup_click_sounds (int which);
+       void   setup_click_sounds (Sample**, Sample const *, framecnt_t*, framecnt_t, std::string const &);
        void   clear_clicks ();
        void   click (framepos_t start, framecnt_t nframes);
 
@@ -1400,6 +1440,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        Glib::Mutex controllables_lock;
        Controllables controllables;
 
+       boost::shared_ptr<PBD::Controllable> _solo_cut_control;
+
        void reset_native_file_format();
        bool first_file_data_format_reset;
        bool first_file_header_format_reset;
@@ -1425,7 +1467,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /* realtime "apply to set of routes" operations */
        SessionEvent* get_rt_event (
                boost::shared_ptr<RouteList> rl, bool yn,
-               SessionEvent::RTeventCallback after, bool group_override, 
+               SessionEvent::RTeventCallback after, bool group_override,
                void (Session::*method) (boost::shared_ptr<RouteList>, bool, bool));
 
        void rt_set_solo (boost::shared_ptr<RouteList>, bool yn, bool group_override);
@@ -1441,7 +1483,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void add_session_range_location (framepos_t, framepos_t);
 
        void setup_midi_machine_control ();
-       void cleanup_stubfiles ();
 
        void route_order_key_changed ();
 
@@ -1456,7 +1497,11 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void start_time_changed (framepos_t);
        void end_time_changed (framepos_t);
 
-       Speakers* _speakers; 
+       void set_track_monitor_input_status (bool);
+       framepos_t compute_stop_limit () const;
+
+       boost::shared_ptr<Speakers> _speakers;
+       void load_nested_sources (const XMLNode& node);
 };
 
 } // namespace ARDOUR