Load a bank.json and all wav files referenced in it.
Deserialize Mixers. Don't initialize anything yet
51 const
char* encoded = path;
56 VAE_DEBUG(
"Started loading bank %s", path)
62 json.append("bank.json");
63 fs::
File file(json.c_str());
64 jsonText.resize(file.size());
65 if (!file.readAll(jsonText.data())) {
67 return
Result::FileOpenError;
69 length = jsonText.size();
70 encoded = jsonText.c_str();
75 json_settings settings = { };
82 json = json_parse_ex(&settings, encoded, length, 0);
85 json_value& data = (*json);
87 bank.name = (
const char*) data[
"name"];
88 bank.id = (json_int_t) data[
"id"];
94 auto sources = data[
"sources"];
95 if (sources.type == json_array) {
97 bank.sources.resize(sources.u.array.length);
98 for (auto& iraw : sources.u.array) {
104 String asd = (
const char*) i[
"name"];
106 Source& s = bank.sources[id];
108 VAE_ERROR(
"Duplicate Source id %i in bank %i", s.id, bank.id)
109 return
Result::BankFormatDuplicateIndex;
112 s.name = (const
char*) i["name"];
113 s.path = (const
char*) i["path"];
115 if (i["gain"].type == json_double) s.gain = (
double) i["gain"];
116 if (i["resample"].type == json_boolean) s.resample = i["resample"];
117 if (i["stream"].type == json_boolean) s.stream = i["stream"];
126 VAE_ERROR(
"Failed to load source %s", s.path.c_str())
134 auto mixers = data[
"mixers"];
135 if (mixers.type == json_array) {
137 bank.mixers.resize(mixers.u.array.length);
138 for (auto& iraw : mixers.u.array) {
143 if (mixers.u.array.length <=
id) {
144 VAE_ERROR(
"Mixer %i:%i id out of bounds.",
id, bank.id);
148 auto& m = bank.mixers[id];
151 VAE_ERROR(
"Duplicate Mixer id %i in bank %i", m.id, bank.id)
152 return
Result::BankFormatDuplicateIndex;
155 m.name = (const
char*) i["name"];
158 if (i["parent"].type == json_integer) m.parent = (json_int_t) i["parent"];
159 if (i["gain"].type == json_double) m.gain = (
double) i["gain"];
161 if (m.
id != Mixer::MasterMixerHandle && m.
id <= m.parent) {
164 VAE_ERROR(
"Mixer %i:%i tried to mix to %i. ",
id, bank.id, m.parent);
168 auto effects = i[
"effects"];
169 if (effects.type != json_array || effects.u.array.length == 0) {
continue; }
172 for (
auto& iraw : effects.u.array) {
175 json_int_t index = i[
"index"];
176 auto& e = m.effects[index];
177 e.bypassed = i[
"bypassed"];
181 for (
auto& j : i[
"parameters"].u.array) {
183 e.parameters[paramIndex].name = (
const char*) (*j)[0];
184 e.parameters[paramIndex].value = (double) (*j)[1];
191 auto events = data[
"events"];
194 bank.events.resize(events.u.array.length);
195 for (auto& iraw : events.u.array) {
199 if (events.u.array.length <=
id) {
200 VAE_ERROR(
"Event %i:%i id out of bounds.",
id, bank.id)
201 return
Result::BankFormatIndexError;
204 Event& e = bank.events[
id];
207 VAE_ERROR(
"Duplicate Event id %i in bank %i", e.id, bank.id)
208 return
Result::BankFormatDuplicateIndex;
212 e.name = (const
char*) i["name"];
220 if (i[
"force_mixer"].type == json_boolean) e.force_mixer = i[
"force_mixer"];
221 if (i[
"spatial"].type == json_boolean) e.spatial = i[
"spatial"];
222 if (i[
"critical"].type == json_boolean) e.critical = i[
"critical"];
223 if (i[
"loop"].type == json_boolean) e.loop = i[
"loop"];
224 if (i[
"hrtf"].type == json_boolean) e.HRTF = i[
"hrtf"];
225 if (i[
"attenuate"].type == json_boolean) e.attenuate = i[
"attenuate"];
226 if (i[
"mixer"].type == json_integer) e.mixer = (json_int_t) i[
"mixer"];
227 if (i[
"gain"].type == json_double) e.gain = (double) i[
"gain"];
228 if (i[
"source"].type == json_integer) e.source = (json_int_t) i[
"source"];
229 if (i[
"on_end"].type == json_integer) e.on_end = (json_int_t) i[
"on_end"];
231 if (i[
"chained_events"].type == json_array) {
232 auto onStart = i[
"chained_events"].u.array;
234 VAE_ERROR(
"Event %i:%i has too many chained chained_events events.",
id, bank.id)
235 return
Result::TooManyRecords;
237 for (
size_t j = 0; j < onStart.length; j++) {
238 e.chained_events[j] = (json_int_t) (*onStart.values[j]);
245 json_value_free_ex(&settings, json);
SourceLoader mSourceLoader
static void * allocate(size_t size, int zero, void *context)
static void deallocate(void *ptr, void *context)
constexpr Size MaxChainedEvents
How many chained events can fit in chain_events on the core::Event structure.
tklb::StackString< 16 > IdString
Non optional string used to id things.
tklb::String< HeapBuffer< char > > PathString
Non optional string used for locations, maybe replaceable with a unique_ptr or something.
constexpr SourceHandle InvalidSourceHandle
constexpr EventHandle InvalidEventHandle
GenericHandle EventHandle
The handle used to address events within a bank.
Result
Return Types for most engine functions.
@ BankFormatError
Generic bank loading error.
@ BankFormatBadMixHirarchy
A mixer can only write to mixers with lower ids than themselves (no recursion)
@ BankFormatIndexError
A index is out of bounds.
GenericHandle SourceHandle
constexpr MixerHandle InvalidMixerHandle
HeapBuffer< char > String
@ random
triggers one random chained_events event
@ emit
Emits an event to the EventCallback defined in the engine config.
@ start
Starts a source if defined and every Event in chained_events.
@ stop
Stops a source if defined and stops every voice started from a event in chained_events.
@ ogg
Uses stb_vorbis to decode oggs.
@ wav
Uses dr_wav to decode wavs.
@ generator
Not implemented.
Result load(Source &s, const char *path)
Loads a wav file for the resource.
#define VAE_ERROR(msg,...)
#define VAE_DEBUG(msg,...)
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_PROFILER_SCOPE()
Profiles a scope.