Fix a few return types.
[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/interthread_info.h"
25 #include "ardour/route.h"
26 #include "ardour/public_diskstream.h"
27
28 namespace ARDOUR {
29
30 class Session;
31 class Playlist;
32 class RouteGroup;
33 class Source;
34 class Region;
35 class Diskstream;
36
37 class Track : public Route, public PublicDiskstream
38 {
39   public:
40         Track (Session&, std::string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
41         virtual ~Track ();
42
43         int init ();
44
45         bool set_name (const std::string& str);
46
47         TrackMode mode () const { return _mode; }
48         virtual int set_mode (TrackMode /*m*/) { return false; }
49         virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
50         PBD::Signal0<void> TrackModeChanged;
51
52         virtual void set_monitoring (MonitorChoice);
53         MonitorChoice monitoring_choice() const { return _monitoring; }
54         MonitorState monitoring_state () const;
55         PBD::Signal0<void> MonitoringChanged;
56
57         MeterState metering_state () const;
58         
59         virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
60                              bool state_changing);
61
62         int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
63                          bool& need_butler);
64
65         virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
66                           int declick, bool& need_butler) = 0;
67
68         bool needs_butler() const { return _needs_butler; }
69
70         virtual DataType data_type () const = 0;
71
72         bool can_record();
73
74         void use_new_diskstream ();
75         virtual boost::shared_ptr<Diskstream> create_diskstream() = 0;
76         virtual void set_diskstream (boost::shared_ptr<Diskstream>);
77
78         void set_latency_compensation (framecnt_t);
79
80         enum FreezeState {
81                 NoFreeze,
82                 Frozen,
83                 UnFrozen
84         };
85
86         FreezeState freeze_state() const;
87
88         virtual void freeze_me (InterThreadInfo&) = 0;
89         virtual void unfreeze () = 0;
90
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         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
95         virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo&, 
96                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
97         virtual int export_stuff (BufferSet& bufs, framepos_t start_frame, framecnt_t nframes,
98                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export) = 0;
99
100         XMLNode&    get_state();
101         XMLNode&    get_template();
102         virtual int set_state (const XMLNode&, int version);
103         static void zero_diskstream_id_in_xml (XMLNode&);
104
105         boost::shared_ptr<AutomationControl> rec_enable_control() { return _rec_enable_control; }
106
107         bool record_enabled() const;
108         void set_record_enabled (bool yn, void *src);
109
110         bool using_diskstream_id (PBD::ID) const;
111
112         void set_block_size (pframes_t);
113
114         /* PublicDiskstream interface */
115         boost::shared_ptr<Playlist> playlist ();
116         void request_jack_monitors_input (bool);
117         void ensure_jack_monitors_input (bool);
118         bool destructive () const;
119         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
120         void set_capture_offset ();
121         std::list<boost::shared_ptr<Source> > steal_write_sources();
122         void reset_write_sources (bool, bool force = false);
123         float playback_buffer_load () const;
124         float capture_buffer_load () const;
125         int do_refill ();
126         int do_flush (RunContext, bool force = false);
127         void set_pending_overwrite (bool);
128         int seek (framepos_t, bool complete_refill = false);
129         bool hidden () const;
130         int can_internal_playback_seek (framecnt_t);
131         int internal_playback_seek (framecnt_t);
132         void non_realtime_input_change ();
133         void non_realtime_locate (framepos_t);
134         void non_realtime_set_speed ();
135         int overwrite_existing_buffers ();
136         framecnt_t get_captured_frames (uint32_t n = 0) const;
137         int set_loop (Location *);
138         void transport_looped (framepos_t);
139         bool realtime_set_speed (double, bool);
140         void transport_stopped_wallclock (struct tm &, time_t, bool);
141         bool pending_overwrite () const;
142         double speed () const;
143         void prepare_to_stop (framepos_t);
144         void set_slaved (bool);
145         ChanCount n_channels ();
146         framepos_t get_capture_start_frame (uint32_t n = 0) const;
147         AlignStyle alignment_style () const;
148         AlignChoice alignment_choice () const;
149         framepos_t current_capture_start () const;
150         framepos_t current_capture_end () const;
151         void playlist_modified ();
152         int use_playlist (boost::shared_ptr<Playlist>);
153         void set_align_style (AlignStyle, bool force=false);
154         void set_align_choice (AlignChoice, bool force=false);
155         int use_copy_playlist ();
156         int use_new_playlist ();
157         void adjust_playback_buffering ();
158         void adjust_capture_buffering ();
159
160         PBD::Signal0<void> DiskstreamChanged;
161         PBD::Signal0<void> FreezeChange;
162         /* Emitted when our diskstream is set to use a different playlist */
163         PBD::Signal0<void> PlaylistChanged;
164         PBD::Signal0<void> RecordEnableChanged;
165         PBD::Signal0<void> SpeedChanged;
166         PBD::Signal0<void> AlignmentStyleChanged;
167
168   protected:
169         XMLNode& state (bool full);
170
171         boost::shared_ptr<Diskstream> _diskstream;
172         MeterPoint    _saved_meter_point;
173         /** used to keep track of processors that we are deactivating during record,
174             if `do-not-record-plugins' is enabled.
175         */
176         std::list<boost::weak_ptr<Processor> > _deactivated_processors;
177         TrackMode     _mode;
178         bool          _needs_butler;
179         MonitorChoice _monitoring;
180
181         //private: (FIXME)
182         struct FreezeRecordProcessorInfo {
183                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
184                         : state (st), processor (proc) {}
185
186                 XMLNode                      state;
187                 boost::shared_ptr<Processor> processor;
188                 PBD::ID                      id;
189         };
190
191         struct FreezeRecord {
192                 FreezeRecord()
193                         : have_mementos(false)
194                 {}
195
196                 ~FreezeRecord();
197
198                 boost::shared_ptr<Playlist>        playlist;
199                 std::vector<FreezeRecordProcessorInfo*> processor_info;
200                 bool                               have_mementos;
201                 FreezeState                        state;
202         };
203
204         struct RecEnableControl : public AutomationControl {
205                 RecEnableControl (boost::shared_ptr<Track> t);
206
207                 void set_value (double);
208                 double get_value (void) const;
209
210                 boost::shared_ptr<Track> track;
211         };
212
213         virtual void set_state_part_two () = 0;
214
215         FreezeRecord          _freeze_record;
216         XMLNode*              pending_state;
217         bool                  _destructive;
218
219         void maybe_declick (BufferSet&, framecnt_t, int);
220
221         boost::shared_ptr<RecEnableControl> _rec_enable_control;
222         
223         framecnt_t check_initial_delay (framecnt_t nframes, framecnt_t&);
224
225 private:
226
227         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &) = 0;
228         
229         void diskstream_playlist_changed ();
230         void diskstream_record_enable_changed ();
231         void diskstream_speed_changed ();
232         void diskstream_alignment_style_changed ();
233
234         void parameter_changed (std::string);
235         void deactivate_visible_processors ();
236         void activate_deactivated_processors ();
237 };
238
239 }; /* namespace ARDOUR*/
240
241 #endif /* __ardour_track_h__ */