Use PBD::sys::path and SessionDirectory in Session::remove_pending_capture_state...
[ardour.git] / libs / ardour / import.cc
index b81f438490497b96356a3a09cdf4da3082b57698..bc16cde1568a1de2af7e7274ca978f9f51baeb04 100644 (file)
@@ -34,7 +34,9 @@
 #include <pbd/basename.h>
 
 #include <ardour/ardour.h>
+#include <ardour/types.h>
 #include <ardour/session.h>
+#include <ardour/session_directory.h>
 #include <ardour/audio_diskstream.h>
 #include <ardour/sndfilesource.h>
 #include <ardour/sndfile_helpers.h>
@@ -117,7 +119,6 @@ Session::import_audiofile (import_status& status)
        float *data = 0;
        Sample **channel_data = 0;
        long nfiles = 0;
-       long n;
        string basepath;
        string sounds_dir;
        nframes_t so_far;
@@ -143,14 +144,16 @@ Session::import_audiofile (import_status& status)
                importable = new ImportableSource (in, &info);
        }
 
-       for (n = 0; n < info.channels; ++n) {
+       for (int n = 0; n < info.channels; ++n) {
                newfiles.push_back (boost::shared_ptr<AudioFileSource>());
        }
 
-       sounds_dir = discover_best_sound_dir ();
+       SessionDirectory sdir(get_best_session_directory_for_new_source ());
+       sounds_dir = sdir.sound_path().to_string();
+
        basepath = PBD::basename_nosuffix (status.paths.front());
 
-       for (n = 0; n < info.channels; ++n) {
+       for (int n = 0; n < info.channels; ++n) {
 
                bool goodfile = false;
 
@@ -162,7 +165,7 @@ Session::import_audiofile (import_status& status)
                                        snprintf (buf, sizeof(buf), "%s/%s-R.wav", sounds_dir.c_str(), basepath.c_str());
                                }
                        } else if (info.channels > 1) {
-                               snprintf (buf, sizeof(buf), "%s/%s-c%lu.wav", sounds_dir.c_str(), basepath.c_str(), n+1);
+                               snprintf (buf, sizeof(buf), "%s/%s-c%d.wav", sounds_dir.c_str(), basepath.c_str(), n+1);
                        } else {
                                snprintf (buf, sizeof(buf), "%s/%s.wav", sounds_dir.c_str(), basepath.c_str());
                        }
@@ -184,7 +187,8 @@ Session::import_audiofile (import_status& status)
                } while ( !goodfile);
 
                try { 
-                       newfiles[n] = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createWritable (*this, buf, false, frame_rate()));
+                       newfiles[n] = boost::dynamic_pointer_cast<AudioFileSource> (
+                               SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate()));
                }
 
                catch (failed_constructor& err) {
@@ -199,7 +203,7 @@ Session::import_audiofile (import_status& status)
        data = new float[nframes * info.channels];
        channel_data = new Sample * [ info.channels ];
        
-       for (n = 0; n < info.channels; ++n) {
+       for (int n = 0; n < info.channels; ++n) {
                channel_data[n] = new Sample[nframes];
        }
 
@@ -222,7 +226,8 @@ Session::import_audiofile (import_status& status)
                /* de-interleave */
                                
                for (chn = 0; chn < info.channels; ++chn) {
-                       
+
+                       nframes_t n;
                        for (x = chn, n = 0; n < nfread; x += info.channels, ++n) {
                                channel_data[chn][n] = (Sample) data[x];
                        }
@@ -257,7 +262,7 @@ Session::import_audiofile (import_status& status)
        if (status.multichan) {
                /* all sources are used in a single multichannel region */
 
-               for (n = 0; n < nfiles && !status.cancel; ++n) {
+               for (int n = 0; n < nfiles && !status.cancel; ++n) {
                        /* flush the final length to the header */
                        newfiles[n]->update_header(0, *now, xnow);
                        sources.push_back(newfiles[n]);
@@ -274,7 +279,7 @@ Session::import_audiofile (import_status& status)
                status.new_regions.push_back (r);
 
        } else {
-               for (n = 0; n < nfiles && !status.cancel; ++n) {
+               for (int n = 0; n < nfiles && !status.cancel; ++n) {
 
                        /* flush the final length to the header */
 
@@ -309,14 +314,13 @@ Session::import_audiofile (import_status& status)
        }
        
        if (channel_data) {
-               for (n = 0; n < info.channels; ++n) {
+               for (int n = 0; n < info.channels; ++n) {
                        delete [] channel_data[n];
                }
                delete [] channel_data;
        }
 
        if (status.cancel) {
-
                status.new_regions.clear ();
 
                for (vector<string>::iterator i = new_paths.begin(); i != new_paths.end(); ++i) {