38d36ea5d086bc1440bfe9ad3d09479785247d40
[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 int no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
52                         bool state_changing, bool can_record, bool rec_monitors_input);
53
54         int silent_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
55                          bool can_record, bool rec_monitors_input, bool& need_butler);
56
57         virtual int roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
58                           int declick, bool can_record, bool rec_monitors_input, bool& need_butler) = 0;
59
60         bool needs_butler() const { return _needs_butler; }
61         void toggle_monitor_input ();
62
63         virtual DataType data_type () const = 0;
64
65         bool can_record();
66
67         virtual void use_new_diskstream () = 0;
68         virtual void set_diskstream (boost::shared_ptr<Diskstream>);
69
70         nframes_t update_total_latency();
71         void           set_latency_delay (nframes_t);
72
73         enum FreezeState {
74                 NoFreeze,
75                 Frozen,
76                 UnFrozen
77         };
78
79         FreezeState freeze_state() const;
80
81         virtual void freeze_me (InterThreadInfo&) = 0;
82         virtual void unfreeze () = 0;
83
84         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
85         virtual boost::shared_ptr<Region> bounce_range (nframes_t start, nframes_t end, InterThreadInfo&, bool enable_processing = true) = 0;
86
87         XMLNode&    get_state();
88         XMLNode&    get_template();
89         virtual int set_state (const XMLNode&, int version) = 0;
90         static void zero_diskstream_id_in_xml (XMLNode&);
91
92         boost::shared_ptr<PBD::Controllable> rec_enable_control() { return _rec_enable_control; }
93
94         bool record_enabled() const;
95         void set_record_enabled (bool yn, void *src);
96
97         /* XXX: unfortunate that this is exposed */
98         PBD::ID const & diskstream_id () const;
99
100         void set_block_size (nframes_t);
101
102         /* PublicDiskstream interface */
103         boost::shared_ptr<Playlist> playlist ();
104         void monitor_input (bool);
105         bool destructive () const;
106         std::list<boost::shared_ptr<Source> > & last_capture_sources ();
107         void set_capture_offset ();
108         std::list<boost::shared_ptr<Source> > steal_write_sources();
109         void reset_write_sources (bool, bool force = false);
110         float playback_buffer_load () const;
111         float capture_buffer_load () const;
112         int do_refill ();
113         int do_flush (RunContext, bool force = false);
114         uint32_t read_data_count() const;
115         uint32_t write_data_count() const;
116         void set_pending_overwrite (bool);
117         int seek (framepos_t, bool complete_refill = false);
118         bool hidden () const;
119         int can_internal_playback_seek (framepos_t);
120         int internal_playback_seek (framepos_t);
121         void non_realtime_input_change ();
122         void non_realtime_locate (framepos_t);
123         void non_realtime_set_speed ();
124         int overwrite_existing_buffers ();
125         framecnt_t get_captured_frames (uint32_t n = 0);
126         int set_loop (Location *);
127         void transport_looped (framepos_t);
128         bool realtime_set_speed (double, bool);
129         void transport_stopped_wallclock (struct tm &, time_t, bool);
130         bool pending_overwrite () const;
131         double speed () const;
132         void prepare_to_stop (framepos_t);
133         void set_slaved (bool);
134         ChanCount n_channels ();
135         framepos_t get_capture_start_frame (uint32_t n = 0);
136         AlignStyle alignment_style () const;
137         framepos_t current_capture_start () const;
138         framepos_t current_capture_end () const;
139         void playlist_modified ();
140         int use_playlist (boost::shared_ptr<Playlist>);
141         void set_align_style (AlignStyle);
142         int use_copy_playlist ();
143         int use_new_playlist ();
144         void adjust_playback_buffering ();
145         void adjust_capture_buffering ();
146
147         PBD::Signal0<void> DiskstreamChanged;
148         PBD::Signal0<void> FreezeChange;
149         PBD::Signal0<void> PlaylistChanged;
150         PBD::Signal0<void> RecordEnableChanged;
151         PBD::Signal0<void> SpeedChanged;
152         PBD::Signal0<void> AlignmentStyleChanged;
153
154   protected:
155         virtual XMLNode& state (bool full) = 0;
156
157         boost::shared_ptr<Diskstream> _diskstream;
158         MeterPoint  _saved_meter_point;
159         TrackMode   _mode;
160         bool        _needs_butler;
161
162         ChanCount input_streams () const;
163
164         //private: (FIXME)
165         struct FreezeRecordProcessorInfo {
166                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
167                         : state (st), processor (proc) {}
168
169                 XMLNode                      state;
170                 boost::shared_ptr<Processor> processor;
171                 PBD::ID                      id;
172         };
173
174         struct FreezeRecord {
175                 FreezeRecord()
176                         : have_mementos(false)
177                 {}
178
179                 ~FreezeRecord();
180
181                 boost::shared_ptr<Playlist>        playlist;
182                 std::vector<FreezeRecordProcessorInfo*> processor_info;
183                 bool                               have_mementos;
184                 FreezeState                        state;
185         };
186
187         struct RecEnableControllable : public PBD::Controllable {
188                 RecEnableControllable (Track&);
189
190                 void set_value (double);
191                 double get_value (void) const;
192
193                 Track& track;
194         };
195
196         virtual void set_state_part_two () = 0;
197
198         FreezeRecord          _freeze_record;
199         XMLNode*              pending_state;
200         bool                  _destructive;
201
202         boost::shared_ptr<RecEnableControllable> _rec_enable_control;
203
204 private:
205         void diskstream_playlist_changed ();
206         void diskstream_record_enable_changed ();
207         void diskstream_speed_changed ();
208         void diskstream_alignment_style_changed ();
209 };
210
211 }; /* namespace ARDOUR*/
212
213 #endif /* __ardour_track_h__ */