most of libardour now actually compiles
[ardour.git] / libs / ardour / ardour / session.h
index 780c68f2b0ab2f86dfcaaf15e3b4fa25cdee5f5b..a782680082ac5f800807d5dfe630eac392fb7f84 100644 (file)
@@ -34,7 +34,7 @@
 #include <boost/weak_ptr.hpp>
 #include <boost/utility.hpp>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 
 #include "pbd/error.h"
 #include "pbd/event_loop.h"
@@ -48,6 +48,7 @@
 #include "midi++/types.h"
 
 #include "timecode/time.h"
+#include "ltc/ltc.h"
 
 #include "ardour/ardour.h"
 #include "ardour/chan_count.h"
@@ -64,6 +65,7 @@
 #include <jack/session.h>
 #endif
 
+
 class XMLTree;
 class XMLNode;
 struct _AEffect;
@@ -193,7 +195,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        std::string new_audio_source_name (const std::string&, uint32_t nchans, uint32_t chan, bool destructive);
        std::string new_midi_source_name (const std::string&);
        std::string new_source_path_from_name (DataType type, const std::string&);
-       RouteList new_route_from_template (uint32_t how_many, const std::string& template_path);
+        RouteList new_route_from_template (uint32_t how_many, const std::string& template_path, const std::string& name);
 
        void process (pframes_t nframes);
 
@@ -247,7 +249,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<Route> route_by_id (PBD::ID);
        boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
        boost::shared_ptr<Track> track_by_diskstream_id (PBD::ID);
-       void routes_using_input_from (const std::string& str, RouteList& rl);
+        void routes_using_input_from (const std::string& str, RouteList& rl);
 
        bool route_name_unique (std::string) const;
        bool route_name_internal (std::string) const;
@@ -357,7 +359,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                return mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
        }
 
-       float timecode_frames_per_second() const;
+       double timecode_frames_per_second() const;
        bool timecode_drop_frames() const;
 
        /* Locations */
@@ -390,9 +392,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void rename_state (std::string old_name, std::string new_name);
        void remove_pending_capture_state ();
        int rename (const std::string&);
+       bool get_nsm_state () const { return _under_nsm_control; }
+       void set_nsm_state (bool state) { _under_nsm_control = state; }
 
        PBD::Signal1<void,std::string> StateSaved;
        PBD::Signal0<void> StateReady;
+       PBD::Signal0<void> SaveSession;
 
        std::vector<std::string*>* possible_states() const;
        static std::vector<std::string*>* possible_states (std::string path);
@@ -503,9 +508,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        static PBD::Signal1<void, framepos_t> StartTimeChanged;
        static PBD::Signal1<void, framepos_t> EndTimeChanged;
 
-       std::vector<SyncSource> get_available_sync_options() const;
        void   request_sync_source (Slave*);
-       bool   synced_to_jack() const { return config.get_external_sync() && config.get_sync_source() == JACK; }
+       bool   synced_to_jack() const { return config.get_external_sync() && Config->get_sync_source() == JACK; }
 
        double transport_speed() const { return _transport_speed; }
        bool   transport_stopped() const { return _transport_speed == 0.0f; }
