/[svn]/linuxsampler/trunk/src/hostplugins/lv2/PluginLv2.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/hostplugins/lv2/PluginLv2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2303 by capela, Thu Nov 24 17:00:29 2011 UTC revision 2304 by schoenebeck, Wed Jan 18 01:32:26 2012 UTC
# Line 42  namespace { Line 42  namespace {
42          MapPath = 0;          MapPath = 0;
43          MakePath = 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: init 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_STATE_MAP_PATH_URI)) {              } else if (!strcmp(Features[i]->URI, LV2_STATE_MAP_PATH_URI)) {
# Line 104  namespace { Line 104  namespace {
104    
105      String PluginLv2::PathToState(const String& path) {      String PluginLv2::PathToState(const String& path) {
106          if (MapPath) {          if (MapPath) {
107                  char* cstr = MapPath->abstract_path(MapPath->handle,              char* cstr = MapPath->abstract_path(MapPath->handle, path.c_str());
                                                 path.c_str());  
108              const String abstract_path(cstr);              const String abstract_path(cstr);
109              free(cstr);              free(cstr);
110              return abstract_path;              return abstract_path;
# Line 115  namespace { Line 114  namespace {
114    
115      String PluginLv2::PathFromState(const String& path) {      String PluginLv2::PathFromState(const String& path) {
116          if (MapPath) {          if (MapPath) {
117                  char* cstr = MapPath->absolute_path(MapPath->handle,              char* cstr = MapPath->absolute_path(MapPath->handle, path.c_str());
                                                 path.c_str());  
118              const String abstract_path(cstr);              const String abstract_path(cstr);
119              free(cstr);              free(cstr);
120              return abstract_path;              return abstract_path;
# Line 124  namespace { Line 122  namespace {
122          return path;          return path;
123      }      }
124    
125      void PluginLv2::Save(LV2_State_Store_Function store, LV2_State_Handle handle) {      void PluginLv2::SetStateFeatures(const LV2_Feature* const* Features)
126          if (MakePath) {      {
127                  char* path = MakePath->path(MapPath->handle,          for (int i = 0 ; Features[i] ; i++) {
128                                              "linuxsampler");              dmsg(2, ("linuxsampler: state feature: %s\n", Features[i]->URI));
129              dmsg(2, ("saving to file %s\n", path));              if (!strcmp(Features[i]->URI, LV2_STATE_MAP_PATH_URI)) {
130                    MapPath = (LV2_State_Map_Path*)Features[i]->data;
131                } else if (!strcmp(Features[i]->URI, LV2_STATE_MAKE_PATH_URI)) {
132                    MakePath = (LV2_State_Make_Path*)Features[i]->data;
133                }
134            }
135        }
136    
137              std::ofstream out(path);      void PluginLv2::Save(LV2_State_Store_Function store, LV2_State_Handle handle,
138                             uint32_t flags, const LV2_Feature* const* features)
139        {
140            LV2_State_Map_Path*  OldMapPath  = MapPath;
141            LV2_State_Make_Path* OldMakePath = MakePath;
142            SetStateFeatures(features);
143    
144            if (MakePath && MapPath) {
145                char* abs_path = MakePath->path(MakePath->handle, "linuxsampler");
146                dmsg(2, ("saving to file %s\n", abs_path));
147    
148                std::ofstream out(abs_path);
149              out << GetState();              out << GetState();
150    
151                char* path = MapPath->abstract_path(MapPath->handle, abs_path);
152    
153              store(handle,              store(handle,
154                    uri_to_id(NULL, NS_LS "state-file"),                    uri_to_id(NULL, NS_LS "state-file"),
155                    path,                    path,
156                    strlen(path) + 1,                    strlen(path) + 1,
157                    uri_to_id(NULL, LV2_STATE_PATH_URI),                    uri_to_id(NULL, LV2_STATE_PATH_URI),
158                    LV2_STATE_IS_PORTABLE);                    LV2_STATE_IS_PORTABLE);
159    
160                free(path);
161                free(abs_path);
162          } else {          } else {
163              dmsg(2, ("saving to string\n"));              dmsg(2, ("saving to string\n"));
164    
# Line 153  namespace { Line 173  namespace {
173                    LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);                    LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
174          }          }
175          dmsg(2, ("saving done\n"));          dmsg(2, ("saving done\n"));
176    
177            MapPath  = OldMapPath;
178            MakePath = OldMakePath;
179      }      }
180    
181      void PluginLv2::Restore(LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle) {      void PluginLv2::Restore(LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle,
182                                uint32_t rflags, const LV2_Feature* const* features)
183        {
184            LV2_State_Map_Path*  OldMapPath  = MapPath;
185            LV2_State_Make_Path* OldMakePath = MakePath;
186            SetStateFeatures(features);
187    
188          size_t   size;          size_t   size;
189          uint32_t type;          uint32_t type;
190          uint32_t flags;          uint32_t flags;
# Line 192  namespace { Line 221  namespace {
221          // No valid state found, reset to default state          // No valid state found, reset to default state
222          dmsg(2, ("linuxsampler: restoring default state\n"));          dmsg(2, ("linuxsampler: restoring default state\n"));
223          SetState(DefaultState);          SetState(DefaultState);
224    
225            MapPath  = OldMapPath;
226            MakePath = OldMakePath;
227      }      }
228    
229      LV2_Handle instantiate(const LV2_Descriptor* descriptor,      LV2_Handle instantiate(const LV2_Descriptor* descriptor,
# Line 220  namespace { Line 252  namespace {
252          delete static_cast<PluginLv2*>(instance);          delete static_cast<PluginLv2*>(instance);
253      }      }
254    
255      void save(LV2_Handle handle, LV2_State_Store_Function store, LV2_State_Handle state,      void save(LV2_Handle handle, LV2_State_Store_Function store,
256                  LV2_State_Handle state,
257                uint32_t flags, const LV2_Feature* const* features) {                uint32_t flags, const LV2_Feature* const* features) {
258          return static_cast<PluginLv2*>(handle)->Save(store, state);          return static_cast<PluginLv2*>(handle)->Save(
259                store, state, flags, features);
260      }      }
261    
262      void restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve, LV2_State_Handle state,      void restore(LV2_Handle handle, LV2_State_Retrieve_Function retrieve,
263                     LV2_State_Handle state,
264                   uint32_t flags, const LV2_Feature* const* features) {                   uint32_t flags, const LV2_Feature* const* features) {
265          return static_cast<PluginLv2*>(handle)->Restore(retrieve, state);          return static_cast<PluginLv2*>(handle)->Restore(
266                retrieve, state, flags, features);
267      }      }
268    
269      PluginInfo PluginInfo::Instance;      PluginInfo PluginInfo::Instance;

Legend:
Removed from v.2303  
changed lines
  Added in v.2304

  ViewVC Help
Powered by ViewVC