Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -8,11 +8,16 @@
8 8
 #pragma once
9 9
 
10 10
 #include <memory>
11
-#include "XSFPlayer.h"
11
+#include <string>
12
+#include <type_traits>
13
+#include <vector>
12 14
 #include "DialogBuilder.h"
13 15
 #include "convert.h"
14 16
 #include "windowsh_wrapper.h"
15
-#include <windowsx.h>
17
+
18
+enum class PeakType;
19
+enum class VolumeType;
20
+class XSFPlayer;
16 21
 
17 22
 class XSFConfigIO
18 23
 {
... ...
@@ -28,11 +33,11 @@ private:
28 33
 	}
29 34
 
30 35
 	// non-enum versions
31
-	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> &&std::is_arithmetic_v<T>, T> GetValueInternal(const std::string &name, const T &defaultValue) const
36
+	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> && std::is_arithmetic_v<T>, T> GetValueInternal(const std::string &name, const T &defaultValue) const
32 37
 	{
33 38
 		return convertTo<T>(this->GetValueString(name, std::to_string(defaultValue)));
34 39
 	}
35
-	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> &&std::is_arithmetic_v<T>> SetValueInternal(const std::string &name, const T &value)
40
+	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> && std::is_arithmetic_v<T>> SetValueInternal(const std::string &name, const T &value)
36 41
 	{
37 42
 		this->SetValueString(name, std::to_string(value));
38 43
 	}
Browse code

A few more conversion changes:

* To go along with the previous change, XSFConfig now had internal get/set value functions that use type traits to choose between the enum and non-enum versions. (This also means I do not need to manually double-cast enums now.)
* Fix bug with the Windows API string conversions, so they do not include the trailing null byte in the output string.
* Added function to trim trailing 0s (and the decimal point if necessary) from a string that came from a double.

Naram Qashat authored on 2021/03/19 14:27:11
Showing 1 changed files
... ...
@@ -16,6 +16,26 @@
16 16
 
17 17
 class XSFConfigIO
18 18
 {
19
+private:
20
+	// enum versions
21
+	template<typename T> typename std::enable_if_t<std::is_enum_v<T>, T> GetValueInternal(const std::string &name, const T &defaultValue) const
22
+	{
23
+		return convertTo<T>(this->GetValueString(name, std::to_string(static_cast<std::underlying_type_t<T>>(defaultValue))));
24
+	}
25
+	template<typename T> typename std::enable_if_t<std::is_enum_v<T>> SetValueInternal(const std::string &name, const T &value)
26
+	{
27
+		this->SetValueString(name, std::to_string(static_cast<std::underlying_type_t<T>>(value)));
28
+	}
29
+
30
+	// non-enum versions
31
+	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> &&std::is_arithmetic_v<T>, T> GetValueInternal(const std::string &name, const T &defaultValue) const
32
+	{
33
+		return convertTo<T>(this->GetValueString(name, std::to_string(defaultValue)));
34
+	}
35
+	template<typename T> typename std::enable_if_t<!std::is_enum_v<T> &&std::is_arithmetic_v<T>> SetValueInternal(const std::string &name, const T &value)
36
+	{
37
+		this->SetValueString(name, std::to_string(value));
38
+	}
19 39
 protected:
20 40
 	XSFConfigIO() { }
21 41
 public:
... ...
@@ -24,10 +44,10 @@ public:
24 44
 
25 45
 	virtual ~XSFConfigIO() { }
26 46
 	virtual void SetValueString(const std::string &name, const std::string &value) = 0;
27
-	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueString(name, std::to_string(value)); }
47
+	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueInternal(name, value); }
28 48
 	void SetValue(const std::string &name, const std::string &value) { this->SetValueString(name, value); }
29 49
 	virtual std::string GetValueString(const std::string &name, const std::string &defaultValue) const = 0;
30
-	template<typename T> T GetValue(const std::string &name, const T &defaultValue) const { return convertTo<T>(this->GetValueString(name, std::to_string(defaultValue))); }
50
+	template<typename T> T GetValue(const std::string &name, const T &defaultValue) const { return this->GetValueInternal(name, defaultValue); }
31 51
 	std::string GetValue(const std::string &name, const std::string &defaultValue) const { return this->GetValueString(name, defaultValue); }
32 52
 	virtual void SetHInstance(HINSTANCE) { }
33 53
 	virtual HINSTANCE GetHInstance() const { return nullptr; }
Browse code

Some conversion replacements:

* Replace the (w)stringify functions with the standard std::to_(w)string functions.
* Replace convertTo with versions that use type_traits to determine which standard string conversion function to call, as well as handle enums specically.

Naram Qashat authored on 2021/03/19 11:57:21
Showing 1 changed files
... ...
@@ -24,10 +24,10 @@ public:
24 24
 
