major fixes to automation editing
[ardour.git] / libs / ardour / coreaudiosource.cc
index fa22dde3471e407558e17fc67065cb4761ce1d1d..3c81b18fd4fb2ee129a8d230d4fb180f75e234b6 100644 (file)
 using namespace ARDOUR;
 using namespace PBD;
 
-CoreAudioSource::CoreAudioSource (const XMLNode& node)
-       : AudioFileSource (node)
+CoreAudioSource::CoreAudioSource (Session& s, const XMLNode& node)
+       : AudioFileSource (s, node)
 {
        init (_name);
 }
 
-CoreAudioSource::CoreAudioSource (const string& idstr, Flag flags)
-       : AudioFileSource(idstr, flags)
+CoreAudioSource::CoreAudioSource (Session& s, const string& idstr, Flag flags)
+       : AudioFileSource(s, idstr, flags)
 {
        init (idstr);
 }
 
 void 
-CoreAudioSource::init (const string& idstr)
+CoreAudioSource::init (string idstr)
 {
        string::size_type pos;
 
@@ -84,13 +84,6 @@ CoreAudioSource::init (const string& idstr)
                error << string_compose ("CoreAudioSource: %1 (%2)", cax.mOperation, name()) << endmsg;
                throw failed_constructor ();
        }
-       
-       if (_build_peakfiles) {
-               if (initialize_peakfile (false, _path)) {
-                       error << string_compose("CoreAudioSource: initialize peakfile failed (%1)", name()) << endmsg;
-                       throw failed_constructor ();
-               }
-       }
 }
 
 CoreAudioSource::~CoreAudioSource ()
@@ -105,8 +98,8 @@ CoreAudioSource::~CoreAudioSource ()
        cerr << "deletion done" << endl;
 }
 
-jack_nframes_t
-CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const
+nframes_t
+CoreAudioSource::read_unlocked (Sample *dst, nframes_t start, nframes_t cnt) const
 {
        try {
                af.Seek (start);
@@ -188,7 +181,57 @@ CoreAudioSource::sample_rate() const
 }
 
 int
-CoreAudioSource::update_header (jack_nframes_t when, struct tm&, time_t)
+CoreAudioSource::update_header (nframes_t when, struct tm&, time_t)
 {
        return 0;
 }
+
+int
+CoreAudioSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
+{
+       FSRef ref; 
+       ExtAudioFileRef af = 0;
+       size_t size;
+       CFStringRef name;
+       int ret = -1;
+
+       if (FSPathMakeRef ((UInt8*)path.c_str(), &ref, 0) != noErr) {
+               goto out;
+       }
+       
+       if (ExtAudioFileOpen(&ref, &af) != noErr) {
+               goto out;
+       }
+       
+       AudioStreamBasicDescription absd;
+       memset(&absd, 0, sizeof(absd));
+       size = sizeof(AudioStreamBasicDescription);
+       if (ExtAudioFileGetProperty (af, kExtAudioFileProperty_FileDataFormat, &size, &absd) != noErr) {
+               goto out;
+       }
+       
+       _info.samplerate = absd.mSampleRate;
+       _info.channels   = absd.mChannelsPerFrame;
+
+       size = sizeof(_info.length);
+       if (ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &size, &_info.length) != noErr) {
+               goto out;
+       }
+       
+       size = sizeof(CFStringRef);
+       if (AudioFormatGetProperty(kAudioFormatProperty_FormatName, sizeof(absd), &absd, &size, &name) != noErr) {
+               goto out;
+       }
+
+       _info.format_name = CFStringRefToStdString(name);
+
+       // XXX it would be nice to find a way to get this information if it exists
+
+       _info.timecode = 0;
+       ret = 0;
+       
+  out:
+       ExtAudioFileDispose (af);
+       return ret;
+       
+}