Selection of visible note range (full range vs fit contents, selectable from midi...
[ardour.git] / libs / ardour / ardour / session.h
index d173f434070ea201de17a04c9270f493ba5f6a00..8a5165396832da0645519a63eb5c21aea45fc92f 100644 (file)
@@ -27,6 +27,7 @@
 #include <set>
 #include <stack>
 
+#include <boost/scoped_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 #include <boost/dynamic_bitset.hpp>
 
@@ -86,12 +87,12 @@ class MidiDiskstream;
 class AudioFileSource;
 class MidiSource;
 class Auditioner;
-class Insert;
+class Processor;
 class Send;
-class Redirect;
+class IOProcessor;
 class PortInsert;
 class PluginInsert;
-class Connection;
+class Bundle;
 class TempoMap;
 class AudioTrack;
 class NamedSelection;
@@ -106,6 +107,8 @@ class MidiTrack;
 class MidiRegion;
 class SMFSource;
 
+class SessionDirectory;
+
 struct AudioExportSpecification;
 struct RouteGroup;
 
@@ -240,14 +243,10 @@ class Session : public PBD::StatefulDestructible
        
        virtual ~Session ();
 
-
-       static int find_session (string str, string& path, string& snapshot, bool& isnew);
-       
        string path() const { return _path; }
        string name() const { return _name; }
        string snap_name() const { return _current_snapshot_name; }
        string raid_path () const;
-       string export_dir () const;
 
        void set_snap_name ();
 
@@ -258,17 +257,10 @@ class Session : public PBD::StatefulDestructible
        bool deletion_in_progress() const { return _state_of_the_state & Deletion; }
        sigc::signal<void> DirtyChanged;
 
-       std::string sound_dir (bool with_path = true) const;
-       std::string peak_dir () const;
-       std::string dead_sound_dir () const;
+       const SessionDirectory& session_directory () const { return *(_session_dir.get()); }
+
        std::string automation_dir () const;
 
-       static string suffixed_search_path (std::string suffix, bool data);
-       static string control_protocol_path ();
-       static string template_path ();
-       static string template_dir ();
-       static void get_template_list (list<string>&);
-       
        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);
        
@@ -280,7 +272,7 @@ class Session : public PBD::StatefulDestructible
 
        BufferSet& get_silent_buffers (ChanCount count = ChanCount::ZERO);
        BufferSet& get_scratch_buffers (ChanCount count = ChanCount::ZERO);
-       BufferSet& get_send_buffers (ChanCount count = ChanCount::ZERO);
+       BufferSet& get_mix_buffers (ChanCount count = ChanCount::ZERO);
        
        void add_diskstream (boost::shared_ptr<Diskstream>);
        boost::shared_ptr<Diskstream> diskstream_by_id (const PBD::ID& id);
@@ -356,6 +348,7 @@ class Session : public PBD::StatefulDestructible
        sigc::signal<void,nframes_t> PositionChanged; /* sent after any non-sequential motion */
        sigc::signal<void> DurationChanged;
        sigc::signal<void> HaltOnXrun;
+       sigc::signal<void> TransportLooped;
 
        sigc::signal<void,RouteList&> RouteAdded;
 
@@ -425,14 +418,10 @@ class Session : public PBD::StatefulDestructible
        int save_state (string snapshot_name, bool pending = false);
        int restore_state (string snapshot_name);
        int save_template (string template_name);
-        int save_history (string snapshot_name = "");
-        int restore_history (string snapshot_name);
+       int save_history (string snapshot_name = "");
+       int restore_history (string snapshot_name);
        void remove_state (string snapshot_name);
        void rename_state (string old_name, string new_name);
-
-       static int rename_template (string old_name, string new_name);
-
-       static int delete_template (string name);
        
        sigc::signal<void,string> StateSaved;
        sigc::signal<void> StateReady;
@@ -443,8 +432,10 @@ class Session : public PBD::StatefulDestructible
        XMLNode& get_state();
        int      set_state(const XMLNode& node); // not idempotent
        XMLNode& get_template();
