|
56 | 56 | #include "types.h" // for device_info |
57 | 57 | #include "utils/color_out.h" // for color_printf, TBOLD, TRED |
58 | 58 | #include "utils/fs.h" // for get_install_root, get_temp_file |
59 | | -#include "utils/macros.h" // for IS_KEY_PREFIX |
| 59 | +#include "utils/macros.h" // for ARR_COUNT, IS_KEY_PREFIX |
60 | 60 |
|
61 | 61 | struct module; |
62 | 62 |
|
@@ -183,40 +183,35 @@ get_soundfont() |
183 | 183 | if (env_fs != NULL) { |
184 | 184 | return strdup(env_fs); |
185 | 185 | } |
186 | | - const bool force_bundled_sf = |
187 | | - getenv("ULTRAGRID_BUNDLED_SF") != NULL && |
188 | | - strcmp(getenv("ULTRAGRID_BUNDLED_SF"), "1") == 0; |
189 | | - const char *roots[2] = { "/usr", get_install_root() }; |
190 | | - if (force_bundled_sf) { |
191 | | - roots[0] = get_install_root(); |
192 | | - roots[1] = "/usr"; |
193 | | - } |
| 186 | + char bundled[MAX_PATH_SIZE]; |
| 187 | + snprintf_ch(bundled, "%s/%s", get_data_path(), "default.sf3"); |
194 | 188 | const char *sf_candidates[] = { |
195 | | - // without install prefix |
196 | | - "/share/soundfonts/default.sf2", |
197 | | - "/share/soundfonts/default.sf3", |
198 | | - "/share/sounds/sf2/default-GM.sf2", |
199 | | - "/share/sounds/sf3/default-GM.sf3", // Ubuntu |
| 189 | + "/usr/share/soundfonts/default.sf2", |
| 190 | + "/usr/share/soundfonts/default.sf3", |
| 191 | + "/usr/share/sounds/sf2/default-GM.sf2", |
| 192 | + "/usr/share/sounds/sf3/default-GM.sf3", // Ubuntu |
| 193 | + bundled, |
200 | 194 | }; |
201 | | - for (size_t i = 0; i < sizeof roots / sizeof roots[0]; ++i) { |
202 | | - for (size_t j = 0; |
203 | | - j < sizeof sf_candidates / sizeof sf_candidates[0]; ++j) { |
204 | | - const char *root = roots[i]; |
205 | | - const size_t len = |
206 | | - strlen(root) + strlen(sf_candidates[j]) + 1; |
207 | | - char path[len]; |
208 | | - strncpy(path, root, len - 1); |
209 | | - strncat(path, sf_candidates[j], len - strlen(path) - 1); |
210 | | - FILE *f = fopen(path, "rb"); |
211 | | - debug_msg(MOD_NAME |
212 | | - "Trying to open sound font '%s': %s\n", |
213 | | - path, f ? "success, setting" : "failed"); |
214 | | - if (!f) { |
215 | | - continue; |
216 | | - } |
217 | | - fclose(f); |
218 | | - return strdup(path); |
| 195 | + |
| 196 | + const char *force_bundled_sf = getenv("ULTRAGRID_BUNDLED_SF"); |
| 197 | + if (force_bundled_sf != NULL && strcmp(force_bundled_sf, "1") == 0) { |
| 198 | + for (size_t i = ARR_COUNT(sf_candidates) - 1; i > 0; --i) { |
| 199 | + sf_candidates[i] = sf_candidates[i - 1]; |
| 200 | + } |
| 201 | + sf_candidates[0] = bundled; |
| 202 | + } |
| 203 | + |
| 204 | + for (size_t i = 0; i < ARR_COUNT(sf_candidates); ++i) { |
| 205 | + const char *path = sf_candidates[i]; |
| 206 | + FILE *f = fopen(path, "rb"); |
| 207 | + debug_msg(MOD_NAME |
| 208 | + "Trying to open sound font '%s': %s\n", |
| 209 | + path, f ? "success, setting" : "failed"); |
| 210 | + if (!f) { |
| 211 | + continue; |
219 | 212 | } |
| 213 | + fclose(f); |
| 214 | + return strdup(path); |
220 | 215 | } |
221 | 216 | MSG(ERROR, "Cannot find any suitable sound font!\n"); |
222 | 217 | return NULL; |
|
0 commit comments