ExternalSource refactoring.
authorTaybin Rutkin <taybin@taybin.com>
Fri, 10 Mar 2006 17:09:59 +0000 (17:09 +0000)
committerTaybin Rutkin <taybin@taybin.com>
Fri, 10 Mar 2006 17:09:59 +0000 (17:09 +0000)
git-svn-id: svn://localhost/trunk/ardour2@373 d708f5d6-7413-0410-9779-e7cbd77b26cf

18 files changed:
SConstruct
gtk2_ardour/editor.h
gtk2_ardour/editor_ops.cc
gtk2_ardour/regionview.cc
gtk2_ardour/sfdb_ui.cc
gtk2_ardour/sfdb_ui.h
gtk2_ardour/taperegionview.cc
libs/ardour/SConscript
libs/ardour/ardour/coreaudio_source.h
libs/ardour/ardour/externalsource.h [new file with mode: 0644]
libs/ardour/ardour/sndfile_helpers.h
libs/ardour/ardour/sndfilesource.h
libs/ardour/coreaudio_source.cc
libs/ardour/externalsource.cc [new file with mode: 0644]
libs/ardour/session_state.cc
libs/ardour/sndfile_helpers.cc
libs/ardour/sndfilesource.cc
libs/ardour/source.cc

index 9f229746e5c44ff0e7ed231747d1fc00333e8690..431fccb6ca1f5a76ca9aa04c45fbe0193c961430 100644 (file)
@@ -409,7 +409,7 @@ if conf.CheckCHeader('alsa/asoundlib.h'):
     subst_dict['%MIDITYPE%'] = "alsa/sequencer"
 elif conf.CheckCHeader('/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h'):
     # this line is needed because scons can't handle -framework in ParseConfig() yet.
-    libraries['sysmidi'] = LibraryInfo (LINKFLAGS= '-framework CoreMIDI -framework CoreFoundation -framework CoreAudio -framework CoreServices -framework AudioUnit -bind_at_load')
+    libraries['sysmidi'] = LibraryInfo (LINKFLAGS= '-framework CoreMIDI -framework CoreFoundation -framework CoreAudio -framework CoreServices -framework AudioUnit -framework AudioToolbox -bind_at_load')
     env['SYSMIDI'] = 'CoreMIDI'
     subst_dict['%MIDITAG%'] = "ardour"
     subst_dict['%MIDITYPE%'] = "coremidi"
index ede72ef8088000022a3f700ec651ba23a258947e..bc85af07bebfe80d6fc3b5d0e518dd224e1e522c 100644 (file)
@@ -45,7 +45,7 @@
 #include <ardour/tempo.h>
 #include <ardour/location.h>
 #include <ardour/region.h>
-#include <ardour/sndfile_helpers.h>
+#include <ardour/externalsource.h>
 
 #include "audio_clock.h"
 #include "gtk-custom-ruler.h"
@@ -954,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, SoundFileInfo& finfo, const string & action, bool multiple_pending);
+       int  reject_because_rate_differs (const string & path, ARDOUR::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);
index bff2f14c441e173487918039d7fc99c65a9c31cf..1e790868042c93a220169d81847306091813412c 100644 (file)
@@ -38,7 +38,7 @@
 #include <ardour/audioregion.h>
 #include <ardour/diskstream.h>
 #include <ardour/filesource.h>
-#include <ardour/sndfilesource.h>
+#include <ardour/externalsource.h>
 #include <ardour/utils.h>
 #include <ardour/location.h>
 #include <ardour/named_selection.h>
@@ -2179,7 +2179,7 @@ Editor::do_embed_sndfiles (vector<string> paths, bool split)
 void
 Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
 {
-       SndFileSource *source = 0; /* keep g++ quiet */
+       ExternalSource *source = 0; /* keep g++ quiet */
        AudioRegion::SourceList sources;
        string idspec;
        string linked_path;
@@ -2202,8 +2202,9 @@ Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check
        }
 
        /* note that we temporarily truncated _id at the colon */
-       if (!get_soundfile_info (path, finfo)) {
-               error << string_compose(_("Editor: cannot open file \"%1\""), selection ) << endmsg;
+       string error_msg;
+       if (!ExternalSource::get_soundfile_info (path, finfo, error_msg)) {
+               error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), selection, error_msg ) << endmsg;
                return;
        }
        
