writable session patch, forward ported from 2.X

git-svn-id: svn://localhost/ardour2/branches/3.0@5770 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-10-13 20:43:28 +00:00
parent c221b09560
commit 8c4ce1e2ce
17 changed files with 109 additions and 61 deletions

View file

@ -68,7 +68,7 @@ protected:
virtual int move_dependents_to_trash() { return 0; }
bool removable () const;
Glib::ustring _path;
Glib::ustring _take_id;
bool _file_is_new;

View file

@ -248,7 +248,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable
std::string raid_path () const;
void set_snap_name ();
bool writable() const { return _writable; }
void set_dirty ();
void set_clean ();
bool dirty() const { return _state_of_the_state & Dirty; }
@ -1041,6 +1042,7 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable
float _meter_falloff;
bool _non_soloed_outs_muted;
uint32_t _listen_cnt;
bool _writable;
void set_worst_io_latencies ();
void set_worst_io_latencies_x (IOChange, void *) {

View file

@ -79,7 +79,7 @@ class Source : public SessionObject, public boost::noncopyable
int set_state (const XMLNode&);
bool destructive() const { return (_flags & Destructive); }
bool writable () const { return _flags & Writable; }
bool writable () const { return (_flags & Writable); }
virtual bool set_destructive (bool /*yn*/) { return false; }
virtual bool length_mutable() const { return false; }
@ -128,6 +128,7 @@ class Source : public SessionObject, public boost::noncopyable
private:
uint32_t _in_use;
void fix_writable_flags ();
};
}

View file

