summaryrefslogtreecommitdiff
path: root/libs/ardour/audiofilesource.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-11-19 16:45:16 +0000
committerDavid Robillard <d@drobilla.net>2006-11-19 16:45:16 +0000
commitef6b25432d9c46d71b08c0f7d5f2686df428c4e8 (patch)
tree9b30d87b6670aadce365c9b112321dd674a0bab4 /libs/ardour/audiofilesource.cc
parentaf105afe6cde5b0088647cea7d5e4e3314f8478b (diff)
Merged with trunk R1141
git-svn-id: svn://localhost/ardour2/branches/midi@1142 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/audiofilesource.cc')
-rw-r--r--libs/ardour/audiofilesource.cc107
1 files changed, 35 insertions, 72 deletions
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index 3078521466..16cb990ec2 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -36,7 +36,6 @@
#include <ardour/audiofilesource.h>
#include <ardour/sndfile_helpers.h>
#include <ardour/sndfilesource.h>
-#include <ardour/destructive_filesource.h>
#include <ardour/session.h>
#include <ardour/source_factory.h>
@@ -66,6 +65,7 @@ AudioFileSource::AudioFileSource (Session& s, string idstr, Flag flags)
: AudioSource (s, idstr), _flags (flags)
{
/* constructor used for existing external to session files. file must exist already */
+ _is_embedded = AudioFileSource::determine_embeddedness (idstr);
if (init (idstr, true)) {
throw failed_constructor ();
@@ -77,6 +77,7 @@ AudioFileSource::AudioFileSource (Session& s, std::string path, Flag flags, Samp
: AudioSource (s, path), _flags (flags)
{
/* constructor used for new internal-to-session files. file cannot exist */
+ _is_embedded = false;
if (init (path, false)) {
throw failed_constructor ();
@@ -106,6 +107,12 @@ AudioFileSource::~AudioFileSource ()
}
bool
+AudioFileSource::determine_embeddedness (std::string path)
+{
+ return (path.find("/") == 0);
+}
+
+bool
AudioFileSource::removable () const
{
return (_flags & Removable) && ((_flags & RemoveAtDestroy) || ((_flags & RemovableIfEmpty) && length() == 0));
@@ -170,80 +177,16 @@ bool
AudioFileSource::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;
+ if (CoreAudioSource::get_soundfile_info (path, _info, error_msg) == 0) {
+ return true;
}
-
- 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;
+ if (SndFileSource::get_soundfile_info (path, _info, error_msg) != 0) {
+ return true;
}
- 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;
+ return false;
}
XMLNode&
@@ -277,6 +220,17 @@ AudioFileSource::set_state (const XMLNode& node)
}
+ if ((prop = node.property (X_("name"))) != 0) {
+ _is_embedded = AudioFileSource::determine_embeddedness (prop->value());
+ } else {
+ _is_embedded = false;
+ }
+
+ if ((prop = node.property (X_("destructive"))) != 0) {
+ /* old style, from the period when we had DestructiveFileSource */
+ _flags = Flag (_flags | Destructive);
+ }
+
return 0;
}
@@ -318,6 +272,11 @@ AudioFileSource::mark_take (string id)
int
AudioFileSource::move_to_trash (const string trash_dir_name)
{
+ if (is_embedded()) {
+ cerr << "tried to move an embedded region to trash" << endl;
+ return -1;
+ }
+
string newpath;
if (!writable()) {
@@ -465,7 +424,11 @@ AudioFileSource::find (string pathstr, bool must_exist, bool& isnew)
/* external files and/or very very old style sessions include full paths */
_path = pathstr;
- _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
+ if (is_embedded()) {
+ _name = pathstr;
+ } else {
+ _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
+ }
if (access (_path.c_str(), R_OK) != 0) {
@@ -521,7 +484,7 @@ AudioFileSource::handle_header_position_change ()
}
void
-AudioFileSource::set_timeline_position (nframes_t pos)
+AudioFileSource::set_timeline_position (int64_t pos)
{
timeline_position = pos;
}