libopenmpt_plugin_settings.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * libopenmpt_plugin_settings.hpp
  3. * ------------------------------
  4. * Purpose: libopenmpt plugin settings
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #ifndef LIBOPENMPT_PLUGIN_SETTINGS_HPP
  10. #define LIBOPENMPT_PLUGIN_SETTINGS_HPP
  11. #ifndef NOMINMAX
  12. #define NOMINMAX
  13. #endif
  14. #include <windows.h>
  15. #include <string>
  16. namespace libopenmpt {
  17. namespace plugin {
  18. typedef void (*changed_func)();
  19. struct libopenmpt_settings {
  20. bool no_default_format = true;
  21. int samplerate = 48000;
  22. int channels = 2;
  23. int mastergain_millibel = 0;
  24. int stereoseparation = 100;
  25. int use_amiga_resampler = 0;
  26. int amiga_filter_type = 0;
  27. int repeatcount = 0;
  28. int interpolationfilterlength = 8;
  29. int ramping = -1;
  30. int vis_allow_scroll = 1;
  31. changed_func changed = nullptr;
  32. };
  33. class settings : public libopenmpt_settings {
  34. private:
  35. std::basic_string<TCHAR> subkey;
  36. protected:
  37. virtual void read_setting( const std::string & /* key */ , const std::basic_string<TCHAR> & key, int & val ) {
  38. HKEY regkey = HKEY();
  39. if ( RegOpenKeyEx( HKEY_CURRENT_USER, ( TEXT("Software\\libopenmpt\\") + subkey ).c_str(), 0, KEY_READ, &regkey ) == ERROR_SUCCESS ) {
  40. DWORD v = val;
  41. DWORD type = REG_DWORD;
  42. DWORD typesize = sizeof(v);
  43. if ( RegQueryValueEx( regkey, key.c_str(), NULL, &type, (BYTE *)&v, &typesize ) == ERROR_SUCCESS )
  44. {
  45. val = v;
  46. }
  47. RegCloseKey( regkey );
  48. regkey = HKEY();
  49. }
  50. }
  51. virtual void write_setting( const std::string & /* key */, const std::basic_string<TCHAR> & key, int val ) {
  52. HKEY regkey = HKEY();
  53. if ( RegCreateKeyEx( HKEY_CURRENT_USER, ( TEXT("Software\\libopenmpt\\") + subkey ).c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &regkey, NULL ) == ERROR_SUCCESS ) {
  54. DWORD v = val;
  55. DWORD type = REG_DWORD;
  56. DWORD typesize = sizeof(v);
  57. if ( RegSetValueEx( regkey, key.c_str(), 0, type, (const BYTE *)&v, typesize ) == ERROR_SUCCESS )
  58. {
  59. // ok
  60. }
  61. RegCloseKey( regkey );
  62. regkey = HKEY();
  63. }
  64. }
  65. public:
  66. settings( const std::basic_string<TCHAR> & subkey, bool no_default_format_ )
  67. : subkey(subkey)
  68. {
  69. no_default_format = no_default_format_;
  70. }
  71. void load()
  72. {
  73. #ifdef UNICODE
  74. #define read_setting(a,b,c) read_setting( b , L ## b , c)
  75. #else
  76. #define read_setting(a,b,c) read_setting( b , b , c)
  77. #endif
  78. read_setting( subkey, "Samplerate_Hz", samplerate );
  79. read_setting( subkey, "Channels", channels );
  80. read_setting( subkey, "MasterGain_milliBel", mastergain_millibel );
  81. read_setting( subkey, "StereoSeparation_Percent", stereoseparation );
  82. read_setting( subkey, "RepeatCount", repeatcount );
  83. read_setting( subkey, "InterpolationFilterLength", interpolationfilterlength );
  84. read_setting( subkey, "UseAmigaResampler", use_amiga_resampler );
  85. read_setting( subkey, "AmigaFilterType", amiga_filter_type );
  86. read_setting( subkey, "VolumeRampingStrength", ramping );
  87. read_setting( subkey, "VisAllowScroll", vis_allow_scroll );
  88. #undef read_setting
  89. }
  90. void save()
  91. {
  92. #ifdef UNICODE
  93. #define write_setting(a,b,c) write_setting( b , L ## b , c)
  94. #else
  95. #define write_setting(a,b,c) write_setting( b , b , c)
  96. #endif
  97. write_setting( subkey, "Samplerate_Hz", samplerate );
  98. write_setting( subkey, "Channels", channels );
  99. write_setting( subkey, "MasterGain_milliBel", mastergain_millibel );
  100. write_setting( subkey, "StereoSeparation_Percent", stereoseparation );
  101. write_setting( subkey, "RepeatCount", repeatcount );
  102. write_setting( subkey, "InterpolationFilterLength", interpolationfilterlength );
  103. write_setting( subkey, "UseAmigaResampler", use_amiga_resampler );
  104. write_setting( subkey, "AmigaFilterType", amiga_filter_type );
  105. write_setting( subkey, "VolumeRampingStrength", ramping );
  106. write_setting( subkey, "VisAllowScroll", vis_allow_scroll );
  107. #undef write_setting
  108. }
  109. virtual ~settings()
  110. {
  111. return;
  112. }
  113. };
  114. } // namespace plugin
  115. } // namespace libopenmpt
  116. #endif // LIBOPENMPT_PLUGIN_SETTINGS_HPP