_session->begin_reversible_command (_("Edit crossfade"));
XMLNode& before = xfade->get_state ();
-
+
_apply_to (xfade);
- _session->add_command (new MementoCommand<Crossfade> (*xfade.get(), &before, &xfade->get_state()));
+ _session->add_command (new MementoCommand<Crossfade> (*xfade.get(), &before, &xfade->get_state ()));
_session->commit_reversible_command ();
}
playlist->freeze ();
}
+ /* this movement may result in a crossfade being modified, so we need to get undo
+ data from the playlist as well as the region.
+ */
+
+ r = modified_playlists.insert (playlist);
+ if (r.second) {
+ playlist->clear_changes ();
+ }
+
rv->region()->set_position (where, (void*) this);
_editor->session()->add_command (new StatefulDiffCommand (rv->region()));
RegionMoveDrag::add_stateful_diff_commands_for_playlists (PlaylistSet const & playlists)
{
for (PlaylistSet::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
- _editor->session()->add_command (new StatefulDiffCommand (*i));
+ StatefulDiffCommand* c = new StatefulDiffCommand (*i);
+ if (!c->empty()) {
+ _editor->session()->add_command (new StatefulDiffCommand (*i));
+ } else {
+ delete c;
+ }
}
}
/* pick up changes to existing regions */
- vector<StatefulDiffCommand*> cmds;
+ vector<Command*> cmds;
playlist->rdiff (cmds);
- for (vector<StatefulDiffCommand*>::iterator j = cmds.begin(); j != cmds.end(); ++j) {
- _session->add_command (*j);
- }
+ _session->add_commands (cmds);
/* pick up changes to the playlist itself (adds/removes)
*/
playlist->add_region (r, start);
}
- vector<StatefulDiffCommand*> cmds;
+ vector<Command*> cmds;
playlist->rdiff (cmds);
- for (vector<StatefulDiffCommand*>::iterator j = cmds.begin(); j != cmds.end(); ++j) {
- _session->add_command (*j);
- }
+ _session->add_commands (cmds);
_session->add_command (new StatefulDiffCommand (playlist));
}
playlist->nudge_after (start, distance, forwards);
- vector<StatefulDiffCommand*> cmds;
+ vector<Command*> cmds;
playlist->rdiff (cmds);
-
- for (vector<StatefulDiffCommand*>::iterator c = cmds.begin(); c != cmds.end(); ++c) {
- _session->add_command (*c);
- }
+ _session->add_commands (cmds);
_session->add_command (new StatefulDiffCommand (playlist));
}
pl->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue);
- vector<StatefulDiffCommand*> cmds;
-
+ vector<Command*> cmds;
pl->rdiff (cmds);
-
- for (vector<StatefulDiffCommand*>::iterator c = cmds.begin(); c != cmds.end(); ++c) {
- _session->add_command (*c);
- }
-
+ _session->add_commands (cmds);
+
_session->add_command (new StatefulDiffCommand (pl));
commit = true;
}
if ((what_we_got = playlist->cut (time)) != 0) {
_editor.get_cut_buffer().add (what_we_got);
- vector<StatefulDiffCommand*> cmds;
-
+ vector<Command*> cmds;
playlist->rdiff (cmds);
-
- for (vector<StatefulDiffCommand*>::iterator c = cmds.begin(); c != cmds.end(); ++c) {
- _session->add_command (*c);
- }
+ _session->add_commands (cmds);
+
_session->add_command (new StatefulDiffCommand (playlist));
}
break;
case Clear:
if ((what_we_got = playlist->cut (time)) != 0) {
- vector<StatefulDiffCommand*> cmds;
-
+
+ vector<Command*> cmds;
playlist->rdiff (cmds);
-
- for (vector<StatefulDiffCommand*>::iterator c = cmds.begin(); c != cmds.end(); ++c) {
- _session->add_command (*c);
- }
+ _session->add_commands (cmds);
_session->add_command (new StatefulDiffCommand (playlist));
what_we_got->release ();
}
class AudioRegion;
class Source;
+namespace Properties {
+ /* fake the type, since crossfades are handled by SequenceProperty which doesn't
+ care about such things.
+ */
+ extern PBD::PropertyDescriptor<bool> crossfades;
+}
+
+class AudioPlaylist;
+
+class CrossfadeListProperty : public PBD::SequenceProperty<std::list<boost::shared_ptr<Crossfade> > >
+{
+public:
+ CrossfadeListProperty (AudioPlaylist &);
+
+ void get_content_as_xml (boost::shared_ptr<Crossfade>, XMLNode &) const;
+ boost::shared_ptr<Crossfade> get_content_from_xml (XMLNode const &) const;
+
+private:
+ CrossfadeListProperty* clone () const;
+ CrossfadeListProperty* create () const;
+
+ friend class AudioPlaylist;
+ /* we live and die with our playlist, no lifetime management needed */
+ AudioPlaylist& _playlist;
+};
+
+
class AudioPlaylist : public ARDOUR::Playlist
{
- public:
+public:
typedef std::list<boost::shared_ptr<Crossfade> > Crossfades;
+ static void make_property_quarks ();
- public:
AudioPlaylist (Session&, const XMLNode&, bool hidden = false);
AudioPlaylist (Session&, std::string name, bool hidden = false);
AudioPlaylist (boost::shared_ptr<const AudioPlaylist>, std::string name, bool hidden = false);
bool destroy_region (boost::shared_ptr<Region>);
+ void update (const CrossfadeListProperty::ChangeRecord &);
+
protected:
/* playlist "callbacks" */
void remove_dependents (boost::shared_ptr<Region> region);
private:
- Crossfades _crossfades;
+ CrossfadeListProperty _crossfades;
Crossfades _pending_xfade_adds;
void crossfade_invalidated (boost::shared_ptr<Region>);
/* the usual XML constructor */
- Crossfade (const Playlist&, XMLNode&);
+ Crossfade (const Playlist&, XMLNode const &);
virtual ~Crossfade();
static void make_property_quarks ();
RegionListProperty (Playlist&);
RegionListProperty* clone () const;
-
- boost::shared_ptr<Region> lookup_id (const PBD::ID& id) const;
+ void get_content_as_xml (boost::shared_ptr<Region>, XMLNode &) const;
+ boost::shared_ptr<Region> get_content_from_xml (XMLNode const &) const;
private:
RegionListProperty* create () const;
void update (const RegionListProperty::ChangeRecord&);
void clear_owned_changes ();
- void rdiff (std::vector<PBD::StatefulDiffCommand*>&) const;
+ void rdiff (std::vector<Command*>&) const;
boost::shared_ptr<Region> region_by_id (const PBD::ID&) const;
_current_trans.top()->add_command (cmd);
}
+ void add_commands (std::vector<Command*> const & cmds);
+
std::map<PBD::ID,PBD::StatefulDestructible*> registry;
// these commands are implemented in libs/ardour/session_command.cc
#include <cstdlib>
-
#include "ardour/types.h"
#include "ardour/debug.h"
#include "ardour/configuration.h"
using namespace std;
using namespace PBD;
+namespace ARDOUR {
+ namespace Properties {
+ PBD::PropertyDescriptor<bool> crossfades;
+ }
+}
+
+void
+AudioPlaylist::make_property_quarks ()
+{
+ Properties::crossfades.property_id = g_quark_from_static_string (X_("crossfades"));
+ DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for crossfades = %1\n", Properties::crossfades.property_id));
+}
+
+CrossfadeListProperty::CrossfadeListProperty (AudioPlaylist& pl)
+ : SequenceProperty<std::list<boost::shared_ptr<Crossfade> > > (Properties::crossfades.property_id, boost::bind (&AudioPlaylist::update, &pl, _1))
+ , _playlist (pl)
+{
+
+}
+
+
+CrossfadeListProperty *
+CrossfadeListProperty::create () const
+{
+ return new CrossfadeListProperty (_playlist);
+}
+
+CrossfadeListProperty *
+CrossfadeListProperty::clone () const
+{
+ return new CrossfadeListProperty (*this);
+}
+
+void
+CrossfadeListProperty::get_content_as_xml (boost::shared_ptr<Crossfade> xfade, XMLNode & node) const
+{
+ /* Crossfades are not written to any state when they are no
+ longer in use, so we must write their state here.
+ */
+
+ XMLNode& c = xfade->get_state ();
+ node.add_child_nocopy (c);
+}
+
+boost::shared_ptr<Crossfade>
+CrossfadeListProperty::get_content_from_xml (XMLNode const & node) const
+{
+ XMLNodeList const c = node.children ();
+ assert (c.size() == 1);
+ return boost::shared_ptr<Crossfade> (new Crossfade (_playlist, *c.front()));
+}
+
+
AudioPlaylist::AudioPlaylist (Session& session, const XMLNode& node, bool hidden)
: Playlist (session, node, DataType::AUDIO, hidden)
+ , _crossfades (*this)
{
#ifndef NDEBUG
const XMLProperty* prop = node.property("type");
assert(!prop || DataType(prop->value()) == DataType::AUDIO);
#endif
+ add_property (_crossfades);
+
in_set_state++;
set_state (node, Stateful::loading_state_version);
in_set_state--;
AudioPlaylist::AudioPlaylist (Session& session, string name, bool hidden)
: Playlist (session, name, DataType::AUDIO, hidden)
+ , _crossfades (*this)
{
+ add_property (_crossfades);
}
AudioPlaylist::AudioPlaylist (boost::shared_ptr<const AudioPlaylist> other, string name, bool hidden)
: Playlist (other, name, hidden)
+ , _crossfades (*this)
{
+ add_property (_crossfades);
+
RegionList::const_iterator in_o = other->regions.begin();
RegionList::iterator in_n = regions.begin();
AudioPlaylist::AudioPlaylist (boost::shared_ptr<const AudioPlaylist> other, nframes_t start, nframes_t cnt, string name, bool hidden)
: Playlist (other, start, cnt, name, hidden)
+ , _crossfades (*this)
{
+ add_property (_crossfades);
+
/* this constructor does NOT notify others (session) */
}
s (*i);
}
}
+
+void
+AudioPlaylist::update (const CrossfadeListProperty::ChangeRecord& change)
+{
+ for (CrossfadeListProperty::ChangeContainer::const_iterator i = change.added.begin(); i != change.added.end(); ++i) {
+ add_crossfade (*i);
+ }
+
+ /* don't remove crossfades here; they will be dealt with by the dependency code */
+}
initialize ();
}
-Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
+Crossfade::Crossfade (const Playlist& playlist, XMLNode const & node)
: AudioRegion (playlist.session(), 0, 0, "unnamed crossfade")
, CROSSFADE_DEFAULT_PROPERTIES
, _fade_in (Evoral::Parameter(FadeInAutomation)) // linear (gain coefficient) => -inf..+6dB
{
boost::shared_ptr<Region> r;
- XMLProperty* prop;
+ XMLProperty const * prop;
LocaleGuard lg (X_("POSIX"));
/* we have to find the in/out regions before we can do anything else */
#include "ardour/debug.h"
#include "ardour/filesystem_paths.h"
#include "ardour/mix.h"
-#include "ardour/playlist.h"
+#include "ardour/audioplaylist.h"
#include "ardour/plugin_manager.h"
#include "ardour/process_thread.h"
#include "ardour/profile.h"
AudioRegion::make_property_quarks ();
RouteGroup::make_property_quarks ();
Playlist::make_property_quarks ();
+ AudioPlaylist::make_property_quarks ();
/* this is a useful ready to use PropertyChange that many
things need to check. This avoids having to compose
: SequenceProperty<std::list<boost::shared_ptr<Region> > > (Properties::regions.property_id, boost::bind (&Playlist::update, &pl, _1))
, _playlist (pl)
{
+
}
-boost::shared_ptr<Region>
-RegionListProperty::lookup_id (const ID& id) const
+RegionListProperty *
+RegionListProperty::clone () const
{
- boost::shared_ptr<Region> ret = _playlist.region_by_id (id);
-
- if (!ret) {
- ret = RegionFactory::region_by_id (id);
- }
+ return new RegionListProperty (*this);
+}
- return ret;
+RegionListProperty *
+RegionListProperty::create () const
+{
+ return new RegionListProperty (_playlist);
}
-RegionListProperty* RegionListProperty::clone () const
+void
+RegionListProperty::get_content_as_xml (boost::shared_ptr<Region> region, XMLNode & node) const
{
- return new RegionListProperty (*this);
+ /* All regions (even those which are deleted) have their state saved by other
+ code, so we can just store ID here.
+ */
+
+ node.add_property ("id", region->id().to_s ());
}
-RegionListProperty* RegionListProperty::create () const
+boost::shared_ptr<Region>
+RegionListProperty::get_content_from_xml (XMLNode const & node) const
{
- return new RegionListProperty (_playlist);
+ XMLProperty const * prop = node.property ("id");
+ assert (prop);
+
+ PBD::ID id (prop->value ());
+
+ boost::shared_ptr<Region> ret = _playlist.region_by_id (id);
+
+ if (!ret) {
+ ret = RegionFactory::region_by_id (id);
+ }
+
+ return ret;
}
Playlist::Playlist (Session& sess, string nom, DataType type, bool hide)
}
void
-Playlist::rdiff (vector<StatefulDiffCommand*>& cmds) const
+Playlist::rdiff (vector<Command*>& cmds) const
{
RegionLock rlock (const_cast<Playlist *> (this));
Stateful::rdiff (cmds);
_history.add (&ut);
}
+void
+Session::add_commands (vector<Command*> const & cmds)
+{
+ for (vector<Command*>::const_iterator i = cmds.begin(); i != cmds.end(); ++i) {
+ add_command (*i);
+ }
+}
+
void
Session::begin_reversible_command(const string& name)
{
obj.includes = ['.', '../surfaces/control_protocol', '..']
obj.name = 'libardour'
obj.target = 'ardour'
- obj.uselib = 'GLIBMM GTHREAD AUBIO SIGCPP XML UUID JACK SNDFILE SAMPLERATE LRDF OSX COREAUDIO'
+ obj.uselib = 'GLIBMM GTHREAD AUBIO SIGCPP XML UUID JACK SNDFILE SAMPLERATE LRDF OSX COREAUDIO CURL DL'
obj.uselib_local = 'libpbd libmidipp libevoral libvamphost libvampplugin libtaglib librubberband libaudiographer'
obj.vnum = LIBARDOUR_LIB_VERSION
obj.install_path = os.path.join(bld.env['LIBDIR'], 'ardour3')
virtual XMLNode &get_state();
virtual int set_state(const XMLNode&, int /*version*/) { /* noop */ return 0; }
+ virtual bool empty () const {
+ return false;
+ }
+
protected:
Command() {}
Command(const std::string& name) : _name(name) {}
virtual void get_changes_as_properties (PropertyList& changes, Command *) const = 0;
/** Collect StatefulDiffCommands for changes to anything that we own */
- virtual void rdiff (std::vector<StatefulDiffCommand*> &) const {}
+ virtual void rdiff (std::vector<Command*> &) const {}
/** Look in an XML node written by get_changes_as_xml and, if XML from this property
* is found, create a property with the changes from the XML.
#include "pbd/id.h"
#include "pbd/property_basics.h"
#include "pbd/property_list.h"
+#include "pbd/stateful_diff_command.h"
namespace PBD {
SequenceProperty (PropertyID id, const boost::function<void(const ChangeRecord&)>& update)
: PropertyBase (id), _update_callback (update) {}
- virtual typename Container::value_type lookup_id (const PBD::ID&) const = 0;
-
void invert () {
_changes.removed.swap (_changes.added);
}
for (typename ChangeContainer::iterator i = _changes.added.begin(); i != _changes.added.end(); ++i) {
XMLNode* add_node = new XMLNode ("Add");
child->add_child_nocopy (*add_node);
- add_node->add_property ("id", (*i)->id().to_s());
+ get_content_as_xml (*i, *add_node);
}
}
if (!_changes.removed.empty()) {
for (typename ChangeContainer::iterator i = _changes.removed.begin(); i != _changes.removed.end(); ++i) {
XMLNode* remove_node = new XMLNode ("Remove");
child->add_child_nocopy (*remove_node);
- remove_node->add_property ("id", (*i)->id().to_s());
+ get_content_as_xml (*i, *remove_node);
}
}
}
+ /** Get a representation of one of our items as XML. The representation must be sufficient to
+ * restore the item's state later; an ID is ok if someone else is storing the item state,
+ * otherwise it needs to be the full state. The supplied node is an <Add> or <Remove>
+ * which this method can either add properties or children to.
+ */
+ virtual void get_content_as_xml (typename ChangeContainer::value_type, XMLNode &) const = 0;
+
bool set_value (XMLNode const &) {
/* XXX: not used, but probably should be */
assert (false);
XMLNodeList const & grandchildren = (*i)->children ();
for (XMLNodeList::const_iterator j = grandchildren.begin(); j != grandchildren.end(); ++j) {
- XMLProperty const * prop = (*j)->property ("id");
- assert (prop);
- PBD::ID id (prop->value ());
- typename Container::value_type v = lookup_id (id);
+
+ typename Container::value_type v = get_content_from_xml (**j);
assert (v);
+
if ((*j)->name() == "Add") {
p->_changes.added.insert (v);
} else if ((*j)->name() == "Remove") {
return p;
}
+ /** Given an <Add> or <Remove> node as passed into get_content_to_xml, obtain an item */
+ virtual typename Container::value_type get_content_from_xml (XMLNode const & node) const = 0;
+
void clear_owned_changes () {
for (typename Container::iterator i = begin(); i != end(); ++i) {
(*i)->clear_changes ();
}
}
- void rdiff (std::vector<StatefulDiffCommand*>& cmds) const {
+ void rdiff (std::vector<Command*>& cmds) const {
for (typename Container::const_iterator i = begin(); i != end(); ++i) {
if ((*i)->changed ()) {
StatefulDiffCommand* sdc = new StatefulDiffCommand (*i);
return _val.erase (f, l);
}
+ void remove (const typename Container::value_type& v) {
+ _changes.remove (v);
+ _val.remove (v);
+ }
+
void push_back (const typename Container::value_type& v) {
_changes.add (v);
_val.push_back (v);
void clear_changes ();
virtual void clear_owned_changes ();
PropertyList* get_changes_as_properties (Command *) const;
- virtual void rdiff (std::vector<StatefulDiffCommand*> &) const;
+ virtual void rdiff (std::vector<Command*> &) const;
bool changed() const;
/* create a property list from an XMLNode
XMLNode& get_state ();
+ bool empty () const;
+
private:
boost::weak_ptr<Stateful> _object; ///< the object in question
PBD::PropertyList* _changes; ///< property changes to execute this command
}
void
-Stateful::rdiff (vector<StatefulDiffCommand*>& cmds) const
+Stateful::rdiff (vector<Command*>& cmds) const
{
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
i->second->rdiff (cmds);
return *node;
}
+
+bool
+StatefulDiffCommand::empty () const
+{
+ return _changes->empty();
+}