Skip to content

Commit

Permalink
ysfx: add api for finding imported files
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Dec 18, 2024
1 parent f550aef commit 4c2922b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions exports/ysfx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ysfx_get_input_name
ysfx_get_output_name
ysfx_wants_meters
ysfx_get_gfx_dim
ysfx_resolve_path_and_allocate
ysfx_free_resolved_path
ysfx_has_section
ysfx_slider_exists
ysfx_slider_get_name
Expand Down
6 changes: 5 additions & 1 deletion include/ysfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ YSFX_API const char *ysfx_get_output_name(ysfx_t *fx, uint32_t index);
YSFX_API bool ysfx_wants_meters(ysfx_t *fx);
// get requested dimensions of the graphics area; 0 means host should decide
YSFX_API bool ysfx_get_gfx_dim(ysfx_t *fx, uint32_t dim[2]);
// resolve an import path; note that this returns a char* string that needs to be freed with ysfx_free_resolved_path after use
YSFX_API char *ysfx_resolve_path_and_allocate(ysfx_t* fx, const char* name, const char* origin);
// free a path returned by ysfx_resolve_path_and_allocate
YSFX_API void ysfx_free_resolved_path(char *path);


typedef enum ysfx_section_type_e {
ysfx_section_init = 1,
Expand Down Expand Up @@ -246,7 +251,6 @@ YSFX_API ysfx_real ysfx_normalized_to_ysfx_value(ysfx_real value, const ysfx_sli
// convert normalized slider value to ysfx value taking into account curve shape
YSFX_API ysfx_real ysfx_ysfx_value_to_normalized(ysfx_real value, const ysfx_slider_curve_t *curve);


typedef enum ysfx_compile_option_e {
// skip compiling the @serialize section
ysfx_compile_no_serialize = 1 << 0,
Expand Down
23 changes: 23 additions & 0 deletions sources/ysfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,29 @@ const char *ysfx_get_file_path(ysfx_t *fx)
return fx->source.main_file_path.c_str();
}

char *ysfx_resolve_path_and_allocate(ysfx_t* fx, const char* name, const char* origin)
{
if (!fx) return nullptr;
std::string result = ysfx_resolve_import_path(fx, std::string(name), std::string{origin});

if (result.empty()) return nullptr;

char* cPath = static_cast<char*>(malloc(result.size() + 1));
if (cPath) {
strcpy(cPath, result.c_str());
} else {
return nullptr;
}

return cPath;
}

void ysfx_free_resolved_path(char *path)
{
free(path);
path = nullptr;
}

const char *ysfx_get_author(ysfx_t *fx)
{
ysfx_source_unit_t *main = fx->source.main.get();
Expand Down

0 comments on commit 4c2922b

Please sign in to comment.