Skip to content

Commit

Permalink
New option for system-specific background music
Browse files Browse the repository at this point in the history
  • Loading branch information
lbrpdx committed Jun 22, 2019
1 parent b544347 commit 7ede94d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions es-app/src/FileData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void FileData::launchGame(Window* window)

window->init();
VolumeControl::getInstance()->init();
AudioManager::getInstance()->setName(mSystem->getName()); // batocera system-specific music
AudioManager::getInstance()->init(); // batocera
window->normalizeNextUpdate();

Expand Down
8 changes: 8 additions & 0 deletions es-app/src/guis/GuiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,14 @@ void GuiMenu::openSoundSettings_batocera() {
AudioManager::getInstance()->stopMusic();
});

// batocera - music per system
auto music_per_system = std::make_shared<SwitchComponent>(mWindow);
music_per_system->setState(!(SystemConf::getInstance()->get("audio.persystem") == "0"));
s->addWithLabel(_("ONLY PLAY SYSTEM-SPECIFIC MUSIC FOLDER"), music_per_system);
s->addSaveFunc([music_per_system] {
SystemConf::getInstance()->set("audio.persystem", music_per_system->getState() ? "1" : "0");
});

// disable sounds
//auto sounds_enabled = std::make_shared<SwitchComponent>(mWindow);
//sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds"));
Expand Down
11 changes: 11 additions & 0 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ApiSystem.h"
#include "SystemConf.h"
#include "guis/GuiMenu.h"
#include "AudioManager.h"

// buffer values for scrolling velocity (left, stopped, right)
const int logoBuffersLeft[] = { -5, -2, -1 };
Expand Down Expand Up @@ -299,6 +300,16 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
mSystemInfo.setOpacity((unsigned char)(Math::lerp(infoStartOpacity, 0.f, t) * 255));
}, (int)(infoStartOpacity * (goFast ? 10 : 150)));

// batocera - per system music folder
if(SystemConf::getInstance()->get("audio.persystem") == "1" && SystemConf::getInstance()->get("audio.bgmusic") != "0") {
if (getSelected()->isGameSystem()) {
if (AudioManager::getInstance()->getName() != getSelected()->getName()) {
AudioManager::getInstance()->setName(getSelected()->getName());
AudioManager::getInstance()->playRandomMusic(0);
}
}
}

unsigned int gameCount = getSelected()->getDisplayedGameCount();

// also change the text after we've fully faded out
Expand Down
10 changes: 10 additions & 0 deletions es-app/src/views/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "SystemData.h"
#include "Window.h"
#include "guis/GuiDetectDevice.h"
#include "SystemConf.h"
#include "AudioManager.h"

ViewController* ViewController::sInstance = NULL;

Expand Down Expand Up @@ -131,6 +133,14 @@ void ViewController::goToGameList(SystemData* system)
mState.viewing = GAME_LIST;
mState.system = system;

// batocera
if(SystemConf::getInstance()->get("audio.persystem") == "1" && SystemConf::getInstance()->get("audio.bgmusic") != "0") {
if (AudioManager::getInstance()->getName() != system->getName()) {
AudioManager::getInstance()->setName(system->getName());
AudioManager::getInstance()->playRandomMusic(0);
}
}

if (mCurrentView)
{
mCurrentView->onHide();
Expand Down
16 changes: 15 additions & 1 deletion es-core/src/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SDL.h>
#include <unistd.h>
#include "utils/FileSystemUtil.h"
#include "SystemConf.h"

std::vector<std::shared_ptr<Sound>> AudioManager::sSoundVector;
SDL_AudioSpec AudioManager::sAudioFormat;
Expand Down Expand Up @@ -169,10 +170,16 @@ void AudioManager::stop()
SDL_PauseAudio(1);
}

// batocera - per system music folder
void AudioManager::setName(std::string newname) {
mSystem = newname;
}

// batocera
void AudioManager::getMusicIn(const std::string &path, std::vector<std::string>& all_matching_files) {
Utils::FileSystem::stringList dirContent;
std::string extension;
std::string last_path;

if(!Utils::FileSystem::isDirectory(path)) {
return;
Expand All @@ -187,7 +194,14 @@ void AudioManager::getMusicIn(const std::string &path, std::vector<std::string>&
}
} else if(Utils::FileSystem::isDirectory(*it)) {
if(strcmp(extension.c_str(), ".") != 0 && strcmp(extension.c_str(), "..") != 0) {
getMusicIn(*it, all_matching_files);
// batocera - if music_per_system
last_path = it->substr(it->find_last_of("/") + 1);
if (SystemConf::getInstance()->get("audio.persystem") != "1") {
getMusicIn(*it, all_matching_files);
}
else if (strcmp(getName().c_str(), last_path.c_str()) == 0) {
getMusicIn(*it, all_matching_files);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion es-core/src/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <vector>
#include "SDL_mixer.h"
#include <string> // batocera

class Sound;

Expand All @@ -22,6 +23,7 @@ class AudioManager
static Mix_Music* currentMusic; // batocera
void getMusicIn(const std::string &path, std::vector<std::string>& all_matching_files); // batocera
static void musicEnd_callback(); // batocera
std::string mSystem = ""; // batocera (per system music folder)

public:
static std::shared_ptr<AudioManager> & getInstance();
Expand All @@ -38,7 +40,9 @@ class AudioManager
// batocera
void playRandomMusic(bool continueIfPlaying = true);
void stopMusic();

inline const std::string getName() const { return mSystem; }
void setName(std::string name);

virtual ~AudioManager();
};

Expand Down

0 comments on commit 7ede94d

Please sign in to comment.