-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from SpaceYoshi/soundHandler
Implemented SoundHandler, which is a singleton class
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Docs used to create this file: https://learn.microsoft.com/en-us/previous-versions/dd743680(v=vs.85) | ||
*/ | ||
|
||
|
||
#include "SoundHandler.h" | ||
|
||
#include <Windows.h> | ||
#include <Mmsystem.h> | ||
|
||
#pragma comment (lib, "winmm.lib") | ||
|
||
// From: https://stackoverflow.com/a/62762272/23283336 | ||
std::wstring SoundHandler::convertToLCPWSTR(const std::string& s) | ||
{ | ||
const int slength = static_cast<int>(s.length()) + 1; | ||
const int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); | ||
wchar_t* buf = new wchar_t[len]; | ||
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); | ||
std::wstring r(buf); | ||
delete[] buf; | ||
return r; | ||
} | ||
|
||
void SoundHandler::playSoundSnippet(const std::string& fileName) | ||
{ | ||
PlaySound(convertToLCPWSTR(fileName).c_str(), 0, SND_FILENAME | SND_ASYNC); | ||
} | ||
|
||
void SoundHandler::forceStopSound() | ||
{ | ||
PlaySound(NULL, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include "easylogging++.h" | ||
|
||
class SoundHandler | ||
{ | ||
private: | ||
SoundHandler() = default; | ||
~SoundHandler() = default; | ||
|
||
SoundHandler(const SoundHandler&) = delete; | ||
SoundHandler& operator=(const SoundHandler&) = delete; | ||
|
||
|
||
static std::wstring convertToLCPWSTR(const std::string& s); | ||
public: | ||
static SoundHandler& getInstance() { | ||
static SoundHandler instance; | ||
return instance; | ||
} | ||
|
||
static void playSoundSnippet(const std::string& fileName); | ||
static void forceStopSound(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.