25 25
 	virtual ~XSFConfigIO() { }
26 26
 	virtual void SetValueString(const std::string &name, const std::string &value) = 0;
27
-	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueString(name, stringify(value)); }
27
+	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueString(name, std::to_string(value)); }
28 28
 	void SetValue(const std::string &name, const std::string &value) { this->SetValueString(name, value); }
29 29
 	virtual std::string GetValueString(const std::string &name, const std::string &defaultValue) const = 0;
30
-	template<typename T> T GetValue(const std::string &name, const T &defaultValue) const { return convertTo<T>(this->GetValueString(name, stringify(defaultValue))); }
30
+	template<typename T> T GetValue(const std::string &name, const T &defaultValue) const { return convertTo<T>(this->GetValueString(name, std::to_string(defaultValue))); }
31 31
 	std::string GetValue(const std::string &name, const std::string &defaultValue) const { return this->GetValueString(name, defaultValue); }
32 32
 	virtual void SetHInstance(HINSTANCE) { }
33 33
 	virtual HINSTANCE GetHInstance() const { return nullptr; }
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-05
5 4
  *
6 5
  * Partially based on the vio*sf framework
7 6
  */
Browse code

[NCSF] Fix volume issues with a little help from the Nintendo DS SDK.

Also added a clone of DeSmuME's Sound View that is only build during a
debug build, which helped to identify the above issues.

Naram Qashat authored on 2014/10/05 20:00:09
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
4
+ * Last modification on 2014-10-05
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -27,9 +27,11 @@ public:
27 27
 	virtual void SetValueString(const std::string &name, const std::string &value) = 0;
28 28
 	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueString(name, stringify(value)); }
29 29
 	void SetValue(const std::string &name, const std::string &value) { this->SetValueString(name, value); }
30
-	virtual std::string GetValueString(const std::string &name, const std::string &defaultValue) = 0;
31
-	template<typename T> T GetValue(const std::string &name, const T &defaultValue) { return convertTo<T>(this->GetValueString(name, stringify(defaultValue))); }
32
-	std::string GetValue(const std::string &name, const std::string &defaultValue) { return this->GetValueString(name, defaultValue); }
30
+	virtual std::string GetValueString(const std::string &name, const std::string &defaultValue) const = 0;
31
+	template<typename T> T GetValue(const std::string &name, const T &defaultValue) const { return convertTo<T>(this->GetValueString(name, stringify(defaultValue))); }
32
+	std::string GetValue(const std::string &name, const std::string &defaultValue) const { return this->GetValueString(name, defaultValue); }
33
+	virtual void SetHInstance(HINSTANCE) { }
34
+	virtual HINSTANCE GetHInstance() const { return nullptr; }
33 35
 };
34 36
 
35 37
 class XSFConfig
... ...
@@ -81,6 +83,8 @@ public:
81 83
 	void ResetConfigDefaults(HWND hwndDlg);
82 84
 	void SaveConfigDialog(HWND hwndDlg);
83 85
 	void CopyConfigToMemory(XSFPlayer *xSFPlayer, bool preLoad);
86
+	void SetHInstance(HINSTANCE hInstance);
87
+	HINSTANCE GetHInstance() const;
84 88
 
85 89
 	virtual void About(HWND parent) = 0;
86 90
 
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-08
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -24,12 +24,12 @@ public:
24 24
 	static XSFConfigIO *Create();
25 25
 
26 26
 	virtual ~XSFConfigIO() { }
27
-	virtual void SetValueString(const std::wstring &name, const std::wstring &value) = 0;
28
-	template<typename T> void SetValue(const std::wstring &name, const T &value) { this->SetValueString(name, wstringify(value)); }
29
-	void SetValue(const std::wstring &name, const std::wstring &value) { this->SetValueString(name, value); }
30
-	virtual std::wstring GetValueString(const std::wstring &name, const std::wstring &defaultValue) = 0;
31
-	template<typename T> T GetValue(const std::wstring &name, const T &defaultValue) { return convertTo<T>(this->GetValueString(name, wstringify(defaultValue))); }
32
-	std::wstring GetValue(const std::wstring &name, const std::wstring &defaultValue) { return this->GetValueString(name, defaultValue); }
27
+	virtual void SetValueString(const std::string &name, const std::string &value) = 0;
28
+	template<typename T> void SetValue(const std::string &name, const T &value) { this->SetValueString(name, stringify(value)); }
29
+	void SetValue(const std::string &name, const std::string &value) { this->SetValueString(name, value); }
30
+	virtual std::string GetValueString(const std::string &name, const std::string &defaultValue) = 0;
31
+	template<typename T> T GetValue(const std::string &name, const T &defaultValue) { return convertTo<T>(this->GetValueString(name, stringify(defaultValue))); }
32
+	std::string GetValue(const std::string &name, const std::string &defaultValue) { return this->GetValueString(name, defaultValue); }
33 33
 };
