mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-20 11:46:36 +02:00
add sound sfxr loaders
This commit is contained in:
38
framework/sound/src/mm/sound_loader_sfxr.cpp
Normal file
38
framework/sound/src/mm/sound_loader_sfxr.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "./sound_loader_sfxr.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "./soloud_json.hpp"
|
||||
|
||||
#include <mm/services/filesystem.hpp>
|
||||
|
||||
|
||||
namespace MM {
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrPreset::load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const {
|
||||
auto sfxr = std::make_shared<::SoLoud::Sfxr>();
|
||||
sfxr->loadPreset(preset, seed);
|
||||
return sfxr;
|
||||
}
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrJson::load(const nlohmann::json& j) const {
|
||||
auto sfxr = std::make_shared<::SoLoud::Sfxr>();
|
||||
*sfxr = j;
|
||||
return sfxr;
|
||||
}
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrFile::load(const std::string& path, MM::Engine& engine) const {
|
||||
auto& fs = engine.getService<MM::Services::FilesystemService>();
|
||||
|
||||
if (!fs.isFile(path.c_str())) {
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto j = fs.readJson(path.c_str());
|
||||
|
||||
return SoundLoaderSfxrJson{}.load(j);
|
||||
}
|
||||
|
||||
} // MM
|
||||
|
28
framework/sound/src/mm/sound_loader_sfxr.hpp
Normal file
28
framework/sound/src/mm/sound_loader_sfxr.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <soloud_sfxr.h>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
namespace MM {
|
||||
|
||||
// fwd
|
||||
class Engine;
|
||||
|
||||
struct SoundLoaderSfxrPreset {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const;
|
||||
};
|
||||
|
||||
struct SoundLoaderSfxrJson {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const nlohmann::json& j) const;
|
||||
};
|
||||
|
||||
struct SoundLoaderSfxrFile {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const std::string& path, MM::Engine& engine) const;
|
||||
};
|
||||
|
||||
} // MM
|
||||
|
@ -9,8 +9,10 @@ namespace MM {
|
||||
std::shared_ptr<::SoLoud::Wav> SoundLoaderWavFile::load(const std::string& path, Engine& engine) const {
|
||||
auto& fs = engine.getService<Services::FilesystemService>();
|
||||
|
||||
if (!fs.isFile(path.c_str()))
|
||||
if (!fs.isFile(path.c_str())) {
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto h = fs.open(path.c_str());
|
||||
|
||||
@ -19,7 +21,7 @@ std::shared_ptr<::SoLoud::Wav> SoundLoaderWavFile::load(const std::string& path,
|
||||
auto ptr = std::make_shared<::SoLoud::Wav>();
|
||||
auto r = ptr->loadFile(&sl_f);
|
||||
if (r != ::SoLoud::SO_NO_ERROR) {
|
||||
// log error
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user