enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / ardour / sndfilesource.cc
index 8df88a2732f5a9648dcb85e5e4fdcaa11c43a536..4522e8a54dc794cd106ea0a362297625a0c932a5 100644 (file)
@@ -30,7 +30,7 @@
 #include <sys/stat.h>
 
 #include <glib.h>
-#include <glib/gstdio.h>
+#include "pbd/gstdio_compat.h"
 
 #include <glibmm/convert.h>
 #include <glibmm/fileutils.h>
@@ -41,7 +41,7 @@
 #include "ardour/utils.h"
 #include "ardour/session.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -78,7 +78,7 @@ SndFileSource::SndFileSource (Session& s, const XMLNode& node)
 }
 
 /** Constructor for existing external-to-session files.
-    Files created this way are never writable or removable 
+    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)
@@ -103,8 +103,8 @@ SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flag
        }
 }
 
-/** This constructor is used to construct new internal-to-session 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)
@@ -152,6 +152,23 @@ SndFileSource::SndFileSource (Session& s, const string& path, const string& orig
                _flags = Flag (_flags & ~Broadcast);
                break;
 
+       case RF64_WAV:
+               fmt = SF_FORMAT_RF64;
+               _flags = Flag (_flags & ~Broadcast);
+               _flags = Flag (_flags | RF64_RIFF);
+               break;
+
+       case MBWF:
+               fmt = SF_FORMAT_RF64;
+               _flags = Flag (_flags | Broadcast);
+               _flags = Flag (_flags | RF64_RIFF);
+               break;
+
+       case RF64:
+               fmt = SF_FORMAT_RF64;
+               _flags = Flag (_flags & ~Broadcast);
+               break;
+
        default:
                fatal << string_compose (_("programming error: %1"), X_("unsupported audio header format requested")) << endmsg;
                abort(); /*NOTREACHED*/
@@ -238,6 +255,7 @@ SndFileSource::close ()
        if (_sndfile) {
                sf_close (_sndfile);
                _sndfile = 0;
+               file_closed ();
        }
 }
 
@@ -264,7 +282,7 @@ SndFileSource::open ()
                             _ ("SndFileSource: cannot open file \"%1\" for %2"),
                             _path,
                             (writable () ? "read+write" : "reading")) << endmsg;
-               return false;
+               return -1;
        }
 
        _sndfile = sf_open_fd (fd, writable() ? SFM_RDWR : SFM_READ, &_info, true);
@@ -296,6 +314,19 @@ SndFileSource::open ()
 
        _length = _info.frames;
 
+#ifdef HAVE_RF64_RIFF
+       if (_file_is_new && _length == 0 && writable()) {
+               if (_flags & RF64_RIFF) {
+                       if (sf_command (_sndfile, SFC_RF64_AUTO_DOWNGRADE, 0, 0) != SF_TRUE) {
+                               char errbuf[256];
+                               sf_error_str (_sndfile, errbuf, sizeof (errbuf) - 1);
+                               error << string_compose (_("Cannot mark RF64 audio file for automatic downgrade to WAV: %1"), errbuf)
+                                     << endmsg;
+                       }
+               }
+       }
+#endif
+
        if (!_broadcast_info) {
                _broadcast_info = new BroadcastInfo;
        }
@@ -318,12 +349,12 @@ SndFileSource::open ()
                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);
        }
@@ -350,7 +381,7 @@ SndFileSource::open ()
                         }
                 }
         }
-       
+
        return 0;
 }
 
@@ -371,7 +402,7 @@ framecnt_t
 SndFileSource::read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const
 {
        assert (cnt >= 0);
-       
+
        framecnt_t nread;
        float *ptr;
        framecnt_t real_cnt;