Merging from trunk
[ardour.git] / gtk2_ardour / sfdb_ui.cc
index 149b7f66ca65a9d9cd4da02ccc5044ebaeef37ca..79546880de0644c3f04719b48ed4831bf2d69c0f 100644 (file)
 #include <gtkmm/box.h>
 #include <gtkmm/stock.h>
 
-#include <pbd/basename.h>
+#include <pbd/convert.h>
 
 #include <gtkmm2ext/utils.h>
 
 #include <ardour/audio_library.h>
 #include <ardour/audioregion.h>
-#include <ardour/externalsource.h>
+#include <ardour/audiofilesource.h>
 
 #include "ardour_ui.h"
 #include "gui_thread.h"
 #include "i18n.h"
 
 using namespace ARDOUR;
+using namespace PBD;
 using namespace std;
 
-string length2string (const int32_t frames, const float sample_rate);
-
 SoundFileBox::SoundFileBox ()
        :
        _session(0),
@@ -124,12 +123,12 @@ SoundFileBox::setup_labels (string filename)
        path = filename;
 
        string error_msg;
-       if(!ExternalSource::get_soundfile_info (filename, sf_info, error_msg)) {
+       if(!AudioFileSource::get_soundfile_info (filename, sf_info, error_msg)) {
                return false;
        }
 
        length.set_alignment (0.0f, 0.0f);
-       length.set_text (string_compose("Length: %1", length2string(sf_info.length, sf_info.samplerate)));
+       length.set_text (string_compose("Length: %1", PBD::length2string(sf_info.length, sf_info.samplerate)));
 
        format.set_alignment (0.0f, 0.0f);
        format.set_text (sf_info.format_name);
@@ -189,12 +188,12 @@ SoundFileBox::play_btn_clicked ()
 
        if (region_cache.find (path) == region_cache.end()) {
                AudioRegion::SourceList srclist;
-               ExternalSource* sfs;
+               AudioFileSource* afs;
 
                for (int n = 0; n < sf_info.channels; ++n) {
                        try {
-                               sfs = ExternalSource::create (path+":"+string_compose("%1", n), false);
-                               srclist.push_back(sfs);
+                               afs = AudioFileSource::create (path+":"+string_compose("%1", n));
+                               srclist.push_back(afs);
 
                        } catch (failed_constructor& err) {
                                error << _("Could not access soundfile: ") << path << endmsg;
@@ -207,7 +206,7 @@ SoundFileBox::play_btn_clicked ()
                }
 
                string result;
-               _session->region_name (result, PBD::basename(srclist[0]->name()), false);
+               _session->region_name (result, Glib::path_get_basename(srclist[0]->name()), false);
                AudioRegion* a_region = new AudioRegion(srclist, 0, srclist[0]->length(), result, 0, Region::DefaultFlags, false);
                region_cache[path] = a_region;
        }
@@ -288,7 +287,7 @@ SoundFileBox::field_selected ()
        }
 }
 
-SoundFileBrowser::SoundFileBrowser (string title)
+SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s)
        : ArdourDialog (title, false),
          chooser (Gtk::FILE_CHOOSER_ACTION_OPEN)
 {
@@ -297,6 +296,8 @@ SoundFileBrowser::SoundFileBrowser (string title)
        chooser.set_select_multiple (true);
 
        chooser.signal_update_preview().connect(mem_fun(*this, &SoundFileBrowser::update_preview));
+
+       set_session (s);
 }
 
 void
@@ -311,9 +312,9 @@ SoundFileBrowser::update_preview ()
        chooser.set_preview_widget_active(preview.setup_labels(chooser.get_filename()));
 }
 
-SoundFileChooser::SoundFileChooser (string title)
+SoundFileChooser::SoundFileChooser (string title, ARDOUR::Session* s)
        :
-       SoundFileBrowser(title)
+       SoundFileBrowser(title, s)
 {
        add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
        add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
@@ -329,12 +330,12 @@ static const char *import_mode_strings[] = {
 
 vector<string> SoundFileOmega::mode_strings;
 
-SoundFileOmega::SoundFileOmega (string title)
-       : SoundFileBrowser (title),
+SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s)
+       : SoundFileBrowser (title, s),
          split_check (_("Split Channels"))
 {
        if (mode_strings.empty()) {
-               mode_strings = internationalize (import_mode_strings);
+               mode_strings = PBD::internationalize (import_mode_strings);
        }
 
        ARDOUR_UI::instance()->tooltips().set_tip(split_check,