39 |
Out[0] = 0; |
Out[0] = 0; |
40 |
Out[1] = 0; |
Out[1] = 0; |
41 |
UriMap = 0; |
UriMap = 0; |
42 |
PathSupport = 0; |
MapPath = 0; |
43 |
NewFileSupport = 0; |
MakePath = 0; |
44 |
for (int i = 0 ; Features[i] ; i++) { |
for (int i = 0 ; Features[i] ; i++) { |
45 |
dmsg(2, ("linuxsampler: host feature: %s\n", Features[i]->URI)); |
dmsg(2, ("linuxsampler: host feature: %s\n", Features[i]->URI)); |
46 |
if (!strcmp(Features[i]->URI, LV2_URI_MAP_URI)) { |
if (!strcmp(Features[i]->URI, LV2_URI_MAP_URI)) { |
47 |
UriMap = (LV2_URI_Map_Feature*)Features[i]->data; |
UriMap = (LV2_URI_Map_Feature*)Features[i]->data; |
48 |
} else if (!strcmp(Features[i]->URI, LV2_FILES_PATH_SUPPORT_URI)) { |
} else if (!strcmp(Features[i]->URI, LV2_STATE_MAP_PATH_URI)) { |
49 |
PathSupport = (LV2_Files_Path_Support*)Features[i]->data; |
MapPath = (LV2_State_Map_Path*)Features[i]->data; |
50 |
} else if (!strcmp(Features[i]->URI, LV2_FILES_NEW_FILE_SUPPORT_URI)) { |
} else if (!strcmp(Features[i]->URI, LV2_STATE_MAKE_PATH_URI)) { |
51 |
NewFileSupport = (LV2_Files_New_File_Support*)Features[i]->data; |
MakePath = (LV2_State_Make_Path*)Features[i]->data; |
52 |
} |
} |
53 |
} |
} |
54 |
|
|
103 |
} |
} |
104 |
|
|
105 |
String PluginLv2::PathToState(const String& path) { |
String PluginLv2::PathToState(const String& path) { |
106 |
if (PathSupport) { |
if (MapPath) { |
107 |
char* cstr = PathSupport->abstract_path(PathSupport->host_data, |
char* cstr = MapPath->abstract_path(MapPath->handle, |
108 |
path.c_str()); |
path.c_str()); |
109 |
const String abstract_path(cstr); |
const String abstract_path(cstr); |
110 |
free(cstr); |
free(cstr); |
111 |
return abstract_path; |
return abstract_path; |
114 |
} |
} |
115 |
|
|
116 |
String PluginLv2::PathFromState(const String& path) { |
String PluginLv2::PathFromState(const String& path) { |
117 |
if (PathSupport) { |
if (MapPath) { |
118 |
char* cstr = PathSupport->absolute_path(PathSupport->host_data, |
char* cstr = MapPath->absolute_path(MapPath->handle, |
119 |
path.c_str()); |
path.c_str()); |
120 |
const String abstract_path(cstr); |
const String abstract_path(cstr); |
121 |
free(cstr); |
free(cstr); |
122 |
return abstract_path; |
return abstract_path; |
124 |
return path; |
return path; |
125 |
} |
} |
126 |
|
|
127 |
void PluginLv2::Save(LV2_Persist_Store_Function store, void* host_data) { |
void PluginLv2::Save(LV2_State_Store_Function store, LV2_State_Handle handle) { |
128 |
if (NewFileSupport) { |
if (MakePath) { |
129 |
char* path = NewFileSupport->new_file_path(PathSupport->host_data, |
char* path = MakePath->path(MapPath->handle, |
130 |
"linuxsampler"); |
"linuxsampler"); |
131 |
dmsg(2, ("saving to file %s\n", path)); |
dmsg(2, ("saving to file %s\n", path)); |
132 |
|
|
133 |
std::ofstream out(path); |
std::ofstream out(path); |
134 |
out << GetState(); |
out << GetState(); |
135 |
|
|
136 |
const String abstract_path = PathToState(path); |
store(handle, |
|
|
|
|
store(host_data, |
|
137 |
uri_to_id(NULL, NS_LS "state-file"), |
uri_to_id(NULL, NS_LS "state-file"), |
138 |
abstract_path.c_str(), |
path, |
139 |
abstract_path.length() + 1, |
strlen(path) + 1, |
140 |
uri_to_id(NULL, LV2_FILES_URI "#AbstractPath"), |
uri_to_id(NULL, LV2_STATE_PATH_URI), |
141 |
LV2_PERSIST_IS_PORTABLE); |
LV2_STATE_IS_PORTABLE); |
142 |
} else { |
} else { |
143 |
dmsg(2, ("saving to string\n")); |
dmsg(2, ("saving to string\n")); |
144 |
|
|
145 |
std::ostringstream out; |
std::ostringstream out; |
146 |
out << GetState(); |
out << GetState(); |
147 |
|
|
148 |
store(host_data, |
store(handle, |
149 |
uri_to_id(NULL, NS_LS "state-string"), |
uri_to_id(NULL, NS_LS "state-string"), |
150 |
out.str().c_str(), |
out.str().c_str(), |
151 |
out.str().length() + 1, |
out.str().length() + 1, |
152 |
uri_to_id(NULL, NS_ATOM "String"), |
uri_to_id(NULL, NS_ATOM "String"), |
153 |
LV2_PERSIST_IS_POD | LV2_PERSIST_IS_PORTABLE); |
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); |
154 |
} |
} |
155 |
dmsg(2, ("saving done\n")); |
dmsg(2, ("saving done\n")); |
156 |
} |
} |
157 |
|
|
158 |
void PluginLv2::Restore(LV2_Persist_Retrieve_Function retrieve, void* data) { |
void PluginLv2::Restore(LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle) { |
159 |
size_t size; |
size_t size; |
160 |
uint32_t type; |
uint32_t type; |
161 |
uint32_t flags; |
uint32_t flags; |
162 |
|
|
163 |
|
// Attempt to restore from state-file |
164 |
const void* value = retrieve( |
const void* value = retrieve( |
165 |
data, |
handle, |
166 |
uri_to_id(NULL, NS_LS "state-file"), |
uri_to_id(NULL, NS_LS "state-file"), |
167 |
&size, &type, &flags); |
&size, &type, &flags); |
|
|
|
168 |
if (value) { |
if (value) { |
169 |
assert(type == uri_to_id(NULL, LV2_FILES_URI "#AbstractPath")); |
assert(type == uri_to_id(NULL, LV2_STATE_PATH_URI)); |
170 |
const String path = PathFromState((const char*)value); |
const String path((const char*)value); |
171 |
dmsg(2, ("linuxsampler: restoring from file %s\n", path.c_str())); |
dmsg(2, ("linuxsampler: restoring from file %s\n", path.c_str())); |
172 |
std::ifstream in(path.c_str()); |
std::ifstream in(path.c_str()); |
173 |
String state; |
String state; |
176 |
return; |
return; |
177 |
} |
} |
178 |
|
|
179 |
|
// Attempt to restore from state-string |
180 |
value = retrieve( |
value = retrieve( |
181 |
data, |
handle, |
182 |
uri_to_id(NULL, NS_LS "state-string"), |
uri_to_id(NULL, NS_LS "state-string"), |
183 |
&size, &type, &flags); |
&size, &type, &flags); |
184 |
if (value) { |
if (value) { |
220 |
delete static_cast<PluginLv2*>(instance); |
delete static_cast<PluginLv2*>(instance); |
221 |
} |
} |
222 |
|
|
223 |
void save(LV2_Handle handle, LV2_Persist_Store_Function store, void* callback_data) { |
void save(LV2_Handle handle, LV2_State_Store_Function store, LV2_State_Handle state, |
224 |
return static_cast<PluginLv2*>(handle)->Save(store, callback_data); |
uint32_t flags, const LV2_Feature* const* features) { |
225 |
|
return static_cast<PluginLv2*>(handle)->Save(store, state); |
226 |
} |
} |
227 |
|
|
228 |
void restore(LV2_Handle handle, LV2_Persist_Retrieve_Function store, void* callback_data) { |
void restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve, LV2_State_Handle state, |
229 |
return static_cast<PluginLv2*>(handle)->Restore(store, callback_data); |
uint32_t flags, const LV2_Feature* const* features) { |
230 |
|
return static_cast<PluginLv2*>(handle)->Restore(retrieve, state); |
231 |
} |
} |
232 |
|
|
233 |
PluginInfo PluginInfo::Instance; |
PluginInfo PluginInfo::Instance; |
241 |
Lv2.instantiate = instantiate; |
Lv2.instantiate = instantiate; |
242 |
Lv2.run = run; |
Lv2.run = run; |
243 |
Lv2.extension_data = extension_data; |
Lv2.extension_data = extension_data; |
244 |
Persist.save = save; |
StateInterface.save = save; |
245 |
Persist.restore = restore; |
StateInterface.restore = restore; |
246 |
} |
} |
247 |
|
|
248 |
|
|
249 |
const void* extension_data(const char* uri) { |
const void* extension_data(const char* uri) { |
250 |
dmsg(2, ("linuxsampler: extension_data %s\n", uri)); |
dmsg(2, ("linuxsampler: extension_data %s\n", uri)); |
251 |
if (strcmp(uri, LV2_PERSIST_URI) == 0) { |
if (strcmp(uri, LV2_STATE_URI "#Interface") == 0) { |
252 |
return PluginInfo::Lv2PersistDescriptor(); |
return PluginInfo::Lv2StateInterface(); |
253 |
} |
} |
254 |
return 0; |
return 0; |
255 |
} |
} |