add a static flag to force writing LV2 state
authorRobin Gareus <robin@gareus.org>
Wed, 21 Sep 2016 01:45:57 +0000 (03:45 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 21 Sep 2016 01:45:57 +0000 (03:45 +0200)
This is needed for save-as and archiving, LV2 state may not be saved
otherwise if lilv_state_equals() returns true.

Also if thestate is saved as part of save-as or archiving or
template, the state-version did increase.
Upcoming normal save will reference a plugin state that does not exist
in the current session bundle.

libs/ardour/ardour/lv2_plugin.h
libs/ardour/lv2_plugin.cc

index 269c158714e0ed56126883888335a280dfa5e1d8..a1e38fda32f6fd5e3024338525826e35a8f3a3c5 100644 (file)
@@ -63,6 +63,8 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
        LV2Plugin (const LV2Plugin &);
        ~LV2Plugin ();
 
+       static bool force_state_save;
+
        std::string unique_id () const;
        const char* uri () const;
        const char* label () const;
index 25ae65e17ba174fdc60ddd6fb4aa8bdf060f5662..2d19ea94581e18f6c1743a90cdb96203557700ac 100644 (file)
@@ -109,6 +109,8 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
+bool LV2Plugin::force_state_save = false;
+
 class LV2World : boost::noncopyable {
 public:
        LV2World ();
@@ -1248,7 +1250,7 @@ LV2Plugin::add_state(XMLNode* root) const
                        0,
                        NULL);
 
-               if (!_plugin_state_dir.empty()
+               if (!_plugin_state_dir.empty() || force_state_save
                    || !_impl->state
                    || !lilv_state_equals(state, _impl->state)) {
                        lilv_state_save(_world.world,
@@ -1259,13 +1261,19 @@ LV2Plugin::add_state(XMLNode* root) const
                                        new_dir.c_str(),
                                        "state.ttl");
 
-                       if (_plugin_state_dir.empty()) {
+                       if (force_state_save) {
+                               // archive or save-as
+                               lilv_state_free(state);
+                               --_state_version;
+                       }
+                       else if (_plugin_state_dir.empty()) {
                                // normal session save
                                lilv_state_free(_impl->state);
                                _impl->state = state;
                        } else {
                                // template save (dedicated state-dir)
                                lilv_state_free(state);
+                               --_state_version;
                        }
                } else {
                        // State is identical, decrement version and nuke directory