Merge branch 'cairocanvas' of git.ardour.org:ardour/ardour into cairocanvas
[ardour.git] / libs / ardour / ardour / session.h
index 525dfbd84961b0878a03d4f78b1a45886f439e94..40ada138a6dac0f8027d0536da423afbba66110a 100644 (file)
@@ -36,6 +36,8 @@
 
 #include <glibmm/threads.h>
 
+#include <ltc.h>
+
 #include "pbd/error.h"
 #include "pbd/event_loop.h"
 #include "pbd/rcu.h"
@@ -48,7 +50,6 @@
 #include "midi++/types.h"
 
 #include "timecode/time.h"
-#include "ltc/ltc.h"
 
 #include "ardour/ardour.h"
 #include "ardour/chan_count.h"
@@ -110,6 +111,8 @@ class IOProcessor;
 class ImportStatus;
 class MidiClockTicker;
 class MidiControlUI;
+class MidiPortManager;
+class MidiPort;
 class MidiRegion;
 class MidiSource;
 class MidiTrack;
@@ -126,6 +129,7 @@ class Route;
 class RouteGroup;
 class SMFSource;
 class Send;
+class SceneChanger;
 class SessionDirectory;
 class SessionMetadata;
 class SessionPlaylists;
@@ -138,7 +142,7 @@ class WindowsVSTPlugin;
 
 extern void setup_enum_writer ();
 
-class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionList, public SessionEventManager
+class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionList, public SessionEventManager
 {
   public:
        enum RecordState {
@@ -159,6 +163,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        virtual ~Session ();
 
+        static int get_info_from_path (const std::string& xmlpath, float& sample_rate, SampleFormat& data_format);
+
        std::string path() const { return _path; }
        std::string name() const { return _name; }
        std::string snap_name() const { return _current_snapshot_name; }
@@ -189,8 +195,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        std::string peak_path (std::string) const;
 
-       std::string change_source_path_by_name (std::string oldpath, std::string oldname, std::string newname, bool destructive);
-
        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&);
@@ -233,12 +237,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                return _bundles.reader ();
        }
 
-       struct RoutePublicOrderSorter {
+       struct LIBARDOUR_API RoutePublicOrderSorter {
                bool operator() (boost::shared_ptr<Route>, boost::shared_ptr<Route> b);
        };
 
+       void set_order_hint (uint32_t order_hint) {_order_hint = order_hint;};
         void notify_remote_id_change ();
-        void sync_order_keys (RouteSortOrderKey);
+        void sync_order_keys ();
 
        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>));
@@ -381,9 +386,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        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
-       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);
        int restore_state (std::string snapshot_name);
        int save_template (std::string template_name);
@@ -501,7 +503,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void timecode_time_subframes (framepos_t when, Timecode::Time&);
 
        void timecode_duration (framecnt_t, Timecode::Time&) const;
-       void timecode_duration_string (char *, framecnt_t) const;
+        void timecode_duration_string (char *, size_t len, framecnt_t) const;
 
        framecnt_t convert_to_frames (AnyTime const & position);
        framecnt_t any_duration_to_frames (framepos_t position, AnyTime const & duration);
@@ -510,7 +512,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        static PBD::Signal1<void, framepos_t> EndTimeChanged;
 
        void   request_sync_source (Slave*);
-       bool   synced_to_jack() const { return config.get_external_sync() && Config->get_sync_source() == JACK; }
+       bool   synced_to_engine() const { return config.get_external_sync() && Config->get_sync_source() == Engine; }
 
        double transport_speed() const { return _transport_speed; }
        bool   transport_stopped() const { return _transport_speed == 0.0f; }
@@ -556,6 +558,11 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        int remove_last_capture ();
 
+        /** handlers should return 0 for "everything OK", and any other value for
+        * "cannot setup audioengine".
+        */
+        static PBD::Signal1<int,uint32_t> AudioEngineSetupRequired;
+
        /** handlers should return -1 for "stop cleanup",
            0 for "yes, delete this playlist",
            1 for "no, don't delete this playlist".
@@ -574,11 +581,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<AudioFileSource> create_audio_source_for_session (
                size_t, std::string const &, uint32_t, bool destructive);
 
-       boost::shared_ptr<MidiSource> create_midi_source_for_session (
-               Track*, std::string const &);
+       boost::shared_ptr<MidiSource> create_midi_source_for_session (std::string const &);
+       boost::shared_ptr<MidiSource> create_midi_source_by_stealing_name (boost::shared_ptr<Track>);
 
        boost::shared_ptr<Source> source_by_id (const PBD::ID&);
-       boost::shared_ptr<Source> source_by_path_and_channel (const std::string&, uint16_t);
+       boost::shared_ptr<AudioFileSource> source_by_path_and_channel (const std::string&, uint16_t) const;
+       boost::shared_ptr<MidiSource> source_by_path (const std::string&) const;
        uint32_t count_sources_by_origin (const std::string&);
 
        void add_playlist (boost::shared_ptr<Playlist>, bool unused = false);
@@ -748,6 +756,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        /* VST support */
 
