2 Copyright (C) 2000 Paul Davis
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.
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.
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.
18 $Id: diskstream.h 579 2006-06-12 19:56:37Z essej $
21 #ifndef __ardour_audio_diskstream_h__
22 #define __ardour_audio_diskstream_h__
24 #include <sigc++/signal.h>
34 #include <pbd/fastlog.h>
35 #include <pbd/ringbufferNPT.h>
38 #include <ardour/ardour.h>
39 #include <ardour/configuration.h>
40 #include <ardour/session.h>
41 #include <ardour/route_group.h>
42 #include <ardour/route.h>
43 #include <ardour/port.h>
44 #include <ardour/utils.h>
45 #include <ardour/diskstream.h>
46 #include <ardour/audioplaylist.h>
55 class AudioFileSource;
58 class AudioDiskstream : public Diskstream
61 AudioDiskstream (Session &, const string& name, Diskstream::Flag f = Recordable);
62 AudioDiskstream (Session &, const XMLNode&);
64 void set_io (ARDOUR::IO& io);
66 AudioDiskstream& ref() { _refcnt++; return *this; }
67 //void unref() { if (_refcnt) _refcnt--; if (_refcnt == 0) delete this; }
68 //uint32_t refcnt() const { return _refcnt; }
70 float playback_buffer_load() const;
71 float capture_buffer_load() const;
73 //void set_align_style (AlignStyle);
74 //void set_persistent_align_style (AlignStyle);
76 string input_source (uint32_t n=0) const {
77 if (n < channels.size()) {
78 return channels[n].source ? channels[n].source->name() : "";
84 Port *input_source_port (uint32_t n=0) const {
85 if (n < channels.size()) return channels[n].source; return 0;
88 void set_record_enabled (bool yn, void *src);
89 //void set_speed (double);
91 float peak_power(uint32_t n=0) {
92 float x = channels[n].peak_power;
93 channels[n].peak_power = 0.0f;
95 return 20.0f * fast_log10(x);
97 return minus_infinity();
101 int use_playlist (Playlist *);
102 int use_new_playlist ();
103 int use_copy_playlist ();
105 void start_scrub (jack_nframes_t where) {} // FIXME?
106 void end_scrub () {} // FIXME?
108 Playlist *playlist () { return _playlist; }
110 Sample *playback_buffer (uint32_t n=0) {
111 if (n < channels.size())
112 return channels[n].current_playback_buffer;
116 Sample *capture_buffer (uint32_t n=0) {
117 if (n < channels.size())
118 return channels[n].current_capture_buffer;
122 AudioFileSource *write_source (uint32_t n=0) {
123 if (n < channels.size())
124 return channels[n].write_source;
129 int remove_channel ();
134 XMLNode& get_state(void);
135 int set_state(const XMLNode& node);
137 void monitor_input (bool);
139 // FIXME: these don't belong here
140 static void swap_by_ptr (Sample *first, Sample *last) {
141 while (first < last) {
148 static void swap_by_ptr (Sample *first, Sample *last, jack_nframes_t n) {
156 //void handle_input_change (IOChange, void *src);
158 //static sigc::signal<void> DiskOverrun;
159 //static sigc::signal<void> DiskUnderrun;
160 //static sigc::signal<void,AudioDiskstream*> AudioDiskstreamCreated; // XXX use a ref with sigc2
161 static sigc::signal<void,list<AudioFileSource*>*> DeleteSources;
164 friend class Session;
166 /* the Session is the only point of access for these
167 because they require that the Session is "inactive"
168 while they are called.
171 void set_pending_overwrite(bool);
172 int overwrite_existing_buffers ();
173 void reverse_scrub_buffer (bool to_forward) {} // FIXME?
174 void set_block_size (jack_nframes_t);
175 int internal_playback_seek (jack_nframes_t distance);
176 int can_internal_playback_seek (jack_nframes_t distance);
177 int rename_write_sources ();
178 void reset_write_sources (bool, bool force = false);
179 void non_realtime_input_change ();
182 friend class Auditioner;
183 int seek (jack_nframes_t which_sample, bool complete_refill = false);
186 friend class AudioTrack;
188 int process (jack_nframes_t transport_frame, jack_nframes_t nframes, jack_nframes_t offset, bool can_record, bool rec_monitors_input);
189 bool commit (jack_nframes_t nframes);
193 /* use unref() to destroy a diskstream */
198 Sample *playback_wrap_buffer;
199 Sample *capture_wrap_buffer;
200 Sample *speed_buffer;
204 AudioFileSource *fades_source;
205 AudioFileSource *write_source;
208 Sample *current_capture_buffer;
209 Sample *current_playback_buffer;
211 RingBufferNPT<Sample> *playback_buf;
212 RingBufferNPT<Sample> *capture_buf;
214 Sample* scrub_buffer;
215 Sample* scrub_forward_buffer;
216 Sample* scrub_reverse_buffer;
218 RingBufferNPT<Sample>::rw_vector playback_vector;
219 RingBufferNPT<Sample>::rw_vector capture_vector;
221 RingBufferNPT<CaptureTransition> * capture_transition_buf;
222 // the following are used in the butler thread only
223 jack_nframes_t curr_capture_cnt;
226 typedef vector<ChannelInfo> ChannelList;
228 /* the two central butler operations */
230 int do_flush (char * workbuf, bool force = false);
231 int do_refill (Sample *mixdown_buffer, float *gain_buffer, char *workbuf);
233 virtual int non_realtime_do_refill() { return do_refill(0, 0, 0); }
235 int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, char * workbuf, jack_nframes_t& start, jack_nframes_t cnt,
236 ChannelInfo& channel_info, int channel, bool reversed);
238 /* XXX fix this redundancy ... */
240 //void playlist_changed (Change);
241 //void playlist_modified ();
242 void playlist_deleted (Playlist*);
243 void session_controls_changed (Session::ControlType) {} // FIXME?
245 void finish_capture (bool rec_monitors_input);
246 void clean_up_capture (struct tm&, time_t, bool abort) {} // FIXME?
247 void transport_stopped (struct tm&, time_t, bool abort);
254 vector<CaptureInfo*> capture_info;
255 Glib::Mutex capture_info_lock;
257 void init (Diskstream::Flag);
259 void init_channel (ChannelInfo &chan);
260 void destroy_channel (ChannelInfo &chan);
262 int use_new_write_source (uint32_t n=0);
263 int use_new_fade_source (uint32_t n=0) { return 0; } // FIXME?
265 int find_and_use_playlist (const string&);
267 void allocate_temporary_buffers ();
269 int create_input_port () { return 0; } // FIXME?
270 int connect_input_port () { return 0; } // FIXME?
271 int seek_unlocked (jack_nframes_t which_sample) { return 0; } // FIXME?
273 int ports_created () { return 0; } // FIXME?
275 //bool realtime_set_speed (double, bool global_change);
276 void non_realtime_set_speed ();
278 std::list<Region*> _last_capture_regions;
279 std::vector<AudioFileSource*> capturing_sources;
280 int use_pending_capture_data (XMLNode& node);
282 void get_input_sources ();
283 void check_record_status (jack_nframes_t transport_frame, jack_nframes_t nframes, bool can_record);
284 void set_align_style_from_io();
285 void setup_destructive_playlist ();
286 void use_destructive_playlist ();
289 ChannelList channels;
290 AudioPlaylist* _playlist;
293 }; /* namespace ARDOUR */
295 #endif /* __ardour_audio_diskstream_h__ */