Add BGM channel framework and setup audio event system.
This commit is contained in:
@@ -40,6 +40,47 @@ All rights reserved.
|
||||
#include "DEFINES.h"
|
||||
|
||||
INCLUDE_game
|
||||
INCLUDE_DATA
|
||||
|
||||
void Audio::Initialize(){
|
||||
Audio&instance=game->audioEngine;
|
||||
for(auto&[key,data]:DATA["Events"]){
|
||||
instance.events.insert(key);
|
||||
}
|
||||
for(auto&[songName,data]:DATA["BGM"]){
|
||||
int channelCounter=0;
|
||||
|
||||
BGM&bgm=instance.bgm[songName];
|
||||
|
||||
bgm.SetName(data["Track Name"].GetString());
|
||||
|
||||
while(data.HasProperty(std::format("channel[{}]",channelCounter))){
|
||||
bgm.AddChannel(data[std::format("channel[{}]",channelCounter)].GetString());
|
||||
channelCounter++;
|
||||
}
|
||||
|
||||
if(!data.HasProperty("Default Volume"))ERR(std::format("WARNING! Track {} does not have a Default Volume parameter!",bgm.GetName()));
|
||||
if(data["Default Volume"].GetValueCount()!=bgm.GetChannelCount())ERR(std::format("WARNING! Default Volume parameters do not match channel count. {} != {}",data["Default Volume"].GetValueCount(),bgm.GetChannelCount()));
|
||||
|
||||
VolumeList volumes;
|
||||
for(int i=0;i<data["Default Volume"].GetValueCount();i++){
|
||||
volumes.push_back(data["Default Volume"].GetInt(i));
|
||||
}
|
||||
bgm.AddEventVolumes("Default Volume",volumes);
|
||||
|
||||
if(data.HasProperty("Fade Time"))bgm.SetFadeTime(data["Fade Time"].GetReal());
|
||||
|
||||
if(data.HasProperty("Events")){
|
||||
for(auto&[eventName,data]:DATA["Events"]){
|
||||
VolumeList volumes;
|
||||
for(int i=0;i<data.GetValueCount();i++){
|
||||
volumes.push_back(data.GetInt(i));
|
||||
}
|
||||
bgm.AddEventVolumes(eventName,volumes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MiniAudio&Audio::Engine(){
|
||||
return game->audioEngine.audioEngine;
|
||||
@@ -52,6 +93,38 @@ void Audio::PlayBGM(const std::string_view sound,const bool loop=true){
|
||||
Engine().Play(std::string(sound));
|
||||
};
|
||||
|
||||
void Audio::BGM::SetFadeTime(const float fadeTime){
|
||||
this->fadeTime=fadeTime;
|
||||
}
|
||||
|
||||
void Audio::BGM::AddEventVolumes(const Event&eventName,const VolumeList&volumes){
|
||||
eventVolumes.AddEventInfo(eventName,volumes);
|
||||
}
|
||||
|
||||
const size_t Audio::BGM::GetChannelCount()const{
|
||||
return channelNames.size();
|
||||
}
|
||||
|
||||
const SongName&Audio::BGM::GetName()const{
|
||||
return songName;
|
||||
}
|
||||
|
||||
void Audio::BGM::SetName(std::string_view name){
|
||||
songName=name;
|
||||
}
|
||||
void Audio::BGM::AddChannel(const ChannelName&name){
|
||||
channelNames.push_back(name);
|
||||
}
|
||||
|
||||
const VolumeList&Audio::EventData::GetVolumes(const Event&event)const{
|
||||
if(eventInfo.find(event)!=eventInfo.end())return eventInfo.at(event);
|
||||
return eventInfo.at("Default Volume");
|
||||
}
|
||||
|
||||
void Audio::EventData::AddEventInfo(const Event&eventName,const VolumeList&volumes){
|
||||
eventInfo[eventName]=volumes;
|
||||
}
|
||||
|
||||
std::string operator""_SFX(const char*key,size_t length){
|
||||
return "sfx_directory"_S+std::string(key,length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user