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