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>
36 #include <pbd/stateful.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>
56 class AudioFileSource;
59 class AudioDiskstream : public Diskstream
62 AudioDiskstream (Session &, const string& name, Diskstream::Flag f = Recordable);
63 AudioDiskstream (Session &, const XMLNode&);
65 void set_io (ARDOUR::IO& io);
67 AudioDiskstream& ref() { _refcnt++; return *this; }
68 //void unref() { if (_refcnt) _refcnt--; if (_refcnt == 0) delete this; }
69 //uint32_t refcnt() const { return _refcnt; }
71 float playback_buffer_load() const;
72 float capture_buffer_load() const;
74 //void set_align_style (AlignStyle);
75 //void set_persistent_align_style (AlignStyle);
77 string input_source (uint32_t n=0) const {
78 if (n < channels.size()) {
79 return channels[n].source ? channels[n].source->name() : "";
85 Port *input_source_port (uint32_t n=0) const {
86 if (n < channels.size()) return channels[n].source; return 0;
89 void set_record_enabled (bool yn, void *src);
90 //void set_speed (double);
92 float peak_power(uint32_t n=0) {
93 float x = channels[n].peak_power;
94 channels[n].peak_power = 0.0f;
96 return 20.0f * fast_log10(x);
98 return minus_infinity();
102 int use_playlist (Playlist *);
103 int use_new_playlist ();
104 int use_copy_playlist ();
106 void start_scrub (jack_nframes_t where) {} // FIXME?
107 void end_scrub () {} // FIXME?
109 Playlist *playlist () { return _playlist; }
111 Sample *playback_buffer (uint32_t n=0) {
112 if (n < channels.size())
113 return channels[n].current_playback_buffer;
117 Sample *capture_buffer (uint32_t n=0) {
118 if (n < channels.size())
119 return channels[n].current_capture_buffer;
123 AudioFileSource *write_source (uint32_t n=0) {
124 if (n < channels.size())
125 return channels[n].write_source;
130 int remove_channel ();
135 XMLNode& get_state(void);
136 int set_state(const XMLNode& node);
138 void monitor_input (bool);
140 // FIXME: these don't belong here
141 static void swap_by_ptr (Sample *first, Sample *last) {
142 while (first < last) {
149 static void swap_by_ptr (Sample *first, Sample *last, jack_nframes_t n) {
157 //void handle_input_change (IOChange, void *src);
159 //static sigc::signal<void> DiskOverrun;
160 //static sigc::signal<void> DiskUnderrun;
161 //static sigc::signal<void,AudioDiskstream*> AudioDiskstreamCreated; // XXX use a ref with sigc2
162 static sigc::signal<void,list<AudioFileSource*>*> DeleteSources;
164 int set_loop (Location *loc);
165 sigc::signal<void,Location *> LoopSet;
167 std::list<Region*>& last_capture_regions () {
168 return _last_capture_regions;
171 void handle_input_change (IOChange, void *src);
173 const PBD::ID& id() const { return _id; }
175 XMLNode* deprecated_io_node;
178 friend class Session;
180 /* the Session is the only point of access for these
181 because they require that the Session is "inactive"
182 while they are called.
185 void set_pending_overwrite(bool);
186 int overwrite_existing_buffers ();
187 void reverse_scrub_buffer (bool to_forward) {} // FIXME?
188 void set_block_size (jack_nframes_t);
189 int internal_playback_seek (jack_nframes_t distance);
190 int can_internal_playback_seek (jack_nframes_t distance);
191 int rename_write_sources ();
192 void reset_write_sources (bool, bool force = false);
193 void non_realtime_input_change ();
196 friend class Auditioner;
197 int seek (jack_nframes_t which_sample, bool complete_refill = false);
200 friend class AudioTrack;
202 int process (jack_nframes_t transport_frame, jack_nframes_t nframes, jack_nframes_t offset, bool can_record, bool rec_monitors_input);
203 bool commit (jack_nframes_t nframes);
207 /* use unref() to destroy a diskstream */
212 Sample *playback_wrap_buffer;
213 Sample *capture_wrap_buffer;
214 Sample *speed_buffer;
218 AudioFileSource *fades_source;
219 AudioFileSource *write_source;
222 Sample *current_capture_buffer;
223 Sample *current_playback_buffer;
225 RingBufferNPT<Sample> *playback_buf;
226 RingBufferNPT<Sample> *capture_buf;
228 Sample* scrub_buffer;
229 Sample* scrub_forward_buffer;
230 Sample* scrub_reverse_buffer;
232 RingBufferNPT<Sample>::rw_vector playback_vector;
233 RingBufferNPT<Sample>::rw_vector capture_vector;
235 RingBufferNPT<CaptureTransition> * capture_transition_buf;
236 // the following are used in the butler thread only
237 jack_nframes_t curr_capture_cnt;
240 typedef vector<ChannelInfo> ChannelList;
242 /* the two central butler operations */
244 int do_flush (char * workbuf, bool force = false);
245 int do_refill (Sample *mixdown_buffer, float *gain_buffer, char *workbuf);
247 virtual int non_realtime_do_refill() { return do_refill(0, 0, 0); }
249 int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, char * workbuf, jack_nframes_t& start, jack_nframes_t cnt,
250 ChannelInfo& channel_info, int channel, bool reversed);
252 /* XXX fix this redundancy ... */
254 //void playlist_changed (Change);
255 //void playlist_modified ();
256 void playlist_deleted (Playlist*);
257 void session_controls_changed (Session::ControlType) {} // FIXME?
259 void finish_capture (bool rec_monitors_input);
260 void clean_up_capture (struct tm&, time_t, bool abort) {} // FIXME?
261 void transport_stopped (struct tm&, time_t, bool abort);
268 vector<CaptureInfo*> capture_info;
269 Glib::Mutex capture_info_lock;
271 void init (Diskstream::Flag);
273 void init_channel (ChannelInfo &chan);
274 void destroy_channel (ChannelInfo &chan);
276 int use_new_write_source (uint32_t n=0);
277 int use_new_fade_source (uint32_t n=0) { return 0; } // FIXME?
279 int find_and_use_playlist (const string&);
281 void allocate_temporary_buffers ();
283 int create_input_port () { return 0; } // FIXME?
284 int connect_input_port () { return 0; } // FIXME?
285 int seek_unlocked (jack_nframes_t which_sample) { return 0; } // FIXME?
287 int ports_created () { return 0; } // FIXME?
289 //bool realtime_set_speed (double, bool global_change);
290 void non_realtime_set_speed ();
292 std::list<Region*> _last_capture_regions;
293 std::vector<AudioFileSource*> capturing_sources;
294 int use_pending_capture_data (XMLNode& node);
296 void get_input_sources ();
297 void check_record_status (jack_nframes_t transport_frame, jack_nframes_t nframes, bool can_record);
298 void set_align_style_from_io();
299 void setup_destructive_playlist ();
300 void use_destructive_playlist ();
302 ChannelList channels;
303 AudioPlaylist* _playlist;
304 void engage_record_enable (void* src);
305 void disengage_record_enable (void* src);
308 }; /* namespace ARDOUR */
310 #endif /* __ardour_audio_diskstream_h__ */