new Session::default_track_name_pattern (DataType) method, based on an idea in Tracks
[ardour.git] / libs / ardour / ardour / session.h
index 30afd00fdb5489f16a896d7d70279c8e7d7f59e2..a2f8c164c8659b59a2760ff66794c17cfe6fc4e2 100644 (file)
@@ -176,13 +176,21 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        bool dirty() const { return _state_of_the_state & Dirty; }
        void set_deletion_in_progress ();
        void clear_deletion_in_progress ();
+       bool reconnection_in_progress() const { return _reconnecting_routes_in_progress; }
        bool deletion_in_progress() const { return _state_of_the_state & Deletion; }
+       bool routes_deletion_in_progress() const { return _route_deletion_in_progress; }
+
        PBD::Signal0<void> DirtyChanged;
 
+       PBD::Signal1<void, bool> RouteAddedOrRemoved;
+
        const SessionDirectory& session_directory () const { return *(_session_dir.get()); }
 
        static PBD::Signal1<void,std::string> Dialog;
 
+       PBD::Signal0<void> BatchUpdateStart;
+       PBD::Signal0<void> BatchUpdateEnd;
+
        int ensure_subdirs ();
 
        std::string automation_dir () const;  ///< Automation data
@@ -211,6 +219,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        BufferSet& get_mix_buffers (ChanCount count = ChanCount::ZERO);
 
        bool have_rec_enabled_track () const;
+    bool have_rec_disabled_track () const;
 
        bool have_captured() const { return _have_captured; }
 
@@ -289,9 +298,19 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        PBD::Signal0<void> IOConnectionsComplete;
 
+       /* Timecode status signals */
+       PBD::Signal1<void, bool> MTCSyncStateChanged;
+       
        /* Record status signals */
 
-       PBD::Signal0<void> RecordStateChanged;
+       PBD::Signal0<void> RecordStateChanged; /* signals changes in recording state (i.e. are we recording) */
+       /* XXX may 2015: paul says: it isn't clear to me that this has semantics that cannot be inferrred
+          from the previous signal and session state.
+       */
+       PBD::Signal0<void> RecordArmStateChanged; /* signals changes in recording arming */
+
+       /* Emited when session is loaded */
+       PBD::Signal0<void> SessionLoaded;
 
        /* Transport mechanism signals */
 
@@ -328,6 +347,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        /* Step Editing status changed */
        PBD::Signal1<void,bool> StepEditStatusChange;
 
+       /* Timecode state signals */
+       PBD::Signal0<void> MtcOrLtcInputPortChanged;
+       
        void queue_event (SessionEvent*);
 
        void request_roll_at_and_return (framepos_t start, framepos_t return_to);
@@ -397,8 +419,11 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
                std::string new_parent_folder;  /* parent folder where new session folder will be created */
                std::string new_name;           /* name of newly saved session */
                bool        switch_to;     /* true if we should be working on newly saved session after save-as; false otherwise */
+               bool        include_media; /* true if the newly saved session should contain references to media */
                bool        copy_media;    /* true if media files (audio, media, etc) should be copied into newly saved session; false otherwise */
                bool        copy_external; /* true if external media should be consolidated into the newly saved session; false otherwise */
+
+               std::string final_session_folder_name; /* filled in by * Session::save_as(), provides full path to newly saved session */
                
                /* emitted as we make progress. 3 arguments passed to signal
                 * handler:
@@ -419,7 +444,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        };
 
        int save_as (SaveAs&);
-       int save_state (std::string snapshot_name, bool pending = false, bool switch_to_snapshot = false);
+       int save_state (std::string snapshot_name, bool pending = false, bool switch_to_snapshot = false, bool template_only = false);
        int restore_state (std::string snapshot_name);
        int save_template (std::string template_name);
        int save_history (std::string snapshot_name = "");
@@ -427,7 +452,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void remove_state (std::string snapshot_name);
        void rename_state (std::string old_name, std::string new_name);
        void remove_pending_capture_state ();
-       int rename (const std::string&, bool after_copy = false);
+       int rename (const std::string&);
        bool get_nsm_state () const { return _under_nsm_control; }
        void set_nsm_state (bool state) { _under_nsm_control = state; }
        bool save_default_options ();
@@ -533,13 +558,17 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
                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 remove_routes (boost::shared_ptr<RouteList>);
+       void remove_route (boost::shared_ptr<Route>);
+
+       void resort_routes ();
+       void resort_routes_using (boost::shared_ptr<RouteList>);
 
        AudioEngine & engine() { return _engine; }
        AudioEngine const & engine () const { return _engine; }
 
+       static std::string default_track_name_pattern (DataType);
+       
        /* Time */
 
        framepos_t transport_frame () const {return _transport_frame; }
@@ -580,7 +609,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void   request_sync_source (Slave*);
        bool   synced_to_engine() const { return _slave && config.get_external_sync() && Config->get_sync_source() == Engine; }
-
+       bool   synced_to_mtc () const { return config.get_external_sync() && Config->get_sync_source() == MTC && g_atomic_int_get (const_cast<gint*>(&_mtc_active)); }
+       
        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; }
@@ -590,6 +620,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        TempoMap&       tempo_map()       { return *_tempo_map; }
        const TempoMap& tempo_map() const { return *_tempo_map; }
 
