static int get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg);
protected:
+ void close ();
framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const;
framecnt_t write_unlocked (Sample *, framecnt_t) { return 0; }
*/
int rename (const std::string& name);
- virtual void release_descriptor () {}
+ virtual void close () = 0;
-protected:
+ protected:
FileSource (Session& session, DataType type,
const std::string& path,
const std::string& origin,
bool clamped_at_unity() const { return false; }
protected:
+ void close() {}
friend class SourceFactory;
SilentFileSource (Session& s, const XMLNode& x, framecnt_t len, float srate)
void prevent_deletion ();
protected:
+ void close ();
void set_path (const std::string& newpath);
void flush_midi (const Lock& lock);
static int get_soundfile_info (const std::string& path, SoundFileInfo& _info, std::string& error_msg);
protected:
+ void close ();
+
void set_path (const std::string& p);
void set_header_timeline_position ();
bool clamped_at_unity() const { return false; }
protected:
+ void close ();
framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const;
framecnt_t write_unlocked (Sample */*dst*/, framecnt_t /*cnt*/) { return 0; }
{
}
+void
+CoreAudioSource::close ()
+{
+ af.Close ();
+}
+
int
CoreAudioSource::safe_read (Sample* dst, framepos_t start, framecnt_t cnt, AudioBufferList& abl) const
{
void
FileSource::set_path (const std::string& newpath)
{
+ close ();
_path = newpath;
set_within_session_from_path (newpath);
if (_within_session) {
return 0;
}
+void
+SMFSource::close ()
+{
+ /* nothing to do: file descriptor is never kept open */
+}
+
/** All stamps in audio frames */
framecnt_t
SMFSource::read_unlocked (const Lock& lock,
throw failed_constructor();
}
} else {
- /* normal mode: do not open the file here - do that in write_unlocked() as needed
+ /* normal mode: do not open the file here - do that in {read,write}_unlocked() as needed
*/
}
}
AudioFileSource::HeaderPositionOffsetChanged.connect_same_thread (header_position_connection, boost::bind (&SndFileSource::handle_header_position_change, this));
}
+void
+SndFileSource::close ()
+{
+ if (_sndfile) {
+ sf_close (_sndfile);
+ _sndfile = 0;
+ }
+}
+
int
SndFileSource::open ()
{
SndFileSource::~SndFileSource ()
{
- if (_sndfile) {
- sf_close (_sndfile);
- _sndfile = 0;
- }
+ close ();
delete _broadcast_info;
delete [] xfade_buf;
}
return cnt;
}
- if (_sndfile == 0) {
- error << string_compose (_("could not allocate file %1 for reading."), _path) << endmsg;
+ if (const_cast<SndFileSource*>(this)->open()) {
+ error << string_compose (_("could not open file %1 for reading."), _path) << endmsg;
return 0;
- }
+ }
if (start > _length) {
delete [] _src_buffer;
}
+void
+SrcFileSource::close ()
+{
+ boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (_source);
+ if (fs) {
+ fs->close ();
+ }
+}
+
framecnt_t
SrcFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const
{