b7f5c1f5f4638c5acad041f644e0cdf0d601d4c6
[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         bool set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure);
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         bool can_record();
84
85         void set_latency_compensation (framecnt_t);
86         void update_latency_information ();
87         enum FreezeState {
88                 NoFreeze,
89                 Frozen,
90                 UnFrozen
91         };
92
93         FreezeState freeze_state() const;
94
95         virtual void freeze_me (InterThreadInfo&) = 0;
96         virtual void unfreeze () = 0;
97
98         /** Test if the track can be bounced with the given settings.
99          * If sends/inserts/returns are present in the signal path or the given track
100          * has no audio outputs bouncing is not possible.
101          *
102          * @param endpoint the processor to tap the signal off (or nil for the top)
103          * @param include_endpoint include the given processor in the bounced audio.
104          * @return true if the track can be bounced, or false otherwise.
105          */
106         virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
107
108         /** bounce track from session start to session end to new region
109          *
110          * @param itt asynchronous progress report and cancel
111          * @return a new audio region (or nil in case of error)
112          */
113         virtual boost::shared_ptr<Region> bounce (InterThreadInfo& itt) = 0;
114
115         /** Bounce the given range to a new audio region.
116          * @param start start time (in samples)
117          * @param end end time (in samples)
118          * @param itt asynchronous progress report and cancel
119          * @param endpoint the processor to tap the signal off (or nil for the top)
120          * @param include_endpoint include the given processor in the bounced audio.
121          * @return a new audio region (or nil in case of error)
122          */
123         virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo& itt,
124                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
125         virtual int export_stuff (BufferSet& bufs, framepos_t start_frame, framecnt_t nframes,
126                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
127
128         XMLNode&    get_state();
129         XMLNode&    get_template();
130         virtual int set_state (const XMLNode&, int version);
131         static void zero_diskstream_id_in_xml (XMLNode&);
132
133         boost::shared_ptr<AutomationControl> rec_enable_control() const { return _record_enable_control; }
134         boost::shared_ptr<AutomationControl> rec_safe_control() const { return _record_safe_control; }
135
136         int prep_record_enabled (bool);
137         bool can_be_record_enabled ();
138         bool can_be_record_safe ();
139
140         void use_captured_sources (SourceList&, CaptureInfos const &);
141
142         void set_block_size (pframes_t);
143
144         boost::shared_ptr<Playlist> playlist ();
145         void request_input_monitoring (bool);
146         void ensure_input_monitoring (bool);
147         bool destructive () const;
148         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
149         std::string steal_write_source_name ();
150         void reset_write_sources (bool, bool force = false);
151         float playback_buffer_load () const;
152         float capture_buffer_load () const;
153         int do_refill ();
154         int do_flush (RunContext, bool force = false);
155         void set_pending_overwrite (bool);
156         int seek (framepos_t, bool complete_refill = false);
157         int can_internal_playback_seek (framecnt_t);
158         int internal_playback_seek (framecnt_t);
159         void non_realtime_locate (framepos_t);
160         void realtime_handle_transport_stopped ();
161         void non_realtime_speed_change ();
162         int overwrite_existing_buffers ();
163         framecnt_t get_captured_frames (uint32_t n = 0) const;
164         int set_loop (ARDOUR::Location *);
165         void transport_looped (framepos_t);
166         bool realtime_speed_change ();
167         void transport_stopped_wallclock (struct tm &, time_t, bool);
168         bool pending_overwrite () const;
169         void prepare_to_stop (framepos_t, framepos_t);
170         void set_slaved (bool);
171         ChanCount n_channels ();
172         framepos_t get_capture_start_frame (uint32_t n = 0) const;
173         AlignStyle alignment_style () const;
174         AlignChoice alignment_choice () const;
175         framepos_t current_capture_start () const;
176         framepos_t current_capture_end () const;
177         void set_align_style (AlignStyle, bool force=false);
178         void set_align_choice (AlignChoice, bool force=false);
179         void playlist_modified ();
180         int use_playlist (DataType, boost::shared_ptr<Playlist>);
181         int find_and_use_playlist (DataType, PBD::ID const &);
182         int use_copy_playlist ();
183         int use_new_playlist ();
184         void adjust_playback_buffering ();
185         void adjust_capture_buffering ();
186
187         void set_disk_io_position (DiskIOPoint);
188         DiskIOPoint disk_io_point() const { return _disk_io_point; }
189
190         PBD::Signal0<void> FreezeChange;
191         PBD::Signal0<void> PlaylistChanged;
192         PBD::Signal0<void> SpeedChanged;
193         PBD::Signal0<void> AlignmentStyleChanged;
194
195   protected:
196         XMLNode& state (bool full);
197
198         boost::shared_ptr<DiskReader> _disk_reader;
199         boost::shared_ptr<DiskWriter> _disk_writer;
200         boost::shared_ptr<Playlist>   _playlists[DataType::num_types];
201
202         MeterPoint    _saved_meter_point;
203         DiskIOPoint   _disk_io_point;
204         TrackMode     _mode;
205         bool          _needs_butler;
206         boost::shared_ptr<MonitorControl> _monitoring_control;
207
208         //private: (FIXME)
209         struct FreezeRecordProcessorInfo {
210                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
211                         : state (st), processor (proc) {}
212
213                 XMLNode                      state;
214                 boost::shared_ptr<Processor> processor;
215                 PBD::ID                      id;
216         };
217
218         struct FreezeRecord {
219                 FreezeRecord()
220                         : have_mementos(false)
221                 {}
222
223                 ~FreezeRecord();
224
225                 boost::shared_ptr<Playlist>        playlist;
226                 std::vector<FreezeRecordProcessorInfo*> processor_info;
227                 bool                               have_mementos;
228                 FreezeState                        state;
229         };
230
231         virtual void set_state_part_two () = 0;
232
233         FreezeRecord _freeze_record;
234         XMLNode*      pending_state;
235         bool         _destructive;
236
237         void maybe_declick (BufferSet&, framecnt_t, int);
238
239         boost::shared_ptr<AutomationControl> _record_enable_control;
240         boost::shared_ptr<AutomationControl> _record_safe_control;
241
242         virtual void record_enable_changed (bool, PBD::Controllable::GroupControlDisposition);
243         virtual void record_safe_changed (bool, PBD::Controllable::GroupControlDisposition);
244
245         framecnt_t check_initial_delay (framecnt_t nframes, framepos_t&);
246         virtual void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
247
248         AlignChoice _alignment_choice;
249         void set_align_choice_from_io ();
250         void input_changed ();
251
252         void use_captured_audio_sources (SourceList&, CaptureInfos const &);
253         void use_captured_midi_sources (SourceList&, CaptureInfos const &);
254
255 private:
256         void parameter_changed (std::string const & p);
257         void setup_invisible_processors_oh_children_of_mine (ProcessorList&);
258         void add_processors_oh_children_of_mine ();
259
260         std::string _diskstream_name;
261 };
262
263 }; /* namespace ARDOUR*/
264
265 namespace PBD {
266         DEFINE_ENUM_CONVERT(ARDOUR::Track::FreezeState);
267 }
268
269 #endif /* __ardour_track_h__ */