+       static int  vst_current_loading_id;
+       static const char* vst_can_do_strings[];
+       static const int vst_can_do_string_count;
+
        static intptr_t vst_callback (
                AEffect* effect,
                int32_t opcode,
@@ -813,8 +825,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::shared_ptr<SessionPlaylists> playlists;
 
        void send_mmc_locate (framepos_t);
-       int send_full_time_code (framepos_t);
-       void send_song_position_pointer (framepos_t);
+        void queue_full_time_code () { _send_timecode_update = true; }
+        void queue_song_position_pointer () { /* currently does nothing */ }
 
        bool step_editing() const { return (_step_editors > 0); }
 
@@ -857,12 +869,32 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
         */
         static PBD::Signal2<void,std::string,std::string> VersionMismatch;
 
+       SceneChanger* scene_changer() const { return _scene_changer; }
+
         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; }
 
+       MIDI::Port* midi_input_port () const;
+       MIDI::Port* midi_output_port () const;
+       MIDI::Port* mmc_output_port () const;
+       MIDI::Port* mmc_input_port () const;
+
+       MIDI::Port* scene_input_port () const;
+       MIDI::Port* scene_output_port () const;
+
+       boost::shared_ptr<MidiPort> scene_in () const;
+       boost::shared_ptr<MidiPort> scene_out () const;
+       
+       boost::shared_ptr<MidiPort> midi_clock_output_port () const;
+       boost::shared_ptr<MidiPort> midi_clock_input_port () const;
+       boost::shared_ptr<MidiPort> mtc_output_port () const;
+       boost::shared_ptr<MidiPort> mtc_input_port () const;
+    
+       MIDI::MachineControl& mmc() { return *_mmc; }
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -1046,7 +1078,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        boost::scoped_ptr<SessionDirectory> _session_dir;
 
        void hookup_io ();
-       void when_engine_running ();
        void graph_reordered ();
 
        /** current snapshot name, without the .ardour suffix */
@@ -1112,8 +1143,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void             auto_loop_changed (Location *);
        void             auto_loop_declick_range (Location *, framepos_t &, framepos_t &);
 
-       void first_stage_init (std::string path, std::string snapshot_name);
-       int  second_stage_init ();
+        int  ensure_engine (uint32_t desired_sample_rate);
+       void pre_engine_init (std::string path);
+       int  post_engine_init ();
+        int  immediately_post_engine ();
        void remove_empty_sounds ();
 
        void setup_midi_control ();
@@ -1216,7 +1249,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        framepos_t        ltc_timecode_offset;
        bool              ltc_timecode_negative_offset;
 
-       jack_latency_range_t ltc_out_latency;
+       LatencyRange      ltc_out_latency;
 
        void ltc_tx_initialize();
        void ltc_tx_cleanup();
@@ -1238,7 +1271,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        int           start_midi_thread ();
 
-       void set_play_loop (bool yn);
+       void set_play_loop (bool yn, double speed);
        void unset_play_loop ();
        void overwrite_some_buffers (Track *);
        void flush_all_inserts ();
@@ -1261,6 +1294,13 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        void engine_halted ();
        void xrun_recovery ();
 
+    /* These are synchronous and so can only be called from within the process
+     * cycle
+     */
+
+    int  send_full_time_code (framepos_t, pframes_t nframes);
+    void send_song_position_pointer (framepos_t);
+
        TempoMap    *_tempo_map;
        void          tempo_map_changed (const PBD::PropertyChange&);
 
@@ -1328,9 +1368,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
   private:
        SourceMap sources;
 
-  public:
-       SourceMap get_sources() { return sources; }
-
   private:
        int load_sources (const XMLNode& node);
        XMLNode& get_sources_as_xml ();
@@ -1429,9 +1466,8 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
         */
        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);
+        int  backend_sync_callback (TransportState, framepos_t);
+
        void process_rtop (SessionEvent*);
 
        void  update_latency (bool playback);
@@ -1490,13 +1526,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
                float opt
                );
 
-       /* number of hardware ports we're using,
-          based on max (requested,available)
-       */
-
-       ChanCount n_physical_outputs;
-       ChanCount n_physical_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);
 
@@ -1576,6 +1605,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        GraphEdges _current_route_graph;
 
        uint32_t next_control_id () const;
+       uint32_t _order_hint;
        bool ignore_route_processor_changes;
 
        MidiClockTicker* midi_clock;
@@ -1585,6 +1615,20 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
         void reconnect_ltc_input ();
         void reconnect_ltc_output ();
+
+       /* Scene Changing */
+       SceneChanger* _scene_changer;
+       
+       /* persistent, non-track related MIDI ports */
+       MidiPortManager* _midi_ports;
+       MIDI::MachineControl* _mmc;
+       
+       void setup_ltc ();
+       void setup_click ();
+       void setup_click_state (const XMLNode*);
+       void setup_bundles ();
+       
+       static int get_session_info_from_path (XMLTree& state_tree, const std::string& xmlpath);
 };
 
 } // namespace ARDOUR