+       unsigned int    get_xrun_count () const {return _xrun_count; }
+       void            reset_xrun_count () {_xrun_count = 0; }
+
        /* region info  */
 
        boost::shared_ptr<Region> find_whole_file_parent (boost::shared_ptr<Region const>) const;
@@ -691,6 +724,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        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_record_safe (boost::shared_ptr<RouteList>, bool yn, 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);
@@ -699,6 +733,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        PBD::Signal0<void> SoloChanged;
        PBD::Signal0<void> IsolatedChanged;
 
+       PBD::Signal0<void> session_routes_reconnected;
+
        /* monitor/master out */
 
        void add_monitor_section ();
@@ -814,9 +850,18 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void maybe_update_session_range (framepos_t, framepos_t);
 
+       /* temporary hacks to allow selection to be pushed from GUI into backend.
+          Whenever we move the selection object into libardour, these will go away.
+        */
+       void set_range_selection (framepos_t start, framepos_t end);
+       void set_object_selection (framepos_t start, framepos_t end);
+       void clear_range_selection ();
+       void clear_object_selection ();
+       
        /* buffers for gain and pan */
 
        gain_t* gain_automation_buffer () const;
+       gain_t* trim_automation_buffer () const;
        gain_t* send_gain_automation_buffer () const;
        pan_t** pan_automation_buffer () const;
 
@@ -968,6 +1013,10 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
     
        MIDI::MachineControl& mmc() { return *_mmc; }
 
+       void reconnect_midi_scene_ports (bool);
+       void reconnect_mtc_ports ();
+       void reconnect_mmc_ports (bool);
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -1037,7 +1086,11 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        bool                    _writable;
        bool                    _was_seamless;
        bool                    _under_nsm_control;
+       unsigned int            _xrun_count;
 
+       void mtc_status_changed (bool);
+       PBD::ScopedConnection mtc_status_connection;
+       
        void initialize_latencies ();
        void set_worst_io_latencies ();
        void set_worst_playback_latency ();
@@ -1075,6 +1128,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        bool have_first_delta_accumulator;
 
        SlaveState _slave_state;
+       gint _mtc_active;
        framepos_t slave_wait_end;
 
        void reset_slave_state ();
@@ -1217,7 +1271,6 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void update_skips (Location*, bool consolidate);
        void update_marks (Location* loc);
-       void update_loop (Location* loc);
        void consolidate_skips (Location*);
        void sync_locations_to_skips ();
        void _sync_locations_to_skips ();
@@ -1239,6 +1292,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        int  post_engine_init ();
        int  immediately_post_engine ();
        void remove_empty_sounds ();
+       
+       void session_loaded ();
 
        void setup_midi_control ();
        int  midi_read (MIDI::Port *);
@@ -1266,6 +1321,21 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void *do_work();
 
+       /* Signal Forwarding */
+       void emit_route_signals ();
+       void emit_thread_run ();
+       static void *emit_thread (void *);
+       void emit_thread_start ();
+       void emit_thread_terminate ();
+
+       pthread_t       _rt_emit_thread;
+       bool            _rt_thread_active;
+
+       pthread_mutex_t _rt_emit_mutex;
+       pthread_cond_t  _rt_emit_cond;
+       bool            _rt_emit_pending;
+
+
        /* SessionEventManager interface */
 
        void process_event (SessionEvent*);
@@ -1386,6 +1456,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void engine_halted ();
        void xrun_recovery ();
        void set_track_loop (bool);
+       bool select_playhead_priority_target (framepos_t&);
+       void follow_playhead_priority ();
        
        /* These are synchronous and so can only be called from within the process
         * cycle
@@ -1413,6 +1485,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        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;
+       bool _reconnecting_routes_in_progress;
+       bool _route_deletion_in_progress;
+
        uint32_t destructive_index;
 
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&, int);
@@ -1420,7 +1495,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void route_processors_changed (RouteProcessorChange);
 
-       bool find_route_name (std::string const &, uint32_t& id, char* name, size_t name_len, bool);
+       bool find_route_name (std::string const &, uint32_t& id, std::string& name, 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,
@@ -1607,6 +1682,12 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void set_play_range (std::list<AudioRange>&, bool leave_rolling);
        void unset_play_range ();
 
+       /* temporary hacks to allow selection to be pushed from GUI into backend
+          Whenever we move the selection object into libardour, these will go away.
+       */
+       Evoral::Range<framepos_t> _range_selection;
+       Evoral::Range<framepos_t> _object_selection;
+       
        /* main outs */
        uint32_t main_outs;
 
@@ -1649,8 +1730,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        mutable bool have_looped; ///< Used in ::audible_frame(*)
 
-       void update_have_rec_enabled_track ();
+       void update_route_record_state ();
        gint _have_rec_enabled_track;
+       gint _have_rec_disabled_track;
 
        static int ask_about_playlist_deletion (boost::shared_ptr<Playlist>);
 
@@ -1673,12 +1755,13 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        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_record_safe (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;
 
-       void add_session_range_location (framepos_t, framepos_t);
+       void set_session_range_location (framepos_t, framepos_t);
 
        void setup_midi_machine_control ();
 
@@ -1731,6 +1814,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void save_as_bring_callback (uint32_t, uint32_t, std::string);
 
        static int get_session_info_from_path (XMLTree& state_tree, const std::string& xmlpath);
+       static const uint32_t session_end_shift;
 };