Clean up State API:
[ardour.git] / libs / ardour / ardour / track.h
index 39f9a52ec5fc28348d03177ce983e7b258bd367f..6b024274f0fe1f258f429f2ffffb04f19ae23ecb 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
+#include "pbd/enum_convert.h"
+
 #include "ardour/interthread_info.h"
+#include "ardour/recordable.h"
 #include "ardour/route.h"
-#include "ardour/public_diskstream.h"
 
 namespace ARDOUR {
 
@@ -32,13 +34,24 @@ class Playlist;
 class RouteGroup;
 class Source;
 class Region;
-class Diskstream;
+class DiskReader;
+class DiskWriter;
 class IO;
-
-class LIBARDOUR_API Track : public Route, public PublicDiskstream
+class Location;
+class RecordEnableControl;
+class RecordSafeControl;
+
+/** A track is an route (bus) with a recordable diskstream and
+ * related objects relevant to recording, playback and editing.
+ *
+ * Specifically a track has a playlist object that describes material
+ * to be played from disk, and modifies that object during recording and
+ * editing.
+ */
+class LIBARDOUR_API Track : public Route, public Recordable
 {
-  public:
-       Track (Session&, std::string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
+public:
+       Track (Session&, std::string name, PresentationInfo::Flag f = PresentationInfo::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
        virtual ~Track ();
 
        int init ();
@@ -47,38 +60,15 @@ class LIBARDOUR_API Track : public Route, public PublicDiskstream
        void resync_track_name ();
 
        TrackMode mode () const { return _mode; }
-       virtual int set_mode (TrackMode /*m*/) { return false; }
-       virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
-       PBD::Signal0<void> TrackModeChanged;
-
-       virtual void set_monitoring (MonitorChoice);
-       MonitorChoice monitoring_choice() const { return _monitoring; }
-        MonitorState monitoring_state () const;
-       PBD::Signal0<void> MonitoringChanged;
 
        MeterState metering_state () const;
 
-       virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
-                            bool state_changing);
-
-       int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
-                        bool& need_butler);
-
-       virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
-                         int declick, bool& need_butler) = 0;
+       bool set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure);
 
        bool needs_butler() const { return _needs_butler; }
 
-       virtual DataType data_type () const = 0;
-
        bool can_record();
 
