Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jukebox volume slider #402

Merged
merged 11 commits into from
Aug 21, 2023
6 changes: 0 additions & 6 deletions Source/Core/AudioCommon/AudioCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ std::unique_ptr<SoundStream> g_sound_stream;

static bool s_audio_dump_start = false;

// SlippiChange: Added as a hook for the Jukebox to call.
int AudioCommonGetCurrentVolume()
{
return SConfig::GetInstance().m_IsMuted ? 0 : SConfig::GetInstance().m_Volume;
}

namespace AudioCommon
{
static const int AUDIO_VOLUME_MIN = 0;
Expand Down
10 changes: 0 additions & 10 deletions Source/Core/AudioCommon/AudioCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ class CMixer;

extern std::unique_ptr<SoundStream> g_sound_stream;

// SlippiChange: Added as a hook for the Jukebox to call.
//
// I've intentionally kept this outside of the C++ namespace as I am unsure of the risks
// of having this inside there with regards to how Rust receives it.
//
// If someone can prove that it's safe, then feel free to move it back into the namespace
// proper. For now, I've just prefixed the method name with the namespace name
// for grep-ability.
int AudioCommonGetCurrentVolume();

namespace AudioCommon
{
void InitSoundStream(void *hwnd);
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void SConfig::SaveCoreSettings(IniFile &ini)
core->Set("Latency", iLatency);
core->Set("ReduceTimingDispersion", bReduceTimingDispersion);
core->Set("SlippiJukeboxEnabled", bSlippiJukeboxEnabled);
core->Set("SlippiJukeboxVolume", iSlippiJukeboxVolume);
core->Set("SlippiOnlineDelay", m_slippiOnlineDelay);
core->Set("SlippiEnableSpectator", m_enableSpectator);
core->Set("SlippiSpectatorLocalPort", m_spectator_local_port);
Expand Down Expand Up @@ -622,6 +623,7 @@ void SConfig::LoadCoreSettings(IniFile &ini)
core->Get("Latency", &iLatency, 0);
core->Get("ReduceTimingDispersion", &bReduceTimingDispersion, false);
core->Get("SlippiJukeboxEnabled", &bSlippiJukeboxEnabled, true);
core->Get("SlippiJukeboxVolume", &iSlippiJukeboxVolume, 100);
core->Get("SlippiEnableSpectator", &m_enableSpectator, true);
core->Get("SlippiSpectatorLocalPort", &m_spectator_local_port, 51441);
core->Get("SlippiOnlineDelay", &m_slippiOnlineDelay, 2);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ struct SConfig : NonCopyable

bool bReduceTimingDispersion = false;
bool bSlippiJukeboxEnabled = true;
int iSlippiJukeboxVolume = 100;

MeleeLagReductionCode iLagReductionCode = MELEE_LAG_REDUCTION_CODE_UNSET;
bool bHasShownLagReductionWarning = false;
Expand Down
40 changes: 26 additions & 14 deletions Source/Core/Core/HW/EXI_DeviceSlippi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ bool CEXISlippi::shouldAdvanceOnlineFrame(s32 frame)

// 8/8/23: I want to disable forced frame advances for now. I think they're largely unnecessary because of the
// dynamic emulation speed and cause more jarring frame drops.

// if (offsetUs < -t2 && !isCurrentlyAdvancing)
//{
// isCurrentlyAdvancing = true;
Expand Down Expand Up @@ -1692,7 +1692,7 @@ void CEXISlippi::handleCaptureSavestate(u8 *payload)

s32 frame = payload[0] << 24 | payload[1] << 16 | payload[2] << 8 | payload[3];

u64 startTime = Common::Timer::GetTimeUs();
// u64 startTime = Common::Timer::GetTimeUs();

// Grab an available savestate
std::unique_ptr<SlippiSavestate> ss;
Expand All @@ -1719,7 +1719,7 @@ void CEXISlippi::handleCaptureSavestate(u8 *payload)
ss->Capture();
activeSavestates[frame] = std::move(ss);

u32 timeDiff = (u32)(Common::Timer::GetTimeUs() - startTime);
// u32 timeDiff = (u32)(Common::Timer::GetTimeUs() - startTime);
// INFO_LOG(SLIPPI_ONLINE, "SLIPPI ONLINE: Captured savestate for frame %d in: %f ms", frame,
// ((double)timeDiff) / 1000);
}
Expand All @@ -1736,7 +1736,7 @@ void CEXISlippi::handleLoadSavestate(u8 *payload)
return;
}

u64 startTime = Common::Timer::GetTimeUs();
// u64 startTime = Common::Timer::GetTimeUs();

// Fetch preservation blocks
std::vector<SlippiSavestate::PreserveBlock> blocks;
Expand All @@ -1761,7 +1761,7 @@ void CEXISlippi::handleLoadSavestate(u8 *payload)

activeSavestates.clear();

u32 timeDiff = (u32)(Common::Timer::GetTimeUs() - startTime);
// u32 timeDiff = (u32)(Common::Timer::GetTimeUs() - startTime);
// INFO_LOG(SLIPPI_ONLINE, "SLIPPI ONLINE: Loaded savestate for frame %d in: %f ms", frame, ((double)timeDiff) /
// 1000);
}
Expand Down Expand Up @@ -2563,7 +2563,7 @@ void CEXISlippi::setMatchSelections(u8 *payload)

s.stageId = Common::swap16(&payload[4]);
u8 stageSelectOption = payload[6];
u8 onlineMode = payload[7];
// u8 onlineMode = payload[7];

s.isStageSelected = stageSelectOption == 1 || stageSelectOption == 3;
if (stageSelectOption == 3)
Expand Down Expand Up @@ -2714,7 +2714,6 @@ std::vector<u8> CEXISlippi::loadPremadeText(u8 *payload)

