Optimize automation-event process splitting
[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 RecordEnableControl;
41 class RecordSafeControl;
42
43 /** A track is an route (bus) with a recordable diskstream and
44  * related objects relevant to recording, playback and editing.
45  *
46  * Specifically a track has a playlist object that describes material
47  * to be played from disk, and modifies that object during recording and
48  * editing.
49  */
50 class LIBARDOUR_API Track : public Route, public Recordable
51 {
52 public:
53         Track (Session&, std::string name, PresentationInfo::Flag f = PresentationInfo::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
54         virtual ~Track ();
55
56         int init ();
57
58         bool set_name (const std::string& str);
59         void resync_track_name ();
60
61         TrackMode mode () const { return _mode; }
62
63         MeterState metering_state () const;
64
65         bool set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure);
66
67         bool needs_butler () const { return _needs_butler; }
68         bool declick_in_progress () const;
69
70         bool can_record();
71
72         enum FreezeState {
73                 NoFreeze,
74                 Frozen,
75                 UnFrozen
76         };
77
78         FreezeState freeze_state() const;
79
80         virtual void freeze_me (InterThreadInfo&) = 0;
81         virtual void unfreeze () = 0;
82
83         /** Test if the track can be bounced with the given settings.
84          * If sends/inserts/returns are present in the signal path or the given track
85          * has no audio outputs bouncing is not possible.
86          *
87          * @param endpoint the processor to tap the signal off (or nil for the top)
88          * @param include_endpoint include the given processor in the bounced audio.
89          * @return true if the track can be bounced, or false otherwise.
90          */
91         virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
92
93         /** bounce track from session start to session end to new region
94          *
95          * @param itt asynchronous progress report and cancel
96          * @return a new audio region (or nil in case of error)
97          */
98         virtual boost::shared_ptr<Region> bounce (InterThreadInfo& itt) = 0;
99
100         /** Bounce the given range to a new audio region.
101          * @param start start time (in samples)
102          * @param end end time (in samples)
103          * @param itt asynchronous progress report and cancel
104          * @param endpoint the processor to tap the signal off (or nil for the top)
105          * @param include_endpoint include the given processor in the bounced audio.
106          * @return a new audio region (or nil in case of error)
107          */
108         virtual boost::shared_ptr<Region> bounce_range (samplepos_t start, samplepos_t end, InterThreadInfo& itt,
109                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
110         virtual int export_stuff (BufferSet& bufs, samplepos_t start_sample, samplecnt_t nframes,
111                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
112
113         virtual int set_state (const XMLNode&, int version);
114         static void zero_diskstream_id_in_xml (XMLNode&);
115
116         boost::shared_ptr<AutomationControl> rec_enable_control() const { return _record_enable_control; }
117         boost::shared_ptr<AutomationControl> rec_safe_control() const { return _record_safe_control; }
118
119         int prep_record_enabled (bool);
120         bool can_be_record_enabled ();
121         bool can_be_record_safe ();
122
123         void use_captured_sources (SourceList&, CaptureInfos const &);
124
125         void set_block_size (pframes_t);
126
127         boost::shared_ptr<Playlist> playlist ();
128         void request_input_monitoring (bool);
129         void ensure_input_monitoring (bool);
130         bool destructive () const;
131         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
132         std::string steal_write_source_name ();
133         void reset_write_sources (bool, bool force = false);
134         float playback_buffer_load () const;
135         float capture_buffer_load () const;
136         int do_refill ();
137         int do_flush (RunContext, bool force = false);
138         void set_pending_overwrite (bool);
139         int seek (samplepos_t, bool complete_refill = false);
140         int can_internal_playback_seek (samplecnt_t);
141         int internal_playback_seek (samplecnt_t);
142         void non_realtime_locate (samplepos_t);
143         void realtime_handle_transport_stopped ();
144         int overwrite_existing_buffers ();
145         samplecnt_t get_captured_samples (uint32_t n = 0) const;
146         void transport_looped (samplepos_t);
147         void transport_stopped_wallclock (struct tm &, time_t, bool);
148         bool pending_overwrite () const;
149         void set_slaved (bool);
150         ChanCount n_channels ();
151         samplepos_t get_capture_start_sample (uint32_t n = 0) const;
152         AlignStyle alignment_style () const;
153         AlignChoice alignment_choice () const;
154         samplepos_t current_capture_start () const;
155         samplepos_t current_capture_end () const;
156         void set_align_style (AlignStyle, bool force=false);
157         void set_align_choice (AlignChoice, bool force=false);
158         void playlist_modified ();
159         int use_playlist (DataType, boost::shared_ptr<Playlist>);
160         int find_and_use_playlist (DataType, PBD::ID const &);
161         int use_copy_playlist ();
162         int use_new_playlist (DataType);
163         int use_default_new_playlist () {
164                 return use_new_playlist (data_type());
165         }
166         void adjust_playback_buffering ();
167         void adjust_capture_buffering ();
168
169         PBD::Signal0<void> FreezeChange;
170         PBD::Signal0<void> PlaylistChanged;
171         PBD::Signal0<void> SpeedChanged;
172         PBD::Signal0<void> AlignmentStyleChanged;
173
174 protected:
175         XMLNode& state (bool save_template);
176
177         boost::shared_ptr<Playlist>   _playlists[DataType::num_types];
178
179         MeterPoint    _saved_meter_point;
180         TrackMode     _mode;
181         bool          _needs_butler;
182
183         //private: (FIXME)
184         struct FreezeRecordProcessorInfo {
185                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
186                         : state (st), processor (proc) {}
187
188                 XMLNode                      state;
189                 boost::shared_ptr<Processor> processor;
190                 PBD::ID                      id;
191         };
192
193         struct FreezeRecord {
194                 FreezeRecord()
195                         : have_mementos(false)
196                 {}
197
198                 ~FreezeRecord();
199
200                 boost::shared_ptr<Playlist>        playlist;
201                 std::vector<FreezeRecordProcessorInfo*> processor_info;
202                 bool                               have_mementos;
203                 FreezeState                        state;
204         };
205
206         virtual void set_state_part_two () = 0;
207
208         FreezeRecord _freeze_record;
209         XMLNode*      pending_state;
210         bool         _destructive;
211
212         boost::shared_ptr<AutomationControl> _record_enable_control;
213         boost::shared_ptr<AutomationControl> _record_safe_control;
214
215         virtual void record_enable_changed (bool, PBD::Controllable::GroupControlDisposition);
216         virtual void record_safe_changed (bool, PBD::Controllable::GroupControlDisposition);
217
218         virtual void monitoring_changed (bool, PBD::Controllable::GroupControlDisposition);
219
220         AlignChoice _alignment_choice;
221         void set_align_choice_from_io ();
222         void input_changed ();
223
224         void use_captured_audio_sources (SourceList&, CaptureInfos const &);
225         void use_captured_midi_sources (SourceList&, CaptureInfos const &);
226
227 private:
228         void parameter_changed (std::string const & p);
229
230         std::string _diskstream_name;
231 };
232
233 }; /* namespace ARDOUR*/
234
235 namespace PBD {
236         DEFINE_ENUM_CONVERT(ARDOUR::Track::FreezeState);
237 }
238
239 #endif /* __ardour_track_h__ */