4dae06eeffe19c77adb469d0b1dfe7b202b1bbf1
[ardour.git] / libs / ardour / ardour / audio_track.h
1 /*
2     Copyright (C) 2002-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     $Id$
19 */
20
21 #ifndef __ardour_audio_track_h__
22 #define __ardour_audio_track_h__
23
24 #include <ardour/route.h>
25
26 namespace ARDOUR {
27
28 class Session;
29 class DiskStream;
30 class AudioPlaylist;
31 class RouteGroup;
32
33 class AudioTrack : public Route
34 {
35   public:
36         AudioTrack (Session&, string name, Route::Flag f = Route::Flag (0), TrackMode m = Normal);
37         AudioTrack (Session&, const XMLNode&);
38         ~AudioTrack ();
39         
40         int set_name (string str, void *src);
41
42         int  roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, 
43
44                    jack_nframes_t offset, int declick, bool can_record, bool rec_monitors_input);
45         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);
47         int  silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, 
48                           jack_nframes_t offset, bool can_record, bool rec_monitors_input);
49
50         void toggle_monitor_input ();
51
52         bool can_record() const { return true; }
53         void set_record_enable (bool yn, void *src);
54
55         DiskStream& disk_stream() const { return *diskstream; }
56         int set_diskstream (DiskStream&, void *);
57         int use_diskstream (string name);
58         int use_diskstream (id_t id);
59
60         TrackMode mode() const { return _mode; }
61         void set_mode (TrackMode m);
62         sigc::signal<void> ModeChanged;
63
64         jack_nframes_t update_total_latency();
65         void set_latency_delay (jack_nframes_t);
66         
67         int export_stuff (vector<Sample*>& buffers, char * workbuf, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t end_frame);
68
69         sigc::signal<void,void*> diskstream_changed;
70
71         enum FreezeState {
72                 NoFreeze,
73                 Frozen,
74                 UnFrozen
75         };
76
77         FreezeState freeze_state() const;
78
79         sigc::signal<void> FreezeChange;
80  
81         void freeze (InterThreadInfo&);
82         void unfreeze ();
83
84         void bounce (InterThreadInfo&);
85         void bounce_range (jack_nframes_t start, jack_nframes_t end, InterThreadInfo&);
86
87         XMLNode& get_state();
88         int set_state(const XMLNode& node);
89
90         MIDI::Controllable& midi_rec_enable_control() {
91                 return _midi_rec_enable_control;
92         }
93
94         void reset_midi_control (MIDI::Port*, bool);
95         void send_all_midi_feedback ();
96
97         bool record_enabled() const;
98         void set_meter_point (MeterPoint, void* src);
99
100   protected:
101         DiskStream *diskstream;
102         MeterPoint _saved_meter_point;
103         TrackMode _mode;
104
105         void passthru_silence (jack_nframes_t start_frame, jack_nframes_t end_frame, 
106                                jack_nframes_t nframes, jack_nframes_t offset, int declick,
107                                bool meter);
108
109         uint32_t n_process_buffers ();
110
111   private:
112         struct FreezeRecordInsertInfo {
113             FreezeRecordInsertInfo(XMLNode& st) 
114                     : state (st), insert (0) {}
115
116             XMLNode  state;
117             Insert*  insert;
118             id_t     id;
119             UndoAction memento;
120         };
121
122         struct FreezeRecord {
123             FreezeRecord() {
124                     playlist = 0;
125                     have_mementos = false;
126             }
127
128             ~FreezeRecord();
129
130             AudioPlaylist* playlist;
131             vector<FreezeRecordInsertInfo*> insert_info;
132             bool have_mementos;
133             FreezeState state;
134         };
135
136         FreezeRecord _freeze_record;
137         XMLNode* pending_state;
138
139         void diskstream_record_enable_changed (void *src);
140         void diskstream_input_channel_changed (void *src);
141
142         void input_change_handler (void *src);
143
144         sigc::connection recenable_connection;
145         sigc::connection ic_connection;
146
147         XMLNode& state(bool);
148
149         int deprecated_use_diskstream_connections ();
150         void set_state_part_two ();
151         void set_state_part_three ();
152
153         struct MIDIRecEnableControl : public MIDI::Controllable {
154                 MIDIRecEnableControl (AudioTrack&, MIDI::Port *);
155                 void set_value (float);
156                 void send_feedback (bool);
157                 MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool val, bool force = false);
158                 AudioTrack& track;
159                 bool setting;
160                 bool last_written;
161         };
162
163         MIDIRecEnableControl _midi_rec_enable_control;
164
165         bool _destructive;
166 };
167
168 }; /* namespace ARDOUR*/
169
170 #endif /* __ardour_audio_track_h__ */