Add an API to query if the audible frame is latent pending a locate
[ardour.git] / libs / ardour / ardour / track.h
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_track_h__
20 #define __ardour_track_h__
21
22 #include <boost/shared_ptr.hpp>
23
24 #include "ardour/interthread_info.h"
25 #include "ardour/recordable.h"
26 #include "ardour/route.h"
27 #include "ardour/public_diskstream.h"
28
29 namespace ARDOUR {
30
31 class Session;
32 class Playlist;
33 class RouteGroup;
34 class Source;
35 class Region;
36 class Diskstream;
37 class IO;
38 class MonitorControl;
39 class RecordEnableControl;
40 class RecordSafeControl;
41
42 /** A track is an route (bus) with a recordable diskstream and
43  * related objects relevant to tracking, playback and editing.
44  *
45  * Specifically a track has regions and playlist objects.
46  */
47 class LIBARDOUR_API Track : public Route, public Recordable, public PublicDiskstream
48 {
49   public:
50         Track (Session&, std::string name, PresentationInfo::Flag f = PresentationInfo::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
51         virtual ~Track ();
52
53         int init ();
54
55         bool set_name (const std::string& str);
56         void resync_track_name ();
57
58         TrackMode mode () const { return _mode; }
59 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
60         virtual int set_mode (TrackMode /*m*/) { return false; }
61         virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
62         PBD::Signal0<void> TrackModeChanged;
63 #endif
64
65         boost::shared_ptr<MonitorControl> monitoring_control() const { return _monitoring_control; }
66
67         MonitorState monitoring_state () const;
68         MeterState metering_state () const;
69
70         virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
71                              bool state_changing);
72
73         int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
74                          bool& need_butler);
75
76         virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
77                           int declick, bool& need_butler) = 0;
78
79         bool needs_butler() const { return _needs_butler; }
80
81         virtual DataType data_type () const = 0;
82
83         bool can_record();
84
85         void use_new_diskstream ();
86         virtual boost::shared_ptr<Diskstream> create_diskstream() = 0;
87         virtual void set_diskstream (boost::shared_ptr<Diskstream>);
88
89         void set_latency_compensation (framecnt_t);
90
91         enum FreezeState {
92                 NoFreeze,
93                 Frozen,
94                 UnFrozen
95         };
96
97         FreezeState freeze_state() const;
98
99         virtual void freeze_me (InterThreadInfo&) = 0;
100         virtual void unfreeze () = 0;
101
102         /** Test if the track can be bounced with the given settings.
103          * If sends/inserts/returns are present in the signal path or the given track
104          * has no audio outputs bouncing is not possible.
105          *
106          * @param endpoint the processor to tap the signal off (or nil for the top)
107          * @param include_endpoint include the given processor in the bounced audio.
108          * @return true if the track can be bounced, or false otherwise.
109          */
110         virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
111
112         /** bounce track from session start to session end to new region
113          *
114          * @param itt asynchronous progress report and cancel
115          * @return a new audio region (or nil in case of error)
116          */
117         virtual boost::shared_ptr<Region> bounce (InterThreadInfo& itt) = 0;
118
119         /** Bounce the given range to a new audio region.
120          * @param start start time (in samples)
121          * @param end end time (in samples)
122          * @param itt asynchronous progress report and cancel
123          * @param endpoint the processor to tap the signal off (or nil for the top)
124          * @param include_endpoint include the given processor in the bounced audio.
125          * @return a new audio region (or nil in case of error)
126          */
127         virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo& itt,
128                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
129         virtual int export_stuff (BufferSet& bufs, framepos_t start_frame, framecnt_t nframes,
130                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
131
132         XMLNode&    get_state();
133         XMLNode&    get_template();
134         virtual int set_state (const XMLNode&, int version);
135         static void zero_diskstream_id_in_xml (XMLNode&);
136
137         boost::shared_ptr<AutomationControl> rec_enable_control() const { return _record_enable_control; }
138         boost::shared_ptr<AutomationControl> rec_safe_control() const { return _record_safe_control; }
139
140         int prep_record_enabled (bool);
141         bool can_be_record_enabled ();
142         bool can_be_record_safe ();
143
144         bool using_diskstream_id (PBD::ID) const;
145
146         void set_block_size (pframes_t);
147
148         /* PublicDiskstream interface */
149         boost::shared_ptr<Playlist> playlist ();
150         void request_input_monitoring (bool);
151         void ensure_input_monitoring (bool);
152         bool destructive () const;
153         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
154         void set_capture_offset ();
155         std::string steal_write_source_name ();
156         void reset_write_sources (bool, bool force = false);
157         float playback_buffer_load () const;
158         float capture_buffer_load () const;
159         int do_refill ();
160         int do_flush (RunContext, bool force = false);
161         void set_pending_overwrite (bool);
162         int seek (framepos_t, bool complete_refill = false);
163         bool hidden () const;
164         int can_internal_playback_seek (framecnt_t);
165         int internal_playback_seek (framecnt_t);
166         void non_realtime_input_change ();
167         void non_realtime_locate (framepos_t);
168         void non_realtime_set_speed ();
169         int overwrite_existing_buffers ();
170         framecnt_t get_captured_frames (uint32_t n = 0) const;
171         int set_loop (Location *);
172         void transport_looped (framepos_t);
173         bool realtime_set_speed (double, bool);
174         void transport_stopped_wallclock (struct tm &, time_t, bool);
175         bool pending_overwrite () const;
176         double speed () const;
177         void prepare_to_stop (framepos_t, framepos_t);
178         void set_slaved (bool);
179         ChanCount n_channels ();
180         framepos_t get_capture_start_frame (uint32_t n = 0) const;
181         AlignStyle alignment_style () const;
182         AlignChoice alignment_choice () const;
183         framepos_t current_capture_start () const;
184         framepos_t current_capture_end () const;
185         void playlist_modified ();
186         int use_playlist (boost::shared_ptr<Playlist>);
187         void set_align_style (AlignStyle, bool force=false);
188         void set_align_choice (AlignChoice, bool force=false);
189         int use_copy_playlist ();
190         int use_new_playlist ();
191         void adjust_playback_buffering ();
192         void adjust_capture_buffering ();
193
194         PBD::Signal0<void> DiskstreamChanged;
195         PBD::Signal0<void> FreezeChange;
196         /* Emitted when our diskstream is set to use a different playlist */
197         PBD::Signal0<void> PlaylistChanged;
198         PBD::Signal0<void> SpeedChanged;
199         PBD::Signal0<void> AlignmentStyleChanged;
200
201   protected:
202         XMLNode& state (bool full);
203
204         boost::shared_ptr<Diskstream> _diskstream;
205         MeterPoint    _saved_meter_point;
206         TrackMode     _mode;
207         bool          _needs_butler;
208         boost::shared_ptr<MonitorControl> _monitoring_control;
209
210         //private: (FIXME)
211         struct FreezeRecordProcessorInfo {
212                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
213                         : state (st), processor (proc) {}
214
215                 XMLNode                      state;
216                 boost::shared_ptr<Processor> processor;
217                 PBD::ID                      id;
218         };
219
220         struct FreezeRecord {
221                 FreezeRecord()
222                         : have_mementos(false)
223                 {}
224
225                 ~FreezeRecord();
226
227                 boost::shared_ptr<Playlist>        playlist;
228                 std::vector<FreezeRecordProcessorInfo*> processor_info;
229                 bool                               have_mementos;
230                 FreezeState                        state;
231         };
232
233         virtual void set_state_part_two () = 0;
234
235         FreezeRecord          _freeze_record;
236         XMLNode*              pending_state;
237         bool                  _destructive;
238
239         void maybe_declick (BufferSet&, framecnt_t, int);
240
241         boost::shared_ptr<AutomationControl> _record_enable_control;
242         boost::shared_ptr<AutomationControl> _record_safe_control;
243
244         virtual void record_enable_changed (bool, PBD::Controllable::GroupControlDisposition);
245         virtual void record_safe_changed (bool, PBD::Controllable::GroupControlDisposition);
246
247         framecnt_t check_initial_delay (framecnt_t nframes, framepos_t&);
248         virtual void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
249
250 private:
251
252         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &) = 0;
253
254         void diskstream_playlist_changed ();
255         void diskstream_speed_changed ();
256         void diskstream_alignment_style_changed ();
257         void parameter_changed (std::string const & p);
258
259         std::string _diskstream_name;
260 };
261
262 }; /* namespace ARDOUR*/
263
264 #endif /* __ardour_track_h__ */