@ -2065,7 +2065,7 @@ AudioDiskstream::reset_write_sources (bool mark_write_complete, bool /*force*/)
boost::shared_ptr<ChannelList> c = channels.reader();
uint32_t n;
if (!recordable()) {
if (!_session.writable() || !recordable()) {
return;
}

View file

@ -67,7 +67,7 @@ FileSource::FileSource (Session& session, DataType type,
FileSource::FileSource (Session& session, const XMLNode& node, bool /*must_exist*/)
: Source(session, node)
, _file_is_new(false)
, _file_is_new (false)
{
_path = _name;
_is_embedded = (_path.find(PATH_SEP) != string::npos);

View file

@ -63,52 +63,52 @@
#include "pbd/search_path.h"
#include "pbd/stacktrace.h"
#include "ardour/audio_diskstream.h"
#include "ardour/audio_track.h"
#include "ardour/audioengine.h"
#include "ardour/audiofilesource.h"
#include "ardour/audioplaylist.h"
#include "ardour/audioregion.h"
#include "ardour/auditioner.h"
#include "ardour/buffer.h"
#include "ardour/configuration.h"
#include "ardour/control_protocol_manager.h"
#include "ardour/crossfade.h"
#include "ardour/cycle_timer.h"
#include "ardour/directory_names.h"
#include "ardour/filename_extensions.h"
#include "ardour/io_processor.h"
#include "ardour/location.h"
#include "ardour/midi_diskstream.h"
#include "ardour/midi_patch_manager.h"
#include "ardour/midi_playlist.h"
#include "ardour/midi_region.h"
#include "ardour/midi_source.h"
#include "ardour/midi_track.h"
#include "ardour/named_selection.h"
#include "ardour/playlist_factory.h"
#include "ardour/processor.h"
#include "ardour/region_factory.h"
#include "ardour/route_group.h"
#include "ardour/send.h"
#include "ardour/session.h"
#include "ardour/session_directory.h"
#include "ardour/session_utils.h"
#include "ardour/session_state_utils.h"
#include "ardour/session_metadata.h"
#include "ardour/buffer.h"
#include "ardour/audio_diskstream.h"
#include "ardour/midi_diskstream.h"
#include "ardour/utils.h"
#include "ardour/audioplaylist.h"
#include "ardour/midi_playlist.h"
#include "ardour/smf_source.h"
#include "ardour/audiofilesource.h"
#include "ardour/session_state_utils.h"
#include "ardour/session_utils.h"
#include "ardour/silentfilesource.h"
#include "ardour/sndfilesource.h"
#include "ardour/midi_source.h"
#include "ardour/sndfile_helpers.h"
#include "ardour/auditioner.h"
#include "ardour/io_processor.h"
#include "ardour/send.h"
#include "ardour/processor.h"
#include "ardour/user_bundle.h"
#include "ardour/slave.h"
#include "ardour/tempo.h"
#include "ardour/audio_track.h"
#include "ardour/midi_track.h"
#include "ardour/midi_patch_manager.h"
#include "ardour/cycle_timer.h"
#include "ardour/utils.h"
#include "ardour/named_selection.h"
#include "ardour/version.h"
#include "ardour/location.h"
#include "ardour/audioregion.h"
#include "ardour/midi_region.h"
#include "ardour/crossfade.h"
#include "ardour/control_protocol_manager.h"
#include "ardour/region_factory.h"
#include "ardour/smf_source.h"
#include "ardour/sndfile_helpers.h"
#include "ardour/sndfilesource.h"
#include "ardour/source_factory.h"
#include "ardour/playlist_factory.h"
#include "ardour/filename_extensions.h"
#include "ardour/directory_names.h"
#include "ardour/template_utils.h"
#include "ardour/tempo.h"
#include "ardour/ticker.h"
#include "ardour/route_group.h"
#include "ardour/user_bundle.h"
#include "ardour/utils.h"
#include "ardour/utils.h"
#include "ardour/version.h"
#include "control_protocol/control_protocol.h"
@ -140,6 +140,14 @@ Session::first_stage_init (string fullpath, string snapshot_name)
_path += '/';
}
if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS) && ::access (_path.c_str(), W_OK)) {
cerr << "Session non-writable based on " << _path << endl;
_writable = false;
} else {
cerr << "Session writable based on " << _path << endl;
_writable = true;
}
/* these two are just provisional settings. set_state()
will likely override them.
*/
@ -665,7 +673,7 @@ Session::save_state (string snapshot_name, bool pending)
XMLTree tree;
sys::path xml_path(_session_dir->root_path());
if (_state_of_the_state & CannotSave) {
if (!_writable || (_state_of_the_state & CannotSave)) {
return 1;
}
@ -790,6 +798,15 @@ Session::load_state (string snapshot_name)
set_dirty();
/* writable() really reflects the whole folder, but if for any
reason the session state file can't be written to, still
make us unwritable.
*/
if (::access (xmlpath.to_string().c_str(), W_OK) != 0) {
_writable = false;
}
if (!state_tree->read (xmlpath.to_string())) {
error << string_compose(_("Could not understand ardour file %1"), xmlpath.to_string()) << endmsg;
delete state_tree;
@ -2795,7 +2812,10 @@ Session::controllable_by_id (const PBD::ID& id)
void
Session::add_instant_xml (XMLNode& node, bool write_to_config)
{
Stateful::add_instant_xml (node, _path);
if (_writable) {
Stateful::add_instant_xml (node, _path);
}
if (write_to_config) {
Config->add_instant_xml (node);
}
@ -2812,6 +2832,10 @@ Session::save_history (string snapshot_name)
{
XMLTree tree;
if (!_writable) {
return 0;
}
if (snapshot_name.empty()) {
snapshot_name = _current_snapshot_name;
}
@ -2833,7 +2857,6 @@ Session::save_history (string snapshot_name)
}
}
if (!Config->get_save_history() || Config->get_saved_history_depth() < 0) {
return 0;
}

View file

@ -55,6 +55,7 @@ Source::Source (Session& s, DataType type, const string& name, Flag flags)
_analysed = false;
_timestamp = 0;
_in_use = 0;
fix_writable_flags ();
}
Source::Source (Session& s, const XMLNode& node)
@ -70,6 +71,8 @@ Source::Source (Session& s, const XMLNode& node)
if (set_state (node) || _type == DataType::NIL) {
throw failed_constructor();
}
fix_writable_flags ();
}
Source::~Source ()
@ -77,6 +80,15 @@ Source::~Source ()
notify_callbacks ();
}
void
Source::fix_writable_flags ()
{
if (!_session.writable()) {
_flags = Flag (_flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy|CanRename));
}
}
XMLNode&
Source::get_state ()
{

View file

@ -170,6 +170,10 @@ Track::can_record()
void
Track::set_record_enable (bool yn, void *src)
{
if (!_session.writable()) {
return;
}
if (_freeze_record.state == Frozen) {
return;
}