2 Copyright (C) 2010 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.
20 /** @file libs/pbd/sndfile_manager.cc
21 * @brief A FileDescriptor for files opened using libsndfile.
25 #include <sys/types.h>
29 #include "pbd/compose.h"
30 #include "pbd/sndfile_manager.h"
31 #include "pbd/debug.h"
36 /** @param file_name Filename.
37 * @param writeable true to open writeable, otherwise false.
38 * @param info SF_INFO for the file.
41 SndFileDescriptor::SndFileDescriptor (string const & file_name, bool writeable, SF_INFO* info)
42 : FileDescriptor (file_name, writeable)
46 manager()->add (this);
49 SndFileDescriptor::~SndFileDescriptor ()
51 manager()->remove (this);
54 /** @return SNDFILE*, or 0 on error */
56 SndFileDescriptor::allocate ()
58 bool const f = manager()->allocate (this);
63 /* this is ok thread-wise because allocate () has incremented
64 the Descriptor's refcount, so the file will not be closed
70 SndFileDescriptor::close ()
72 /* we must have a lock on the FileManager's mutex */
80 SndFileDescriptor::is_open () const
82 /* we must have a lock on the FileManager's mutex */
88 SndFileDescriptor::open ()
90 /* we must have a lock on the FileManager's mutex */
92 _sndfile = sf_open (_path.c_str(), _writeable ? SFM_RDWR : SFM_READ, _info);
93 return (_sndfile == 0);