2018-04-12 16:08:48 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-04-12 16:08:48 +02:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2018-04-12 16:08:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "taisei.h"
|
|
|
|
|
2019-03-05 20:43:01 +01:00
|
|
|
#include "resource.h"
|
2018-04-12 16:08:48 +02:00
|
|
|
#include "bgm.h"
|
2019-03-05 20:43:01 +01:00
|
|
|
#include "audio/backend.h"
|
|
|
|
#include "sfxbgm_common.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2019-03-11 00:21:43 +01:00
|
|
|
static char *bgm_path(const char *name) {
|
2019-03-05 20:43:01 +01:00
|
|
|
return sfxbgm_make_path(BGM_PATH_PREFIX, name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_bgm_path(const char *path) {
|
|
|
|
return sfxbgm_check_path(BGM_PATH_PREFIX, path, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MusicImpl *load_music(const char *path) {
|
|
|
|
if(!path) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _a_backend.funcs.music_load(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *load_bgm_begin(const char *path, uint flags) {
|
|
|
|
Music *mus = calloc(1, sizeof(Music));
|
|
|
|
|
|
|
|
if(strendswith(path, ".bgm")) {
|
2019-03-11 00:21:43 +01:00
|
|
|
char *basename = resource_util_basename(BGM_PATH_PREFIX, path);
|
|
|
|
mus->meta = get_resource_data(RES_BGM_METADATA, basename, flags);
|
|
|
|
free(basename);
|
2019-03-05 20:43:01 +01:00
|
|
|
|
2019-03-11 00:21:43 +01:00
|
|
|
if(mus->meta) {
|
|
|
|
mus->impl = load_music(mus->meta->loop_path);
|
2019-03-05 20:43:01 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mus->impl = load_music(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!mus->impl) {
|
|
|
|
free(mus);
|
|
|
|
mus = NULL;
|
|
|
|
log_error("Failed to load bgm '%s'", path);
|
2019-03-11 00:21:43 +01:00
|
|
|
} else if(mus->meta->loop_point > 0) {
|
|
|
|
_a_backend.funcs.music_set_loop_point(mus->impl, mus->meta->loop_point);
|
2019-03-05 20:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mus;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *load_bgm_end(void *opaque, const char *path, uint flags) {
|
|
|
|
return opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unload_bgm(void *vmus) {
|
|
|
|
Music *mus = vmus;
|
|
|
|
_a_backend.funcs.music_unload(mus->impl);
|
|
|
|
free(mus);
|
|
|
|
}
|
2018-04-12 16:08:48 +02:00
|
|
|
|
|
|
|
ResourceHandler bgm_res_handler = {
|
|
|
|
.type = RES_BGM,
|
|
|
|
.typename = "bgm",
|
|
|
|
.subdir = BGM_PATH_PREFIX,
|
|
|
|
|
|
|
|
.procs = {
|
|
|
|
.find = bgm_path,
|
|
|
|
.check = check_bgm_path,
|
|
|
|
.begin_load = load_bgm_begin,
|
|
|
|
.end_load = load_bgm_end,
|
|
|
|
.unload = unload_bgm,
|
|
|
|
},
|
|
|
|
};
|