34 34
 
35 35
 class XSFConfig
... ...
@@ -41,7 +41,7 @@ protected:
41 41
 	VolumeType volumeType;
42 42
 	PeakType peakType;
43 43
 	unsigned sampleRate;
44
-	std::wstring titleFormat;
44
+	std::string titleFormat;
45 45
 	DialogTemplate configDialog, configDialogProperty, infoDialog;
46 46
 	std::vector<unsigned> supportedSampleRates;
47 47
 	std::unique_ptr<XSFConfigIO> configIO;
... ...
@@ -58,17 +58,17 @@ protected:
58 58
 	virtual void CopySpecificConfigToMemory(XSFPlayer *xSFPlayer, bool preLoad) = 0;
59 59
 public:
60 60
 	static bool initPlayInfinitely;
61
-	static std::wstring initSkipSilenceOnStartSec, initDetectSilenceSec, initDefaultLength, initDefaultFade, initTitleFormat;
61
+	static std::string initSkipSilenceOnStartSec, initDetectSilenceSec, initDefaultLength, initDefaultFade, initTitleFormat;
62 62
 	static double initVolume;
63 63
 	static VolumeType initVolumeType;
64 64
 	static PeakType initPeakType;
65 65
 	// These are not defined in XSFConfig.cpp, they should be defined in your own config's source.
66 66
 	static unsigned initSampleRate;
67
-	static std::wstring commonName;
68
-	static std::wstring versionNumber;
67
+	static std::string commonName;
68
+	static std::string versionNumber;
69 69
 	// The Create function is not defined in XSFConfig.cpp, it should be defined in your own config's source and return a pointer to your config's class.
70 70
 	static XSFConfig *Create();
71
-	static const String &CommonNameWithVersion();
71
+	static const std::string &CommonNameWithVersion();
72 72
 
73 73
 	virtual ~XSFConfig() { }
74 74
 	void LoadConfig();
... ...
@@ -92,5 +92,5 @@ public:
92 92
 	double GetVolume() const;
93 93
 	VolumeType GetVolumeType() const;
94 94
 	PeakType GetPeakType() const;
95
-	const std::wstring &GetTitleFormat() const;
95
+	const std::string &GetTitleFormat() const;
96 96
 };
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -1,13 +1,12 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-02
4
+ * Last modification on 2014-09-08
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
8 8
 
9
-#ifndef XSFCONFIG_H
10
-#define XSFCONFIG_H
9
+#pragma once
11 10
 
12 11
 #include <memory>
13 12
 #include "XSFPlayer.h"
... ...
@@ -95,5 +94,3 @@ public:
95 94
 	PeakType GetPeakType() const;
96 95
 	const std::wstring &GetTitleFormat() const;
97 96
 };
98
-
99
-#endif
Browse code

Added new interpolation methods, added version number in plugin description.

Naram Qashat authored on 2013/04/02 22:40:32
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-30
4
+ * Last modification on 2013-04-02
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -69,6 +69,7 @@ public:
69 69
 	static std::wstring versionNumber;
70 70
 	// The Create function is not defined in XSFConfig.cpp, it should be defined in your own config's source and return a pointer to your config's class.
71 71
 	static XSFConfig *Create();
72
+	static const String &CommonNameWithVersion();
72 73
 
73 74
 	virtual ~XSFConfig() { }
74 75
 	void LoadConfig();
Browse code

Cleanup of some warnings, updating modification dates, using nullptr instead of NULL in some cases.

Naram Qashat authored on 2013/03/30 16:17:42
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Core configuration handler
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-25
4
+ * Last modification on 2013-03-30
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
Browse code

Utilized more C++11 constructs. Also attempted to fix issue with the Info Box not wanting to come up anymore if the file doesn't exist.

Naram Qashat authored on 2013/03/30 07:36:38
Showing 1 changed files
... ...
@@ -45,7 +45,7 @@ protected:
45 45
 	std::wstring titleFormat;
46 46
 	DialogTemplate configDialog, configDialogProperty, infoDialog;
47 47
 	std::vector<unsigned> supportedSampleRates;
48
-	std::auto_ptr<XSFConfigIO> configIO;
48
+	std::unique_ptr<XSFConfigIO> configIO;
49 49
 
50 50
 	XSFConfig();
