first part of using appropriate .ext extensions for the current chosen native file...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 22 Jul 2010 02:27:06 +0000 (02:27 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 22 Jul 2010 02:27:06 +0000 (02:27 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7468 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/ardour.h
libs/ardour/ardour/session.h
libs/ardour/ardour/utils.h
libs/ardour/file_source.cc
libs/ardour/import.cc
libs/ardour/session.cc
libs/ardour/session_state.cc
libs/ardour/utils.cc

index 11a5940c7c0df6ef82cef1309fb0c37489d0f23d..4d98913d34238504f4ed9df8a5f1c083be8f8a7d 100644 (file)
@@ -54,7 +54,7 @@ namespace ARDOUR {
        int cleanup ();
        bool no_auto_connect ();
        void make_property_quarks ();
-
+        
        extern PBD::PropertyChange bounds_change;
 
        std::string get_ardour_revision ();
index ac528081ffb40ba28bc32a3ab0201cd68630177e..21bde800d303d041a32479ff5720522eabeb8dc5 100644 (file)
@@ -180,7 +180,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        Glib::ustring peak_path (Glib::ustring) const;
 
-       static std::string change_source_path_by_name (std::string oldpath, std::string oldname, std::string newname, bool destructive);
+       std::string change_source_path_by_name (std::string oldpath, std::string oldname, std::string newname, bool destructive);
 
        std::string peak_path_from_audio_path (std::string) const;
        std::string new_audio_source_name (const std::string&, uint32_t nchans, uint32_t chan, bool destructive);
index f4c7e585c42722139d624565f92acd233fa05743..b91a6500db87303021c5433cc46015eed5a4f69f 100644 (file)
@@ -34,7 +34,8 @@
 
 bool string_is_affirmative (const std::string&);
 
-#include "ardour.h"
+#include "ardour/ardour.h"
+#include "ardour/data_type.h"
 
 class XMLNode;
 
@@ -103,6 +104,8 @@ float meter_falloff_to_float (ARDOUR::MeterFalloff);
 ARDOUR::MeterFalloff meter_falloff_from_float (float);
 float meter_falloff_to_db_per_sec (float);
 
+const char* native_header_format_extension (ARDOUR::HeaderFormat, const ARDOUR::DataType& type);
+
 #if defined(HAVE_COREAUDIO) || defined(HAVE_AUDIOUNITS)
 std::string CFStringRefToStdString(CFStringRef stringRef);
 #endif // HAVE_COREAUDIO
index d0eb64b8aafdac4dd9f13554dfc5334a56d0348f..512d37a10b5745195131fa62c6c0a3bce80d3237 100644 (file)
@@ -383,7 +383,7 @@ FileSource::set_source_name (const ustring& newname, bool destructive)
 {
        Glib::Mutex::Lock lm (_lock);
        ustring oldpath = _path;
-       ustring newpath = Session::change_source_path_by_name (oldpath, _name, newname, destructive);
+       ustring newpath = _session.change_source_path_by_name (oldpath, _name, newname, destructive);
 
        if (newpath.empty()) {
                error << string_compose (_("programming error: %1"), "cannot generate a changed file path") << endmsg;
index 7d986539dffa4c31001128c136821c00b010e867..156186dbe4251a57dfcbdb05832e529978fbbc67 100644 (file)
@@ -117,25 +117,25 @@ open_importable_source (const string& path, nframes_t samplerate, ARDOUR::SrcQua
 }
 
 static std::string
-get_non_existent_filename (DataType type, const bool allow_replacing, const std::string& destdir, const std::string& basename, uint channel, uint channels)
+get_non_existent_filename (HeaderFormat hf, DataType type, const bool allow_replacing, const std::string& destdir, const std::string& basename, uint channel, uint channels)
 {
        char buf[PATH_MAX+1];
        bool goodfile = false;
        string base(basename);
-       const char* ext = (type == DataType::AUDIO) ? "wav" : "mid";
+       string ext = native_header_format_extension (hf, type);
 
        do {
 
                if (type == DataType::AUDIO && channels == 2) {
                        if (channel == 0) {
-                               snprintf (buf, sizeof(buf), "%s-L.wav", base.c_str());
+                               snprintf (buf, sizeof(buf), "%s-L%s", base.c_str(), ext.c_str());
                        } else {
-                               snprintf (buf, sizeof(buf), "%s-R.wav", base.c_str());
+                               snprintf (buf, sizeof(buf), "%s-R%s", base.c_str(), ext.c_str());
                        }
                } else if (channels > 1) {
-                       snprintf (buf, sizeof(buf), "%s-c%d.%s", base.c_str(), channel, ext);
+                       snprintf (buf, sizeof(buf), "%s-c%d%s", base.c_str(), channel, ext.c_str());
                } else {
-                       snprintf (buf, sizeof(buf), "%s.%s", base.c_str(), ext);
+                       snprintf (buf, sizeof(buf), "%s%s", base.c_str(), ext.c_str());
                }
 
 
@@ -160,7 +160,7 @@ get_non_existent_filename (DataType type, const bool allow_replacing, const std:
 }
 
 static vector<string>
-get_paths_for_new_sources (const bool allow_replacing, const string& import_file_path, const string& session_dir, uint channels)
+get_paths_for_new_sources (HeaderFormat hf, const bool allow_replacing, const string& import_file_path, const string& session_dir, uint channels)
 {
        vector<string> new_paths;
        const string basename = basename_nosuffix (import_file_path);
@@ -175,7 +175,7 @@ get_paths_for_new_sources (const bool allow_replacing, const string& import_file
                                ? sdir.midi_path().to_string() : sdir.sound_path().to_string();
 
                filepath += '/';
-               filepath += get_non_existent_filename (type, allow_replacing, filepath, basename, n, channels);
+               filepath += get_non_existent_filename (hf, type, allow_replacing, filepath, basename, n, channels);
                new_paths.push_back (filepath);
        }
 
@@ -478,7 +478,8 @@ Session::import_audiofiles (ImportStatus& status)
                        }
                }
 
-               vector<string> new_paths = get_paths_for_new_sources (status.replace_existing_source, *p,
+               vector<string> new_paths = get_paths_for_new_sources (config.get_native_file_header_format(),
+                                                                      status.replace_existing_source, *p,
                                                                      get_best_session_directory_for_new_source (),
                                                                      channels);
                Sources newfiles;
index 344a20f86046dba5c00718f3bdb7f69d37469591..e939ffc694fcca1bb4ba1456c386c5cf0d9d8f7d 100644 (file)
@@ -2695,7 +2695,7 @@ Session::change_source_path_by_name (string path, string oldname, string newname
                path += prefix;
                path += '-';
                path += new_legalized;
-               path += ".wav";  /* XXX gag me with a spoon */
+               path += native_header_format_extension (config.get_native_file_header_format(), DataType::AUDIO);
 
                 path = Glib::build_filename (dir, path);
 
@@ -2805,6 +2805,7 @@ Session::new_audio_source_name (const string& base, uint32_t nchan, uint32_t cha
        char buf[PATH_MAX+1];
        const uint32_t limit = 10000;
        string legalized;
+        string ext = native_header_format_extension (config.get_native_file_header_format(), DataType::AUDIO);
 
        buf[0] = '\0';
        legalized = legalize_for_path (base);
@@ -2824,22 +2825,22 @@ Session::new_audio_source_name (const string& base, uint32_t nchan, uint32_t cha
                        if (destructive) {
 
                                if (nchan < 2) {
-                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav",
-                                                       spath.c_str(), cnt, legalized.c_str());
+                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s%s",
+                                                  spath.c_str(), cnt, legalized.c_str(), ext.c_str());
                                } else if (nchan == 2) {
                                        if (chan == 0) {
-                                               snprintf (buf, sizeof(buf), "%s/T%04d-%s%%L.wav",
-                                                               spath.c_str(), cnt, legalized.c_str());
+                                               snprintf (buf, sizeof(buf), "%s/T%04d-%s%%L%s",
+                                                          spath.c_str(), cnt, legalized.c_str(), ext.c_str());
                                        } else {
-                                               snprintf (buf, sizeof(buf), "%s/T%04d-%s%%R.wav",
-                                                               spath.c_str(), cnt, legalized.c_str());
+                                               snprintf (buf, sizeof(buf), "%s/T%04d-%s%%R%s",
+                                                          spath.c_str(), cnt, legalized.c_str(), ext.c_str());
                                        }
                                } else if (nchan < 26) {
-                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s%%%c.wav",
-                                                       spath.c_str(), cnt, legalized.c_str(), 'a' + chan);
+                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s%%%c%s",
+                                                  spath.c_str(), cnt, legalized.c_str(), 'a' + chan, ext.c_str());
                                } else {
-                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav",
-                                                       spath.c_str(), cnt, legalized.c_str());
+                                       snprintf (buf, sizeof(buf), "%s/T%04d-%s%s",
+                                                  spath.c_str(), cnt, legalized.c_str(), ext.c_str());
                                }
 
                        } else {
@@ -2848,17 +2849,17 @@ Session::new_audio_source_name (const string& base, uint32_t nchan, uint32_t cha
                                spath += legalized;
 
                                if (nchan < 2) {
-                                       snprintf (buf, sizeof(buf), "%s-%u.wav", spath.c_str(), cnt);
+                                       snprintf (buf, sizeof(buf), "%s-%u%s", spath.c_str(), cnt, ext.c_str());
                                } else if (nchan == 2) {
                                        if (chan == 0) {
-                                               snprintf (buf, sizeof(buf), "%s-%u%%L.wav", spath.c_str(), cnt);
+                                               snprintf (buf, sizeof(buf), "%s-%u%%L%s", spath.c_str(), cnt, ext.c_str());
                                        } else {
-                                               snprintf (buf, sizeof(buf), "%s-%u%%R.wav", spath.c_str(), cnt);
+                                               snprintf (buf, sizeof(buf), "%s-%u%%R%s", spath.c_str(), cnt, ext.c_str());
                                        }
                                } else if (nchan < 26) {
-                                       snprintf (buf, sizeof(buf), "%s-%u%%%c.wav", spath.c_str(), cnt, 'a' + chan);
+                                       snprintf (buf, sizeof(buf), "%s-%u%%%c%s", spath.c_str(), cnt, 'a' + chan, ext.c_str());
                                } else {
-                                       snprintf (buf, sizeof(buf), "%s-%u.wav", spath.c_str(), cnt);
+                                       snprintf (buf, sizeof(buf), "%s-%u%s", spath.c_str(), cnt, ext.c_str());
                                }
                        }
 
@@ -3468,6 +3469,7 @@ Session::write_one_track (AudioTrack& track, nframes_t start, nframes_t end,
        SessionDirectory sdir(get_best_session_directory_for_new_source ());
        const string sound_dir = sdir.sound_path().to_string();
        nframes_t len = end - start;
+        string ext;
 
        if (end <= start) {
                error << string_compose (_("Cannot write a range where end <= start (e.g. %1 <= %2)"),
@@ -3493,10 +3495,12 @@ Session::write_one_track (AudioTrack& track, nframes_t start, nframes_t end,
                goto out;
        }
 
+        ext = native_header_format_extension (config.get_native_file_header_format(), DataType::AUDIO);
+
        for (uint32_t chan_n=0; chan_n < nchans.n_audio(); ++chan_n) {
 
                for (x = 0; x < 99999; ++x) {
-                       snprintf (buf, sizeof(buf), "%s/%s-%d-bounce-%" PRIu32 ".wav", sound_dir.c_str(), playlist->name().c_str(), chan_n, x+1);
+                       snprintf (buf, sizeof(buf), "%s/%s-%d-bounce-%" PRIu32 "%s", sound_dir.c_str(), playlist->name().c_str(), chan_n, x+1, ext.c_str());
                        if (access (buf, F_OK) != 0) {
                                break;
                        }
index 9e4d2f281a060b11102fb4181ee7284885b6e8fc..6c6da8702d6df602a872809eb2e40ffebb08ebf8 100644 (file)
@@ -1832,7 +1832,7 @@ Session::path_from_region_name (DataType type, string name, string identifier)
        sys::path source_dir = ((type == DataType::AUDIO)
                ? sdir.sound_path() : sdir.midi_path());
 
-       string ext = ((type == DataType::AUDIO) ? ".wav" : ".mid");
+        string ext = native_header_format_extension (config.get_native_file_header_format(), type);
 
        for (n = 0; n < 999999; ++n) {
                if (identifier.length()) {
index 2bfe16222d1ca5c8ec9ce71aab45b39291e396f6..abdba63803f8270dfbaa4ca5e24a53991360ee6a 100644 (file)
@@ -509,6 +509,35 @@ string_is_affirmative (const std::string& str)
        return str == "1" || str == "y" || str == "Y" || (!g_strncasecmp(str.c_str(), "yes", str.length()));
 }
 
+const char*
+native_header_format_extension (HeaderFormat hf, const DataType& type)
+{
+        if (type == DataType::MIDI) {
+                return ".mid";
+        }
+        
+        switch (hf) {
+        case BWF:
+                return ".wav";
+        case WAVE:
+                return ".wav";
+        case WAVE64:
+                return ".w64";
+        case CAF:
+                return ".caf";
+        case AIFF:
+                return ".aif";
+        case iXML:
+                return ".ixml";
+        case RF64:
+                return ".rf64";
+        }
+
+        fatal << string_compose (_("programming error: unknown native header format: %1"), hf);
+        /*NOTREACHED*/
+        return ".wav";
+}
+
 extern "C" {
        void c_stacktrace() { stacktrace (cerr); }
 }