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