Skip to content

Commit

Permalink
Fix #46, add m_DirectMusic->Stop() to `CMusicSys_Bass::PlayThemeByS…
Browse files Browse the repository at this point in the history
…cript` + apply clang-tidy fixes (#51)

* Fix #46, add `m_DirectMusic->Stop()` to `CMusicSys_Bass::PlayThemeByScript` + apply clang-tidy fixes

* Apply clang-tidy fixes to Externals.hpp
  • Loading branch information
piotrmacha authored Oct 19, 2024
1 parent f9e3183 commit 5f4fca5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 44 deletions.
39 changes: 18 additions & 21 deletions src/Gothic/CMusicSys_Bass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace GOTHIC_NAMESPACE
{
namespace BassEvent
{
void Event_OnEnd(const NH::Bass::Event& event, void* userData)
inline void Event_OnEnd(const NH::Bass::Event& event, void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnEnd");

NH::Bass::Event::MusicEnd data = std::get<NH::Bass::Event::MusicEnd>(event.Data);
zSTRING filename{ data.Theme->GetAudioFile(data.AudioId).Filename.c_str() };
zSTRING name{ data.Theme->GetName().c_str() };
auto [theme, audioId] = std::get<NH::Bass::Event::MusicEnd>(event.Data);
const zSTRING filename{theme->GetAudioFile(audioId).Filename.c_str()};
const zSTRING name{theme->GetName().c_str()};
log->Trace("{0}, {1}", name.ToChar(), filename.ToChar());

for (int i = 0; i < Globals->Event_OnEnd_Functions.GetNumInList(); i++)
Expand All @@ -20,14 +20,13 @@ namespace GOTHIC_NAMESPACE
}
}

void Event_OnTransition(const NH::Bass::Event& event, void* userData)
inline void Event_OnTransition(const NH::Bass::Event& event, void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnTransition");

NH::Bass::Event::MusicTransition data = std::get<NH::Bass::Event::MusicTransition>(event.Data);
zSTRING filename{ data.Theme->GetAudioFile(data.AudioId).Filename.c_str() };
zSTRING name{ data.Theme->GetName().c_str() };
float timeLeft = data.TimeLeft;
auto [theme, audioId, timeLeft] = std::get<NH::Bass::Event::MusicTransition>(event.Data);
const zSTRING filename{theme->GetAudioFile(audioId).Filename.c_str()};
const zSTRING name{theme->GetName().c_str()};
log->Trace("{0}, {1}", name.ToChar(), filename.ToChar());

for (int i = 0; i < Globals->Event_OnTransition_Functions.GetNumInList(); i++)
Expand All @@ -39,13 +38,13 @@ namespace GOTHIC_NAMESPACE
}
}

void Event_OnChange(const NH::Bass::Event& event, void* userData)
inline void Event_OnChange(const NH::Bass::Event& event, void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnChange");

NH::Bass::Event::MusicChange data = std::get<NH::Bass::Event::MusicChange>(event.Data);
zSTRING filename{ data.Theme->GetAudioFile(data.AudioId).Filename.c_str() };
zSTRING name{ data.Theme->GetName().c_str() };
const auto [theme, audioId] = std::get<NH::Bass::Event::MusicChange>(event.Data);
const zSTRING filename{theme->GetAudioFile(audioId).Filename.c_str()};
const zSTRING name{ theme->GetName().c_str() };
log->Trace("{0}, {1}", name.ToChar(), filename.ToChar());

Globals->BassMusic_ActiveThemeFilename = filename;
Expand All @@ -61,7 +60,7 @@ namespace GOTHIC_NAMESPACE
}
}

class CMusicSys_Bass : public zCMusicSystem
class CMusicSys_Bass final : public zCMusicSystem
{
private:
NH::Logger* log = NH::CreateLogger("zBassMusic::CMusicSys_Bass");
Expand All @@ -80,7 +79,7 @@ namespace GOTHIC_NAMESPACE

const auto fileLen = static_cast<size_t>(file.Length());
const auto extStart = fileLen - validExt.size();
const std::string_view fileExt{ std::next(file.ToChar(), extStart), validExt.size() };
const std::string_view fileExt{ std::next(file.ToChar(), static_cast<uint32_t>(extStart)), validExt.size() };

auto toLowerSimple = [](const char t_char)
{
Expand Down Expand Up @@ -117,7 +116,7 @@ namespace GOTHIC_NAMESPACE
return m_ActiveTheme;
}

zCMusicTheme* theme = new zCMusicTheme;
auto* theme = new zCMusicTheme;
theme->name = identifier;

if (!(NH::Bass::Options->CreateMainParserCMusicTheme && parser->CreateInstance(identifier, &theme->fileName)))
Expand Down Expand Up @@ -167,6 +166,7 @@ namespace GOTHIC_NAMESPACE
return m_DirectMusic->PlayThemeByScript(id, manipulate, done);
}

m_DirectMusic->Stop();
nowPlaying = identifier;
m_ActiveTheme = nullptr;
m_BassEngine->GetCommandQueue().AddCommand(std::make_shared<NH::Bass::ChangeZoneCommand>(identifier.ToChar()));
Expand All @@ -177,10 +177,7 @@ namespace GOTHIC_NAMESPACE
}
}

void PlayTheme(zCMusicTheme* theme,
float const& volume = zMUS_THEME_VOL_DEFAULT,
zTMus_TransType const& transition = zMUS_TR_DEFAULT,
zTMus_TransSubType const& subTransition = zMUS_TRSUB_DEFAULT) override
void PlayTheme(zCMusicTheme* theme, float const& volume, zTMus_TransType const& transition, zTMus_TransSubType const& subTransition) override
{
log->Trace("PlayTheme: {0}", theme->fileName.ToChar());

Expand Down Expand Up @@ -229,7 +226,7 @@ namespace GOTHIC_NAMESPACE
return m_BassEngine->GetVolume();
}

void SetVolume(float volume) override
void SetVolume(const float volume) override
{
m_BassEngine->SetVolume(volume);
m_DirectMusic->SetVolume(volume);
Expand Down
40 changes: 17 additions & 23 deletions src/Gothic/Externals.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include <thread>
#include <string>
#include <sstream>

namespace GOTHIC_NAMESPACE
{
int BassMusic_Play()
inline int BassMusic_Play()
{
zSTRING id;
parser->GetParameter(id);
Expand All @@ -19,31 +15,31 @@ namespace GOTHIC_NAMESPACE
return 0;
}

int BassMusic_OnEndEvent()
inline int BassMusic_OnEndEvent()
{
int funcId;
parser->GetParameter(funcId);
Globals->Event_OnEnd_Functions.Insert(funcId);
return 0;
}

int BassMusic_OnTransitionEvent()
inline int BassMusic_OnTransitionEvent()
{
int funcId;
parser->GetParameter(funcId);
Globals->Event_OnTransition_Functions.Insert(funcId);
return 0;
}

int BassMusic_OnChangeEvent()
inline int BassMusic_OnChangeEvent()
{
int funcId;
parser->GetParameter(funcId);
Globals->Event_OnChange_Functions.Insert(funcId);
return 0;
}

int BassMusic_SetFullScriptControl()
inline int BassMusic_SetFullScriptControl()
{
int active;
parser->GetParameter(active);
Expand All @@ -55,7 +51,7 @@ namespace GOTHIC_NAMESPACE
return 0;
}

int BassMuisc_Opt_TransitionTime()
inline int BassMusic_Opt_TransitionTime()
{
float time;
parser->GetParameter(time);
Expand All @@ -64,7 +60,7 @@ namespace GOTHIC_NAMESPACE
return 0;
}

int BassMusic_Opt_ForceDisableReverb()
inline int BassMusic_Opt_ForceDisableReverb()
{
int enabled;
parser->GetParameter(enabled);
Expand All @@ -73,7 +69,7 @@ namespace GOTHIC_NAMESPACE
return 0;
}

int BassMusic_Opt_ForceFadeTransition()
inline int BassMusic_Opt_ForceFadeTransition()
{
int enabled;
parser->GetParameter(enabled);
Expand All @@ -83,7 +79,7 @@ namespace GOTHIC_NAMESPACE
}

// func void BassMusic_AddMidiFile(var string theme, var string filter, var midiFilename)
int BassMusic_AddMidiFile()
inline int BassMusic_AddMidiFile()
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::AddMidiFile");

Expand All @@ -92,7 +88,7 @@ namespace GOTHIC_NAMESPACE
parser->GetParameter(filter);
parser->GetParameter(theme);

auto target = NH::Bass::Engine::GetInstance()->GetMusicManager().GetTheme(theme.ToChar());
const auto target = NH::Bass::Engine::GetInstance()->GetMusicManager().GetTheme(theme.ToChar());
if (!target)
{
log->Error("Theme {0} not found", theme.ToChar());
Expand All @@ -104,7 +100,7 @@ namespace GOTHIC_NAMESPACE
}

// func void BassMusic_AddTransitionTimePoint(var string theme, var string filter, var float start, var float duration, var int effect, var float nextStart, var float nextDuration, var int nextEffect)
int BassMusic_AddTransitionTimePoint()
inline int BassMusic_AddTransitionTimePoint()
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::AddTransitionTimePoint");

Expand All @@ -120,24 +116,22 @@ namespace GOTHIC_NAMESPACE
parser->GetParameter(filter);
parser->GetParameter(theme);

auto target = NH::Bass::Engine::GetInstance()->GetMusicManager().GetTheme(theme.ToChar());
const auto target = NH::Bass::Engine::GetInstance()->GetMusicManager().GetTheme(theme.ToChar());
if (!target)
{
log->Error("Theme {0} not found", theme.ToChar());
return 0;
}

NH::Bass::Transition::TimePoint tp { start, duration, (NH::Bass::TransitionEffect)effect, nextStart, nextDuration, (NH::Bass::TransitionEffect)nextEffect };
NH::Bass::Transition::TimePoint tp { start, duration, static_cast<NH::Bass::TransitionEffect>(effect), nextStart, nextDuration, static_cast<NH::Bass::TransitionEffect>(nextEffect) };
target->GetTransitionInfo().AddTimePoint(tp, filter.ToChar());

return 0;
}

// func void BassMusic_AddJingle(var string name, var string filter, var string jingle, var float delay)
int BassMusic_AddJingle()
inline int BassMusic_AddJingle()
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::AddJingle");

zSTRING name, filter, jingle;
float delay;
parser->GetParameter(delay);
Expand All @@ -150,7 +144,7 @@ namespace GOTHIC_NAMESPACE
return 0;
}

void DefineExternalsMusic()
inline void DefineExternalsMusic()
{
parserMusic->AddClassOffset(Globals->BassMusicThemeClassName, sizeof(BassMusicTheme));
parserMusic->AddClassOffset(Globals->BassMusicThemeAudioClassName, sizeof(BassMusicThemeAudio));
Expand All @@ -159,7 +153,7 @@ namespace GOTHIC_NAMESPACE
parserMusic->DefineExternal("BassMusic_AddJingle", BassMusic_AddJingle, zPAR_TYPE_VOID, zPAR_TYPE_STRING, zPAR_TYPE_STRING, zPAR_TYPE_STRING, zPAR_TYPE_FLOAT, zPAR_TYPE_VOID);
}

void DefineExternals()
inline void DefineExternals()
{
parser->DefineExternalVar("BassMusic_ActiveThemeFilename", &Globals->BassMusic_ActiveThemeFilename, zPAR_TYPE_STRING, 1);
parser->DefineExternalVar("BassMusic_ActiveThemeID", &Globals->BassMusic_ActiveThemeID, zPAR_TYPE_STRING, 1);
Expand All @@ -171,7 +165,7 @@ namespace GOTHIC_NAMESPACE
parser->DefineExternal("BassMusic_OnTransitionEvent", BassMusic_OnTransitionEvent, zPAR_TYPE_VOID, zPAR_TYPE_FUNC, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_OnChangeEvent", BassMusic_OnChangeEvent, zPAR_TYPE_VOID, zPAR_TYPE_FUNC, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_SetFullScriptControl", BassMusic_SetFullScriptControl, zPAR_TYPE_VOID, zPAR_TYPE_INT, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_Opt_TransitionTime", BassMuisc_Opt_TransitionTime, zPAR_TYPE_VOID, zPAR_TYPE_FLOAT, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_Opt_TransitionTime", BassMusic_Opt_TransitionTime, zPAR_TYPE_VOID, zPAR_TYPE_FLOAT, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_Opt_ForceDisableReverb", BassMusic_Opt_ForceDisableReverb, zPAR_TYPE_VOID, zPAR_TYPE_INT, zPAR_TYPE_VOID);
parser->DefineExternal("BassMusic_Opt_ForceFadeTransition", BassMusic_Opt_ForceFadeTransition, zPAR_TYPE_VOID, zPAR_TYPE_INT, zPAR_TYPE_VOID);

Expand Down

0 comments on commit 5f4fca5

Please sign in to comment.