rename all Evoral source from .(hpp|cpp)$ to .(h|cc)
[ardour.git] / libs / ardour / ardour / track.h
1 /*
2  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2008-2018 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef __ardour_track_h__
23 #define __ardour_track_h__
24
25 #include <boost/shared_ptr.hpp>
26
27 #include "pbd/enum_convert.h"
28
29 #include "ardour/interthread_info.h"
30 #include "ardour/recordable.h"
31 #include "ardour/route.h"
32
33 namespace ARDOUR {
34
35 class Session;
36 class Playlist;
37 class RouteGroup;
38 class Source;
39 class Region;
40 class DiskReader;
41 class DiskWriter;
42 class IO;
43 class RecordEnableControl;
44 class RecordSafeControl;
45
46 /** A track is an route (bus) with a recordable diskstream and
47  * related objects relevant to recording, playback and editing.
48  *
49  * Specifically a track has a playlist object that describes material
50  * to be played from disk, and modifies that object during recording and
51  * editing.
52  */
53 class LIBARDOUR_API Track : public Route, public Recordable
54 {
55 public:
56         Track (Session&, std::string name, PresentationInfo::Flag f = PresentationInfo::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
57         virtual ~Track ();
58
59         int init ();
60
61         bool set_name (const std::string& str);
62         void resync_track_name ();
63
64         TrackMode mode () const { return _mode; }
65
66         MeterState metering_state () const;
67
68         bool set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure);
69
70         bool declick_in_progress () const;
71
72         bool can_record();
73
74         enum FreezeState {
75                 NoFreeze,
76                 Frozen,
77                 UnFrozen
78         };
79
80         FreezeState freeze_state() const;
81
82         virtual void freeze_me (InterThreadInfo&) = 0;
83         virtual void unfreeze () = 0;
84
85         /** Test if the track can be bounced with the given settings.
86          * If sends/inserts/returns are present in the signal path or the given track
87          * has no audio outputs bouncing is not possible.
88          *
89          * @param endpoint the processor to tap the signal off (or nil for the top)
90          * @param include_endpoint include the given processor in the bounced audio.
91          * @return true if the track can be bounced, or false otherwise.
92          */
93         virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
94
95         /** bounce track from session start to session end to new region
96          *
97          * @param itt asynchronous progress report and cancel
98          * @return a new audio region (or nil in case of error)
99          */
100         virtual boost::shared_ptr<Region> bounce (InterThreadInfo& itt) = 0;
101
102         /** Bounce the given range to a new audio region.
103          * @param start start time (in samples)
104          * @param end end time (in samples)
105          * @param itt asynchronous progress report and cancel
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 a new audio region (or nil in case of error)
109          */
110         virtual boost::shared_ptr<Region> bounce_range (samplepos_t start, samplepos_t end, InterThreadInfo& itt,
111                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
112         virtual int export_stuff (BufferSet& bufs, samplepos_t start_sample, samplecnt_t nframes,
113                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
114
115         virtual int set_state (const XMLNode&, int version);
116         static void zero_diskstream_id_in_xml (XMLNode&);
117
118         boost::shared_ptr<AutomationControl> rec_enable_control() const { return _record_enable_control; }
119         boost::shared_ptr<AutomationControl> rec_safe_control() const { return _record_safe_control; }
120
121         int prep_record_enabled (bool);
122         bool can_be_record_enabled ();
123         bool can_be_record_safe ();
124
125         void use_captured_sources (SourceList&, CaptureInfos const &);
126
127         void set_block_size (pframes_t);
128
129         boost::shared_ptr<Playlist> playlist ();
130         void request_input_monitoring (bool);
131         void ensure_input_monitoring (bool);
132         bool destructive () const;
133         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
134         std::string steal_write_source_name ();
135         void reset_write_sources (bool, bool force = false);
136         float playback_buffer_load () const;
137         float capture_buffer_load () const;
138         int do_refill ();
139         int do_flush (RunContext, bool force = false);
140         void set_pending_overwrite ();
141         int seek (samplepos_t, bool complete_refill = false);
142         bool can_internal_playback_seek (samplecnt_t);
143         void internal_playback_seek (samplecnt_t);
144         void non_realtime_locate (samplepos_t);
145         bool overwrite_existing_buffers ();
146         samplecnt_t get_captured_samples (uint32_t n = 0) const;
147         void transport_looped (samplepos_t);
148         void transport_stopped_wallclock (struct tm &, time_t, bool);
149         bool pending_overwrite () const;
150         void set_slaved (bool);
151         ChanCount n_channels ();
152         samplepos_t get_capture_start_sample (uint32_t n = 0) const;
153         AlignStyle alignment_style () const;
154         AlignChoice alignment_choice () const;
155         samplepos_t current_capture_start () const;
156         samplepos_t current_capture_end () const;
157         void set_align_style (AlignStyle, bool force=false);
158         void set_align_choice (AlignChoice, bool force=false);
159         void playlist_modified ();
160         int use_playlist (DataType, boost::shared_ptr<Playlist>);
161         int find_and_use_playlist (DataType, PBD::ID const &);
162         int use_copy_playlist ();
163         int use_new_playlist (DataType);
164         int use_default_new_playlist () {
165                 return use_new_playlist (data_type());
166         }
167         void adjust_playback_buffering ();
168         void adjust_capture_buffering ();
169
170         PBD::Signal0<void> FreezeChange;
171         PBD::Signal0<void> PlaylistChanged;
172         PBD::Signal0<void> SpeedChanged;
173         PBD::Signal0<void> AlignmentStyleChanged;
174
175 protected:
176         XMLNode& state (bool save_template);
177
178         boost::shared_ptr<Playlist>   _playlists[DataType::num_types];
179
180         MeterPoint    _saved_meter_point;
181         TrackMode     _mode;
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__ */