-       
-       void add_instant_xml (XMLNode&, const std::string& dir);
+
+       /// The instant xml file is written to the session directory
+       void add_instant_xml (XMLNode&);
+       XMLNode * instant_xml (const std::string& str);
 
        enum StateOfTheState {
                Clean = 0x0,
@@ -658,9 +649,11 @@ class Session : public PBD::StatefulDestructible
        sigc::signal<void> NamedSelectionAdded;
        sigc::signal<void> NamedSelectionRemoved;
 
-        /* Curves and AutomationLists (TODO when they go away) */
-        void add_curve(Curve*);
-        void add_automation_list(AutomationList*);
+       /* Curves and AutomationLists (TODO when they go away) */
+       void add_curve(Curve*);
+       void add_automation_list(AutomationList*);
+       
+       nframes_t automation_interval () const { return _automation_interval; }
 
        /* fade curves */
 
@@ -717,15 +710,15 @@ class Session : public PBD::StatefulDestructible
        
        nframes_t available_capture_duration();
 
-       /* I/O Connections */
+       /* I/O bundles */
 
-       template<class T> void foreach_connection (T *obj, void (T::*func)(Connection *));
-       void add_connection (Connection *);
-       void remove_connection (Connection *);
-       Connection *connection_by_name (string) const;
+       template<class T> void foreach_bundle (T *obj, void (T::*func)(Bundle *));
+       void add_bundle (Bundle *);
+       void remove_bundle (Bundle *);
+       Bundle *bundle_by_name (string) const;
 
-       sigc::signal<void,Connection *> ConnectionAdded;
-       sigc::signal<void,Connection *> ConnectionRemoved;
+       sigc::signal<void,Bundle *> BundleAdded;
+       sigc::signal<void,Bundle *> BundleRemoved;
 
        /* MIDI */
 
@@ -762,6 +755,9 @@ class Session : public PBD::StatefulDestructible
 
        /* History (for editors, mixers, UIs etc.) */
 
+       /** Undo some transactions.
+        * @param n Number of transactions to undo.
+        */
        void undo (uint32_t n) {
                _history.undo (n);
        }
@@ -786,9 +782,9 @@ class Session : public PBD::StatefulDestructible
 
        std::map<PBD::ID, PBD::StatefulThingWithGoingAway*> registry;
 
-        // these commands are implemented in libs/ardour/session_command.cc
+       // these commands are implemented in libs/ardour/session_command.cc
        Command* memento_command_factory(XMLNode* n);
-        void register_with_memento_command_factory(PBD::ID, PBD::StatefulThingWithGoingAway*);
+       void register_with_memento_command_factory(PBD::ID, PBD::StatefulThingWithGoingAway*);
 
        Command* global_state_command_factory (const XMLNode& n);
 
@@ -898,19 +894,6 @@ class Session : public PBD::StatefulDestructible
        void request_play_range (bool yn);
        bool get_play_range () const { return _play_range; }
 
-       /* favorite dirs */
-       typedef vector<string> FavoriteDirs;
-
-       static int read_favorite_dirs (FavoriteDirs&);
-
-       static int write_favorite_dirs (FavoriteDirs&);
-       
-       /* file suffixes */
-
-       static const char* template_suffix() { return _template_suffix; }
-       static const char* statefile_suffix() { return _statefile_suffix; }
-       static const char* pending_suffix() { return _pending_suffix; }
-
        /* buffers for gain and pan */
 
        gain_t* gain_automation_buffer () const { return _gain_automation_buffer; }
@@ -932,25 +915,13 @@ class Session : public PBD::StatefulDestructible
                                  void* ptr,
                                  float opt);
 
-       typedef float (*compute_peak_t)                 (Sample *, nframes_t, float);
-       typedef void  (*find_peaks_t)                   (Sample *, nframes_t, float *, float*);
-       typedef void  (*apply_gain_to_buffer_t)         (Sample *, nframes_t, float);
-       typedef void  (*mix_buffers_with_gain_t)        (Sample *, Sample *, nframes_t, float);
-       typedef void  (*mix_buffers_no_gain_t)          (Sample *, Sample *, nframes_t);
-
-       static compute_peak_t           compute_peak;
-       static find_peaks_t             find_peaks;
-       static apply_gain_to_buffer_t   apply_gain_to_buffer;
-       static mix_buffers_with_gain_t  mix_buffers_with_gain;
-       static mix_buffers_no_gain_t    mix_buffers_no_gain;
-
        static sigc::signal<void> SendFeedback;
 
        /* Controllables */
 
-       PBD::Controllable* controllable_by_id (const PBD::ID&);
+       boost::shared_ptr<PBD::Controllable> controllable_by_id (const PBD::ID&);
 
-       void add_controllable (PBD::Controllable*);
+       void add_controllable (boost::shared_ptr<PBD::Controllable>);
        void remove_controllable (PBD::Controllable*);
 
   protected:
@@ -969,14 +940,13 @@ class Session : public PBD::StatefulDestructible
        void update_latency_compensation (bool, bool);
        
   private:
-       int  create (bool& new_session, string* mix_template, nframes_t initial_length);
        void destroy ();
 
-       nframes_t compute_initial_length ();
+       void initialize_start_and_end_locations(nframes_t start, nframes_t end);
+       bool create_session_file();
+       bool create_session_file_from_template (const string& template_path);
 
