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