Browse code

Some template cleanup:

* Move the ToIntegral function from NCSF specifically to the framework in general, so it can be used in the base framework's code too.
* Use type traits a bit more.
* Move convertTo into the ConvertFuncs class.

Naram Qashat authored on 2021/04/05 21:47:28
Showing 1 changed files
... ...
@@ -14,6 +14,7 @@
14 14
 #include <cstdint>
15 15
 #include "common.h"
16 16
 #include "consts.h"
17
+#include "convert.h"
17 18
 
18 19
 struct Player;
19 20
 
... ...
@@ -55,7 +56,7 @@ struct Track
55 56
 {
56 57
 	std::int8_t trackId;
57 58
 
58
-	std::bitset<ToIntegral(TrackState::Bits)> state;
59
+	std::bitset<ConvertFuncs::ToIntegral(TrackState::Bits)> state;
59 60
 	std::uint8_t num, prio;
60 61
 	Player *ply;
61 62
 
... ...
@@ -82,7 +83,7 @@ struct Track
82 83
 	std::uint8_t modType, modSpeed, modDepth, modRange;
83 84
 	std::uint16_t modDelay;
84 85
 
85
-	std::bitset<ToIntegral(TrackUpdateFlag::Bits)> updateFlags;
86
+	std::bitset<ConvertFuncs::ToIntegral(TrackUpdateFlag::Bits)> updateFlags;
86 87
 
87 88
 	Track();
88 89
 
Browse code

Silence various Visual Studio warnings:

* Fix the ones in my code where I could use a proper type or valid casts.
* Ignore the designer-time and compiler-time warnings in vendor code or in my code where I am unable to suppress them via casting.
(Most of these were ignored already before introducing the CMake scripts, because they were in vendor code or were annoying to deal with.)

Naram Qashat authored on 2021/03/29 00:10:11
Showing 1 changed files
... ...
@@ -42,12 +42,12 @@ struct Override
42 42
 	Override() : overriding(false), cmd(0), value(0), extraValue(0) { }
43 43
 	bool operator()() const { return this->overriding; }
44 44
 	bool &operator()() { return this->overriding; }
45
-	int val(const std::uint8_t **pData, std::function<int (const std::uint8_t **)> reader, bool returnExtra = false)
45
+	template<typename T> T val(const std::uint8_t **pData, std::function<int (const std::uint8_t **)> reader, bool returnExtra = false)
46 46
 	{
47 47
 		if (this->overriding)
48
-			return returnExtra ? this->extraValue : this->value;
48
+			return static_cast<T>(returnExtra ? this->extraValue : this->value);
49 49
 		else
50
-			return reader(pData);
50
+			return static_cast<T>(reader(pData));
51 51
 	}
52 52
 };
53 53
 
... ...
@@ -86,12 +86,12 @@ struct Track
86 86
 
87 87
 	Track();
88 88
 
89
-	void Init(std::uint8_t handle, Player *ply, const std::uint8_t *pos, int n);
89
+	void Init(std::uint8_t handle, Player *ply, const std::uint8_t *pos, std::uint8_t n);
90 90
 	void Zero();
91 91
 	void ClearState();
92 92
 	void Free();
93
-	int NoteOn(int key, int vel, int len);
94
-	int NoteOnTie(int key, int vel);
93
+	int NoteOn(std::uint8_t key, int vel, int len);
94
+	int NoteOnTie(std::uint8_t key, int vel);
95 95
 	void ReleaseAllNotes();
96 96
 	void Run();
97 97
 };
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
... ...
@@ -9,25 +9,27 @@
9 9
 
10 10
 #pragma once
11 11
 
12
-#include <functional>
13 12
 #include <bitset>
13
+#include <functional>
14
+#include <cstdint>
15
+#include "common.h"
14 16
 #include "consts.h"
15 17
 
16 18
 struct Player;
17 19
 
18
-enum StackType
20
+enum class StackType
19 21
 {
20
-	STACKTYPE_CALL,
21
-	STACKTYPE_LOOP
22
+	Call,
23
+	Loop
22 24
 };
23 25
 
24 26
 struct StackValue
25 27
 {
26 28
 	StackType type;
27
-	const uint8_t *dest;
29
+	const std::uint8_t *dest;
28 30
 
29
-	StackValue() : type(STACKTYPE_CALL), dest(nullptr) { }
30
-	StackValue(StackType newType, const uint8_t *newDest) : type(newType), dest(newDest) { }
31
+	StackValue() : type(StackType::Call), dest(nullptr) { }
32
+	StackValue(StackType newType, const std::uint8_t *newDest) : type(newType), dest(newDest) { }
31 33
 };
32 34
 
33 35
 struct Override
... ...
@@ -40,7 +42,7 @@ struct Override
40 42
 	Override() : overriding(false), cmd(0), value(0), extraValue(0) { }
41 43
 	bool operator()() const { return this->overriding; }
42 44
 	bool &operator()() { return this->overriding; }
