summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-28 01:45:15 +0000
committerDavid Robillard <d@drobilla.net>2012-01-28 01:45:15 +0000
commit2858d439020af4d3084d64d36776d77655eb293b (patch)
treea997682b285e8ec358fc6551bac830ee196d4f90 /libs/ardour/ardour
parent66cd3d365cd798045364493426aab11ca7421b01 (diff)
Use new Lilv state API to save LV2 plugin state.
This saves a complete history of plugin state, i.e. save is no longer destructive. However, data is shared as much as possible, and new state is only written if the plugin state has actually changed. There is exactly one link in the entire session directory to any external file, so archiving will work with minimal copying. Not sure sure about the naming of the "externals" directory, but I have nothing better... git-svn-id: svn://localhost/ardour2/branches/3.0@11372 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r--libs/ardour/ardour/lv2_plugin.h53
-rw-r--r--libs/ardour/ardour/lv2_state.h147
-rw-r--r--libs/ardour/ardour/session.h7
-rw-r--r--libs/ardour/ardour/uri_map.h21
4 files changed, 34 insertions, 194 deletions
diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h
index a627c2eb43..6d68ca2674 100644
--- a/libs/ardour/ardour/lv2_plugin.h
+++ b/libs/ardour/ardour/lv2_plugin.h
@@ -120,16 +120,16 @@ class LV2Plugin : public ARDOUR::Plugin
private:
struct Impl;
- Impl* _impl;
- void* _module;
- LV2_Feature** _features;
- framecnt_t _sample_rate;
- float* _control_data;
- float* _shadow_data;
- float* _defaults;
- float* _latency_control_port;
- bool _was_activated;
- bool _has_state_interface;
+ Impl* _impl;
+ void* _module;
+ LV2_Feature** _features;
+ framecnt_t _sample_rate;
+ float* _control_data;
+ float* _shadow_data;
+ float* _defaults;
+ float* _latency_control_port;
+ PBD::ID _insert_id;
+
std::vector<bool> _port_is_input;
std::vector<bool> _port_is_output;
std::vector<bool> _port_is_midi;
@@ -138,8 +138,6 @@ class LV2Plugin : public ARDOUR::Plugin
std::map<std::string,uint32_t> _port_indices;
- PBD::ID _insert_id;
-
typedef struct {
const void* (*extension_data) (const char* uri);
} LV2_DataAccess;
@@ -147,34 +145,21 @@ class LV2Plugin : public ARDOUR::Plugin
LV2_DataAccess _data_access_extension_data;
LV2_Feature _data_access_feature;
LV2_Feature _instance_access_feature;
- LV2_Feature _map_path_feature;
LV2_Feature _make_path_feature;
+ mutable unsigned _state_version;
+
+ bool _was_activated;
+ bool _has_state_interface;
+
static URIMap _uri_map;
static uint32_t _midi_event_type;
static uint32_t _state_path_type;
- const std::string state_dir () const;
-
- static int
- lv2_state_store_callback (void* handle,
- uint32_t key,
- const void* value,
- size_t size,
- uint32_t type,
- uint32_t flags);
-
- static const void*
- lv2_state_retrieve_callback (void* handle,
- uint32_t key,
- size_t* size,
- uint32_t* type,
- uint32_t* flags);
-
- static char* lv2_state_abstract_path (void* host_data,
- const char* absolute_path);
- static char* lv2_state_absolute_path (void* host_data,
- const char* abstract_path);
+ const std::string scratch_dir () const;
+ const std::string file_dir () const;
+ const std::string state_dir (unsigned num) const;
+
static char* lv2_state_make_path (void* host_data,
const char* path);
diff --git a/libs/ardour/ardour/lv2_state.h b/libs/ardour/ardour/lv2_state.h
deleted file mode 100644
index 6c37ebcd0b..0000000000
--- a/libs/ardour/ardour/lv2_state.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- Copyright (C) 2011 Paul Davis
- Author: David Robillard
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#ifndef __ardour_lv2_state_h__
-#define __ardour_lv2_state_h__
-
-#include <stdint.h>
-#include <stdlib.h>
-
-#include <map>
-#include <string>
-
-#include "pbd/error.h"
-
-#include "ardour/uri_map.h"
-#include "lv2/lv2plug.in/ns/ext/state/state.h"
-#include "rdff.h"
-
-namespace ARDOUR {
-
-class LV2Plugin;
-
-struct LV2State {
- LV2State(const LV2Plugin& plug, URIMap& map) : plugin(plug), uri_map(map) {}
-
- struct Value {
- inline Value(uint32_t k, const void* v, size_t s, uint32_t t, uint32_t f)
- : key(k), value(v), size(s), type(t), flags(f)
- {}
-
- const uint32_t key;
- const void* value;
- const size_t size;
- const uint32_t type;
- const uint32_t flags;
- };
-
- typedef std::map<uint32_t, std::string> URIs;
- typedef std::map<uint32_t, Value> Values;
-
- uint32_t file_id_to_runtime_id(uint32_t file_id) const {
- URIs::const_iterator i = uris.find(file_id);
- if (i == uris.end()) {
- PBD::error << "LV2 state refers to undefined URI ID" << endmsg;
- return 0;
- }
- return uri_map.uri_to_id(NULL, i->second.c_str());
- }
-
- int add_uri(uint32_t file_id, const char* str) {
- // TODO: check for clashes (invalid file)
- uris.insert(std::make_pair(file_id, str));
- return 0;
- }
-
- int add_value(uint32_t file_key,
- const void* value,
- size_t size,
- uint32_t file_type,
- uint32_t flags) {
- const uint32_t key = file_id_to_runtime_id(file_key);
- const uint32_t type = file_id_to_runtime_id(file_type);
- if (!key || !type) {
- PBD::error << "Invalid file key or type" << endmsg;
- return 1;
- }
-
- Values::const_iterator i = values.find(key);
- if (i != values.end()) {
- PBD::error << "LV2 state contains duplicate keys" << endmsg;
- return 1;
- } else {
- void* value_copy = malloc(size);
- memcpy(value_copy, value, size); // FIXME: leak
- values.insert(
- std::make_pair(key,
- Value(key, value_copy, size, type, flags)));
- return 0;
- }
- }
-
- void read(RDFF file) {
- RDFFChunk* chunk = (RDFFChunk*)malloc(sizeof(RDFFChunk));
- chunk->size = 0;
- while (!rdff_read_chunk(file, &chunk)) {
- if (rdff_chunk_is_uri(chunk)) {
- RDFFURIChunk* body = (RDFFURIChunk*)chunk->data;
- add_uri(body->id, body->uri);
- } else if (rdff_chunk_is_triple(chunk)) {
- RDFFTripleChunk* body = (RDFFTripleChunk*)chunk->data;
- add_value(body->predicate,
- body->object,
- body->object_size,
- body->object_type,
- LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
- }
- }
- free(chunk);
- }
-
- void write(RDFF file) {
- // Write all referenced URIs to state file
- for (URIs::const_iterator i = uris.begin(); i != uris.end(); ++i) {
- rdff_write_uri(file,
- i->first,
- i->second.length(),
- i->second.c_str());
- }
-
- // Write all values to state file
- for (Values::const_iterator i = values.begin(); i != values.end(); ++i) {
- const uint32_t key = i->first;
- const LV2State::Value& val = i->second;
- rdff_write_triple(file,
- 0,
- key,
- val.type,
- val.size,
- val.value);
- }
- }
-
- const LV2Plugin& plugin;
- URIMap& uri_map;
- URIs uris;
- Values values;
-};
-
-} // namespace ARDOUR
-
-#endif /* __ardour_lv2_state_h__ */
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 823e5e4bbc..e702612338 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -182,9 +182,10 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
int ensure_subdirs ();
- std::string automation_dir () const;
- std::string analysis_dir() const;
- std::string plugins_dir() const;
+ std::string automation_dir () const; ///< Automation data
+ std::string analysis_dir () const; ///< Analysis data
+ std::string plugins_dir () const; ///< Plugin state
+ std::string externals_dir () const; ///< Links to external files
std::string peak_path (std::string) const;
diff --git a/libs/ardour/ardour/uri_map.h b/libs/ardour/ardour/uri_map.h
index 3fb8560022..a6c9dc7a8b 100644
--- a/libs/ardour/ardour/uri_map.h
+++ b/libs/ardour/ardour/uri_map.h
@@ -41,11 +41,12 @@ public:
LV2_Feature* urid_map_feature() { return &_urid_map_feature; }
LV2_Feature* urid_unmap_feature() { return &_urid_unmap_feature; }
- uint32_t uri_to_id(const char* map,
- const char* uri);
+ LV2_URID_Map* urid_map() { return &_urid_map_feature_data; }
+ LV2_URID_Unmap* urid_unmap() { return &_urid_unmap_feature_data; }
- const char* id_to_uri(const char* map,
- uint32_t id);
+ uint32_t uri_to_id(const char* map, const char* uri);
+
+ const char* id_to_uri(const char* map, uint32_t id);
private:
static uint32_t uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
@@ -64,12 +65,12 @@ private:
EventToGlobal _event_to_global;
GlobalToEvent _global_to_event;
- LV2_Feature _uri_map_feature;
- LV2_URI_Map_Feature _uri_map_feature_data;
- LV2_Feature _urid_map_feature;
- LV2_URID_Map _urid_map_feature_data;
- LV2_Feature _urid_unmap_feature;
- LV2_URID_Unmap _urid_unmap_feature_data;
+ LV2_Feature _uri_map_feature;
+ LV2_URI_Map_Feature _uri_map_feature_data;
+ LV2_Feature _urid_map_feature;
+ LV2_URID_Map _urid_map_feature_data;
+ LV2_Feature _urid_unmap_feature;
+ LV2_URID_Unmap _urid_unmap_feature_data;
};