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