43
-	int val(const uint8_t **pData, std::function<int (const uint8_t **)> reader, bool returnExtra = false)
45
+	int val(const std::uint8_t **pData, std::function<int (const std::uint8_t **)> reader, bool returnExtra = false)
44 46
 	{
45 47
 		if (this->overriding)
46 48
 			return returnExtra ? this->extraValue : this->value;
... ...
@@ -51,40 +53,40 @@ struct Override
51 53
 
52 54
 struct Track
53 55
 {
54
-	int8_t trackId;
56
+	std::int8_t trackId;
55 57
 
56
-	std::bitset<TS_BITS> state;
57
-	uint8_t num, prio;
58
+	std::bitset<ToIntegral(TrackState::Bits)> state;
59
+	std::uint8_t num, prio;
58 60
 	Player *ply;
59 61
 
60
-	const uint8_t *startPos;
61
-	const uint8_t *pos;
62
+	const std::uint8_t *startPos;
63
+	const std::uint8_t *pos;
62 64
 	StackValue stack[FSS_TRACKSTACKSIZE];
63
-	uint8_t stackPos;
64
-	uint8_t loopCount[FSS_TRACKSTACKSIZE];
65
+	std::uint8_t stackPos;
66
+	std::uint8_t loopCount[FSS_TRACKSTACKSIZE];
65 67
 	Override overriding;
66 68
 	bool lastComparisonResult;
67 69
 
68 70
 	int wait;
69
-	uint16_t patch;
70
-	uint8_t portaKey, portaTime;
71
-	int16_t sweepPitch;
72
-	uint8_t vol, expr;
73
-	int8_t pan; // -64..63
74
-	uint8_t pitchBendRange;
75
-	int8_t pitchBend;
76
-	int8_t transpose;
71
+	std::uint16_t patch;
72
+	std::uint8_t portaKey, portaTime;
73
+	std::int16_t sweepPitch;
74
+	std::uint8_t vol, expr;
75
+	std::int8_t pan; // -64..63
76
+	std::uint8_t pitchBendRange;
77
+	std::int8_t pitchBend;
78
+	std::int8_t transpose;
77 79
 
78
-	uint8_t a, d, s, r;
80
+	std::uint8_t a, d, s, r;
79 81
 
80
-	uint8_t modType, modSpeed, modDepth, modRange;
81
-	uint16_t modDelay;
82
+	std::uint8_t modType, modSpeed, modDepth, modRange;
83
+	std::uint16_t modDelay;
82 84
 
83
-	std::bitset<TUF_BITS> updateFlags;
85
+	std::bitset<ToIntegral(TrackUpdateFlag::Bits)> updateFlags;
84 86
 
85 87
 	Track();
86 88
 
87
-	void Init(uint8_t handle, Player *ply, const uint8_t *pos, int n);
89
+	void Init(std::uint8_t handle, Player *ply, const std::uint8_t *pos, int n);
88 90
 	void Zero();
89 91
 	void ClearState();
90 92
 	void Free();
Browse code

Correct a few warnings Visual Studio was complaining about.

Naram Qashat authored on 2021/03/20 20:40:21
Showing 1 changed files
... ...
@@ -37,7 +37,7 @@ struct Override
37 37
 	int value;
38 38
 	int extraValue;
39 39
 
40
-	Override() : overriding(false) { }
40
+	Override() : overriding(false), cmd(0), value(0), extraValue(0) { }
41 41
 	bool operator()() const { return this->overriding; }
42 42
 	bool &operator()() { return this->overriding; }
43 43
 	int val(const uint8_t **pData, std::function<int (const uint8_t **)> reader, bool returnExtra = false)
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
  * SSEQ Player - Track structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
5 4
  *
6 5
  * Adapted from source code of FeOS Sound System
7 6
  * By fincs
Browse code

[NCSF] Minor code changes to reduce code duplication.

* Made a function in the Override struct to centralize where it
determines whether to use the override value or not.
* Made a function that returns the number of bytes that a command needs,
and used that to remove all the conditionals for processing a command to
instead handle that within the IF command itself.
Thanks to fincs and Henke37 for the suggestions to do this.

Naram Qashat authored on 2014/10/13 21:21:03
Showing 1 changed files
... ...
@@ -10,6 +10,7 @@
10 10
 
11 11
 #pragma once
12 12
 
13
+#include <functional>
13 14
 #include <bitset>
14 15
 #include "consts.h"
15 16
 
... ...
@@ -40,6 +41,13 @@ struct Override
40 41
 	Override() : overriding(false) { }
41 42
 	bool operator()() const { return this->overriding; }
42 43
 	bool &operator()() { return this->overriding; }
44
+	int val(const uint8_t **pData, std::function<int (const uint8_t **)> reader, bool returnExtra = false)
45
+	{
46
+		if (this->overriding)
47
+			return returnExtra ? this->extraValue : this->value;
48
+		else
49
+			return reader(pData);
50
+	}
43 51
 };
44 52
 
45 53
 struct Track
... ...
@@ -57,7 +65,6 @@ struct Track
57 65
 	uint8_t loopCount[FSS_TRACKSTACKSIZE];
58 66
 	Override overriding;
59 67
 	bool lastComparisonResult;
60
-	bool processCommand;
61 68
 
62 69
 	int wait;
63 70
 	uint16_t patch;
Browse code

[NCSF] Implemented the random, variable, and conditional commands. Also fixed loop counter.

Naram Qashat authored on 2014/10/13 18:00:29
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Track structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-08
4
+ * Last modification on 2014-10-13
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -15,6 +15,33 @@
15 15
 
16 16
 struct Player;
17 17
 
18
+enum StackType
19
+{
20
+	STACKTYPE_CALL,
21
+	STACKTYPE_LOOP
22
+};
23
+
24
+struct StackValue
25
+{
26
+	StackType type;
27
+	const uint8_t *dest;
28
+
29
+	StackValue() : type(STACKTYPE_CALL), dest(nullptr) { }
30
+	StackValue(StackType newType, const uint8_t *newDest) : type(newType), dest(newDest) { }
31
+};
32
+
33
+struct Override
34
+{
35
+	bool overriding;
36
+	int cmd;
37
+	int value;
38
+	int extraValue;
39
+
40
+	Override() : overriding(false) { }
41
+	bool operator()() const { return this->overriding; }
42
+	bool &operator()() { return this->overriding; }
43
+};
44
+
18 45
 struct Track
19 46
 {
20 47
 	int8_t trackId;
... ...
@@ -25,9 +52,12 @@ struct Track
25 52
 
26 53
 	const uint8_t *startPos;
27 54
 	const uint8_t *pos;
28
-	const uint8_t *stack[FSS_TRACKSTACKSIZE];
55
+	StackValue stack[FSS_TRACKSTACKSIZE];
29 56
 	uint8_t stackPos;
30 57
 	uint8_t loopCount[FSS_TRACKSTACKSIZE];
58
+	Override overriding;
59
+	bool lastComparisonResult;
60
+	bool processCommand;
31 61
 
32 62
 	int wait;
33 63
 	uint16_t patch;
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -1,15 +1,14 @@
1 1
 /*
2 2
  * SSEQ Player - Track structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-01
4
+ * Last modification on 2014-09-08
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
8 8
  * https://github.com/fincs/FSS
9 9
  */
10 10
 
11
-#ifndef SSEQPLAYER_TRACK_H
12
-#define SSEQPLAYER_TRACK_H
11
+#pragma once
13 12
 
14 13
 #include <bitset>
15 14
 #include "consts.h"
... ...
@@ -58,5 +57,3 @@ struct Track
58 57
 	void ReleaseAllNotes();
59 58
 	void Run();
60 59
 };
61
-
62
-#endif
Browse code

Corrected issue with terminating the SSEQ player by actually making it stop properly.

Naram Qashat authored on 2013/04/02 03:03:26
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Track structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-21
4
+ * Last modification on 2013-04-01
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -52,6 +52,7 @@ struct Track
52 52
 	void Init(uint8_t handle, Player *ply, const uint8_t *pos, int n);
53 53
 	void Zero();
54 54
 	void ClearState();
55
+	void Free();
55 56
 	int NoteOn(int key, int vel, int len);
56 57
 	int NoteOnTie(int key, int vel);
57 58
 	void ReleaseAllNotes();
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,61 @@
1
+/*
2
+ * SSEQ Player - Track structure
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-21
5
+ *
6
+ * Adapted from source code of FeOS Sound System
7
+ * By fincs
8
+ * https://github.com/fincs/FSS
9
+ */
10
+
11
+#ifndef SSEQPLAYER_TRACK_H
12
+#define SSEQPLAYER_TRACK_H
13
+
14
+#include <bitset>
15
+#include "consts.h"
16
+
17
+struct Player;
18
+
19
+struct Track
20
+{
21
+	int8_t trackId;
22
+
23
+	std::bitset<TS_BITS> state;
24
+	uint8_t num, prio;
25
+	Player *ply;
26
+
27
+	const uint8_t *startPos;
28
+	const uint8_t *pos;
29
+	const uint8_t *stack[FSS_TRACKSTACKSIZE];
30
+	uint8_t stackPos;
31
+	uint8_t loopCount[FSS_TRACKSTACKSIZE];
32
+
33
+	int wait;
34
+	uint16_t patch;
35
+	uint8_t portaKey, portaTime;
36
+	int16_t sweepPitch;
37
+	uint8_t vol, expr;
38
+	int8_t pan; // -64..63
39
+	uint8_t pitchBendRange;
40
+	int8_t pitchBend;
41
+	int8_t transpose;
42
+
43
+	uint8_t a, d, s, r;
44
+
45
+	uint8_t modType, modSpeed, modDepth, modRange;
46
+	uint16_t modDelay;
47
+
48
+	std::bitset<TUF_BITS> updateFlags;
49
+
50
+	Track();
51
+
52
+	void Init(uint8_t handle, Player *ply, const uint8_t *pos, int n);
53
+	void Zero();
54
+	void ClearState();
55
+	int NoteOn(int key, int vel, int len);
56
+	int NoteOnTie(int key, int vel);
57
+	void ReleaseAllNotes();
58
+	void Run();
59
+};
60
+
61
+#endif