1 /*
2  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
6  * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __ardour_silentfilesource_h__
24 #define __ardour_silentfilesource_h__
25 
26 #include <cstring>
27 #include "ardour/audiofilesource.h"
28 
29 namespace ARDOUR {
30 
31 class LIBARDOUR_API SilentFileSource : public AudioFileSource {
32 public:
update_header(samplepos_t,struct tm &,time_t)33 	int update_header (samplepos_t /*when*/, struct tm&, time_t) { return 0; }
flush_header()34 	int flush_header () { return 0; }
sample_rate()35 	float sample_rate () const { return _sample_rate; }
36 
set_length(samplecnt_t len)37 	void set_length (samplecnt_t len) { _length = len; }
flush()38 	void flush () {}
39 
can_be_analysed()40 	bool can_be_analysed() const { return false; }
41 
clamped_at_unity()42 	bool clamped_at_unity() const { return false; }
43 
44 protected:
close()45 	void close() {}
46 	friend class SourceFactory;
47 
SilentFileSource(Session & s,const XMLNode & x,samplecnt_t len,float srate)48 	SilentFileSource (Session& s, const XMLNode& x, samplecnt_t len, float srate)
49 		: Source (s, x)
50 		, AudioFileSource (s, x, false)
51 		, _sample_rate(srate)
52 	{
53 		_length = len;
54 	}
55 
read_unlocked(Sample * dst,samplepos_t start,samplecnt_t cnt)56 	samplecnt_t read_unlocked (Sample *dst, samplepos_t start, samplecnt_t cnt) const {
57 		cnt = std::min (cnt, std::max<samplecnt_t> (0, _length - start));
58 		memset (dst, 0, sizeof (Sample) * cnt);
59 		return cnt;
60 	}
61 
write_unlocked(Sample *,samplecnt_t)62 	samplecnt_t write_unlocked (Sample */*dst*/, samplecnt_t /*cnt*/) { return 0; }
63 
set_header_natural_position()64 	void set_header_natural_position () {}
65 
read_peaks_with_fpp(PeakData * peaks,samplecnt_t npeaks,samplepos_t,samplecnt_t,double,samplecnt_t)66 	int read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos_t /*start*/, samplecnt_t /*cnt*/,
67 				 double /*samples_per_pixel*/, samplecnt_t /*fpp*/) const {
68 		memset (peaks, 0, sizeof (PeakData) * npeaks);
69 		return 0;
70 	}
71 
72 	float _sample_rate;
73 };
74 
75 } // namespace ARDOUR
76 
77 #endif /* __ardour_audiofilesource_h__ */
78 
79