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