summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk2_ardour/editor.h5
-rw-r--r--gtk2_ardour/editor_ops.cc43
-rw-r--r--gtk2_ardour/sfdb_ui.cc31
-rw-r--r--gtk2_ardour/sfdb_ui.h5
4 files changed, 21 insertions, 63 deletions
diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h
index 06d9b6035f..8b0d5cb28f 100644
--- a/gtk2_ardour/editor.h
+++ b/gtk2_ardour/editor.h
@@ -33,8 +33,6 @@
#include <cmath>
-#include <sndfile.h>
-
#include <gtkmm/layout.h>
#include <gtkmm/comboboxtext.h>
@@ -47,6 +45,7 @@
#include <ardour/tempo.h>
#include <ardour/location.h>
#include <ardour/region.h>
+#include <ardour/sndfile_helpers.h>
#include "audio_clock.h"
#include "gtk-custom-ruler.h"
@@ -955,7 +954,7 @@ class Editor : public PublicEditor
void insert_sndfile (bool as_tracks);
void embed_audio (); // inserts into region list
- int reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending);
+ int reject_because_rate_differs (const string & path, SoundFileInfo& finfo, const string & action, bool multiple_pending);
void do_embed_sndfiles (vector<string> paths, bool split);
void embed_sndfile (string path, bool split, bool multiple_files, bool& check_sr);
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index 747b4d47ec..bff2f14c44 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -25,8 +25,6 @@
#include <string>
#include <map>
-#include <sndfile.h>
-
#include <pbd/error.h>
#include <pbd/basename.h>
#include <pbd/pthread_utils.h>
@@ -2104,7 +2102,7 @@ Editor::do_import (vector<string> paths, bool split, bool as_tracks)
}
int
-Editor::reject_because_rate_differs (const string & path, SF_INFO& finfo, const string & action, bool multiple_pending)
+Editor::reject_because_rate_differs (const string & path, SoundFileInfo& finfo, const string & action, bool multiple_pending)
{
if (!session) {
return 1;
@@ -2185,8 +2183,7 @@ Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check
AudioRegion::SourceList sources;
string idspec;
string linked_path;
- SNDFILE *sf;
- SF_INFO finfo;
+ SoundFileInfo finfo;
/* lets see if we can link it into the session */
@@ -2204,18 +2201,11 @@ Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check
path = linked_path;
}
- memset (&finfo, 0, sizeof(finfo));
-
/* note that we temporarily truncated _id at the colon */
-
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
+ if (!get_soundfile_info (path, finfo)) {
+ error << string_compose(_("Editor: cannot open file \"%1\""), selection ) << endmsg;
return;
}
- sf_close (sf);
- sf = 0;
if (check_sample_rate) {
switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
@@ -2319,8 +2309,7 @@ Editor::insert_sndfile (bool as_tracks)
void
Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
{
- SNDFILE *sf;
- SF_INFO finfo;
+ SoundFileInfo finfo;
bool multiple_files;
bool check_sample_rate = true;
@@ -2328,18 +2317,12 @@ Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
- memset (&finfo, 0, sizeof(finfo));
-
- if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
+ if (!get_soundfile_info((*p), finfo)) {
char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
+ error << string_compose(_("Editor: cannot open file \"%1\""), (*p)) << endmsg;
continue;
}
- sf_close (sf);
- sf = 0;
-
/* add a new track */
if (check_sample_rate) {
@@ -2399,21 +2382,15 @@ Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView*
SndFileSource *source = 0; /* keep g++ quiet */
AudioRegion::SourceList sources;
string idspec;
- SNDFILE *sf;
- SF_INFO finfo;
-
- memset (&finfo, 0, sizeof(finfo));
+ SoundFileInfo finfo;
/* note that we temporarily truncated _id at the colon */
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
+ if (!get_soundfile_info (path, finfo)) {
char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
+ error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path) << endmsg;
return;
}
- sf_close (sf);
- sf = 0;
if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
return;
diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc
index 0ad46946bf..210b7faa05 100644
--- a/gtk2_ardour/sfdb_ui.cc
+++ b/gtk2_ardour/sfdb_ui.cc
@@ -22,8 +22,6 @@
#include <map>
#include <cerrno>
-#include <sndfile.h>
-
#include <pbd/basename.h>
#include <gtkmm/box.h>
@@ -42,7 +40,7 @@
using namespace ARDOUR;
-std::string length2string (const int32_t frames, const int32_t sample_rate);
+std::string length2string (const int32_t frames, const float sample_rate);
SoundFileBox::SoundFileBox ()
:
@@ -121,30 +119,15 @@ SoundFileBox::setup_labels (string filename)
{
path = filename;
- SNDFILE *sf;
-
- sf_info.format = 0; // libsndfile says to clear this before sf_open().
-
- if ((sf = sf_open ((char *) filename.c_str(), SFM_READ, &sf_info)) < 0) {
- return false;
- }
-
- sf_close (sf);
-
- if (sf_info.frames == 0 && sf_info.channels == 0 &&
- sf_info.samplerate == 0 && sf_info.format == 0 &&
- sf_info.sections == 0) {
- /* .. ok, it's not a sound file */
- return false;
+ if(!get_soundfile_info (filename, sf_info)) {
+ return false;
}
length.set_alignment (0.0f, 0.0f);
- length.set_text (string_compose("Length: %1", length2string(sf_info.frames, sf_info.samplerate)));
+ length.set_text (string_compose("Length: %1", length2string(sf_info.length, sf_info.samplerate)));
format.set_alignment (0.0f, 0.0f);
- format.set_text (string_compose("Format: %1, %2",
- sndfile_major_format(sf_info.format),
- sndfile_minor_format(sf_info.format)));
+ format.set_text (sf_info.format_name);
channels.set_alignment (0.0f, 0.0f);
channels.set_text (string_compose("Channels: %1", sf_info.channels));
@@ -363,9 +346,9 @@ SoundFileOmega::import_clicked ()
}
std::string
-length2string (const int32_t frames, const int32_t sample_rate)
+length2string (const int32_t frames, const float sample_rate)
{
- int secs = (int) (frames / (float) sample_rate);
+ int secs = (int) (frames / sample_rate);
int hrs = secs / 3600;
secs -= (hrs * 3600);
int mins = secs / 60;
diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h
index d1725ce8f3..9b44fec3ed 100644
--- a/gtk2_ardour/sfdb_ui.h
+++ b/gtk2_ardour/sfdb_ui.h
@@ -25,8 +25,6 @@
#include <string>
#include <vector>
-#include <sndfile.h>
-
#include <sigc++/signal.h>
#include <gtkmm/box.h>
@@ -41,6 +39,7 @@
#include <gtkmm/treeview.h>
#include <ardour/session.h>
+#include <ardour/sndfile_helpers.h>
#include "ardour_dialog.h"
@@ -68,7 +67,7 @@ class SoundFileBox : public Gtk::VBox
LabelModelColumns label_columns;
- SF_INFO sf_info;
+ SoundFileInfo sf_info;
pid_t current_pid;