fix up BWF creation; make CoreAudioSource work; add CAImportable; refactor SourceFact...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 27 Feb 2008 13:56:14 +0000 (13:56 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 27 Feb 2008 13:56:14 +0000 (13:56 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3126 d708f5d6-7413-0410-9779-e7cbd77b26cf

17 files changed:
gtk2_ardour/editor.h
gtk2_ardour/editor_audio_import.cc
gtk2_ardour/editor_canvas.cc
libs/ardour/SConscript
libs/ardour/ardour/audiofilesource.h
libs/ardour/ardour/caimportable.h [new file with mode: 0644]
libs/ardour/ardour/coreaudiosource.h
libs/ardour/ardour/sndfilesource.h
libs/ardour/audiofilesource.cc
libs/ardour/caimportable.cc [new file with mode: 0644]
libs/ardour/coreaudiosource.cc
libs/ardour/playlist.cc
libs/ardour/resampled_source.cc
libs/ardour/session.cc
libs/ardour/sndfilesource.cc
libs/ardour/source_factory.cc
svn_revision.h

index ed87e470f83888ef8ac30a17df89e2279ace6991..281ccff95bb8858e13caa9bf6486cf7c13cf3431 100644 (file)
@@ -1075,7 +1075,10 @@ class Editor : public PublicEditor
        SoundFileOmega* sfbrowser;
        
        void bring_in_external_audio (Editing::ImportMode mode,  nframes64_t& pos);
+
+       void _do_import (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
        void do_import (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
+       bool idle_do_import (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
 
        void _do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
        void do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
index f37659093ec82de6189646336cf2c2cd22c4caa1..2391eae9276df01bf94c44d35de92610f8b4d022 100644 (file)
@@ -280,8 +280,25 @@ Editor::get_nth_selected_audio_track (int nth) const
        return atv->audio_track();
 }      
 
+bool
+Editor::idle_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
+{
+       _do_import (paths, chns, mode, quality, pos);
+       return false;
+}
+
 void
 Editor::do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
+{
+#ifdef GTKOSX
+       Glib::signal_idle().connect (bind (mem_fun (*this, &Editor::idle_do_import), paths, chns, mode, quality, pos));
+#else
+       _do_import (paths, chns, mode, quality, pos);
+#endif
+}
+
+void
+Editor::_do_import (vector<ustring> paths, ImportDisposition chns, ImportMode mode, SrcQuality quality, nframes64_t& pos)
 {
        boost::shared_ptr<AudioTrack> track;
        vector<ustring> to_import;
@@ -653,6 +670,9 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
                                boost::shared_ptr<Source> s;
 
                                if ((s = session->source_by_path_and_channel (path, n)) == 0) {
+
+                                       cerr << "add embed/import source with defer_peaks = true\n";
+
                                        source = boost::dynamic_pointer_cast<AudioFileSource> (SourceFactory::createReadable 
                                                                                               (*session, path,  n,
                                                                                                (mode == ImportAsTapeTrack ? 
index 2d034f5308b8508ccf97715cd079cd5997ad02ed..1c92f2e00cfb2891558b3688e1e0d0e6b9347146 100644 (file)
@@ -498,7 +498,11 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
 
                frame = 0;
 
-               do_embed (paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
+               if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
+                       do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, SrcBest, frame); 
+               } else {
+                       do_embed (paths, Editing::ImportDistinctFiles, ImportAsTrack, frame);
+               }
                
        } else if ((tv = dynamic_cast<AudioTimeAxisView*>(tvp)) != 0) {
 
@@ -507,7 +511,12 @@ Editor::drop_paths (const RefPtr<Gdk::DragContext>& context,
                if (tv->get_diskstream()) {
                        /* select the track, then embed */
                        selection->set (tv);
-                       do_embed (paths, Editing::ImportDistinctFiles, ImportToTrack, frame);
+
+                       if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
+                               do_import (paths, Editing::ImportDistinctFiles, Editing::ImportToTrack, SrcBest, frame); 
+                       } else {
+                               do_embed (paths, Editing::ImportDistinctFiles, ImportToTrack, frame);
+                       }
                }
        }
 
index a2e4c13db06b0b5886c3fbf6d1cd111e8b5dd80a..dce3432065e13a146d9e16d5e0c07d97d2c379c6 100644 (file)
@@ -111,7 +111,7 @@ osc_files = [ 'osc.cc' ]
 vst_files = [ 'vst_plugin.cc', 'session_vst.cc' ]
 lv2_files = [ 'lv2_plugin.cc' ]
 audiounit_files = [ 'audio_unit.cc' ]
-coreaudio_files = [ 'coreaudiosource.cc' ]
+coreaudio_files = [ 'coreaudiosource.cc', 'caimportable.cc' ]
 extra_sources = [ ]
 timefx_sources = [ ]
 
index c339c1cfc69871b34f13361022ba748e405bc6f3..eb156075b9d67c89ebe95c1d6941a979fbc0df9e 100644 (file)
@@ -168,6 +168,8 @@ class AudioFileSource : public AudioSource {
        bool removable() const;
        bool writable() const { return _flags & Writable; }
 
+       static Sample* get_interleave_buffer (nframes_t size);
+
   private:
        Glib::ustring old_peak_path (Glib::ustring audio_path);
        Glib::ustring broken_peak_path (Glib::ustring audio_path);
diff --git a/libs/ardour/ardour/caimportable.h b/libs/ardour/ardour/caimportable.h
new file mode 100644 (file)
index 0000000..dc7f576
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+    Copyright (C) 2007 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 __ardour_ca_importable_source_h__
+#define __ardour_ca_importable_source_h__
+
+#include <pbd/failed_constructor.h>
+#include <ardour/types.h>
+#include <ardour/importable_source.h>
+
+#include <appleutility/CAAudioFile.h>
+
+namespace ARDOUR {
+
+class CAImportableSource : public ImportableSource {
+    public:
+       CAImportableSource (const std::string& path);
+       virtual ~CAImportableSource();
+
+       nframes_t read (Sample* buffer, nframes_t nframes);
+       uint32_t  channels() const;
+       nframes_t length() const;
+       nframes_t samplerate() const;
+       void      seek (nframes_t pos);
+
+   protected:
+       mutable CAAudioFile af;
+};
+
+}
+
+#endif /* __ardour_ca_importable_source_h__ */
index ad21188531de6c350c6cd64466ca74ed745f8c3e..d7282b35bda8581f96f055f908ef6bb134f67ff3 100644 (file)
@@ -21,7 +21,6 @@
 #define __coreaudio_source_h__
 
 #include <appleutility/CAAudioFile.h>
-
 #include <ardour/audiofilesource.h>
 
 namespace ARDOUR {
@@ -48,11 +47,8 @@ class CoreAudioSource : public AudioFileSource {
        mutable CAAudioFile af;
        uint16_t n_channels;
 
-       mutable float *tmpbuf;
-       mutable nframes_t tmpbufsize;
-       mutable Glib::Mutex _tmpbuf_lock;
-
        void init ();
+       int safe_read (Sample*, nframes_t start, nframes_t cnt, AudioBufferList&) const;
 };
 
 }; /* namespace ARDOUR */
index 54964608ee5a2e2e7d57207310a632fda0c62b09..dc83fc6ec146d74e7143491b1c2e17c23265ad98 100644 (file)
@@ -102,8 +102,6 @@ class SndFileSource : public AudioFileSource {
        void handle_header_position_change ();
 
        static int64_t get_timecode_info (SNDFILE* sf, SF_BROADCAST_INFO* binfo, bool& exists);
-       
-       static Sample* get_interleave_buffer (nframes_t size);
 };
 
 } // namespace ARDOUR
index a4a75727a998fcb0167f38581ce7597b4919b376..0ef9fb2dbc2d0a439e99ce1447367d27c9c15f33 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <glibmm/miscutils.h>
 #include <glibmm/fileutils.h>
+#include <glibmm/thread.h>
 
 #include <ardour/audiofilesource.h>
 #include <ardour/sndfile_helpers.h>
@@ -69,6 +70,21 @@ uint64_t           AudioFileSource::header_position_offset = 0;
 /* XXX maybe this too */
 char   AudioFileSource::bwf_serial_number[13] = "000000000000";
 
+struct SizedSampleBuffer {
+    nframes_t size;
+    Sample* buf;
+
+    SizedSampleBuffer (nframes_t sz) : size (sz) { 
+           buf = new Sample[size];
+    }
+
+    ~SizedSampleBuffer() {
+           delete [] buf;
+    }
+};
+
+Glib::StaticPrivate<SizedSampleBuffer> thread_interleave_buffer = GLIBMM_STATIC_PRIVATE_INIT;
+
 AudioFileSource::AudioFileSource (Session& s, ustring path, Flag flags)
        : AudioSource (s, path), _flags (flags),
          _channel (0)
@@ -716,3 +732,22 @@ AudioFileSource::mark_immutable ()
                _flags = Flag (_flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename));
        }
 }
+
+
+Sample*
+AudioFileSource::get_interleave_buffer (nframes_t size)
+{
+       SizedSampleBuffer* ssb;
+
+       if ((ssb = thread_interleave_buffer.get()) == 0) {
+               ssb = new SizedSampleBuffer (size);
+               thread_interleave_buffer.set (ssb);
+       }
+
+       if (ssb->size < size) {
+               ssb = new SizedSampleBuffer (size);
+               thread_interleave_buffer.set (ssb);
+       }
+
+       return ssb->buf;
+}
diff --git a/libs/ardour/caimportable.cc b/libs/ardour/caimportable.cc
new file mode 100644 (file)
index 0000000..229bfa8
--- /dev/null
@@ -0,0 +1,118 @@
+#include <ardour/caimportable.h>
+#include <sndfile.h>
+#include <pbd/error.h>
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace std;
+using namespace PBD;
+
+CAImportableSource::CAImportableSource (const string& path)
+{
+       try {
+               af.Open (path.c_str());
+
+               CAStreamBasicDescription file_format (af.GetFileDataFormat());
+               CAStreamBasicDescription client_format (file_format);
+
+               /* set canonial form (PCM, native float packed, 32 bit, with the correct number of channels
+                  and interleaved (since we plan to deinterleave ourselves)
+               */
+
+               client_format.SetCanonical(client_format.NumberChannels(), true);
+               af.SetClientFormat (client_format);
+
+       } catch (CAXException& cax) {
+               error << string_compose ("CAImportable: %1", cax.mOperation) << endmsg;
+               throw failed_constructor ();
+       }
+
+}
+
+CAImportableSource::~CAImportableSource ()
+{
+}
+
+nframes_t
+CAImportableSource::read (Sample* buffer, nframes_t nframes) 
+{
+       nframes_t nread = 0;
+       AudioBufferList abl;
+       nframes_t per_channel;
+       bool at_end = false;
+
+       abl.mNumberBuffers = 1;
+       abl.mBuffers[0].mNumberChannels = channels();
+
+       per_channel = nframes / abl.mBuffers[0].mNumberChannels;
+
+       while (nread < per_channel) {
+               
+               UInt32 new_cnt = per_channel - nread;
+               
+               abl.mBuffers[0].mDataByteSize = new_cnt * abl.mBuffers[0].mNumberChannels * sizeof(Sample);
+               abl.mBuffers[0].mData = buffer + nread;
+                       
+               try {
+                       af.Read (new_cnt, &abl);
+               } catch (CAXException& cax) {
+                       error << string_compose("CAImportable: %1", cax.mOperation);
+                       return -1;
+               }
+
+               if (new_cnt == 0) {
+                       /* EOF */
+                       at_end = true;
+                       break;
+               }
+
+               nread += new_cnt;
+       }
+
+       if (!at_end && nread < per_channel) {
+               return 0;
+       } else {
+               return nread *  abl.mBuffers[0].mNumberChannels;
+       }
+}
+
+uint
+CAImportableSource::channels () const 
+{
+       return af.GetFileDataFormat().NumberChannels();
+}
+
+nframes_t
+CAImportableSource::length () const 
+{
+       return af.GetNumberFrames();
+}
+
+nframes_t
+CAImportableSource::samplerate() const
+{
+       CAStreamBasicDescription client_asbd;
+
+       try {
+               client_asbd = af.GetClientDataFormat ();
+       } catch (CAXException& cax) {
+               error << string_compose ("CAImportable: %1", cax.mOperation) << endmsg;
+               return 0.0;
+       }
+
+       return client_asbd.mSampleRate;
+}
+
+void
+CAImportableSource::seek (nframes_t pos)
+{
+       try {
+               af.Seek (pos);
+       } catch (CAXException& cax) {
+               error << string_compose ("CAImportable: %1 to %2", cax.mOperation, pos) << endmsg;
+       }
+}
+
+       
+
index 703225e502eaa953eee5c5d40a9afe9f828c1796..011bcce337d400d0ff3aa88a4cb5c58b591694d7 100644 (file)
@@ -1,5 +1,6 @@
 /*
-    Copyright (C) 2006 Paul Davis 
+    Copyright (C) 2006 Paul Davis
+    Written by Taybin Rutkin
 
     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
@@ -17,6 +18,8 @@
 
 */
 
+#include <algorithm>
+
 #include <pbd/error.h>
 #include <ardour/coreaudiosource.h>
 #include <ardour/utils.h>
@@ -28,6 +31,7 @@
 
 #include <AudioToolbox/AudioFormat.h>
 
+using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
@@ -48,18 +52,12 @@ CoreAudioSource::CoreAudioSource (Session& s, const string& path, int chn, Flag
 void 
 CoreAudioSource::init ()
 {
-       tmpbuf = 0;
-       tmpbufsize = 0;
-
-       cerr << "CoreAudioSource::init() " << name() << endl;
-       
        /* note that we temporarily truncated _id at the colon */
        try {
                af.Open(_path.c_str());
 
-               CAStreamBasicDescription file_asbd (af.GetFileDataFormat());
-               n_channels = file_asbd.NumberChannels();
-               cerr << "number of channels: " << n_channels << endl;
+               CAStreamBasicDescription file_format (af.GetFileDataFormat());
+               n_channels = file_format.NumberChannels();
                
                if (_channel >= n_channels) {
                        error << string_compose("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number (%3)", n_channels, _channel, name()) << endmsg;
@@ -68,9 +66,15 @@ CoreAudioSource::init ()
 
                _length = af.GetNumberFrames();
 
-               CAStreamBasicDescription client_asbd(file_asbd);
-               client_asbd.SetCanonical(client_asbd.NumberChannels(), false);
-               af.SetClientFormat (client_asbd);
+               CAStreamBasicDescription client_format (file_format);
+
+               /* set canonial form (PCM, native float packed, 32 bit, with the correct number of channels
+                  and interleaved (since we plan to deinterleave ourselves)
+               */
+
+               client_format.SetCanonical(client_format.NumberChannels(), true);
+               af.SetClientFormat (client_format);
+
        } catch (CAXException& cax) {
                error << string_compose ("CoreAudioSource: %1 (%2)", cax.mOperation, name()) << endmsg;
                throw failed_constructor ();
@@ -79,81 +83,117 @@ CoreAudioSource::init ()
 
 CoreAudioSource::~CoreAudioSource ()
 {
-       cerr << "CoreAudioSource::~CoreAudioSource() " << name() << endl;
        GoingAway (); /* EMIT SIGNAL */
-
-       if (tmpbuf) {
-               delete [] tmpbuf;
-       }
-       
-       cerr << "deletion done" << endl;
 }
 
-nframes_t
-CoreAudioSource::read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const
+int
+CoreAudioSource::safe_read (Sample* dst, nframes_t start, nframes_t cnt, AudioBufferList& abl) const
 {
-       try {
-               af.Seek (start);
-       } catch (CAXException& cax) {
-               error << string_compose("CoreAudioSource: %1 to %2 (%3)", cax.mOperation, start, _name.substr (1)) << endmsg;
-               return 0;
-       }
+       nframes_t nread = 0;
 
-       AudioBufferList abl;
-       abl.mNumberBuffers = 1;
-       abl.mBuffers[0].mNumberChannels = n_channels;
-
-       UInt32 new_cnt = cnt;
-       if (n_channels == 1) {
-               abl.mBuffers[0].mDataByteSize = cnt * sizeof(Sample);
-               abl.mBuffers[0].mData = dst;
+       while (nread < cnt) {
+               
+               try {
+                       af.Seek (start+nread);
+               } catch (CAXException& cax) {
+                       error << string_compose("CoreAudioSource: %1 to %2 (%3)", cax.mOperation, start+nread, _name.substr (1)) << endmsg;
+                       return -1;
+               }
+               
+               UInt32 new_cnt = cnt - nread;
+               
+               abl.mBuffers[0].mDataByteSize = new_cnt * n_channels * sizeof(Sample);
+               abl.mBuffers[0].mData = dst + nread;
+                       
                try {
                        af.Read (new_cnt, &abl);
                } catch (CAXException& cax) {
                        error << string_compose("CoreAudioSource: %1 (%2)", cax.mOperation, _name);
+                       return -1;
                }
-               _read_data_count = new_cnt * sizeof(float);
-               return new_cnt;
-       }
-
-       UInt32 real_cnt = cnt * n_channels;
 
-       {
-               Glib::Mutex::Lock lm (_tmpbuf_lock);
-               
-               if (tmpbufsize < real_cnt) {
-                       
-                       if (tmpbuf) {
-                               delete [] tmpbuf;
+               if (new_cnt == 0) {
+                       /* EOF */
+                       if (start+cnt == _length) {
+                               /* we really did hit the end */
+                               nread = cnt;
                        }
-                       tmpbufsize = real_cnt;
-                       tmpbuf = new float[tmpbufsize];
+                       break;
                }
 
-               abl.mBuffers[0].mDataByteSize = tmpbufsize * sizeof(Sample);
-               abl.mBuffers[0].mData = tmpbuf;
+               nread += new_cnt;
+       }
+
+       if (nread < cnt) {
+               return -1;
+       } else {
+               return 0;
+       }
+}
+       
+
+nframes_t
+CoreAudioSource::read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const
+{
+       nframes_t file_cnt;
+       AudioBufferList abl;
+
+       abl.mNumberBuffers = 1;
+       abl.mBuffers[0].mNumberChannels = n_channels;
+
+       if (start > _length) {
 
-               cerr << "channel: " << _channel << endl;
+               /* read starts beyond end of data, just memset to zero */
                
-               try {
-                       af.Read (real_cnt, &abl);
-               } catch (CAXException& cax) {
-                       error << string_compose("CoreAudioSource: %1 (%2)", cax.mOperation, _name);
-               }
-               float *ptr = tmpbuf + _channel;
-               real_cnt /= n_channels;
+               file_cnt = 0;
+
+       } else if (start + cnt > _length) {
                
-               /* stride through the interleaved data */
+               /* read ends beyond end of data, read some, memset the rest */
+               
+               file_cnt = _length - start;
+
+       } else {
                
-               for (uint32_t n = 0; n < real_cnt; ++n) {
-                       dst[n] = *ptr;
-                       ptr += n_channels;
+               /* read is entirely within data */
+
+               file_cnt = cnt;
+       }
+
+       if (file_cnt != cnt) {
+               nframes_t delta = cnt - file_cnt;
+               memset (dst+file_cnt, 0, sizeof (Sample) * delta);
+       }
+
+       if (file_cnt) {
+
+               if (n_channels == 1) {
+                       if (safe_read (dst, start, file_cnt, abl) == 0) {
+                               _read_data_count = cnt * sizeof (Sample);
+                               return cnt;
+                       }
+                       return 0;
                }
        }
 
+       Sample* interleave_buf = get_interleave_buffer (file_cnt * n_channels);
+       
+       if (safe_read (interleave_buf, start, file_cnt, abl) != 0) {
+               return 0;
+       }
+
        _read_data_count = cnt * sizeof(float);
-               
-       return real_cnt;
+
+       Sample *ptr = interleave_buf + _channel;
+       
+       /* stride through the interleaved data */
+       
+       for (uint32_t n = 0; n < file_cnt; ++n) {
+               dst[n] = *ptr;
+               ptr += n_channels;
+       }
+
+       return cnt;
 }
 
 float
index 3bee54babbd2486f46b7d02b3cb070d0b7e4c57d..b54963cf3c513985a92a8352fb162b15b9c6c1fb 100644 (file)
@@ -334,7 +334,6 @@ Playlist::release_notifications ()
        } 
 }
 
-
 void
 Playlist::notify_modified ()
 {
index cdfdee26046786aa931925a5086670f62a77645f..7db917635c49836e1d9ef7c95baaa6bd97dfd9d9 100644 (file)
@@ -26,7 +26,7 @@
 using namespace ARDOUR;
 using namespace PBD;
 
-const uint32_t ResampledImportableSource::blocksize = 4096U;
+const uint32_t ResampledImportableSource::blocksize = 16384U;
 
 ResampledImportableSource::ResampledImportableSource (boost::shared_ptr<ImportableSource> src, nframes_t rate, SrcQuality srcq)
        : source (src)
index ac7789e5db7e88d6b3c00094d83d1f87832b763d..35eb10ccf0b123bb6cc0af12faa03f68b818df37 100644 (file)
@@ -482,7 +482,7 @@ Session::destroy ()
 
        // auditioner.reset ();
        
-#undef TRACK_DESTRUCTION
+#define TRACK_DESTRUCTION
 #ifdef TRACK_DESTRUCTION
        cerr << "delete named selections\n";
 #endif /* TRACK_DESTRUCTION */
@@ -577,14 +577,19 @@ Session::destroy ()
 
                tmp = i;
                ++tmp;
+               
+               cerr << "Drop refs to " << i->second->name() << endl;
 
                i->second->drop_references ();
 
+               cerr << "move on\n";
+               
                i = tmp;
        }
-
+       
+       cerr << "clear audio sources\n";
        audio_sources.clear ();
-
+       
 #ifdef TRACK_DESTRUCTION
        cerr << "delete mix groups\n";
 #endif /* TRACK_DESTRUCTION */
@@ -2892,6 +2897,8 @@ Session::remove_source (boost::weak_ptr<Source> src)
                return;
        } 
 
+       cerr << "remove source for " << source->name() << endl;
+
        { 
                Glib::Mutex::Lock lm (audio_source_lock);
                
index ffd9c8c752bc8c7bff9a5c87494cb78092aacf99..b6f3accd4e92f0c88a0fa0d349cac1cd3a1a1564 100644 (file)
@@ -25,7 +25,6 @@
 #include <sys/stat.h>
 
 #include <glibmm/miscutils.h>
-#include <glibmm/thread.h>
 #include <pbd/stacktrace.h>
 
 #include <ardour/sndfilesource.h>
@@ -46,21 +45,6 @@ const AudioFileSource::Flag SndFileSource::default_writable_flags = AudioFileSou
                                                                                           AudioFileSource::Removable|
                                                                                           AudioFileSource::RemovableIfEmpty|
                                                                                           AudioFileSource::CanRename);
-struct SizedSampleBuffer {
-    nframes_t size;
-    Sample* buf;
-
-    SizedSampleBuffer (nframes_t sz) : size (sz) { 
-           buf = new Sample[size];
-    }
-
-    ~SizedSampleBuffer() {
-           delete [] buf;
-    }
-};
-
-Glib::StaticPrivate<SizedSampleBuffer> thread_interleave_buffer = GLIBMM_STATIC_PRIVATE_INIT;
-
 SndFileSource::SndFileSource (Session& s, const XMLNode& node)
        : AudioFileSource (s, node)
 {
@@ -96,7 +80,7 @@ SndFileSource::SndFileSource (Session& s, ustring path, SampleFormat sfmt, Heade
        */
 
        file_is_new = true;
-       
+
        switch (hf) {
        case CAF:
                fmt = SF_FORMAT_CAF;
@@ -190,9 +174,8 @@ SndFileSource::SndFileSource (Session& s, ustring path, SampleFormat sfmt, Heade
                        _flags = Flag (_flags & ~Broadcast);
                        delete _broadcast_info;
                        _broadcast_info = 0;
-               }
-               
-       }
+               } 
+       } 
 }
 
 void 
@@ -256,7 +239,7 @@ SndFileSource::open ()
 
        set_timeline_position (get_timecode_info (sf, _broadcast_info, timecode_info_exists));
 
-       if (!timecode_info_exists) {
+       if (_length != 0 && !timecode_info_exists) {
                delete _broadcast_info;
                _broadcast_info = 0;
                _flags = Flag (_flags & ~Broadcast);
@@ -328,6 +311,11 @@ SndFileSource::read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const
                file_cnt = cnt;
        }
        
+       if (file_cnt != cnt) {
+               nframes_t delta = cnt - file_cnt;
+               memset (dst+file_cnt, 0, sizeof (Sample) * delta);
+       }
+
        if (file_cnt) {
 
                if (sf_seek (sf, (sf_count_t) start, SEEK_SET|SFM_READ) != (sf_count_t) start) {
@@ -344,11 +332,6 @@ SndFileSource::read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const
                }
        }
 
-       if (file_cnt != cnt) {
-               nframes_t delta = cnt - file_cnt;
-               memset (dst+file_cnt, 0, sizeof (Sample) * delta);
-       }
-
        real_cnt = cnt * _info.channels;
 
        Sample* interleave_buf = get_interleave_buffer (real_cnt);
@@ -908,20 +891,3 @@ SndFileSource::one_of_several_channels () const
        return _info.channels > 1;
 }
 
-Sample*
-SndFileSource::get_interleave_buffer (nframes_t size)
-{
-       SizedSampleBuffer* ssb;
-
-       if ((ssb = thread_interleave_buffer.get()) == 0) {
-               ssb = new SizedSampleBuffer (size);
-               thread_interleave_buffer.set (ssb);
-       }
-
-       if (ssb->size < size) {
-               ssb = new SizedSampleBuffer (size);
-               thread_interleave_buffer.set (ssb);
-       }
-
-       return ssb->buf;
-}
index deb7e8b8e259cec04b00eb874cca10a50fd77957..7942bfa5e06d41a41bbbb1459c4f38cb3f7eeb09 100644 (file)
 #include <ardour/silentfilesource.h>
 #include <ardour/configuration.h>
 
-#undef USE_COREAUDIO_FOR_FILES
+#ifdef  HAVE_COREAUDIO
+#define USE_COREAUDIO_FOR_FILES
+#endif
 
 #ifdef USE_COREAUDIO_FOR_FILES
 #include <ardour/coreaudiosource.h>
 #endif
 
+
 #include "i18n.h"
 
 using namespace ARDOUR;
@@ -73,6 +76,7 @@ peak_thread_work ()
                if (!as) {
                        continue;
                }
+
                as->setup_peakfile ();
        }
 }
@@ -121,12 +125,12 @@ SourceFactory::createSilent (Session& s, const XMLNode& node, nframes_t nframes,
        return ret;
 }
 
-#ifdef USE_COREAUDIO_FOR_FILES
 boost::shared_ptr<Source>
 SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks)
 {
        try {
-               boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
+
+               boost::shared_ptr<Source> ret (new SndFileSource (s, node));
                if (setup_peakfile (ret, defer_peaks)) {
                        return boost::shared_ptr<Source>();
                }
@@ -138,47 +142,34 @@ SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks)
 
        catch (failed_constructor& err) {       
 
+#ifdef USE_COREAUDIO_FOR_FILES
+
                /* this is allowed to throw */
 
-               boost::shared_ptr<Source> ret (new SndFileSource (s, node));
+               boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
                if (setup_peakfile (ret, defer_peaks)) {
                        return boost::shared_ptr<Source>();
                }
                ret->check_for_analysis_data_on_disk ();
                SourceCreated (ret);
                return ret;
-       }
-
-       return boost::shared_ptr<Source>();
-}
-
 #else
+               throw; // rethrow 
+#endif
 
-boost::shared_ptr<Source>
-SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks)
-{
-       /* this is allowed to throw */
-
-       boost::shared_ptr<Source> ret (new SndFileSource (s, node));
-       
-       if (setup_peakfile (ret, defer_peaks)) {
-               return boost::shared_ptr<Source>();
        }
-       ret->check_for_analysis_data_on_disk ();
-       SourceCreated (ret);
-       return ret;
-}
 
-#endif // USE_COREAUDIO_FOR_FILES
+       return boost::shared_ptr<Source>(); // keep stupid gcc happy
+}
 
-#ifdef USE_COREAUDIO_FOR_FILES
 boost::shared_ptr<Source>
 SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce, bool defer_peaks)
 {
        if (!(flags & Destructive)) {
 
                try {
-                       boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
+
+                       boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
                        if (setup_peakfile (ret, defer_peaks)) {
                                return boost::shared_ptr<Source>();
                        }
@@ -193,7 +184,9 @@ SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource
 
                        /* this is allowed to throw */
 
-                       boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
+#ifdef USE_COREAUDIO_FOR_FILES
+
+                       boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
                        if (setup_peakfile (ret, defer_peaks)) {
                                return boost::shared_ptr<Source>();
                        }
@@ -202,46 +195,19 @@ SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource
                                SourceCreated (ret);
                        }
                        return ret;
+
+#else
+                       throw; // rethrow
+#endif
                }
 
        } else {
 
-               boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
-               if (setup_peakfile (ret, defer_peaks)) {
-                       return boost::shared_ptr<Source>();
-               }
-               ret->check_for_analysis_data_on_disk ();
-               if (announce) {
-                       SourceCreated (ret);
-               }
-               return ret;
        }
 
        return boost::shared_ptr<Source>();
 }
 
-#else
-
-boost::shared_ptr<Source>
-SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce, bool defer_peaks)
-{
-       boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
-
-       if (setup_peakfile (ret, defer_peaks)) {
-               return boost::shared_ptr<Source>();
-       }
-
-       ret->check_for_analysis_data_on_disk ();
-
-       if (announce) {
-               SourceCreated (ret);
-       }
-
-       return ret;
-}
-
-#endif // USE_COREAUDIO_FOR_FILES
-
 boost::shared_ptr<Source>
 SourceFactory::createWritable (Session& s, std::string path, bool destructive, nframes_t rate, bool announce, bool defer_peaks)
 {
index 60a6ecc249b49fc3d36d863c469e891792c2f4b8..c0b5a7cdc86c25b4442f46c2266acff50a3b8686 100644 (file)
@@ -1,4 +1,4 @@
 #ifndef __ardour_svn_revision_h__
 #define __ardour_svn_revision_h__
-static const char* ardour_svn_revision = "3107";
+static const char* ardour_svn_revision = "3117";
 #endif