void CEXISlippi::preparePremadeTextLength(u8 *payload)
{
u8 textId = payload[0];
std::vector<u8> premadeTextData = loadPremadeText(payload);

m_read_queue.clear();
Expand All @@ -2724,7 +2723,6 @@ void CEXISlippi::preparePremadeTextLength(u8 *payload)

void CEXISlippi::preparePremadeTextLoad(u8 *payload)
{
u8 textId = payload[0];
std::vector<u8> premadeTextData = loadPremadeText(payload);

m_read_queue.clear();
Expand Down Expand Up @@ -2762,7 +2760,6 @@ void CEXISlippi::handleChatMessage(u8 *payload)

if (slippi_netplay)
{

auto userInfo = user->GetUserInfo();
auto packet = std::make_unique<sf::Packet>();
// OSD::AddMessage("[Me]: "+ msg, OSD::Duration::VERY_LONG, OSD::Color::YELLOW);
Expand Down Expand Up @@ -3287,16 +3284,16 @@ void CEXISlippi::DMAWrite(u32 _uAddr, u32 _uSize)
case CMD_PLAY_MUSIC:
{
auto args = SlippiExiTypes::Convert<SlippiExiTypes::PlayMusicQuery>(&memPtr[bufLoc]);
slprs_exi_device_jukebox_play_music(slprs_exi_device_ptr, args.offset, args.size);
slprs_jukebox_start_song(slprs_exi_device_ptr, args.offset, args.size);
break;
}
case CMD_STOP_MUSIC:
slprs_exi_device_jukebox_stop_music(slprs_exi_device_ptr);
slprs_jukebox_stop_music(slprs_exi_device_ptr);
break;
case CMD_CHANGE_MUSIC_VOLUME:
{
auto args = SlippiExiTypes::Convert<SlippiExiTypes::ChangeMusicVolumeQuery>(&memPtr[bufLoc]);
slprs_exi_device_jukebox_set_music_volume(slprs_exi_device_ptr, args.volume);
slprs_jukebox_set_melee_music_volume(slprs_exi_device_ptr, args.volume);
break;
}
default:
Expand Down Expand Up @@ -3346,11 +3343,26 @@ void CEXISlippi::ConfigureJukebox()
}
#endif

slprs_exi_device_configure_jukebox(slprs_exi_device_ptr, SConfig::GetInstance().bSlippiJukeboxEnabled,
AudioCommonGetCurrentVolume);
bool jukeboxEnabled = SConfig::GetInstance().bSlippiJukeboxEnabled;
int systemVolume = SConfig::GetInstance().m_IsMuted ? 0 : SConfig::GetInstance().m_Volume;
int jukeboxVolume = SConfig::GetInstance().iSlippiJukeboxVolume;

slprs_exi_device_configure_jukebox(slprs_exi_device_ptr, jukeboxEnabled, systemVolume, jukeboxVolume);
#endif
}

void CEXISlippi::SetJukeboxDolphinSystemVolume()
{
int systemVolume = SConfig::GetInstance().m_IsMuted ? 0 : SConfig::GetInstance().m_Volume;
slprs_jukebox_set_dolphin_system_volume(slprs_exi_device_ptr, systemVolume);
}

void CEXISlippi::SetJukeboxDolphinMusicVolume()
{
int jukeboxVolume = SConfig::GetInstance().iSlippiJukeboxVolume;
slprs_jukebox_set_dolphin_music_volume(slprs_exi_device_ptr, jukeboxVolume);
}

bool CEXISlippi::IsPresent() const
{
return true;
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/EXI_DeviceSlippi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CEXISlippi : public IEXIDevice
void DMARead(u32 addr, u32 size) override;

void ConfigureJukebox();
void SetJukeboxDolphinSystemVolume();
void SetJukeboxDolphinMusicVolume();

bool IsPresent() const override;

Expand Down
10 changes: 8 additions & 2 deletions Source/Core/Core/Slippi/SlippiReplayComm.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "SlippiReplayComm.h"

#include <cctype>
#include <memory>
#include "SlippiReplayComm.h"

#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/Logging/LogManager.h"
#include "Core/ConfigManager.h"

#include <nlohmann/json.hpp>
using json = nlohmann::json;

std::unique_ptr<SlippiReplayComm> g_replayComm;

// https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
Expand Down Expand Up @@ -86,7 +91,8 @@ void SlippiReplayComm::nextReplay()
if (commFileSettings.queue.empty())
{
#ifdef IS_PLAYBACK
if (!queueWasEmpty) std::cout << "[NO_GAME]" << std::endl;
if (!queueWasEmpty)
std::cout << "[NO_GAME]" << std::endl;
queueWasEmpty = true;
#endif
return;
Expand Down
6 changes: 1 addition & 5 deletions Source/Core/Core/Slippi/SlippiReplayComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <queue>
#include <string>

#include <nlohmann/json.hpp>
using json = nlohmann::json;

class SlippiReplayComm
{
public:
Expand All @@ -29,7 +26,7 @@ class SlippiReplayComm
int endFrame = INT_MAX;
bool outputOverlayFiles;
bool isRealTimeMode;
bool shouldResync; // If true, logic will attempt to resync games
bool shouldResync; // If true, logic will attempt to resync games
std::string rollbackDisplayMethod; // off, normal, visible
std::string commandId;
std::string gameStation;
Expand All @@ -51,7 +48,6 @@ class SlippiReplayComm
std::string getReplayPath();

std::string configFilePath;
json fileData;
std::string previousReplayLoaded;
std::string previousCommandId;
int previousIndex;
Expand Down
Loading