project64/Source/Project64-audio/AudioSettings.cpp

191 lines
8.3 KiB
C++
Raw Normal View History

/****************************************************************************
2017-09-11 11:57:21 +00:00
* *
* Project64-audio - A Nintendo 64 audio plugin. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2017 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
2017-09-14 08:07:12 +00:00
#include <Settings/Settings.h>
#include <Project64-audio/trace.h>
#include "SettingsID.h"
#include "AudioSettings.h"
2017-09-14 08:07:12 +00:00
CSettings * g_settings = NULL;
2017-09-14 08:07:12 +00:00
CSettings::CSettings() :
2018-12-20 10:19:14 +00:00
m_Set_SyncViaAudioEnabled(0),
2017-09-14 08:07:12 +00:00
m_Set_EnableAudio(0),
2018-11-26 22:51:47 +00:00
m_Set_FixedAudio(0),
2017-09-28 11:43:58 +00:00
m_Set_SyncAudio(0),
m_Set_FullSpeed(0),
m_Set_LimitFPS(0),
2017-09-14 08:07:12 +00:00
m_Set_basic_mode(0),
m_Set_debugger(0),
m_Set_log_dir(0),
m_Set_log_flush(0),
m_FlushLogs(false),
m_AudioEnabled(true),
m_advanced_options(false),
2017-09-25 12:00:04 +00:00
m_debugger_enabled(false),
m_Volume(100),
2017-10-13 00:57:24 +00:00
m_TinyBuffer(true),
2017-10-13 00:58:35 +00:00
m_FPSBuffer(true),
2018-11-26 22:51:47 +00:00
m_FixedAudio(false),
2017-09-28 11:43:58 +00:00
m_SyncAudio(false),
m_FullSpeed(true)
{
2017-09-14 08:07:12 +00:00
memset(m_log_dir, 0, sizeof(m_log_dir));
RegisterSettings();
ReadSettings();
2017-09-25 12:00:04 +00:00
if (m_Set_EnableAudio != 0) { SettingsRegisterChange(true, m_Set_EnableAudio, this, stSettingsChanged); }
if (m_Set_basic_mode != 0) { SettingsRegisterChange(true, m_Set_basic_mode, this, stSettingsChanged); }
if (m_Set_debugger != 0) { SettingsRegisterChange(true, m_Set_debugger, this, stSettingsChanged); }
if (m_Set_log_flush != 0) { SettingsRegisterChange(true, m_Set_log_flush, this, stSettingsChanged); }
2018-11-26 22:51:47 +00:00
if (m_Set_FixedAudio != 0) { SettingsRegisterChange(true, m_Set_FixedAudio, this, stSettingsChanged); }
2017-09-28 11:43:58 +00:00
if (m_Set_SyncAudio != 0) { SettingsRegisterChange(true, m_Set_SyncAudio, this, stSettingsChanged); }
if (m_Set_FullSpeed != 0) { SettingsRegisterChange(true, m_Set_FullSpeed, this, stSettingsChanged); }
if (m_Set_LimitFPS != 0) { SettingsRegisterChange(true, m_Set_LimitFPS, this, stSettingsChanged); }
2017-09-25 12:00:04 +00:00
SettingsRegisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsRegisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Path, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_InitShutdown, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Interface, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Driver, this, stLogLevelChanged);
2017-09-14 08:07:12 +00:00
}
CSettings::~CSettings()
{
if (m_Set_EnableAudio != 0) { SettingsUnregisterChange(true, m_Set_EnableAudio, this, stSettingsChanged); }
if (m_Set_basic_mode != 0) { SettingsUnregisterChange(true, m_Set_basic_mode, this, stSettingsChanged); }
if (m_Set_debugger != 0) { SettingsUnregisterChange(true, m_Set_debugger, this, stSettingsChanged); }
if (m_Set_log_flush != 0) { SettingsUnregisterChange(true, m_Set_log_flush, this, stSettingsChanged); }
2018-11-26 22:51:47 +00:00
if (m_Set_FixedAudio != 0) { SettingsUnregisterChange(true, m_Set_FixedAudio, this, stSettingsChanged); }
2017-09-28 11:43:58 +00:00
if (m_Set_SyncAudio != 0) { SettingsUnregisterChange(true, m_Set_SyncAudio, this, stSettingsChanged); }
if (m_Set_FullSpeed != 0) { SettingsUnregisterChange(true, m_Set_FullSpeed, this, stSettingsChanged); }
if (m_Set_LimitFPS != 0) { SettingsUnregisterChange(true, m_Set_LimitFPS, this, stSettingsChanged); }
2017-09-25 12:00:04 +00:00
SettingsUnregisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsUnregisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Path, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_InitShutdown, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Interface, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Driver, this, stLogLevelChanged);
2017-09-14 08:07:12 +00:00
}
void CSettings::RegisterSettings(void)
{
SetModuleName("default");
2018-12-20 10:19:14 +00:00
m_Set_SyncViaAudioEnabled = FindSystemSettingId("SyncViaAudioEnabled");
m_Set_EnableAudio = FindSystemSettingId("Enable Audio");
2018-11-26 22:51:47 +00:00
m_Set_FixedAudio = FindSystemSettingId("Fixed Audio");
2017-09-28 11:43:58 +00:00
m_Set_SyncAudio = FindSystemSettingId("Sync Audio");
m_Set_FullSpeed = FindSystemSettingId("Full Speed");
m_Set_LimitFPS = FindSystemSettingId("Limit FPS");
2017-09-14 08:07:12 +00:00
m_Set_basic_mode = FindSystemSettingId("Basic Mode");
m_Set_debugger = FindSystemSettingId("Debugger");
m_Set_log_flush = FindSystemSettingId("Log Auto Flush");
m_Set_log_dir = FindSystemSettingId("Dir:Log");
2017-09-26 20:55:53 +00:00
SetModuleName("Audio");
2017-09-25 12:00:04 +00:00
RegisterSetting(Set_Volume, Data_DWORD_General, "Volume", "Settings", 100, NULL);
2017-09-14 08:07:12 +00:00
RegisterSetting(Set_Logging_MD5, Data_DWORD_General, "MD5", "Logging", g_ModuleLogLevel[TraceMD5], NULL);
RegisterSetting(Set_Logging_Thread, Data_DWORD_General, "Thread", "Logging", g_ModuleLogLevel[TraceThread], NULL);
RegisterSetting(Set_Logging_Path, Data_DWORD_General, "Path", "Logging", g_ModuleLogLevel[TracePath], NULL);
RegisterSetting(Set_Logging_InitShutdown, Data_DWORD_General, "InitShutdown", "Logging", g_ModuleLogLevel[TraceAudioInitShutdown], NULL);
RegisterSetting(Set_Logging_Interface, Data_DWORD_General, "Interface", "Logging", g_ModuleLogLevel[TraceAudioInterface], NULL);
RegisterSetting(Set_Logging_Driver, Data_DWORD_General, "Driver", "Logging", g_ModuleLogLevel[TraceAudioDriver], NULL);
2017-10-13 00:57:24 +00:00
RegisterSetting(Set_TinyBuffer, Data_DWORD_Game, "TinyBuffer", "", (bool)true, NULL);
2017-10-13 00:58:35 +00:00
RegisterSetting(Set_FPSBuffer, Data_DWORD_Game, "FPSBuffer", "", (bool)true, NULL);
2017-09-14 08:07:12 +00:00
LogLevelChanged();
}
2018-12-20 10:19:14 +00:00
void CSettings::SetSyncViaAudioEnabled(bool Enabled)
{
if (m_Set_SyncViaAudioEnabled != 0)
{
SetSystemSetting(m_Set_SyncViaAudioEnabled, Enabled ? 1 : 0);
}
}
2017-09-25 12:00:04 +00:00
void CSettings::SetAudioEnabled(bool Enabled)
2017-09-14 08:07:12 +00:00
{
2017-09-25 12:00:04 +00:00
if (m_Set_EnableAudio != 0)
{
SetSystemSetting(m_Set_EnableAudio, Enabled ? 1 : 0);
}
}
2017-09-14 08:07:12 +00:00
2017-09-25 12:00:04 +00:00
void CSettings::SetVolume(uint32_t Volume)
{
if (m_Set_EnableAudio != 0)
2017-09-14 08:07:12 +00:00
{
2017-09-25 12:00:04 +00:00
SetSetting(Set_Volume, Volume);
2017-09-14 08:07:12 +00:00
}
}
2017-10-13 00:57:24 +00:00
void CSettings::SetTinyBuffer(bool TinyBuffer)
{
2017-10-13 00:58:35 +00:00
SetSetting(Set_TinyBuffer, TinyBuffer ? 1 : 0);
}
2017-10-13 00:57:24 +00:00
void CSettings::SetFPSBuffer(bool FPSBuffer)
{
2017-10-13 00:58:35 +00:00
SetSetting(Set_FPSBuffer, FPSBuffer ? 1 : 0);
}
2017-09-14 08:07:12 +00:00
void CSettings::LogLevelChanged(void)
{
g_ModuleLogLevel[TraceMD5] = GetSetting(Set_Logging_MD5);
g_ModuleLogLevel[TraceThread] = GetSetting(Set_Logging_Thread);
g_ModuleLogLevel[TracePath] = GetSetting(Set_Logging_Path);
g_ModuleLogLevel[TraceAudioInitShutdown] = GetSetting(Set_Logging_InitShutdown);
g_ModuleLogLevel[TraceAudioInterface] = GetSetting(Set_Logging_Interface);
g_ModuleLogLevel[TraceAudioDriver] = GetSetting(Set_Logging_Driver);
}
void CSettings::ReadSettings(void)
2017-09-25 12:00:04 +00:00
{
bool SyncAudio = m_Set_SyncAudio ? GetSystemSetting(m_Set_SyncAudio) != 0 : false;
bool bLimitFPS = m_Set_LimitFPS ? GetSystemSetting(m_Set_LimitFPS) != 0 : true;
2017-09-25 12:00:04 +00:00
m_Volume = GetSetting(Set_Volume);
m_AudioEnabled = m_Set_EnableAudio ? GetSystemSetting(m_Set_EnableAudio) != 0 : true;
m_advanced_options = m_Set_basic_mode ? GetSystemSetting(m_Set_basic_mode) == 0 : false;
m_debugger_enabled = m_advanced_options && m_Set_debugger ? GetSystemSetting(m_Set_debugger) == 1 : false;
2017-10-13 00:57:24 +00:00
m_TinyBuffer = GetSetting(Set_TinyBuffer) != 0;
2017-10-13 00:58:35 +00:00
m_FPSBuffer = GetSetting(Set_FPSBuffer) != 0;
2017-09-28 11:43:58 +00:00
m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false;
2017-09-25 12:00:04 +00:00
m_SyncAudio = ((!m_advanced_options || bLimitFPS) && SyncAudio && m_FullSpeed);
2017-09-25 12:00:04 +00:00
if (m_Set_log_dir != 0)
{
GetSystemSettingSz(m_Set_log_dir, m_log_dir, sizeof(m_log_dir));
}
m_FlushLogs = m_Set_log_flush != 0 ? GetSystemSetting(m_Set_log_flush) != 0 : false;
}
void SetupAudioSettings(void)
{
2017-09-14 08:07:12 +00:00
if (g_settings == NULL)
{
g_settings = new CSettings;
}
}
void CleanupAudioSettings(void)
{
if (g_settings)
{
2017-09-14 08:07:12 +00:00
delete g_settings;
g_settings = NULL;
}
2017-10-13 00:57:24 +00:00
}