c05d222cc21b6d308876c70986b26a1236639650
[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
26 namespace ARDOUR {
27
28 class Session;
29 class Diskstream;
30 class Playlist;
31 class RouteGroup;
32 class Region;
33
34 class Track : public Route
35 {
36   public:
37         Track (Session&, std::string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
38         virtual ~Track ();
39
40         int init ();
41
42         bool set_name (const std::string& str);
43
44         TrackMode mode () const { return _mode; }
45         virtual int set_mode (TrackMode /*m*/) { return false; }
46         virtual bool can_use_mode (TrackMode /*m*/, bool& /*bounce_required*/) { return false; }
47         PBD::Signal0<void> TrackModeChanged;
48
49         virtual int no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
50                         bool state_changing, bool can_record, bool rec_monitors_input);
51
52         int silent_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
53                          bool can_record, bool rec_monitors_input, bool& need_butler);
54
55         virtual int roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
56                           int declick, bool can_record, bool rec_monitors_input, bool& need_butler) = 0;
57
58         bool needs_butler() const { return _needs_butler; }
59         void toggle_monitor_input ();
60
61         bool can_record();
62
63         boost::shared_ptr<Diskstream> diskstream() const { return _diskstream; }
64
65         virtual void use_new_diskstream () = 0;
66         virtual void set_diskstream (boost::shared_ptr<Diskstream>) = 0;
67
68         nframes_t update_total_latency();
69         void           set_latency_delay (nframes_t);
70
71         enum FreezeState {
72                 NoFreeze,
73                 Frozen,
74                 UnFrozen
75         };
76
77         FreezeState freeze_state() const;
78
79         virtual void freeze_me (InterThreadInfo&) = 0;
80         virtual void unfreeze () = 0;
81
82         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
83         virtual boost::shared_ptr<Region> bounce_range (nframes_t start, nframes_t end, InterThreadInfo&, bool enable_processing = true) = 0;
84
85         XMLNode&    get_state();
86         XMLNode&    get_template();
87         virtual int set_state (const XMLNode&, int version) = 0;
88         static void zero_diskstream_id_in_xml (XMLNode&);
89
90         boost::shared_ptr<PBD::Controllable> rec_enable_control() { return _rec_enable_control; }
91
92         bool record_enabled() const;
93         void set_record_enable (bool yn, void *src);
94
95         PBD::Signal0<void> DiskstreamChanged;
96         PBD::Signal0<void> FreezeChange;
97
98   protected:
99         virtual XMLNode& state (bool full) = 0;
100
101         boost::shared_ptr<Diskstream> _diskstream;
102         MeterPoint  _saved_meter_point;
103         TrackMode   _mode;
104         bool        _needs_butler;
105
106         ChanCount input_streams () const;
107
108         //private: (FIXME)
109         struct FreezeRecordProcessorInfo {
110                 FreezeRecordProcessorInfo(XMLNode& st, boost::shared_ptr<Processor> proc)
111                         : state (st), processor (proc) {}
112
113                 XMLNode                      state;
114                 boost::shared_ptr<Processor> processor;
115                 PBD::ID                      id;
116         };
117
118         struct FreezeRecord {
119                 FreezeRecord()
120                         : have_mementos(false)
121                 {}
122
123                 ~FreezeRecord();
124
125                 boost::shared_ptr<Playlist>        playlist;
126                 std::vector<FreezeRecordProcessorInfo*> processor_info;
127                 bool                               have_mementos;
128                 FreezeState                        state;
129         };
130
131         struct RecEnableControllable : public PBD::Controllable {
132                 RecEnableControllable (Track&);
133
134                 void set_value (float);
135                 float get_value (void) const;
136
137                 Track& track;
138         };
139
140         virtual void set_state_part_two () = 0;
141
142         FreezeRecord          _freeze_record;
143         XMLNode*              pending_state;
144         bool                  _destructive;
145
146         boost::shared_ptr<RecEnableControllable> _rec_enable_control;
147 };
148
149 }; /* namespace ARDOUR*/
150
151 #endif /* __ardour_track_h__ */