@@ -613,8 +617,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void set_listen (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_record_enabled (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
        void set_solo_isolated (boost::shared_ptr<RouteList>, bool, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
-       void set_exclusive_input_active (boost::shared_ptr<Route> rt, bool others_on);
        void set_monitoring (boost::shared_ptr<RouteList>, MonitorChoice, SessionEvent::RTeventCallback after = rt_cleanup, bool group_override = false);
+        void set_exclusive_input_active (boost::shared_ptr<RouteList> rt, bool onoff, bool flip_others=false);
 
        PBD::Signal1<void,bool> SoloActive;
        PBD::Signal0<void> SoloChanged;
@@ -731,6 +735,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void request_play_range (std::list<AudioRange>*, bool leave_rolling = false);
        bool get_play_range () const { return _play_range; }
 
+       void maybe_update_session_range (framepos_t, framepos_t);
+
        /* buffers for gain and pan */
 
        gain_t* gain_automation_buffer () const;
@@ -801,6 +807,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        };
 
        SlaveState slave_state() const { return _slave_state; }
+        Slave* slave() const { return _slave; }
 
        boost::shared_ptr<SessionPlaylists> playlists;
 
@@ -843,6 +850,17 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /** Emitted when the session wants Ardour to quit */
        static PBD::Signal0<void> Quit;
 
+        /** Emitted when Ardour is asked to load a session in an older session
+        * format, and makes a backup copy.
+        */
+        static PBD::Signal2<void,std::string,std::string> VersionMismatch;
+
+        boost::shared_ptr<Port> ltc_input_port() const;
+        boost::shared_ptr<Port> ltc_output_port() const;
+
+       boost::shared_ptr<IO> ltc_input_io() { return _ltc_input; }
+       boost::shared_ptr<IO> ltc_output_io() { return _ltc_output; }
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -887,8 +905,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        Slave*                  _slave;
        bool                    _silent;
 
-       void maybe_update_session_range (framepos_t, framepos_t);
-
        // varispeed playback
        double                  _transport_speed;
        double                  _default_transport_speed;
@@ -912,6 +928,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        uint32_t                _solo_isolated_cnt;
        bool                    _writable;
        bool                    _was_seamless;
+       bool                    _under_nsm_control;
 
        void initialize_latencies ();
        void set_worst_io_latencies ();
@@ -931,7 +948,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void process_without_events (pframes_t);
        void process_with_events    (pframes_t);
        void process_audition       (pframes_t);
-       void process_export         (pframes_t);
+        int  process_export         (pframes_t);
        int  process_export_fw      (pframes_t);
 
        void block_processing() { g_atomic_int_set (&processing_prohibited, 1); }
@@ -964,6 +981,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        framepos_t post_export_position;
 
        bool _exporting;
+       bool _export_started;
        bool _export_rolling;
 
        boost::shared_ptr<ExportHandler> export_handler;
@@ -972,6 +990,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int  pre_export ();
        int  stop_audio_export ();
        void finalize_audio_export ();
+       void finalize_export_internal (bool stop_freewheel);
        bool _pre_export_mmc_enabled;
 
        PBD::ScopedConnection export_freewheel_connection;
@@ -1064,7 +1083,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                                PostTransportClearSubstate);
 
        gint _post_transport_work; /* accessed only atomic ops */
-       PostTransportWork post_transport_work() const        { return (PostTransportWork) g_atomic_int_get (&_post_transport_work); }
+        PostTransportWork post_transport_work() const        { return (PostTransportWork) g_atomic_int_get (const_cast<gint*>(&_post_transport_work)); }
        void set_post_transport_work (PostTransportWork ptw) { g_atomic_int_set (&_post_transport_work, (gint) ptw); }
        void add_post_transport_work (PostTransportWork ptw);
 
@@ -1159,7 +1178,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        MIDI::byte mtc_msg[16];
        MIDI::byte mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
        MIDI::byte midi_msg[16];
-       framepos_t outbound_mtc_timecode_frame;
+       double outbound_mtc_timecode_frame;
        Timecode::Time transmitting_timecode_time;
        int next_quarter_frame_to_send;
 
@@ -1177,6 +1196,33 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        int send_midi_time_code_for_cycle (framepos_t, framepos_t, pframes_t nframes);
 
+       LTCEncoder*       ltc_encoder;
+       ltcsnd_sample_t*  ltc_enc_buf;
+
+       Timecode::TimecodeFormat ltc_enc_tcformat;
+       int32_t           ltc_buf_off;
+       int32_t           ltc_buf_len;
+
+       double            ltc_speed;
+       int32_t           ltc_enc_byte;
+       framepos_t        ltc_enc_pos;
+       double            ltc_enc_cnt;
+       framepos_t        ltc_enc_off;
+       bool              restarting;
+
+       framepos_t        ltc_timecode_offset;
+       bool              ltc_timecode_negative_offset;
+
+       LatencyRange      ltc_out_latency;
+
+       void ltc_tx_initialize();
+       void ltc_tx_cleanup();
+       void ltc_tx_reset();
+       void ltc_tx_resync_latency();
+       void ltc_tx_recalculate_position();
+       void ltc_tx_parse_offset();
+       void ltc_tx_send_time_code_for_cycle (framepos_t, framepos_t, double, double, pframes_t nframes);
+
        void reset_record_status ();
 
        int no_roll (pframes_t nframes);
@@ -1229,6 +1275,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        SerializedRCUManager<RouteList>  routes;
 
        void add_routes (RouteList&, bool input_auto_connect, bool output_auto_connect, bool save);
+        void add_routes_inner (RouteList&, bool input_auto_connect, bool output_auto_connect);
+        bool _adding_routes_in_progress;
        uint32_t destructive_index;
 
        boost::shared_ptr<Route> XMLRouteFactory (const XMLNode&, int);
@@ -1258,7 +1306,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* REGION MANAGEMENT */
 
-       mutable Glib::Mutex region_lock;
+       mutable Glib::Threads::Mutex region_lock;
 
        int load_regions (const XMLNode& node);
        int load_compounds (const XMLNode& node);
@@ -1269,7 +1317,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* SOURCES */
 
-       mutable Glib::Mutex source_lock;
+       mutable Glib::Threads::Mutex source_lock;
 
   public:
        typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap;
@@ -1354,7 +1402,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
            could not report free space.
        */
        bool _total_free_4k_blocks_uncertain;
-       Glib::Mutex space_lock;
+       Glib::Threads::Mutex space_lock;
 
        bool no_questions_about_missing_files;
 
@@ -1397,7 +1445,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        Sample*                 click_emphasis_data;
        framecnt_t              click_length;
        framecnt_t              click_emphasis_length;
-       mutable Glib::RWLock    click_lock;
+       mutable Glib::Threads::RWLock    click_lock;
 
        static const Sample     default_click[];
        static const framecnt_t default_click_length;
@@ -1450,7 +1498,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int find_all_sources_across_snapshots (std::set<std::string>& result, bool exclude_this_snapshot);
 
        typedef std::set<boost::shared_ptr<PBD::Controllable> > Controllables;
-       Glib::Mutex controllables_lock;
+       Glib::Threads::Mutex controllables_lock;
        Controllables controllables;
 
        boost::shared_ptr<PBD::Controllable> _solo_cut_control;
@@ -1528,6 +1576,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        bool ignore_route_processor_changes;
 
        MidiClockTicker* midi_clock;
+
+        boost::shared_ptr<IO>   _ltc_input;
+        boost::shared_ptr<IO>   _ltc_output;
+
+        void reconnect_ltc_input ();
+        void reconnect_ltc_output ();
 };
 
 } // namespace ARDOUR