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