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