51 51
 	std::wstring GetTextFromWindow(HWND hwnd);
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,98 @@
1
+/*
2
+ * xSF - Core configuration handler
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Partially based on the vio*sf framework
7
+ */
8
+
9
+#ifndef XSFCONFIG_H
10
+#define XSFCONFIG_H
11
+
12
+#include <memory>
13
+#include "XSFPlayer.h"
14
+#include "DialogBuilder.h"
15
+#include "convert.h"
16
+#include "windowsh_wrapper.h"
17
+#include <windowsx.h>
18
+
19
+class XSFConfigIO
20
+{
21
+protected:
22
+	XSFConfigIO() { }
23
+public:
24
+	// This is not defined in XSFConfig.cpp, it should be defined in your own config's source and return a pointer to your config's I/O class.
25
+	static XSFConfigIO *Create();
26
+
27
+	virtual ~XSFConfigIO() { }
28
+	virtual void SetValueString(const std::wstring &name, const std::wstring &value) = 0;
29
+	template<typename T> void SetValue(const std::wstring &name, const T &value) { this->SetValueString(name, wstringify(value)); }
30
+	void SetValue(const std::wstring &name, const std::wstring &value) { this->SetValueString(name, value); }
31
+	virtual std::wstring GetValueString(const std::wstring &name, const std::wstring &defaultValue) = 0;
32
+	template<typename T> T GetValue(const std::wstring &name, const T &defaultValue) { return convertTo<T>(this->GetValueString(name, wstringify(defaultValue))); }
33
+	std::wstring GetValue(const std::wstring &name, const std::wstring &defaultValue) { return this->GetValueString(name, defaultValue); }
34
+};
35
+
36
+class XSFConfig
37
+{
38
+protected:
39
+	bool playInfinitely;
40
+	unsigned long skipSilenceOnStartSec, detectSilenceSec, defaultLength, defaultFade;
41
+	double volume;
42
+	VolumeType volumeType;
43
+	PeakType peakType;
44
+	unsigned sampleRate;
45
+	std::wstring titleFormat;
46
+	DialogTemplate configDialog, configDialogProperty, infoDialog;
47
+	std::vector<unsigned> supportedSampleRates;
48
+	std::auto_ptr<XSFConfigIO> configIO;
49
+
50
+	XSFConfig();
51
+	std::wstring GetTextFromWindow(HWND hwnd);
52
+	virtual void LoadSpecificConfig() = 0;
53
+	virtual void GenerateSpecificDialogs() = 0;
54
+	virtual void SaveSpecificConfig() = 0;
55
+	virtual INT_PTR CALLBACK ConfigDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
56
+	virtual INT_PTR CALLBACK InfoDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
57
+	virtual void ResetSpecificConfigDefaults(HWND hwndDlg) = 0;
58
+	virtual void SaveSpecificConfigDialog(HWND hwndDlg) = 0;
59
+	virtual void CopySpecificConfigToMemory(XSFPlayer *xSFPlayer, bool preLoad) = 0;
60
+public:
61
+	static bool initPlayInfinitely;
62
+	static std::wstring initSkipSilenceOnStartSec, initDetectSilenceSec, initDefaultLength, initDefaultFade, initTitleFormat;
63
+	static double initVolume;
64
+	static VolumeType initVolumeType;
65
+	static PeakType initPeakType;
66
+	// These are not defined in XSFConfig.cpp, they should be defined in your own config's source.
67
+	static unsigned initSampleRate;
68
+	static std::wstring commonName;
69
+	static std::wstring versionNumber;
70
+	// The Create function is not defined in XSFConfig.cpp, it should be defined in your own config's source and return a pointer to your config's class.
71
+	static XSFConfig *Create();
72
+
73
+	virtual ~XSFConfig() { }
74
+	void LoadConfig();
75
+	void SaveConfig();
76
+	void GenerateDialogs();
77
+	static INT_PTR CALLBACK ConfigDialogProcStatic(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
78
+	static INT_PTR CALLBACK InfoDialogProcStatic(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
79
+	void CallConfigDialog(HINSTANCE hInstance, HWND hwndParent);
80
+	void CallInfoDialog(HINSTANCE hInstance, HWND hwndParent);
81
+	void ResetConfigDefaults(HWND hwndDlg);
82
+	void SaveConfigDialog(HWND hwndDlg);
83
+	void CopyConfigToMemory(XSFPlayer *xSFPlayer, bool preLoad);
84
+
85
+	virtual void About(HWND parent) = 0;
86
+
87
+	bool GetPlayInfinitely() const;
88
+	unsigned long GetSkipSilenceOnStartSec() const;
89
+	unsigned long GetDetectSilenceSec() const;
90
+	unsigned long GetDefaultLength() const;
91
+	unsigned long GetDefaultFade() const;
92
+	double GetVolume() const;
93
+	VolumeType GetVolumeType() const;
94
+	PeakType GetPeakType() const;
95
+	const std::wstring &GetTitleFormat() const;
96
+};
97
+
98
+#endif