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);
|
|
|
|
}
|
|
|
|
|
2020-06-09 02:01:53 +02:00
|
|
|
static void load_bgm(ResourceLoadState *st) {
|
2019-03-05 20:43:01 +01:00
|
|
|
Music *mus = calloc(1, sizeof(Music));
|
|
|
|
|
2020-06-09 02:01:53 +02:00
|
|
|
if(strendswith(st->path, ".bgm")) {
|
|
|
|
mus->meta = get_resource_data(RES_BGM_METADATA, st->name, st->flags);
|
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 {
|
2020-06-09 02:01:53 +02:00
|
|
|
mus->impl = load_music(st->path);
|
2019-03-05 20:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!mus->impl) {
|
|
|
|
free(mus);
|
|
|
|
mus = NULL;
|
2020-06-09 02:01:53 +02:00
|
|
|
log_error("Failed to load bgm '%s'", st->path);
|
|
|
|
res_load_failed(st);
|
|
|
|
} else {
|
|
|
|
if(mus->meta && 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
|
|
|
|
2020-06-09 02:01:53 +02:00
|
|
|
res_load_finished(st, mus);
|
|
|
|
}
|
2019-03-05 20:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-06-09 02:01:53 +02:00
|
|
|
.load = load_bgm,
|
2018-04-12 16:08:48 +02:00
|
|
|
.unload = unload_bgm,
|
|
|
|
},
|
|
|
|
};
|