3.X version of earlier major fix to 2.X: Route::check_initial_delay() should be virtu...
[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 "ardour/route.h"
25 #include "ardour/public_diskstream.h"
26
27 namespace ARDOUR {
28
29 class Session;
30 class Playlist;
31 class RouteGroup;
32 class Source;
33 class Region;
34 class Diskstream;
35
36 class Track : public Route, public PublicDiskstream
37 {
38   public:
39         Track (Session&, std::string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
40         virtual ~Track ();
41
42         int init ();
43
44         bool set_name (const std::string& str);
45
46         TrackMode mode () const { return _mode; }
47         virtual int set_mode (TrackMode /*m*/) { return false; }
48         virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
49         PBD::Signal0<void> TrackModeChanged;
50
51         virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
52                              bool state_changing, bool can_record);
53
54         int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
55                          bool can_record, bool& need_butler);
56
57         virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
58                           int declick, bool can_record, bool& need_butler) = 0;
59
60         bool needs_butler() const { return _needs_butler; }
61         void toggle_monitor_input ();
62
63         virtual DataType data_type () const = 0;
64
65         bool can_record();
66
67         virtual void use_new_diskstream () = 0;
68         virtual void set_diskstream (boost::shared_ptr<Diskstream>);
69
70         void set_latency_compensation (framecnt_t);
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         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
84         virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo&, bool enable_processing = true) = 0;
85
86         XMLNode&    get_state();
87         XMLNode&    get_template();
88         virtual int set_state (const XMLNode&, int version) = 0;
89         static void zero_diskstream_id_in_xml (XMLNode&);
90
91         boost::shared_ptr<PBD::Controllable> rec_enable_control() { return _rec_enable_control; }
92
93         bool record_enabled() const;
94         void set_record_enabled (bool yn, void *src);
95
96         /* XXX: unfortunate that this is exposed */
97         PBD::ID const & diskstream_id () const;
98
99         void set_block_size (pframes_t);
100
101         /** @return true if the track can be bounced, or false if it cannot because
102          *  it has more outputs than diskstream channels.
103          */
104         virtual bool bounceable () const = 0;
105
106         /* PublicDiskstream interface */
107         boost::shared_ptr<Playlist> playlist ();
108         void monitor_input (bool);
109         bool destructive () const;
110         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
111         void set_capture_offset ();
112         std::list<boost::shared_ptr<Source> > steal_write_sources();
113         void reset_write_sources (bool, bool force = false);
114         float playback_buffer_load () const;
115         float capture_buffer_load () const;
116         int do_refill ();
117         int do_flush (RunContext, bool force = false);
118         uint32_t read_data_count() const;
119         uint32_t write_data_count() const;
120         void set_pending_overwrite (bool);
121         int seek (framepos_t, bool complete_refill = false);
122         bool hidden () const;
123         int can_internal_playback_seek (framepos_t);
124         int internal_playback_seek (framepos_t);
125         void non_realtime_input_change ();
126         void non_realtime_locate (framepos_t);
127         void non_realtime_set_speed ();
128         int overwrite_existing_buffers ();
129         framecnt_t get_captured_frames (uint32_t n = 0) const;
130         int set_loop (Location *);
131         void transport_looped (framepos_t);
132         bool realtime_set_speed (double, bool);
133         void transport_stopped_wallclock (struct tm &, time_t, bool);
134         bool pending_overwrite () const;
135         double speed () const;
136         void prepare_to_stop (framepos_t);
137         void set_slaved (bool);
138         ChanCount n_channels ();
139         framepos_t get_capture_start_frame (uint32_t n = 0) const;
140         AlignStyle alignment_style () const;
141         AlignChoice alignment_choice () const;
142         framepos_t current_capture_start () const;
143         framepos_t current_capture_end () const;
144         void playlist_modified ();
145         int use_playlist (boost::shared_ptr<Playlist>);
146         void set_align_style (AlignStyle, bool force=false);
147         void set_align_choice (AlignChoice, bool force=false);
148         int use_copy_playlist ();
149         int use_new_playlist ();
150         void adjust_playback_buffering ();
151         void adjust_capture_buffering ();
152
153         PBD::Signal0<void> DiskstreamChanged;
154         PBD::Signal0<void> FreezeChange;
155         PBD::Signal0<void> PlaylistChanged;
156         PBD::Signal0<void> RecordEnableChanged;
157         PBD::Signal0<void> SpeedChanged;
158         PBD::Signal0<void> AlignmentStyleChanged;
159
160   protected:
161         virtual XMLNode& state (bool full) = 0;
162
163         boost::shared_ptr<Diskstream> _diskstream;
164         MeterPoint  _saved_meter_point;
165         TrackMode   _mode;
166         bool        _needs_butler;
167
168         //private: (FIXME)
169         struct FreezeRecordProcessorInfo {
170                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
171                         : state (st), processor (proc) {}
172
173                 XMLNode                      state;
174                 boost::shared_ptr<Processor> processor;
175                 PBD::ID                      id;
176         };
177
178         struct FreezeRecord {
179                 FreezeRecord()
180                         : have_mementos(false)
181                 {}
182
183                 ~FreezeRecord();
184
185                 boost::shared_ptr<Playlist>        playlist;
186                 std::vector<FreezeRecordProcessorInfo*> processor_info;
187                 bool                               have_mementos;
188                 FreezeState                        state;
189         };
190
191         struct RecEnableControllable : public PBD::Controllable {
192                 RecEnableControllable (Track&);
193
194                 void set_value (double);
195                 double get_value (void) const;
196
197                 Track& track;
198         };
199
200         virtual void set_state_part_two () = 0;
201
202         FreezeRecord          _freeze_record;
203         XMLNode*              pending_state;
204         bool                  _destructive;
205
206         void maybe_declick (BufferSet&, framecnt_t, int);
207
208         virtual bool send_silence () const;
209
210         boost::shared_ptr<RecEnableControllable> _rec_enable_control;
211         
212         framecnt_t check_initial_delay (framecnt_t nframes, framecnt_t&);
213
214 private:
215         void diskstream_playlist_changed ();
216         void diskstream_record_enable_changed ();
217         void diskstream_speed_changed ();
218         void diskstream_alignment_style_changed ();
219 };
220
221 }; /* namespace ARDOUR*/
222
223 #endif /* __ardour_track_h__ */