-       void use_new_diskstream ();
-       virtual boost::shared_ptr<Diskstream> create_diskstream() = 0;
-       virtual void set_diskstream (boost::shared_ptr<Diskstream>);
-
-       void set_latency_compensation (framecnt_t);
-
        enum FreezeState {
                NoFreeze,
                Frozen,
@@ -90,39 +80,55 @@ class LIBARDOUR_API Track : public Route, public PublicDiskstream
        virtual void freeze_me (InterThreadInfo&) = 0;
        virtual void unfreeze () = 0;
 
-       /** @return true if the track can be bounced, or false otherwise.
+       /** Test if the track can be bounced with the given settings.
+        * If sends/inserts/returns are present in the signal path or the given track
+        * has no audio outputs bouncing is not possible.
+        *
+        * @param endpoint the processor to tap the signal off (or nil for the top)
+        * @param include_endpoint include the given processor in the bounced audio.
+        * @return true if the track can be bounced, or false otherwise.
         */
        virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
-       virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
-       virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo&,
+
+       /** bounce track from session start to session end to new region
+        *
+        * @param itt asynchronous progress report and cancel
+        * @return a new audio region (or nil in case of error)
+        */
+       virtual boost::shared_ptr<Region> bounce (InterThreadInfo& itt) = 0;
+
+       /** Bounce the given range to a new audio region.
+        * @param start start time (in samples)
+        * @param end end time (in samples)
+        * @param itt asynchronous progress report and cancel
+        * @param endpoint the processor to tap the signal off (or nil for the top)
+        * @param include_endpoint include the given processor in the bounced audio.
+        * @return a new audio region (or nil in case of error)
+        */
+       virtual boost::shared_ptr<Region> bounce_range (samplepos_t start, samplepos_t end, InterThreadInfo& itt,
                                                        boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
-       virtual int export_stuff (BufferSet& bufs, framepos_t start_frame, framecnt_t nframes,
+       virtual int export_stuff (BufferSet& bufs, samplepos_t start_sample, samplecnt_t nframes,
                                  boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
 
-       XMLNode&    get_state();
-       XMLNode&    get_template();
        virtual int set_state (const XMLNode&, int version);
        static void zero_diskstream_id_in_xml (XMLNode&);
 
-       boost::shared_ptr<AutomationControl> rec_enable_control() { return _rec_enable_control; }
+       boost::shared_ptr<AutomationControl> rec_enable_control() const { return _record_enable_control; }
+       boost::shared_ptr<AutomationControl> rec_safe_control() const { return _record_safe_control; }
 
-       bool record_enabled() const;
-       bool record_safe () const;
-       void set_record_enabled (bool yn, PBD::Controllable::GroupControlDisposition);
-       void set_record_safe (bool yn, PBD::Controllable::GroupControlDisposition);
-       void prep_record_enabled (bool yn, PBD::Controllable::GroupControlDisposition);
+       int prep_record_enabled (bool);
+       bool can_be_record_enabled ();
+       bool can_be_record_safe ();
 
-       bool using_diskstream_id (PBD::ID) const;
+       void use_captured_sources (SourceList&, CaptureInfos const &);
 
        void set_block_size (pframes_t);
 
-       /* PublicDiskstream interface */
        boost::shared_ptr<Playlist> playlist ();
        void request_input_monitoring (bool);
        void ensure_input_monitoring (bool);
        bool destructive () const;
        std::list<boost::shared_ptr<Source> > & last_capture_sources ();
-       void set_capture_offset ();
        std::string steal_write_source_name ();
        void reset_write_sources (bool, bool force = false);
        float playback_buffer_load () const;
@@ -130,55 +136,51 @@ class LIBARDOUR_API Track : public Route, public PublicDiskstream
        int do_refill ();
        int do_flush (RunContext, bool force = false);
        void set_pending_overwrite (bool);
-       int seek (framepos_t, bool complete_refill = false);
-       bool hidden () const;
-       int can_internal_playback_seek (framecnt_t);
-       int internal_playback_seek (framecnt_t);
-       void non_realtime_input_change ();
-       void non_realtime_locate (framepos_t);
-       void non_realtime_set_speed ();
+       int seek (samplepos_t, bool complete_refill = false);
+       int can_internal_playback_seek (samplecnt_t);
+       int internal_playback_seek (samplecnt_t);
+       void non_realtime_locate (samplepos_t);
+       void realtime_handle_transport_stopped ();
+       void non_realtime_speed_change ();
        int overwrite_existing_buffers ();
-       framecnt_t get_captured_frames (uint32_t n = 0) const;
-       int set_loop (Location *);
-       void transport_looped (framepos_t);
-       bool realtime_set_speed (double, bool);
+       samplecnt_t get_captured_samples (uint32_t n = 0) const;
+       int set_loop (ARDOUR::Location *);
+       void transport_looped (samplepos_t);
        void transport_stopped_wallclock (struct tm &, time_t, bool);
        bool pending_overwrite () const;
-       double speed () const;
-       void prepare_to_stop (framepos_t, framepos_t);
        void set_slaved (bool);
        ChanCount n_channels ();
-       framepos_t get_capture_start_frame (uint32_t n = 0) const;
+       samplepos_t get_capture_start_sample (uint32_t n = 0) const;
        AlignStyle alignment_style () const;
        AlignChoice alignment_choice () const;
-       framepos_t current_capture_start () const;
-       framepos_t current_capture_end () const;
-       void playlist_modified ();
-       int use_playlist (boost::shared_ptr<Playlist>);
+       samplepos_t current_capture_start () const;
+       samplepos_t current_capture_end () const;
        void set_align_style (AlignStyle, bool force=false);
        void set_align_choice (AlignChoice, bool force=false);
+       void playlist_modified ();
+       int use_playlist (DataType, boost::shared_ptr<Playlist>);
+       int find_and_use_playlist (DataType, PBD::ID const &);
        int use_copy_playlist ();
-       int use_new_playlist ();
+       int use_new_playlist (DataType);
+       int use_default_new_playlist () {
+               return use_new_playlist (data_type());
+       }
        void adjust_playback_buffering ();
        void adjust_capture_buffering ();
 
-       PBD::Signal0<void> DiskstreamChanged;
        PBD::Signal0<void> FreezeChange;
-       /* Emitted when our diskstream is set to use a different playlist */
        PBD::Signal0<void> PlaylistChanged;
-       PBD::Signal0<void> RecordEnableChanged;
-       PBD::Signal0<void> RecordSafeChanged;
        PBD::Signal0<void> SpeedChanged;
        PBD::Signal0<void> AlignmentStyleChanged;
 
-  protected:
-       XMLNode& state (bool full);
+protected:
+       XMLNode& state (bool save_template);
+
+       boost::shared_ptr<Playlist>   _playlists[DataType::num_types];
 
-       boost::shared_ptr<Diskstream> _diskstream;
        MeterPoint    _saved_meter_point;
        TrackMode     _mode;
        bool          _needs_butler;
-       MonitorChoice _monitoring;
 
        //private: (FIXME)
        struct FreezeRecordProcessorInfo {
@@ -203,41 +205,30 @@ class LIBARDOUR_API Track : public Route, public PublicDiskstream
                FreezeState                        state;
        };
 
-       class RecEnableControl : public AutomationControl {
-       public:
-               RecEnableControl (boost::shared_ptr<Track> t);
-
-               void set_value (double, PBD::Controllable::GroupControlDisposition);
-               void set_value_unchecked (double);
-               double get_value (void) const;
+       virtual void set_state_part_two () = 0;
 
-               boost::weak_ptr<Track> track;
+       FreezeRecord _freeze_record;
+       XMLNode*      pending_state;
+       bool         _destructive;
 
-       private:
-               void _set_value (double, PBD::Controllable::GroupControlDisposition);
-       };
+       void maybe_declick (BufferSet&, samplecnt_t, int);
 
-       virtual void set_state_part_two () = 0;
+       boost::shared_ptr<AutomationControl> _record_enable_control;
+       boost::shared_ptr<AutomationControl> _record_safe_control;
 
-       FreezeRecord          _freeze_record;
-       XMLNode*              pending_state;
-       bool                  _destructive;
+       virtual void record_enable_changed (bool, PBD::Controllable::GroupControlDisposition);
+       virtual void record_safe_changed (bool, PBD::Controllable::GroupControlDisposition);
 
-       void maybe_declick (BufferSet&, framecnt_t, int);
+       virtual void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
 
-       boost::shared_ptr<RecEnableControl> _rec_enable_control;
+       AlignChoice _alignment_choice;
+       void set_align_choice_from_io ();
+       void input_changed ();
 
-       framecnt_t check_initial_delay (framecnt_t nframes, framepos_t&);
+       void use_captured_audio_sources (SourceList&, CaptureInfos const &);
+       void use_captured_midi_sources (SourceList&, CaptureInfos const &);
 
 private:
-
-       virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &) = 0;
-
-       void diskstream_playlist_changed ();
-       void diskstream_record_enable_changed ();
-       void diskstream_record_safe_changed ();
-       void diskstream_speed_changed ();
-       void diskstream_alignment_style_changed ();
        void parameter_changed (std::string const & p);
 
        std::string _diskstream_name;
@@ -245,4 +236,8 @@ private:
 
 }; /* namespace ARDOUR*/
 
+namespace PBD {
+       DEFINE_ENUM_CONVERT(ARDOUR::Track::FreezeState);
+}
+
 #endif /* __ardour_track_h__ */