@@ -2234,7 +2235,7 @@ Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check
                idspec += string_compose(":%1", n);
                
                try {
-                       source = new SndFileSource (idspec.c_str());
+                       source = ExternalSource::create (idspec.c_str());
                        sources.push_back(source);
                } 
 
@@ -2312,14 +2313,14 @@ Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
        SoundFileInfo finfo;
        bool multiple_files;
        bool check_sample_rate = true;
+       string error_msg;
 
        multiple_files = paths.size() > 1;      
 
        for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
                
-               if (!get_soundfile_info((*p), finfo)) {
-                       char errbuf[256];
-                       error << string_compose(_("Editor: cannot open file \"%1\""), (*p)) << endmsg;
+               if (!ExternalSource::get_soundfile_info((*p), finfo, error_msg)) {
+                       error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), error_msg) << endmsg;
                        continue;
                }
                
@@ -2379,16 +2380,16 @@ Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
 void
 Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
 {
-       SndFileSource *source = 0; /* keep g++ quiet */
+       ExternalSource *source = 0; /* keep g++ quiet */
        AudioRegion::SourceList sources;
        string idspec;
        SoundFileInfo finfo;
+       string error_msg;
 
        /* note that we temporarily truncated _id at the colon */
        
-       if (!get_soundfile_info (path, finfo)) {
-               char errbuf[256];
-               error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path) << endmsg;
+       if (!ExternalSource::get_soundfile_info (path, finfo, error_msg)) {
+               error << string_compose(_("Editor: cannot open file \"%1\" (%2)"), path, error_msg) << endmsg;
                return;
        }
        
@@ -2407,7 +2408,7 @@ Editor::insert_sndfile_into (const string & path, bool multi, AudioTimeAxisView*
                idspec += string_compose(":%1", n);
 
                try {
-                       source = new SndFileSource (idspec.c_str());
+                       source = ExternalSource::create (idspec.c_str());
                        sources.push_back(source);
                } 
 
index c47694233fe57e9490f816d8c2e894fea95f31ca..12b72c4fe9380d6399d595d8a07242e1a2c6c9dc 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <ardour/playlist.h>
 #include <ardour/audioregion.h>
-#include <ardour/sndfilesource.h>
 #include <ardour/diskstream.h>
 
 #include "streamview.h"
index 210b7faa056c63185c795a4b7cc2782789bc440b..3c8f258f4aac697cea23f46de173feeee0601317 100644 (file)
@@ -29,8 +29,7 @@
 
 #include <ardour/audio_library.h>
 #include <ardour/audioregion.h>
-#include <ardour/sndfile_helpers.h>
-#include <ardour/sndfilesource.h>
+#include <ardour/externalsource.h>
 
 #include "gui_thread.h"
 #include "prompter.h"
@@ -119,7 +118,8 @@ SoundFileBox::setup_labels (string filename)
 {
        path = filename;
 
-       if(!get_soundfile_info (filename, sf_info)) {
+       string error_msg;
+       if(!ExternalSource::get_soundfile_info (filename, sf_info, error_msg)) {
                return false;
        }
 
@@ -184,11 +184,11 @@ SoundFileBox::play_btn_clicked ()
 
        if (region_cache.find (path) == region_cache.end()) {
                AudioRegion::SourceList srclist;
-               SndFileSource* sfs;
+               ExternalSource* sfs;
 
                for (int n = 0; n < sf_info.channels; ++n) {
                        try {
-                               sfs = new SndFileSource(path+":"+string_compose("%1", n), false);
+                               sfs = ExternalSource::create (path+":"+string_compose("%1", n), false);
                                srclist.push_back(sfs);
 
                        } catch (failed_constructor& err) {
index 9b44fec3ed44305c21866a29cb2a94b914d67bc8..10a5e9e0fccf1c2bc50e24f163b9c22235ded52e 100644 (file)
@@ -39,7 +39,7 @@
 #include <gtkmm/treeview.h>
 
 #include <ardour/session.h>
-#include <ardour/sndfile_helpers.h>
+#include <ardour/externalsource.h>
 
 #include "ardour_dialog.h"
 
@@ -67,7 +67,7 @@ class SoundFileBox : public Gtk::VBox
 
     LabelModelColumns label_columns;
     
-    SoundFileInfo sf_info;
+       ARDOUR::SoundFileInfo sf_info;
 
     pid_t current_pid;
 
index d4b75191eca218cea833d73e68b64fa4b68a25c3..da7adc7935a850c2c209b553821e940170985584 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <ardour/playlist.h>
 #include <ardour/audioregion.h>
-#include <ardour/sndfilesource.h>
 #include <ardour/diskstream.h>
 
 #include "taperegionview.h"
index 59d3d90e8946f2837ffb7505ba03ddf00279b4a9..dd9de55929e2b19b3113c9979cad52357ef951e9 100644 (file)
@@ -37,6 +37,7 @@ cycle_timer.cc
 default_click.cc
 destructive_filesource.cc
 diskstream.cc
+externalsource.cc
 filesource.cc
 gain.cc
 gdither.cc
index 86c6cdc02c813ea0321214c2b96afbe9f616908c..c8634cb9e2604cd2c4a754c0369ee7b61b3a04e0 100644 (file)
 #ifndef __coreaudio_source_h__ 
 #define __coreaudio_source_h__
 
-#include <ardour/source.h>
+#include <ardour/externalsource.h>
 #include <AudioToolbox/ExtendedAudioFile.h>
 
 namespace ARDOUR {
 
-class CoreAudioSource : public Source {
+class CoreAudioSource : public ExternalSource {
   public:
        CoreAudioSource (const string& path_plus_channel, bool build_peak = true);
        CoreAudioSource (const XMLNode&);
        ~CoreAudioSource ();
 
-       jack_nframes_t length() const { return _length; }
        jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
-       void           mark_for_remove() {} // we never remove external sndfiles 
-       string         peak_path(string audio_path);
-       string         old_peak_path(string audio_path);
-       string         path() const { return _path; }
-
-       static void set_peak_dir (string dir) { peak_dir = dir; }
 
   private:
-       static string peak_dir;
-
        ExtAudioFileRef af;
-       uint16_t channel;
        uint16_t n_channels;
+
        mutable float *tmpbuf;
        mutable jack_nframes_t tmpbufsize;
        mutable PBD::Lock _tmpbuf_lock;
-       string  _path;
 
        void init (const string &str, bool build_peak);
        jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
diff --git a/libs/ardour/ardour/externalsource.h b/libs/ardour/ardour/externalsource.h
new file mode 100644 (file)
index 0000000..3ba19dc
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __external_source_h__ 
+#define __external_source_h__
+
+#include <ardour/source.h>
+
+namespace ARDOUR {
+
+struct SoundFileInfo {
+    float    samplerate;
+    uint16_t channels;
+    int64_t length;
+    std::string format_name;
+};
+
+class ExternalSource : public Source {
+  public:
+       virtual ~ExternalSource ();
+
+       string path() const { return _path; }
+
+       virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0;
+
+       void mark_for_remove() {} // we never remove external sndfiles 
+       string peak_path(string audio_path);
+       string old_peak_path(string audio_path);
+
+       static void set_peak_dir (string dir) { peak_dir = dir; }
+
+       static ExternalSource* create (const string& path_plus_channel, bool build_peak = true);
+       static ExternalSource* create (const XMLNode& node);
+       static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error);
+
+  protected:
+       ExternalSource (const string& path_plus_channel, bool build_peak = true);
+       ExternalSource (const XMLNode&);
+
+       static string peak_dir;
+
+       uint16_t channel;
+       string  _path;
+
+       virtual void init (const string &str, bool build_peak) = 0;
+       virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
+};
+
+}; /* namespace ARDOUR */
+
+#endif /* __external_source_h__ */
+
index d7b02dab1ff83ab15fa2d145f10814bc5c08f430..b5cdeb0a7e8652aed39ffab4c7f02e8ede9ea6c6 100644 (file)
@@ -36,13 +36,4 @@ int sndfile_data_width (int format);
 string sndfile_major_format(int);
 string sndfile_minor_format(int);
 
-struct SoundFileInfo {
-       float    samplerate;
-       uint16_t channels;
-       int64_t length;
-       std::string format_name;
-};
-
-bool get_soundfile_info (string path, SoundFileInfo& _info);
-
 #endif /* __sndfile_helpers_h__ */
index a7583c4fe134e2400d13bcd1716da32b87b49902..53e5b9df677f52e3b1b6b1f851e29db0b547856f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2006 Paul Davis 
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     $Id$
 */
 
-#ifndef __playlist_snd_file_buffer_h__ 
-#define __playlist_snd_file_buffer_h__
+#ifndef __sndfile_source_h__ 
+#define __sndfile_source_h__
 
 #include <sndfile.h>
 
-#include <ardour/source.h>
+#include <ardour/externalsource.h>
 
 namespace ARDOUR {
 
-class SndFileSource : public Source {
+class SndFileSource : public ExternalSource {
   public:
        SndFileSource (const string& path_plus_channel, bool build_peak = true);
        SndFileSource (const XMLNode&);
        ~SndFileSource ();
 
-       jack_nframes_t length() const { return _info.frames; }
-       jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
-       void           mark_for_remove() {} // we never remove external sndfiles 
-       string         peak_path(string audio_path);
-       string         old_peak_path(string audio_path);
-       string         path() const { return _path; }
+    jack_nframes_t length() const { return _info.frames; } 
 
-       static void set_peak_dir (string dir) { peak_dir = dir; }
+       jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
 
   private:
-       static string peak_dir;
-
        SNDFILE *sf;
        SF_INFO _info;
-       uint16_t channel;
+
        mutable float *tmpbuf;
        mutable jack_nframes_t tmpbufsize;
        mutable PBD::Lock _tmpbuf_lock;
-       string  _path;
 
        void init (const string &str, bool build_peak);
        jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const;
 };
 
-}; /* namespace EDL */
+}; /* namespace ARDOUR */
 
-#endif /* __playlist_snd_file_buffer_h__ */
+#endif /* __sndfile_source_h__ */
 
index 9cf5318192164b3c92deb9efd261e3d0cbc01171..f9f3971f51979c00749c4f593b9062b39581107d 100644 (file)
 
 */
 
-#include <string>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <pbd/mountpoint.h>
 #include <ardour/coreaudio_source.h>
 
 #include "i18n.h"
 
 using namespace ARDOUR;
 
-string CoreAudioSource::peak_dir = "";
-
 CoreAudioSource::CoreAudioSource (const XMLNode& node)
-       : Source (node)
+       : ExternalSource (node)
 {
-       if (set_state (node)) {
-               throw failed_constructor();
-       }
-
        init (_name, true);
-        SourceCreated (this); /* EMIT SIGNAL */
+       SourceCreated (this); /* EMIT SIGNAL */
 }
 
 CoreAudioSource::CoreAudioSource (const string& idstr, bool build_peak)
-       : Source(build_peak)
+       : ExternalSource(idstr, build_peak)
 {
        init (idstr, build_peak);
 
@@ -73,7 +61,6 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
                file = idstr.substr (0, pos);
        }
 
-
        /* note that we temporarily truncated _id at the colon */
        FSRef ref;
        err = FSPathMakeRef ((UInt8*)file.c_str(), &ref, 0);
@@ -125,9 +112,8 @@ CoreAudioSource::init (const string& idstr, bool build_peak)
 }
 
 CoreAudioSource::~CoreAudioSource ()
-
 {
-        GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (this); /* EMIT SIGNAL */
 
        if (af) {
                ExtAudioFileDispose (af);
@@ -138,12 +124,6 @@ CoreAudioSource::~CoreAudioSource ()
        }
 }
 
-jack_nframes_t
-CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
-{
-       return read (dst, start, cnt, workbuf);
-}
-
 jack_nframes_t
 CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
 {
@@ -204,31 +184,3 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, ch
        return real_cnt;
 }
 
-string
-CoreAudioSource::peak_path (string audio_path)
-{
-       /* XXX hardly bombproof! fix me */
-
-       struct stat stat_file;
-       struct stat stat_mount;
-
-       string mp = mountpoint (audio_path);
-
-       stat (audio_path.c_str(), &stat_file);
-       stat (mp.c_str(), &stat_mount);
-
-       char buf[32];
-       snprintf (buf, sizeof (buf), "%u-%u-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
-
-       string res = peak_dir;
-       res += buf;
-
-       return res;
-}
-
-string
-CoreAudioSource::old_peak_path (string audio_path)
-{
-       return peak_path (audio_path);
-}
-
diff --git a/libs/ardour/externalsource.cc b/libs/ardour/externalsource.cc
new file mode 100644 (file)
index 0000000..de560bf
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <sndfile.h>
+
+#include <pbd/mountpoint.h>
+#include <ardour/externalsource.h>
+#include <ardour/sndfilesource.h>
+#include <ardour/sndfile_helpers.h>
+
+// if these headers come before sigc++ is included
+// the parser throws ObjC++ errors. (nil is a keyword)
+#ifdef HAVE_COREAUDIO 
+#include <ardour/coreaudio_source.h>
+#include <AudioToolbox/ExtendedAudioFile.h>
+#include <AudioToolbox/AudioFormat.h>
+#endif // HAVE_COREAUDIO
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+
+string ExternalSource::peak_dir = "";
+
+ExternalSource::ExternalSource (const XMLNode& node)
+       : Source (node)
+{
+}
+
+ExternalSource::ExternalSource (const string& idstr, bool build_peak)
+       : Source(build_peak)
+{
+}
+
+ExternalSource::~ExternalSource ()
+{
+}
+
+jack_nframes_t
+ExternalSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
+{
+       return read (dst, start, cnt, workbuf);
+}
+
+string
+ExternalSource::peak_path (string audio_path)
+{
+       /* XXX hardly bombproof! fix me */
+
+       struct stat stat_file;
+       struct stat stat_mount;
+
+       string mp = mountpoint (audio_path);
+
+       stat (audio_path.c_str(), &stat_file);
+       stat (mp.c_str(), &stat_mount);
+
+       char buf[32];
+       snprintf (buf, sizeof (buf), "%ld-%ld-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
+
+       string res = peak_dir;
+       res += buf;
+
+       return res;
+}
+
+string
+ExternalSource::old_peak_path (string audio_path)
+{
+       return peak_path (audio_path);
+}
+
+ExternalSource*
+ExternalSource::create (const XMLNode& node)
+{
+       return new SndFileSource (node);
+}
+
+ExternalSource*
+ExternalSource::create (const string& idstr, bool build_peak)
+{
+       return new SndFileSource (idstr, build_peak);
+}
+
+#ifdef HAVE_COREAUDIO
+std::string 
+CFStringRefToStdString(CFStringRef stringRef)
+{
+       CFIndex size = 
+               CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , 
+               kCFStringEncodingASCII);
+           char *buf = new char[size];
+       
+       std::string result;
+
+       if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
+           result = buf;
+       }
+       delete [] buf;
+       return result;
+}
+#endif // HAVE_COREAUDIO
+
+bool
+ExternalSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
+{
+#ifdef HAVE_COREAUDIO
+       OSStatus err = noErr;
+    FSRef ref; 
+       ExtAudioFileRef af = 0;
+       size_t size;
+    CFStringRef name;
+
+    err = FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0);
+       if (err != noErr) {
+        ExtAudioFileDispose (af);
+               goto libsndfile;
+       }
+
+       err = ExtAudioFileOpen(&ref, &af);
+       if (err != noErr) {
+        ExtAudioFileDispose (af);
+               goto libsndfile;
+       }
+
+       AudioStreamBasicDescription absd;
+       memset(&absd, 0, sizeof(absd));
+       size = sizeof(AudioStreamBasicDescription);
+       err = ExtAudioFileGetProperty(af,
+                       kExtAudioFileProperty_FileDataFormat, &size, &absd);
+       if (err != noErr) {
+        ExtAudioFileDispose (af);
+               goto libsndfile;
+       }
+
+       _info.samplerate = absd.mSampleRate;
+       _info.channels   = absd.mChannelsPerFrame;
+
+    size = sizeof(_info.length);
+    err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length);
+    if (err != noErr) {
+        ExtAudioFileDispose (af);
+               goto libsndfile;
+    }
+
+       size = sizeof(CFStringRef);
+       err = AudioFormatGetProperty(
+                       kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name);
+       if (err != noErr) {
+        ExtAudioFileDispose (af);
+               goto libsndfile;
+       }
+
+       _info.format_name = CFStringRefToStdString(name);
+
+    ExtAudioFileDispose (af);
+       return true;
+       
+libsndfile:
+#endif // HAVE_COREAUDIO
+
+       SNDFILE *sf;
+       SF_INFO sf_info;
+
+       sf_info.format = 0; // libsndfile says to clear this before sf_open().
+
+       if ((sf = sf_open ((char*) path.c_str(), SFM_READ, &sf_info)) == 0) { 
+               char errbuf[256];
+               error_msg = sf_error_str (0, errbuf, sizeof (errbuf) - 1);
+               return false;
+       }
+
+       sf_close (sf);
+
+       _info.samplerate  = sf_info.samplerate;
+       _info.channels    = sf_info.channels;
+       _info.length      = sf_info.frames;
+       _info.format_name = string_compose("Format: %1, %2",
+                       sndfile_major_format(sf_info.format),
+                       sndfile_minor_format(sf_info.format));
+
+       return true;
+}
index 8c3438649530e731223cd6a33bb180bc97e87ff0..42614d15d0a82ce7f91b273fa46bf4ec3d9ffb52 100644 (file)
@@ -282,7 +282,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
 int
 Session::second_stage_init (bool new_session)
 {
-       SndFileSource::set_peak_dir (peak_dir());
+       ExternalSource::set_peak_dir (peak_dir());
 
        if (!new_session) {
                if (load_state (_current_snapshot_name)) {
@@ -1802,7 +1802,6 @@ Session::XMLSourceFactory (const XMLNode& node)
                return 0;
        }
 
-
        try {
                if (node.property (X_("destructive")) != 0) {
                        src = new DestructiveFileSource (node, frame_rate());
@@ -1814,7 +1813,7 @@ Session::XMLSourceFactory (const XMLNode& node)
        catch (failed_constructor& err) {
 
                try {
-                       src = new SndFileSource (node);
+                       src = ExternalSource::create (node);
                }
 
                catch (failed_constructor& err) {
@@ -2946,11 +2945,11 @@ Session::cleanup_sources (Session::cleanup_report& rep)
 
        for (SourceList::iterator i = sources.begin(); i != sources.end(); ++i) {
                FileSource* fs;
-               SndFileSource* sfs;
+               ExternalSource* sfs;
                
                if ((fs = dynamic_cast<FileSource*> ((*i).second)) != 0) {
                        all_sources.insert (fs->path());
-               } else if ((sfs = dynamic_cast<SndFileSource*> ((*i).second)) != 0) {
+               } else if ((sfs = dynamic_cast<ExternalSource*> ((*i).second)) != 0) {
                        all_sources.insert (sfs->path());
                } 
        }
index 4ea4a4b5b234b6ee7a8bbb90b16568d36652bd3c..756610716780e121893921627105cdb52175f169 100644 (file)
@@ -4,11 +4,6 @@
 #include <sndfile.h>
 #include <ardour/sndfile_helpers.h>
 
-#ifdef HAVE_COREAUDIO
-#include <AudioToolbox/ExtendedAudioFile.h>
-#include <AudioToolbox/AudioFormat.h>
-#endif // HAVE_COREAUDIO
-
 #include "i18n.h"
 
 using std::map;
@@ -197,101 +192,3 @@ sndfile_minor_format(int format)
        }
 }
 
-#ifdef HAVE_COREAUDIO
-std::string 
-CFStringRefToStdString(CFStringRef stringRef)
-{
-       CFIndex size = 
-               CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , 
-               kCFStringEncodingASCII);
-           char *buf = new char[size];
-       
-       std::string result;
-
-       if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
-           result = buf;
-       }
-       delete [] buf;
-       return result;
-}
-#endif // HAVE_COREAUDIO
-
-bool
-get_soundfile_info (string path, SoundFileInfo& _info)
-{
-#ifdef HAVE_COREAUDIO
-       OSStatus err = noErr;
-    FSRef ref; 
-       ExtAudioFileRef af = 0;
-       size_t size;
-    CFStringRef name;
-
-    err = FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0);
-       if (err != noErr) {
-        ExtAudioFileDispose (af);
-               goto libsndfile;
-       }
-
-       err = ExtAudioFileOpen(&ref, &af);
-       if (err != noErr) {
-        ExtAudioFileDispose (af);
-               goto libsndfile;
-       }
-
-       AudioStreamBasicDescription absd;
-       memset(&absd, 0, sizeof(absd));
-       size = sizeof(AudioStreamBasicDescription);
-       err = ExtAudioFileGetProperty(af,
-                       kExtAudioFileProperty_FileDataFormat, &size, &absd);
-       if (err != noErr) {
-        ExtAudioFileDispose (af);
-               goto libsndfile;
-       }
-
-       _info.samplerate = absd.mSampleRate;
-       _info.channels   = absd.mChannelsPerFrame;
-
-    size = sizeof(_info.length);
-    err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length);
-    if (err != noErr) {
-        ExtAudioFileDispose (af);
-               goto libsndfile;
-    }
-
-       size = sizeof(CFStringRef);
-       err = AudioFormatGetProperty(
-                       kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name);
-       if (err != noErr) {
-        ExtAudioFileDispose (af);
-               goto libsndfile;
-       }
-
-       _info.format_name = CFStringRefToStdString(name);
-
-    ExtAudioFileDispose (af);
-       return true;
-       
-libsndfile:
-#endif // HAVE_COREAUDIO
-
-       SNDFILE *sf;
-       SF_INFO sf_info;
-
-       sf_info.format = 0; // libsndfile says to clear this before sf_open().
-
-       if ((sf = sf_open ((char*) path.c_str(), SFM_READ, &sf_info)) == 0) { 
-               return false;
-       }
-
-       sf_close (sf);
-
-       _info.samplerate  = sf_info.samplerate;
-       _info.channels    = sf_info.channels;
-       _info.length      = sf_info.frames;
-       _info.format_name = string_compose("Format: %1, %2",
-                       sndfile_major_format(sf_info.format),
-                       sndfile_minor_format(sf_info.format));
-
-       return true;
-}
-
index 350a9c2ef1db75e27a0852b5e487c0087a25ff1c..5db5f95c35f07ebc0fa55c7b990df77b4575385b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2006 Paul Davis 
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     $Id$
 */
 
-#include <string>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <pbd/mountpoint.h>
 #include <ardour/sndfilesource.h>
 
 #include "i18n.h"
 
 using namespace ARDOUR;
 
-string SndFileSource::peak_dir = "";
-
 SndFileSource::SndFileSource (const XMLNode& node)
-       : Source (node)
+       : ExternalSource (node)
 {
-       if (set_state (node)) {
-               throw failed_constructor();
-       }
-
        init (_name, true);
-        SourceCreated (this); /* EMIT SIGNAL */
+       SourceCreated (this); /* EMIT SIGNAL */
 }
 
 SndFileSource::SndFileSource (const string& idstr, bool build_peak)
-       : Source(build_peak)
+       : ExternalSource(idstr, build_peak)
 {
        init (idstr, build_peak);
 
@@ -110,7 +98,7 @@ SndFileSource::init (const string& idstr, bool build_peak)
 SndFileSource::~SndFileSource ()
 
 {
-        GoingAway (this); /* EMIT SIGNAL */
+       GoingAway (this); /* EMIT SIGNAL */
 
        if (sf) {
                sf_close (sf);
@@ -121,12 +109,6 @@ SndFileSource::~SndFileSource ()
        }
 }
 
-jack_nframes_t
-SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
-{
-       return read (dst, start, cnt, workbuf);
-}
-
 jack_nframes_t
 SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const
 {
@@ -178,30 +160,3 @@ SndFileSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char
        return nread;
 }
 
-string
-SndFileSource::peak_path (string audio_path)
-{
-       /* XXX hardly bombproof! fix me */
-
-       struct stat stat_file;
-       struct stat stat_mount;
-
-       string mp = mountpoint (audio_path);
-
-       stat (audio_path.c_str(), &stat_file);
-       stat (mp.c_str(), &stat_mount);
-
-       char buf[32];
-       snprintf (buf, sizeof (buf), "%ld-%ld-%d.peak", stat_mount.st_ino, stat_file.st_ino, channel);
-
-       string res = peak_dir;
-       res += buf;
-
-       return res;
-}
-
-string
-SndFileSource::old_peak_path (string audio_path)
-{
-       return peak_path (audio_path);
-}
index 25e9b438994ddbd719c7710830119cb131062a11..2a6337d4414f572ff7a3df6f35007bba7a7d60ab 100644 (file)
@@ -34,8 +34,6 @@
 #include <pbd/pthread_utils.h>
 
 #include <ardour/source.h>
-#include <ardour/filesource.h>
-#include <ardour/sndfilesource.h>
 
 #include "i18n.h"