#ifndef SNDFILE_HH
#define SNDFILE_HH
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <glib.h>
+#include "pbd/gstdio_compat.h"
+
#include <sndfile.h>
#include <string>
SndfileHandle (const SndfileHandle &orig) ;
SndfileHandle & operator = (const SndfileHandle &rhs) ;
+ void close (void) ;
+
/* Mainly for debugging/testing. */
int refCount (void) const { return (p == NULL) ? 0 : p->ref ; }
inline
SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void)
-{ if (sf != NULL) sf_close (sf) ; }
+{ if (sf != NULL) { sf_close (sf) ; } }
+
+
+void
+SndfileHandle::close (void)
+{
+ if (p != NULL && --p->ref == 0)
+ {
+ delete p ;
+ p = NULL;
+ }
+}
+
inline
SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate)
p->sfinfo.sections = 0 ;
p->sfinfo.seekable = 0 ;
- p->sf = sf_open (path, mode, &p->sfinfo) ;
+ bool writable = false;
+ if (mode & SFM_WRITE) {
+ writable = true;
+ }
+#ifdef PLATFORM_WINDOWS
+ int fd = g_open (path, writable ? O_CREAT | O_RDWR : O_RDONLY, writable ? 0644 : 0444);
+#else
+ int fd = ::open (path, writable ? O_CREAT | O_RDWR : O_RDONLY, writable ? 0644 : 0444);
+#endif
+
+ p->sf = sf_open_fd (fd, mode, &p->sfinfo, true) ;
} ;
return ;
p->sfinfo.sections = 0 ;
p->sfinfo.seekable = 0 ;
- p->sf = sf_open (path.c_str (), mode, &p->sfinfo) ;
+ bool writable = false;
+ if (mode & SFM_WRITE) {
+ writable = true;
+ }
+#ifdef PLATFORM_WINDOWS
+ int fd = g_open (path.c_str(), writable ? O_CREAT | O_RDWR : O_RDONLY, writable ? 0644 : 0444);
+#else
+ int fd = ::open (path.c_str(), writable ? O_CREAT | O_RDWR : O_RDONLY, writable ? 0644 : 0444);
+#endif
+
+ p->sf = sf_open_fd (fd, mode, &p->sfinfo, true) ;
} ;
return ;