mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 16:46:35 +01:00
more work on linking file existence and removability
This commit is contained in:
parent
062dd5b71d
commit
5764970709
6 changed files with 73 additions and 31 deletions
|
|
@ -82,6 +82,7 @@ public:
|
||||||
|
|
||||||
static PBD::Signal2<int,std::string,std::vector<std::string> > AmbiguousFileName;
|
static PBD::Signal2<int,std::string,std::vector<std::string> > AmbiguousFileName;
|
||||||
|
|
||||||
|
void existence_check ();
|
||||||
virtual void prevent_deletion ();
|
virtual void prevent_deletion ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#include <appleutility/CAAudioFile.h>
|
#include <appleutility/CAAudioFile.h>
|
||||||
#include <appleutility/CAStreamBasicDescription.h>
|
#include <appleutility/CAStreamBasicDescription.h>
|
||||||
|
|
||||||
|
#include <glibmm/fileutils.h>
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
#include <AudioToolbox/AudioFormat.h>
|
#include <AudioToolbox/AudioFormat.h>
|
||||||
|
|
@ -36,21 +38,32 @@ using namespace std;
|
||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
using namespace PBD;
|
using namespace PBD;
|
||||||
|
|
||||||
|
/** Create a new CoreAudioSource using session state, which implies that the
|
||||||
|
* file must already exist.
|
||||||
|
*/
|
||||||
CoreAudioSource::CoreAudioSource (Session& s, const XMLNode& node)
|
CoreAudioSource::CoreAudioSource (Session& s, const XMLNode& node)
|
||||||
: Source (s, node)
|
: Source (s, node)
|
||||||
, AudioFileSource (s, node)
|
, AudioFileSource (s, node)
|
||||||
{
|
{
|
||||||
init_cafile ();
|
init_cafile ();
|
||||||
|
|
||||||
|
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create a new CoreAudioSource from an existing file. Sources created with this
|
||||||
|
* method are never writable or removable.
|
||||||
|
*/
|
||||||
CoreAudioSource::CoreAudioSource (Session& s, const string& path, int chn, Flag flags)
|
CoreAudioSource::CoreAudioSource (Session& s, const string& path, int chn, Flag flags)
|
||||||
/* files created this way are never writable or removable */
|
|
||||||
: Source (s, DataType::AUDIO, path, Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy))),
|
: Source (s, DataType::AUDIO, path, Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy))),
|
||||||
AudioFileSource (s, path,
|
AudioFileSource (s, path,
|
||||||
Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
|
Source::Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
|
||||||
{
|
{
|
||||||
_channel = chn;
|
_channel = chn;
|
||||||
init_cafile ();
|
init_cafile ();
|
||||||
|
|
||||||
|
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,6 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
|
||||||
, _open (false)
|
, _open (false)
|
||||||
{
|
{
|
||||||
set_within_session_from_path (path);
|
set_within_session_from_path (path);
|
||||||
|
|
||||||
prevent_deletion ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
|
FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
|
||||||
|
|
@ -77,29 +75,28 @@ FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist
|
||||||
|
|
||||||
_path = _name;
|
_path = _name;
|
||||||
_within_session = true;
|
_within_session = true;
|
||||||
|
|
||||||
prevent_deletion ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSource::~FileSource()
|
FileSource::~FileSource()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileSource::existence_check ()
|
||||||
|
{
|
||||||
|
if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
|
||||||
|
prevent_deletion ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FileSource::prevent_deletion ()
|
FileSource::prevent_deletion ()
|
||||||
{
|
{
|
||||||
/* if this file already exists, it cannot be removed, ever
|
if (!(_flags & Destructive)) {
|
||||||
*/
|
mark_immutable ();
|
||||||
|
} else {
|
||||||
if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) {
|
_flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy));
|
||||||
cerr << " ... " << _path << " already exists, marking immutable\n";
|
}
|
||||||
|
|
||||||
if (!(_flags & Destructive)) {
|
|
||||||
mark_immutable ();
|
|
||||||
} else {
|
|
||||||
_flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -3470,6 +3470,15 @@ Session::new_audio_source_name (const string& base, uint32_t nchan, uint32_t cha
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* it is possible that we have the path already
|
||||||
|
* assigned to a source that has not yet been written
|
||||||
|
* (ie. the write source for a diskstream). we have to
|
||||||
|
* check this in order to make sure that our candidate
|
||||||
|
* path isn't used again, because that can lead to
|
||||||
|
* two Sources point to the same file with different
|
||||||
|
* notions of their removability.
|
||||||
|
*/
|
||||||
|
|
||||||
string possible_path = Glib::build_filename (spath, buf);
|
string possible_path = Glib::build_filename (spath, buf);
|
||||||
|
|
||||||
if (source_by_path (possible_path)) {
|
if (source_by_path (possible_path)) {
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,12 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
|
||||||
{
|
{
|
||||||
/* note that origin remains empty */
|
/* note that origin remains empty */
|
||||||
|
|
||||||
if (init(_path, false)) {
|
if (init (_path, false)) {
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
|
|
||||||
/* file is not opened until write */
|
/* file is not opened until write */
|
||||||
|
|
||||||
|
|
@ -94,10 +97,13 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init(_path, true)) {
|
if (init (_path, true)) {
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
|
|
||||||
if (open(_path)) {
|
if (open(_path)) {
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
#include <glibmm/convert.h>
|
#include <glibmm/convert.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <glibmm/fileutils.h>
|
||||||
#include <glibmm/miscutils.h>
|
#include <glibmm/miscutils.h>
|
||||||
|
|
||||||
#include "ardour/sndfilesource.h"
|
#include "ardour/sndfilesource.h"
|
||||||
|
|
@ -57,9 +58,18 @@ const Source::Flag SndFileSource::default_writable_flags = Source::Flag (
|
||||||
SndFileSource::SndFileSource (Session& s, const XMLNode& node)
|
SndFileSource::SndFileSource (Session& s, const XMLNode& node)
|
||||||
: Source(s, node)
|
: Source(s, node)
|
||||||
, AudioFileSource (s, node)
|
, AudioFileSource (s, node)
|
||||||
|
, _descriptor (0)
|
||||||
|
, _broadcast_info (0)
|
||||||
|
, _capture_start (false)
|
||||||
|
, _capture_end (false)
|
||||||
|
, file_pos (0)
|
||||||
|
, xfade_buf (0)
|
||||||
{
|
{
|
||||||
init_sndfile ();
|
init_sndfile ();
|
||||||
|
|
||||||
|
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
|
|
||||||
if (open()) {
|
if (open()) {
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
@ -72,11 +82,20 @@ SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flag
|
||||||
: Source(s, DataType::AUDIO, path, flags)
|
: Source(s, DataType::AUDIO, path, flags)
|
||||||
/* note that the origin of an external file is itself */
|
/* note that the origin of an external file is itself */
|
||||||
, AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
|
, AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
|
||||||
|
, _descriptor (0)
|
||||||
|
, _broadcast_info (0)
|
||||||
|
, _capture_start (false)
|
||||||
|
, _capture_end (false)
|
||||||
|
, file_pos (0)
|
||||||
|
, xfade_buf (0)
|
||||||
{
|
{
|
||||||
_channel = chn;
|
_channel = chn;
|
||||||
|
|
||||||
init_sndfile ();
|
init_sndfile ();
|
||||||
|
|
||||||
|
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
|
|
||||||
if (open()) {
|
if (open()) {
|
||||||
throw failed_constructor ();
|
throw failed_constructor ();
|
||||||
}
|
}
|
||||||
|
|
@ -89,11 +108,20 @@ SndFileSource::SndFileSource (Session& s, const string& path, const string& orig
|
||||||
SampleFormat sfmt, HeaderFormat hf, framecnt_t rate, Flag flags)
|
SampleFormat sfmt, HeaderFormat hf, framecnt_t rate, Flag flags)
|
||||||
: Source(s, DataType::AUDIO, path, flags)
|
: Source(s, DataType::AUDIO, path, flags)
|
||||||
, AudioFileSource (s, path, origin, flags, sfmt, hf)
|
, AudioFileSource (s, path, origin, flags, sfmt, hf)
|
||||||
|
, _descriptor (0)
|
||||||
|
, _broadcast_info (0)
|
||||||
|
, _capture_start (false)
|
||||||
|
, _capture_end (false)
|
||||||
|
, file_pos (0)
|
||||||
|
, xfade_buf (0)
|
||||||
{
|
{
|
||||||
int fmt = 0;
|
int fmt = 0;
|
||||||
|
|
||||||
init_sndfile ();
|
init_sndfile ();
|
||||||
|
|
||||||
|
assert (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
|
||||||
|
existence_check ();
|
||||||
|
|
||||||
_file_is_new = true;
|
_file_is_new = true;
|
||||||
|
|
||||||
switch (hf) {
|
switch (hf) {
|
||||||
|
|
@ -160,24 +188,12 @@ SndFileSource::SndFileSource (Session& s, const string& path, const string& orig
|
||||||
void
|
void
|
||||||
SndFileSource::init_sndfile ()
|
SndFileSource::init_sndfile ()
|
||||||
{
|
{
|
||||||
string file;
|
|
||||||
|
|
||||||
_descriptor = 0;
|
|
||||||
|
|
||||||
// lets try to keep the object initalizations here at the top
|
|
||||||
xfade_buf = 0;
|
|
||||||
_broadcast_info = 0;
|
|
||||||
|
|
||||||
/* although libsndfile says we don't need to set this,
|
/* although libsndfile says we don't need to set this,
|
||||||
valgrind and source code shows us that we do.
|
valgrind and source code shows us that we do.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memset (&_info, 0, sizeof(_info));
|
memset (&_info, 0, sizeof(_info));
|
||||||
|
|
||||||
_capture_start = false;
|
|
||||||
_capture_end = false;
|
|
||||||
file_pos = 0;
|
|
||||||
|
|
||||||
if (destructive()) {
|
if (destructive()) {
|
||||||
xfade_buf = new Sample[xfade_frames];
|
xfade_buf = new Sample[xfade_frames];
|
||||||
_timeline_position = header_position_offset;
|
_timeline_position = header_position_offset;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue