3 * Copyright (C) 2021 Jean Pierre Cimalando
4 * Copyright (C) 2021-2024 Filipe Coelho <falktx@falktx.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
19 #ifndef CARLA_JSFX_UTILS_HPP_INCLUDED
20 #define CARLA_JSFX_UTILS_HPP_INCLUDED
22 #include "CarlaBackend.h"
23 #include "CarlaString.hpp"
25 #include "water/files/File.h"
28 # error YSFX_API is not private
30 #include "ysfx/include/ysfx.h"
32 CARLA_BACKEND_START_NAMESPACE
34 // --------------------------------------------------------------------------------------------------------------------
36 struct CarlaJsfxLogging
38 static void logAll(intptr_t, const ysfx_log_level level
, const char* const message
)
43 carla_stdout("%s: %s", ysfx_log_level_string(level
), message
);
45 case ysfx_log_warning
:
46 carla_stderr("%s: %s", ysfx_log_level_string(level
), message
);
49 carla_stderr2("%s: %s", ysfx_log_level_string(level
), message
);
54 static void logErrorsOnly(intptr_t, const ysfx_log_level level
, const char* const message
)
60 case ysfx_log_warning
:
61 carla_stderr("%s: %s", ysfx_log_level_string(level
), message
);
64 carla_stderr2("%s: %s", ysfx_log_level_string(level
), message
);
70 // --------------------------------------------------------------------------------------------------------------------
72 struct CarlaJsfxCategories
74 static PluginCategory
getFromEffect(ysfx_t
* const effect
)
76 PluginCategory category
= PLUGIN_CATEGORY_OTHER
;
78 if (const uint32_t tagCount
= ysfx_get_tags(effect
, nullptr, 0))
80 std::vector
<const char*> tags
;
81 tags
.resize(tagCount
);
82 ysfx_get_tags(effect
, tags
.data(), tagCount
);
84 for (uint32_t i
=0; i
<tagCount
&& category
== PLUGIN_CATEGORY_OTHER
; ++i
)
86 PluginCategory current
= getFromTag(tags
[i
]);
88 if (current
!= PLUGIN_CATEGORY_NONE
)
96 static PluginCategory
getFromTag(const char* const tag
)
98 if (carla_strcasecmp(tag
, "synthesis") == 0)
99 return PLUGIN_CATEGORY_SYNTH
;
101 if (carla_strcasecmp(tag
, "delay") == 0)
102 return PLUGIN_CATEGORY_DELAY
;
104 if (carla_strcasecmp(tag
, "equalizer") == 0)
105 return PLUGIN_CATEGORY_EQ
;
107 if (carla_strcasecmp(tag
, "filter") == 0)
108 return PLUGIN_CATEGORY_FILTER
;
110 if (carla_strcasecmp(tag
, "distortion") == 0)
111 return PLUGIN_CATEGORY_DISTORTION
;
113 if (carla_strcasecmp(tag
, "dynamics") == 0)
114 return PLUGIN_CATEGORY_DYNAMICS
;
116 if (carla_strcasecmp(tag
, "modulation") == 0)
117 return PLUGIN_CATEGORY_MODULATOR
;
119 if (carla_strcasecmp(tag
, "utility") == 0)
120 return PLUGIN_CATEGORY_UTILITY
;
122 return PLUGIN_CATEGORY_NONE
;
126 // --------------------------------------------------------------------------------------------------------------------
130 static CarlaString
createFileId(const water::File
& rootPath
, const water::File
& filePath
)
132 CarlaString
fileId(filePath
.getRelativePathFrom(rootPath
).toRawUTF8());
134 fileId
.replace('\\', '/');
140 CarlaJsfxUnit() noexcept
145 CarlaJsfxUnit(const water::File
& rootPath
, const water::File
& filePath
)
146 : fFileId(createFileId(rootPath
, filePath
)),
147 fFilePath(rootPath
.getChildFile(fFileId
).getFullPathName().toRawUTF8()),
148 fRootPath(rootPath
.getFullPathName().toRawUTF8()) {}
150 explicit operator bool() const noexcept
152 return fFileId
.isNotEmpty();
155 const CarlaString
& getFileId() const noexcept
160 const CarlaString
& getFilePath() const noexcept
165 const CarlaString
& getRootPath() const noexcept
172 CarlaString fFilePath
;
173 CarlaString fRootPath
;
176 // --------------------------------------------------------------------------------------------------------------------
178 CARLA_BACKEND_END_NAMESPACE
180 #endif // CARLA_JSFX_UTILS_HPP_INCLUDED