From 1e668dfaf2392226db306ccfdaf7dbb6e45a0db4 Mon Sep 17 00:00:00 2001 From: Taybin Rutkin Date: Fri, 10 Mar 2006 17:09:59 +0000 Subject: [PATCH] ExternalSource refactoring. git-svn-id: svn://localhost/trunk/ardour2@373 d708f5d6-7413-0410-9779-e7cbd77b26cf --- SConstruct | 2 +- gtk2_ardour/editor.h | 4 +- gtk2_ardour/editor_ops.cc | 27 ++-- gtk2_ardour/regionview.cc | 1 - gtk2_ardour/sfdb_ui.cc | 10 +- gtk2_ardour/sfdb_ui.h | 4 +- gtk2_ardour/taperegionview.cc | 1 - libs/ardour/SConscript | 1 + libs/ardour/ardour/coreaudio_source.h | 16 +- libs/ardour/ardour/externalsource.h | 68 +++++++++ libs/ardour/ardour/sndfile_helpers.h | 9 -- libs/ardour/ardour/sndfilesource.h | 28 ++-- libs/ardour/coreaudio_source.cc | 56 +------ libs/ardour/externalsource.cc | 203 ++++++++++++++++++++++++++ libs/ardour/session_state.cc | 9 +- libs/ardour/sndfile_helpers.cc | 103 ------------- libs/ardour/sndfilesource.cc | 55 +------ libs/ardour/source.cc | 2 - 18 files changed, 322 insertions(+), 277 deletions(-) create mode 100644 libs/ardour/ardour/externalsource.h create mode 100644 libs/ardour/externalsource.cc diff --git a/SConstruct b/SConstruct index 9f229746e5..431fccb6ca 100644 --- a/SConstruct +++ b/SConstruct @@ -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" diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index ede72ef808..bc85af07be 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -45,7 +45,7 @@ #include #include #include -#include +#include #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 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 bff2f14c44..1e79086804 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -2179,7 +2179,7 @@ Editor::do_embed_sndfiles (vector 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 paths, bool split) SoundFileInfo finfo; bool multiple_files; bool check_sample_rate = true; + string error_msg; multiple_files = paths.size() > 1; for (vector::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 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); } diff --git a/gtk2_ardour/regionview.cc b/gtk2_ardour/regionview.cc index c47694233f..12b72c4fe9 100644 --- a/gtk2_ardour/regionview.cc +++ b/gtk2_ardour/regionview.cc @@ -27,7 +27,6 @@ #include #include -#include #include #include "streamview.h" diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 210b7faa05..3c8f258f4a 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -29,8 +29,7 @@ #include #include -#include -#include +#include #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) { diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h index 9b44fec3ed..10a5e9e0fc 100644 --- a/gtk2_ardour/sfdb_ui.h +++ b/gtk2_ardour/sfdb_ui.h @@ -39,7 +39,7 @@ #include #include -#include +#include #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; diff --git a/gtk2_ardour/taperegionview.cc b/gtk2_ardour/taperegionview.cc index d4b75191ec..da7adc7935 100644 --- a/gtk2_ardour/taperegionview.cc +++ b/gtk2_ardour/taperegionview.cc @@ -27,7 +27,6 @@ #include #include -#include #include #include "taperegionview.h" diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript index 59d3d90e89..dd9de55929 100644 --- a/libs/ardour/SConscript +++ b/libs/ardour/SConscript @@ -37,6 +37,7 @@ cycle_timer.cc default_click.cc destructive_filesource.cc diskstream.cc +externalsource.cc filesource.cc gain.cc gdither.cc diff --git a/libs/ardour/ardour/coreaudio_source.h b/libs/ardour/ardour/coreaudio_source.h index 86c6cdc02c..c8634cb9e2 100644 --- a/libs/ardour/ardour/coreaudio_source.h +++ b/libs/ardour/ardour/coreaudio_source.h @@ -20,36 +20,26 @@ #ifndef __coreaudio_source_h__ #define __coreaudio_source_h__ -#include +#include #include 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 index 0000000000..3ba19dc1d5 --- /dev/null +++ b/libs/ardour/ardour/externalsource.h @@ -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 + +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__ */ + diff --git a/libs/ardour/ardour/sndfile_helpers.h b/libs/ardour/ardour/sndfile_helpers.h index d7b02dab1f..b5cdeb0a7e 100644 --- a/libs/ardour/ardour/sndfile_helpers.h +++ b/libs/ardour/ardour/sndfile_helpers.h @@ -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__ */ diff --git a/libs/ardour/ardour/sndfilesource.h b/libs/ardour/ardour/sndfilesource.h index a7583c4fe1..53e5b9df67 100644 --- a/libs/ardour/ardour/sndfilesource.h +++ b/libs/ardour/ardour/sndfilesource.h @@ -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 @@ -18,46 +18,38 @@ $Id$ */ -#ifndef __playlist_snd_file_buffer_h__ -#define __playlist_snd_file_buffer_h__ +#ifndef __sndfile_source_h__ +#define __sndfile_source_h__ #include -#include +#include 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__ */ diff --git a/libs/ardour/coreaudio_source.cc b/libs/ardour/coreaudio_source.cc index 9cf5318192..f9f3971f51 100644 --- a/libs/ardour/coreaudio_source.cc +++ b/libs/ardour/coreaudio_source.cc @@ -17,33 +17,21 @@ */ -#include -#include -#include -#include - -#include #include #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 index 0000000000..de560bfce5 --- /dev/null +++ b/libs/ardour/externalsource.cc @@ -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 +#include +#include + +#include + +#include +#include +#include +#include + +// if these headers come before sigc++ is included +// the parser throws ObjC++ errors. (nil is a keyword) +#ifdef HAVE_COREAUDIO +#include +#include +#include +#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; +} diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 8c34386495..42614d15d0 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -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 ((*i).second)) != 0) { all_sources.insert (fs->path()); - } else if ((sfs = dynamic_cast ((*i).second)) != 0) { + } else if ((sfs = dynamic_cast ((*i).second)) != 0) { all_sources.insert (sfs->path()); } } diff --git a/libs/ardour/sndfile_helpers.cc b/libs/ardour/sndfile_helpers.cc index 4ea4a4b5b2..7566107167 100644 --- a/libs/ardour/sndfile_helpers.cc +++ b/libs/ardour/sndfile_helpers.cc @@ -4,11 +4,6 @@ #include #include -#ifdef HAVE_COREAUDIO -#include -#include -#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; -} - diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index 350a9c2ef1..5db5f95c35 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -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 @@ -18,33 +18,21 @@ $Id$ */ -#include -#include -#include -#include - -#include #include #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); -} diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 25e9b43899..2a6337d441 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -34,8 +34,6 @@ #include #include -#include -#include #include "i18n.h"