From 123ec9cb3034dc760194e0e9e73f7d597e5d793f Mon Sep 17 00:00:00 2001 From: Taybin Rutkin Date: Wed, 8 Mar 2006 22:24:51 +0000 Subject: [PATCH] Removed direct libsndfile usage. git-svn-id: svn://localhost/trunk/ardour2@362 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.h | 5 ++--- gtk2_ardour/editor_ops.cc | 43 +++++++++------------------------------ gtk2_ardour/sfdb_ui.cc | 31 +++++++--------------------- gtk2_ardour/sfdb_ui.h | 5 ++--- 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 -#include - #include #include @@ -47,6 +45,7 @@ #include #include #include +#include #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 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 #include -#include - #include #include #include @@ -2104,7 +2102,7 @@ Editor::do_import (vector 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 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 paths, bool split) for (vector::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 #include -#include - #include #include @@ -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 #include -#include - #include #include @@ -41,6 +39,7 @@ #include #include +#include #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;