Merge pull request #303 from jpcima/map-path
lv2: add state path mapping
This commit is contained in:
commit
b32eb0caf8
3 changed files with 95 additions and 14 deletions
101
lv2/sfizz.c
101
lv2/sfizz.c
|
|
@ -179,6 +179,20 @@ enum
|
||||||
SFIZZ_STRETCH_TUNING = 11,
|
SFIZZ_STRETCH_TUNING = 11,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
sfizz_lv2_state_free_path(LV2_State_Free_Path_Handle handle,
|
||||||
|
char *path)
|
||||||
|
{
|
||||||
|
(void)handle;
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LV2_State_Free_Path sfizz_State_Free_Path =
|
||||||
|
{
|
||||||
|
.handle = NULL,
|
||||||
|
.free_path = &sfizz_lv2_state_free_path,
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sfizz_lv2_map_required_uris(sfizz_plugin_t *self)
|
sfizz_lv2_map_required_uris(sfizz_plugin_t *self)
|
||||||
{
|
{
|
||||||
|
|
@ -911,9 +925,18 @@ restore(LV2_Handle instance,
|
||||||
const LV2_Feature *const *features)
|
const LV2_Feature *const *features)
|
||||||
{
|
{
|
||||||
UNUSED(flags);
|
UNUSED(flags);
|
||||||
UNUSED(features);
|
|
||||||
sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
|
sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
|
||||||
|
|
||||||
|
LV2_State_Map_Path *map_path = NULL;
|
||||||
|
LV2_State_Free_Path *free_path = &sfizz_State_Free_Path;
|
||||||
|
for (const LV2_Feature *const *f = features; *f; ++f)
|
||||||
|
{
|
||||||
|
if (!strcmp((*f)->URI, LV2_STATE__mapPath))
|
||||||
|
map_path = (LV2_State_Map_Path *)(**f).data;
|
||||||
|
else if (!strcmp((*f)->URI, LV2_STATE__freePath))
|
||||||
|
free_path = (LV2_State_Free_Path *)(**f).data;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch back the saved file path, if any
|
// Fetch back the saved file path, if any
|
||||||
size_t size;
|
size_t size;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
|
|
@ -922,24 +945,46 @@ restore(LV2_Handle instance,
|
||||||
value = retrieve(handle, self->sfizz_sfz_file_uri, &size, &type, &val_flags);
|
value = retrieve(handle, self->sfizz_sfz_file_uri, &size, &type, &val_flags);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
lv2_log_note(&self->logger, "[sfizz] Restoring the file %s\n", (const char *)value);
|
const char *path = (const char *)value;
|
||||||
sfizz_lv2_load_file(instance, (const char *)value);
|
if (map_path)
|
||||||
|
{
|
||||||
|
path = map_path->absolute_path(map_path->handle, path);
|
||||||
|
if (!path)
|
||||||
|
return LV2_STATE_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv2_log_note(&self->logger, "[sfizz] Restoring the file %s\n", path);
|
||||||
|
sfizz_lv2_load_file(instance, path);
|
||||||
|
|
||||||
|
if (map_path)
|
||||||
|
free_path->free_path(free_path->handle, (char *)path);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = retrieve(handle, self->sfizz_scala_file_uri, &size, &type, &val_flags);
|
value = retrieve(handle, self->sfizz_scala_file_uri, &size, &type, &val_flags);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
if (sfizz_load_scala_file(self->synth, (const char *)value))
|
const char *path = (const char *)value;
|
||||||
|
if (map_path)
|
||||||
|
{
|
||||||
|
path = map_path->absolute_path(map_path->handle, path);
|
||||||
|
if (!path)
|
||||||
|
return LV2_STATE_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sfizz_load_scala_file(self->synth, path))
|
||||||
{
|
{
|
||||||
lv2_log_note(&self->logger,
|
lv2_log_note(&self->logger,
|
||||||
"[sfizz] Restoring the scale %s\n", (const char *)value);
|
"[sfizz] Restoring the scale %s\n", path);
|
||||||
strcpy(self->scala_file_path, (const char *)value);
|
strcpy(self->scala_file_path, path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lv2_log_error(&self->logger,
|
lv2_log_error(&self->logger,
|
||||||
"[sfizz] Error while restoring the scale %s\n", (const char *)value);
|
"[sfizz] Error while restoring the scale %s\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map_path)
|
||||||
|
free_path->free_path(free_path->handle, (char *)path);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = retrieve(handle, self->sfizz_num_voices_uri, &size, &type, &val_flags);
|
value = retrieve(handle, self->sfizz_num_voices_uri, &size, &type, &val_flags);
|
||||||
|
|
@ -988,23 +1033,55 @@ save(LV2_Handle instance,
|
||||||
const LV2_Feature *const *features)
|
const LV2_Feature *const *features)
|
||||||
{
|
{
|
||||||
UNUSED(flags);
|
UNUSED(flags);
|
||||||
UNUSED(features);
|
|
||||||
sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
|
sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
|
||||||
|
|
||||||
|
LV2_State_Map_Path *map_path = NULL;
|
||||||
|
LV2_State_Free_Path *free_path = &sfizz_State_Free_Path;
|
||||||
|
for (const LV2_Feature *const *f = features; *f; ++f)
|
||||||
|
{
|
||||||
|
if (!strcmp((*f)->URI, LV2_STATE__mapPath))
|
||||||
|
map_path = (LV2_State_Map_Path *)(**f).data;
|
||||||
|
else if (!strcmp((*f)->URI, LV2_STATE__freePath))
|
||||||
|
free_path = (LV2_State_Free_Path *)(**f).data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *path;
|
||||||
|
|
||||||
// Save the file path
|
// Save the file path
|
||||||
|
path = self->sfz_file_path;
|
||||||
|
if (map_path)
|
||||||
|
{
|
||||||
|
path = map_path->abstract_path(map_path->handle, path);
|
||||||
|
if (!path)
|
||||||
|
return LV2_STATE_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
store(handle,
|
store(handle,
|
||||||
self->sfizz_sfz_file_uri,
|
self->sfizz_sfz_file_uri,
|
||||||
self->sfz_file_path,
|
path,
|
||||||
strlen(self->sfz_file_path) + 1,
|
strlen(path) + 1,
|
||||||
self->atom_path_uri,
|
self->atom_path_uri,
|
||||||
LV2_STATE_IS_POD);
|
LV2_STATE_IS_POD);
|
||||||
|
if (map_path)
|
||||||
|
free_path->free_path(free_path->handle, (char *)path);
|
||||||
|
|
||||||
// Save the scala file path
|
// Save the scala file path
|
||||||
|
path = self->scala_file_path;
|
||||||
|
if (map_path)
|
||||||
|
{
|
||||||
|
path = map_path->abstract_path(map_path->handle, path);
|
||||||
|
if (!path)
|
||||||
|
return LV2_STATE_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
if (!path)
|
||||||
|
return LV2_STATE_ERR_UNKNOWN;
|
||||||
store(handle,
|
store(handle,
|
||||||
self->sfizz_scala_file_uri,
|
self->sfizz_scala_file_uri,
|
||||||
self->scala_file_path,
|
path,
|
||||||
strlen(self->scala_file_path) + 1,
|
strlen(path) + 1,
|
||||||
self->atom_path_uri,
|
self->atom_path_uri,
|
||||||
LV2_STATE_IS_POD);
|
LV2_STATE_IS_POD);
|
||||||
|
if (map_path)
|
||||||
|
free_path->free_path(free_path->handle, (char *)path);
|
||||||
|
|
||||||
// Save the number of voices
|
// Save the number of voices
|
||||||
store(handle,
|
store(handle,
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ midnam:update a lv2:Feature .
|
||||||
lv2:microVersion @LV2PLUGIN_VERSION_MICRO@ ;
|
lv2:microVersion @LV2PLUGIN_VERSION_MICRO@ ;
|
||||||
|
|
||||||
lv2:requiredFeature urid:map, bufsize:boundedBlockLength, work:schedule ;
|
lv2:requiredFeature urid:map, bufsize:boundedBlockLength, work:schedule ;
|
||||||
lv2:optionalFeature lv2:hardRTCapable, opts:options ;
|
lv2:optionalFeature lv2:hardRTCapable, opts:options, state:mapPath, state:freePath ;
|
||||||
lv2:extensionData opts:interface, state:interface, work:interface ;
|
lv2:extensionData opts:interface, state:interface, work:interface ;
|
||||||
|
|
||||||
lv2:optionalFeature midnam:update ;
|
lv2:optionalFeature midnam:update ;
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,11 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
|
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
|
||||||
parser.parseFile(file);
|
|
||||||
|
std::error_code ec;
|
||||||
|
fs::path realFile = fs::canonical(file, ec);
|
||||||
|
|
||||||
|
parser.parseFile(ec ? file : realFile);
|
||||||
if (parser.getErrorCount() > 0)
|
if (parser.getErrorCount() > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue