#ifdef PLATFORM_WINDOWS
#include <glibmm/convert.h>
#endif
+#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include "ardour/sndfilesource.h"
SndFileSource::SndFileSource (Session& s, const XMLNode& node)
: Source(s, node)
, AudioFileSource (s, node)
+ , _descriptor (0)
+ , _broadcast_info (0)
+ , _capture_start (false)
+ , _capture_end (false)
+ , file_pos (0)
+ , xfade_buf (0)
{
init_sndfile ();
+ assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
+ existence_check ();
+
if (open()) {
throw failed_constructor ();
}
}
-/** Files created this way are never writable or removable */
+/** Constructor for existing external-to-session files.
+ Files created this way are never writable or removable
+*/
SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flags)
: Source(s, DataType::AUDIO, path, flags)
/* note that the origin of an external file is itself */
, AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
+ , _descriptor (0)
+ , _broadcast_info (0)
+ , _capture_start (false)
+ , _capture_end (false)
+ , file_pos (0)
+ , xfade_buf (0)
{
_channel = chn;
init_sndfile ();
+ assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
+ existence_check ();
+
if (open()) {
throw failed_constructor ();
}
}
-/** This constructor is used to construct new files, not open existing ones. */
+/** This constructor is used to construct new internal-to-session files,
+ not open existing ones.
+*/
SndFileSource::SndFileSource (Session& s, const string& path, const string& origin,
SampleFormat sfmt, HeaderFormat hf, framecnt_t rate, Flag flags)
: Source(s, DataType::AUDIO, path, flags)
, AudioFileSource (s, path, origin, flags, sfmt, hf)
+ , _descriptor (0)
+ , _broadcast_info (0)
+ , _capture_start (false)
+ , _capture_end (false)
+ , file_pos (0)
+ , xfade_buf (0)
{
int fmt = 0;
init_sndfile ();
+ assert (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
+ existence_check ();
+
_file_is_new = true;
switch (hf) {
}
}
-void
-SndFileSource::init_sndfile ()
+/** Constructor to be called for recovering files being used for
+ * capture. They are in-session, they already exist, they should not
+ * be writable. They are an odd hybrid (from a constructor point of
+ * view) of the previous two constructors.
+ */
+SndFileSource::SndFileSource (Session& s, const string& path, int chn)
+ : Source (s, DataType::AUDIO, path, Flag (0))
+ /* the final boolean argument is not used, its value is irrelevant. see audiofilesource.h for explanation */
+ , AudioFileSource (s, path, Flag (0))
+ , _descriptor (0)
+ , _broadcast_info (0)
+ , _capture_start (false)
+ , _capture_end (false)
+ , file_pos (0)
+ , xfade_buf (0)
{
- string file;
+ _channel = chn;
- _descriptor = 0;
+ init_sndfile ();
- // lets try to keep the object initalizations here at the top
- xfade_buf = 0;
- _broadcast_info = 0;
+ assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
+ existence_check ();
+ if (open()) {
+ throw failed_constructor ();
+ }
+}
+
+void
+SndFileSource::init_sndfile ()
+{
/* although libsndfile says we don't need to set this,
valgrind and source code shows us that we do.
*/
memset (&_info, 0, sizeof(_info));
- _capture_start = false;
- _capture_end = false;
- file_pos = 0;
-
if (destructive()) {
xfade_buf = new Sample[xfade_frames];
_timeline_position = header_position_offset;
delete _broadcast_info;
_broadcast_info = 0;
_flags = Flag (_flags & ~Broadcast);
+ }
+
+ /* Set the broadcast flag if the BWF info is already there. We need
+ * this when recovering or using existing files.
+ */
+
+ if (bwf_info_exists) {
+ _flags = Flag (_flags | Broadcast);
}
if (writable()) {