first compiling, mostly working version of group controls changes
[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         void resync_track_name ();
48
49         TrackMode mode () const { return _mode; }
50         virtual int set_mode (TrackMode /*m*/) { return false; }
51         virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
52         PBD::Signal0<void> TrackModeChanged;
53
54         virtual void set_monitoring (MonitorChoice);
55         MonitorChoice monitoring_choice() const { return _monitoring; }
56         MonitorState monitoring_state () const;
57         PBD::Signal0<void> MonitoringChanged;
58
59         MeterState metering_state () const;
60
61         virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
62                              bool state_changing);
63
64         int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
65                          bool& need_butler);
66
67         virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
68                           int declick, bool& need_butler) = 0;
69
70         bool needs_butler() const { return _needs_butler; }
71
72         virtual DataType data_type () const = 0;
73
74         bool can_record();
75
76         void use_new_diskstream ();
77         virtual boost::shared_ptr<Diskstream> create_diskstream() = 0;
78         virtual void set_diskstream (boost::shared_ptr<Diskstream>);
79
80         void set_latency_compensation (framecnt_t);
81
82         enum FreezeState {
83                 NoFreeze,
84                 Frozen,
85                 UnFrozen
86         };
87
88         FreezeState freeze_state() const;
89
90         virtual void freeze_me (InterThreadInfo&) = 0;
91         virtual void unfreeze () = 0;
92
93         /** @return true if the track can be bounced, or false otherwise.
94          */
95         virtual bool bounceable (boost::shared_ptr<Processor> endpoint, bool include_endpoint) const = 0;
96         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
97         virtual boost::shared_ptr<Region> bounce_range (framepos_t start, framepos_t end, InterThreadInfo&,
98                                                         boost::shared_ptr<Processor> endpoint, bool include_endpoint) = 0;
99         virtual int export_stuff (BufferSet& bufs, framepos_t start_frame, framecnt_t nframes,
100                                   boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) = 0;
101
102         XMLNode&    get_state();
103         XMLNode&    get_template();
104         virtual int set_state (const XMLNode&, int version);
105         static void zero_diskstream_id_in_xml (XMLNode&);
106
107         boost::shared_ptr<AutomationControl> rec_enable_control() { return _rec_enable_control; }
108
109         bool record_enabled() const;
110         bool record_safe () const;
111         void set_record_enabled (bool yn, PBD::Controllable::GroupControlDisposition);
112         void set_record_safe (bool yn, PBD::Controllable::GroupControlDisposition);
113         void prep_record_enabled (bool yn, PBD::Controllable::GroupControlDisposition);
114
115         bool using_diskstream_id (PBD::ID) const;
116
117         void set_block_size (pframes_t);
118
119         /* PublicDiskstream interface */
120         boost::shared_ptr<Playlist> playlist ();
121         void request_input_monitoring (bool);
122         void ensure_input_monitoring (bool);
123         bool destructive () const;
124         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
125         void set_capture_offset ();
126         std::string steal_write_source_name ();
127         void reset_write_sources (bool, bool force = false);
128         float playback_buffer_load () const;
129         float capture_buffer_load () const;
130         int do_refill ();
131         int do_flush (RunContext, bool force = false);
132         void set_pending_overwrite (bool);
133         int seek (framepos_t, bool complete_refill = false);
134         bool hidden () const;
135         int can_internal_playback_seek (framecnt_t);
136         int internal_playback_seek (framecnt_t);
137         void non_realtime_input_change ();
138         void non_realtime_locate (framepos_t);
139         void non_realtime_set_speed ();
140         int overwrite_existing_buffers ();
141         framecnt_t get_captured_frames (uint32_t n = 0) const;
142         int set_loop (Location *);
143         void transport_looped (framepos_t);
144         bool realtime_set_speed (double, bool);
145         void transport_stopped_wallclock (struct tm &, time_t, bool);
146         bool pending_overwrite () const;
147         double speed () const;
148         void prepare_to_stop (framepos_t, framepos_t);
149         void set_slaved (bool);
150         ChanCount n_channels ();
151         framepos_t get_capture_start_frame (uint32_t n = 0) const;
152         AlignStyle alignment_style () const;
153         AlignChoice alignment_choice () const;
154         framepos_t current_capture_start () const;
155         framepos_t current_capture_end () const;
156         void playlist_modified ();
157         int use_playlist (boost::shared_ptr<Playlist>);
158         void set_align_style (AlignStyle, bool force=false);
159         void set_align_choice (AlignChoice, bool force=false);
160         int use_copy_playlist ();
161         int use_new_playlist ();
162         void adjust_playback_buffering ();
163         void adjust_capture_buffering ();
164
165         PBD::Signal0<void> DiskstreamChanged;
166         PBD::Signal0<void> FreezeChange;
167         /* Emitted when our diskstream is set to use a different playlist */
168         PBD::Signal0<void> PlaylistChanged;
169         PBD::Signal0<void> RecordEnableChanged;
170         PBD::Signal0<void> RecordSafeChanged;
171         PBD::Signal0<void> SpeedChanged;
172         PBD::Signal0<void> AlignmentStyleChanged;
173
174   protected:
175         XMLNode& state (bool full);
176
177         boost::shared_ptr<Diskstream> _diskstream;
178         MeterPoint    _saved_meter_point;
179         TrackMode     _mode;
180         bool          _needs_butler;
181         MonitorChoice _monitoring;
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         class RecEnableControl : public AutomationControl {
207         public:
208                 RecEnableControl (boost::shared_ptr<Track> t);
209
210                 void set_value (double, PBD::Controllable::GroupControlDisposition);
211                 void set_value_unchecked (double);
212                 double get_value (void) const;
213
214                 boost::weak_ptr<Track> track;
215
216         private:
217                 void _set_value (double, PBD::Controllable::GroupControlDisposition);
218         };
219
220         virtual void set_state_part_two () = 0;
221
222         FreezeRecord          _freeze_record;
223         XMLNode*              pending_state;
224         bool                  _destructive;
225
226         void maybe_declick (BufferSet&, framecnt_t, int);
227
228         boost::shared_ptr<RecEnableControl> _rec_enable_control;
229
230         framecnt_t check_initial_delay (framecnt_t nframes, framepos_t&);
231
232 private:
233
234         virtual boost::shared_ptr<Diskstream> diskstream_factory (XMLNode const &) = 0;
235
236         void diskstream_playlist_changed ();
237         void diskstream_record_enable_changed ();
238         void diskstream_record_safe_changed ();
239         void diskstream_speed_changed ();
240         void diskstream_alignment_style_changed ();
241         void parameter_changed (std::string const & p);
242
243         std::string _diskstream_name;
244 };
245
246 }; /* namespace ARDOUR*/
247
248 #endif /* __ardour_track_h__ */