EXPERIMENTAL! NEEDS TESTING! remove "offset" from almost everything in the process...
[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
33 class Track : public Route
34 {
35   public:
36         Track (Session&, string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal, DataType default_type = DataType::AUDIO);
37
38         virtual ~Track ();
39         
40         int set_name (string str, void *src);
41
42         TrackMode mode () const { return _mode; }
43         virtual int set_mode (TrackMode m) { return false; }
44         virtual bool can_use_mode (TrackMode m, bool& bounce_required) { return false; }
45         sigc::signal<void> TrackModeChanged;
46
47         virtual int roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, 
48                           int declick, bool can_record, bool rec_monitors_input) = 0;
49         
50         virtual int no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, 
51                              bool state_changing, bool can_record, bool rec_monitors_input) = 0;
52         
53         virtual int silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, 
54                                  bool can_record, bool rec_monitors_input) = 0;
55
56         void toggle_monitor_input ();
57
58         virtual bool can_record();
59
60         boost::shared_ptr<Diskstream> diskstream() const { return _diskstream; }
61
62         virtual int use_diskstream (string name) = 0;
63         virtual int use_diskstream (const PBD::ID& id) = 0;
64
65         nframes_t update_total_latency();
66         void           set_latency_delay (nframes_t);
67
68         enum FreezeState {
69                 NoFreeze,
70                 Frozen,
71                 UnFrozen
72         };
73
74         FreezeState freeze_state() const;
75  
76         virtual void freeze (InterThreadInfo&) = 0;
77         virtual void unfreeze () = 0;
78
79         virtual boost::shared_ptr<Region> bounce (InterThreadInfo&) = 0;
80         virtual boost::shared_ptr<Region> bounce_range (nframes_t start, nframes_t end, InterThreadInfo&, bool enable_processing = true) = 0;
81
82         XMLNode&    get_state();
83         XMLNode&    get_template();
84         virtual int set_state(const XMLNode& node) = 0;
85
86         static void zero_diskstream_id_in_xml (XMLNode&);
87
88         PBD::Controllable& rec_enable_control() { return _rec_enable_control; }
89
90         bool record_enabled() const;
91         void set_record_enable (bool yn, void *src);
92         
93         void set_meter_point (MeterPoint, void* src);
94         
95         sigc::signal<void> DiskstreamChanged;
96         sigc::signal<void> FreezeChange;
97
98   protected:
99         Track (Session& sess, const XMLNode& node, DataType default_type = DataType::AUDIO);
100
101         virtual XMLNode& state (bool full) = 0;
102
103         virtual void passthru_silence (nframes_t start_frame, nframes_t end_frame, 
104                                        nframes_t nframes, int declick, bool meter) = 0;
105
106         virtual uint32_t n_process_buffers () = 0;
107         
108         boost::shared_ptr<Diskstream> _diskstream;
109         MeterPoint  _saved_meter_point;
110         TrackMode   _mode;
111
112         //private: (FIXME)
113         struct FreezeRecordInsertInfo {
114             FreezeRecordInsertInfo(XMLNode& st, boost::shared_ptr<Insert> ins) 
115                     : state (st), insert (ins) {}
116
117             XMLNode                   state;
118             boost::shared_ptr<Insert> insert;
119             PBD::ID                   id;
120             UndoAction                memento;
121         };
122
123         struct FreezeRecord {
124             FreezeRecord()
125                 : have_mementos(false)
126             {}
127
128             ~FreezeRecord();
129
130             boost::shared_ptr<Playlist>     playlist;
131             vector<FreezeRecordInsertInfo*> insert_info;
132             bool                            have_mementos;
133             FreezeState                     state;
134             gain_t                          gain;
135             AutoState                       gain_automation_state;
136             AutoState                       pan_automation_state;
137         };
138
139         struct RecEnableControllable : public PBD::Controllable {
140             RecEnableControllable (Track&);
141             
142             void set_value (float);
143             float get_value (void) const;
144
145             Track& track;
146         };
147
148         //virtual void diskstream_record_enable_changed (void *src) = 0;
149         //virtual void diskstream_input_channel_changed (void *src) = 0;
150
151         //virtual void input_change_handler (void *src) = 0;
152
153         virtual void set_state_part_two () = 0;
154
155         FreezeRecord          _freeze_record;
156         XMLNode*              pending_state;
157         sigc::connection      recenable_connection;
158         sigc::connection      ic_connection;
159         RecEnableControllable _rec_enable_control;
160         bool                  _destructive;
161 };
162
163 }; /* namespace ARDOUR*/
164
165 #endif /* __ardour_track_h__ */