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