-       static const char* _template_suffix;
-       static const char* _statefile_suffix;
-       static const char* _pending_suffix;
+       nframes_t compute_initial_length ();
 
        enum SubState {
                PendingDeclickIn   = 0x1,
@@ -995,6 +965,7 @@ class Session : public PBD::StatefulDestructible
 
        AudioEngine            &_engine;
        mutable gint            processing_prohibited;
+       /// the function called when the main JACK process callback happens
        process_function_type    process_function;
        process_function_type    last_process_function;
        bool                     waiting_for_sync_offset;
@@ -1015,7 +986,7 @@ class Session : public PBD::StatefulDestructible
        nframes_t           last_stop_frame;
        BufferSet*              _scratch_buffers;
        BufferSet*              _silent_buffers;
-       BufferSet*              _send_buffers;
+       BufferSet*              _mix_buffers;
        nframes_t           current_block_size;
        nframes_t          _worst_output_latency;
        nframes_t          _worst_input_latency;
@@ -1119,6 +1090,8 @@ class Session : public PBD::StatefulDestructible
        bool                     loop_changing;
        nframes_t           last_loopend;
 
+       boost::scoped_ptr<SessionDirectory>        _session_dir;
+
        RingBuffer<Event*> pending_events;
 
        void hookup_io ();
@@ -1331,13 +1304,13 @@ class Session : public PBD::StatefulDestructible
        /* cache the most-recently requested time conversions. This helps when we
         * have multiple clocks showing the same time (e.g. the transport frame) */
        bool           last_smpte_valid;
-       jack_nframes_t last_smpte_when;
+       nframes_t last_smpte_when;
        SMPTE::Time    last_smpte;
        
        bool _send_smpte_update; ///< Flag to send a full frame (SMPTE) MTC message this cycle
 
-       int send_full_time_code(jack_nframes_t nframes);
-       int send_midi_time_code_for_cycle(jack_nframes_t nframes);
+       int send_full_time_code(nframes_t nframes);
+       int send_midi_time_code_for_cycle(nframes_t nframes);
 
        nframes_t adjust_apparent_position (nframes_t frames);
        
@@ -1401,7 +1374,7 @@ class Session : public PBD::StatefulDestructible
 
        void set_play_loop (bool yn);
        void overwrite_some_buffers (Diskstream*);
-       void flush_all_redirects ();
+       void flush_all_inserts ();
        void locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void start_locate (nframes_t, bool with_roll, bool with_flush, bool with_loop=false);
        void force_locate (nframes_t frame, bool with_roll = false);
@@ -1548,8 +1521,8 @@ class Session : public PBD::StatefulDestructible
        uint32_t          insert_cnt;
 
 
-       void add_redirect (Redirect *);
-       void remove_redirect (Redirect *);
+       void add_processor (Processor *);
+       void remove_processor (Processor *);
 
        /* S/W RAID */
 
@@ -1574,17 +1547,9 @@ class Session : public PBD::StatefulDestructible
        vector<space_and_path>::iterator last_rr_session_dir;
        uint32_t _total_free_4k_blocks;
        Glib::Mutex space_lock;
-
-       static const char* old_sound_dir_name;
-       static const char* sound_dir_name;
-       static const char* dead_sound_dir_name;
-       static const char* interchange_dir_name;
-       static const char* peak_dir_name;
-       static const char* export_dir_name;
        
        string old_sound_dir (bool with_path = true) const;
-       string discover_best_sound_dir (bool destructive = false);
-       int ensure_sound_dir (string, string&);
+       string get_best_session_directory_for_new_source ();
        void refresh_disk_space ();
 
        mutable gint _playback_load;
@@ -1592,12 +1557,12 @@ class Session : public PBD::StatefulDestructible
        mutable gint _playback_load_min;
        mutable gint _capture_load_min;
 
-       /* I/O Connections */
+       /* I/O bundles */
 
-       typedef list<Connection *> ConnectionList;
-       mutable Glib::Mutex connection_lock;
-       ConnectionList _connections;
-       int load_connections (const XMLNode&);
+       typedef list<Bundle *> BundleList;
+       mutable Glib::Mutex bundle_lock;
+       BundleList  _bundles;
+       int load_bundles (const XMLNode&);
 
        void reverse_diskstream_buffers ();
 
@@ -1685,6 +1650,8 @@ class Session : public PBD::StatefulDestructible
        void allocate_pan_automation_buffers (nframes_t nframes, uint32_t howmany, bool force);
        uint32_t _npan_buffers;
 
+       nframes_t _automation_interval;
+
        /* VST support */
 
        long _vst_callback (VSTPlugin*,
@@ -1709,7 +1676,7 @@ class Session : public PBD::StatefulDestructible
        LayerModel layer_model;
        CrossfadeModel xfade_model;
 
-       typedef std::set<PBD::Controllable*> Controllables;
+       typedef std::set<boost::shared_ptr<PBD::Controllable> > Controllables;
        Glib::Mutex controllables_lock;
        Controllables controllables;