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.
21 #include <sys/resource.h>
22 #include <sys/types.h>
27 #include "pbd/compose.h"
28 #include "pbd/sndfile_manager.h"
29 #include "pbd/debug.h"
34 /** @param n Filename.
35 * @param w true to open writeable, otherwise false.
36 * @param i SF_INFO for the file.
39 SndFileDescriptor::SndFileDescriptor (string const & n, bool w, SF_INFO* i)
40 : FileDescriptor (n, w)
44 manager()->add (this);
47 SndFileDescriptor::~SndFileDescriptor ()
49 manager()->remove (this);
52 /** @return SNDFILE*, or 0 on error */
54 SndFileDescriptor::allocate ()
56 bool const f = manager()->allocate (this);
61 /* this is ok thread-wise because allocate () has incremented
62 the Descriptor's refcount, so the file will not be closed
68 SndFileDescriptor::close ()
70 /* we must have a lock on the FileManager's mutex */
78 SndFileDescriptor::is_open () const
80 /* we must have a lock on the FileManager's mutex */
86 SndFileDescriptor::open ()
88 /* we must have a lock on the FileManager's mutex */
90 _sndfile = sf_open (_path.c_str(), _writeable ? SFM_RDWR : SFM_READ, _info);
91 return (_sndfile == 0);