Browse code

Replace the Sound View dialog with a wxWidgets-based one.

* Removes the one that was orignally based entirely on the DeSmuME one, while still looking most the same but cleaner.
* To accommodate this, I needed to rework how wxWidgets was initialized so the configuration dialog boxes could also work alongside this.
* Needed to add a custom wxApp to handle the above.
* This also means that the configuration dialog no longer needs the plugin's HINSTANCE passed along.
* Had to not disable wxGauge or wxToogleButton for the Sound View dialog.
* Also remove the now-unneeded enums in the XSFConfig*.cpp files.
* Sound View is still done in a thread so its event loop can run independently from the rest of the plugin.
* XSFConfig_NCSF doesn't need to be the one to start the Sound View dialog now.

Naram Qashat authored on 2021/04/10 15:19:43
Showing 1 changed files
... ...
@@ -15,7 +15,21 @@
15 15
 #include <vector>
16 16
 #include <cstddef>
17 17
 #include <cstdint>
18
+#ifdef __GNUC__
19
+# pragma GCC diagnostic push
20
+# pragma GCC diagnostic ignored "-Wold-style-cast"
21
+#elif defined(__clang__)
22
+# pragma clang diagnostic push
23
+# pragma clang diagnostic ignored "-Wold-style-cast"
24
+#endif
25
+#include <wx/app.h>
26
+#ifdef __GNUC__
27
+# pragma GCC diagnostic pop
28
+#elif defined(__clang__)
29
+# pragma clang diagnostic pop
30
+#endif
18 31
 #include "windowsh_wrapper.h"
32
+#include "XSFApp.h"
19 33
 #include "XSFCommon.h"
20 34
 #include "XSFConfig.h"
21 35
 #include "XSFFile.h"
... ...
@@ -28,6 +42,7 @@ extern In_Module inMod;
28 42
 static const XSFFile *xSFFile = nullptr;
29 43
 XSFFile *xSFFileInInfo = nullptr;
30 44
 static std::unique_ptr<XSFPlayer> xSFPlayer;
45
+std::unique_ptr<XSFApp> xSFApp;
31 46
 std::unique_ptr<XSFConfig> xSFConfig;
32 47
 static bool paused;
33 48
 static std::atomic_int seek_needed;
... ...
@@ -83,7 +98,7 @@ void playThread()
83 98
 
84 99
 void config(HWND hwndParent)
85 100
 {
86
-	xSFConfig->CallConfigDialog(inMod.hDllInstance, hwndParent);
101
+	xSFConfig->CallConfigDialog(hwndParent);
87 102
 	if (xSFPlayer)
88 103
 		xSFConfig->CopyConfigToMemory(xSFPlayer.get(), false);
89 104
 }
... ...
@@ -95,6 +110,9 @@ void about(HWND hwndParent)
95 110
 
96 111
 void init()
97 112
 {
113
+	wxEntryStart(inMod.hDllInstance);
114
+	xSFApp.reset(XSFApp::Create());
115
+	wxApp::SetInstance(xSFApp.get());
98 116
 	xSFConfig.reset(XSFConfig::Create());
99 117
 	xSFConfig->LoadConfig();
100 118
 	xSFConfig->GenerateDialogs();
... ...
@@ -105,6 +123,8 @@ void quit()
105 123
 {
106 124
 	xSFPlayer.reset();
107 125
 	xSFConfig.reset();
126
+	xSFApp.reset();
127
+	wxEntryCleanup();
108 128
 }
109 129
 
110 130
 void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
Browse code

Use std::thread in place of the Windows API CreateThread.

Naram Qashat authored on 2021/04/07 21:52:53
Showing 1 changed files
... ...
@@ -6,9 +6,11 @@
6 6
  */
7 7
 
8 8
 #include <algorithm>
9
+#include <atomic>
9 10
 #include <memory>
10 11
 #include <stdexcept>
11 12
 #include <string>
13
+#include <thread>
12 14
 #include <utility>
13 15
 #include <vector>
14 16
 #include <cstddef>
... ...
@@ -28,18 +30,18 @@ XSFFile *xSFFileInInfo = nullptr;
28 30
 static std::unique_ptr<XSFPlayer> xSFPlayer;
29 31
 std::unique_ptr<XSFConfig> xSFConfig;
30 32
 static bool paused;
31
-static int seek_needed;
33
+static std::atomic_int seek_needed;
32 34
 static double decode_pos_ms;
33
-static HANDLE thread_handle = INVALID_HANDLE_VALUE;
34
-static bool killThread = false;
35
+static std::unique_ptr<std::thread> thread_handle;
36
+static std::atomic_bool killThread;
35 37
 
36 38
 static const unsigned NumChannels = 2;
37 39
 static const unsigned BitsPerSample = 16;
38 40
 
39
-DWORD WINAPI playThread(void *b)
41
+void playThread()
40 42
 {
41 43
 	bool done = false;
42
-	while (!*static_cast<bool *>(b))
44
+	while (!killThread)
43 45
 	{
44 46
 		if (seek_needed != -1)
45 47
 		{
... ...
@@ -55,7 +57,7 @@ DWORD WINAPI playThread(void *b)
55 57
 			if (!inMod.outMod->IsPlaying())
56 58
 			{
57 59
 				PostMessage(inMod.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
58
-				return 0;
60
+				return;
59 61
 			}
60 62
 			Sleep(10);
61 63
 		}
... ...
@@ -77,7 +79,6 @@ DWORD WINAPI playThread(void *b)
77 79
 		else
78 80
 			Sleep(20);
79 81
 	}
80
-	return 0;
81 82
 }
82 83
 
83 84
 void config(HWND hwndParent)
... ...
@@ -198,7 +199,7 @@ int play(const in_char *fn)
198 199
 
199 200
 		xSFPlayer = std::move(tmpxSFPlayer);
200 201
 		killThread = false;
201
-		thread_handle = CreateThread(nullptr, 0, playThread, &killThread, 0, nullptr);
202
+		thread_handle.reset(new std::thread(playThread));
202 203
 		return 0;
203 204
 	}
204 205
 	catch (const std::exception &)
... ...
@@ -226,17 +227,9 @@ int isPaused()
226 227
 
227 228
 void stop()
228 229
 {
229
-	if (thread_handle != INVALID_HANDLE_VALUE)
230
-	{
231
-		killThread = true;
232
-		if (WaitForSingleObject(thread_handle, 2000) == WAIT_TIMEOUT)
233
-		{
234
-			MessageBoxW(inMod.hMainWindow, L"error asking thread to die!", L"error killing decode thread", 0);
235
-			TerminateThread(thread_handle, 0);
236
-		}
237
-		CloseHandle(thread_handle);
238
-		thread_handle = INVALID_HANDLE_VALUE;
239
-	}
230
+	killThread = true;
231
+	thread_handle->join();
232
+	thread_handle.reset();
240 233
 	inMod.outMod->Close();
241 234
 	inMod.SAVSADeInit();
242 235
 	xSFPlayer.reset();
Browse code

Use std::unique_ptr in in_xsf.cpp.

Also move the code of the NCSF Player's destructor to Terminate() and call Terminate() in the destructor.

Naram Qashat authored on 2021/04/06 20:45:29
Showing 1 changed files
... ...
@@ -25,8 +25,8 @@
25 25
 extern In_Module inMod;
26 26
 static const XSFFile *xSFFile = nullptr;
27 27
 XSFFile *xSFFileInInfo = nullptr;
28
-static XSFPlayer *xSFPlayer = nullptr;
29
-XSFConfig *xSFConfig = nullptr;
28
+static std::unique_ptr<XSFPlayer> xSFPlayer;
29
+std::unique_ptr<XSFConfig> xSFConfig;
30 30
 static bool paused;
31 31
 static int seek_needed;
32 32
 static double decode_pos_ms;
... ...
@@ -84,7 +84,7 @@ void config(HWND hwndParent)
84 84
 {
85 85
 	xSFConfig->CallConfigDialog(inMod.hDllInstance, hwndParent);
86 86
 	if (xSFPlayer)
87
-		xSFConfig->CopyConfigToMemory(xSFPlayer, false);
87
+		xSFConfig->CopyConfigToMemory(xSFPlayer.get(), false);
88 88
 }
89 89
 
90 90
 void about(HWND hwndParent)
... ...
@@ -94,7 +94,7 @@ void about(HWND hwndParent)
94 94
 
95 95
 void init()
96 96
 {
97
-	xSFConfig = XSFConfig::Create();
97
+	xSFConfig.reset(XSFConfig::Create());
98 98
 	xSFConfig->LoadConfig();
99 99
 	xSFConfig->GenerateDialogs();
100 100
 	xSFConfig->SetHInstance(inMod.hDllInstance);
... ...
@@ -102,8 +102,8 @@ void init()
102 102
 
103 103
 void quit()
104 104
 {
105
-	delete xSFPlayer;
106
-	delete xSFConfig;
105
+	xSFPlayer.reset();
106
+	xSFConfig.reset();
107 107
 }
108 108
 
109 109
 void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
... ...
@@ -196,7 +196,7 @@ int play(const in_char *fn)
196 196
 		inMod.VSASetInfo(tmpxSFPlayer->GetSampleRate(), NumChannels);
197 197
 		inMod.outMod->SetVolume(-666);
198 198
 
199
-		xSFPlayer = tmpxSFPlayer.release();
199
+		xSFPlayer = std::move(tmpxSFPlayer);
200 200
 		killThread = false;
201 201
 		thread_handle = CreateThread(nullptr, 0, playThread, &killThread, 0, nullptr);
202 202
 		return 0;
... ...
@@ -239,8 +239,7 @@ void stop()
239 239
 	}
240 240
 	inMod.outMod->Close();
241 241
 	inMod.SAVSADeInit();
242
-	delete xSFPlayer;
243
-	xSFPlayer = nullptr;
242
+	xSFPlayer.reset();
244 243
 	xSFFile = nullptr;
245 244
 }
246 245
 
Browse code

Use std::filesystem::path for reading/writing files.

Also remove fstream_wfopen.h as it is no longer needed.
Also make XSFFile not store the string of the path but store the path as std::filesystem::path.

Naram Qashat authored on 2021/04/05 00:20:56
Showing 1 changed files
... ...
@@ -165,7 +165,7 @@ int infoBox(const in_char *file, HWND hwndParent)
165 165
 			info += L"\n";
166 166
 		info += ConvertFuncs::StringToWString(keys[x] + "=" + tags[keys[x]]);
167 167
 	}
168
-	MessageBoxW(hwndParent, info.c_str(), ConvertFuncs::StringToWString(xSF->GetFilenameWithoutPath()).c_str(), MB_OK);
168
+	MessageBoxW(hwndParent, info.c_str(), xSF->GetFilenameWithoutPath().wstring().c_str(), MB_OK);
169 169
 	return INFOBOX_EDITED;
170 170
 }
171 171
 
... ...
@@ -391,7 +391,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, c
391 391
 {
392 392
 	try
393 393
 	{
394
-		if (!extendedXSFFile || extendedXSFFile->GetFilename() != fn)
394
+		if (!extendedXSFFile || extendedXSFFile->GetFilepath() != fn)
395 395
 			extendedXSFFile.reset(new XSFFile(fn));
396 396
 		return wrapperWinampSetExtendedFileInfo(data, val);
397 397
 	}
... ...
@@ -405,7 +405,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
405 405
 {
406 406
 	try
407 407
 	{
408
-		if (!extendedXSFFile || ConvertFuncs::StringToWString(extendedXSFFile->GetFilename()) != fn)
408
+		if (!extendedXSFFile || extendedXSFFile->GetFilepath() != fn)
409 409
 			extendedXSFFile.reset(new XSFFile(fn));
410 410
 		return wrapperWinampSetExtendedFileInfo(data, val);
411 411
 	}
... ...
@@ -417,7 +417,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
417 417
 
418 418
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
419 419
 {
420
-	if (!extendedXSFFile || extendedXSFFile->GetFilename().empty())
420
+	if (!extendedXSFFile || extendedXSFFile->GetFilepath().empty())
421 421
 		return 0;
422 422
 	extendedXSFFile->SaveFile();
423 423
 	return 1;
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
... ...
@@ -5,10 +5,20 @@
5 5
  * Partially based on the vio*sf framework
6 6
  */
7 7
 
8
-#include "XSFPlayer.h"
9
-#include "XSFConfig.h"
10
-#include "XSFCommon.h"
8
+#include <algorithm>
9
+#include <memory>
10
+#include <stdexcept>
11
+#include <string>
12
+#include <utility>
13
+#include <vector>
14
+#include <cstddef>
15
+#include <cstdint>
11 16
 #include "windowsh_wrapper.h"
17
+#include "XSFCommon.h"
18
+#include "XSFConfig.h"
19
+#include "XSFFile.h"
20
+#include "XSFPlayer.h"
21
+#include "convert.h"
12 22
 #include "winamp/in2.h"
13 23
 #include "winamp/wa_ipc.h"
14 24
 
... ...
@@ -35,7 +45,7 @@ DWORD WINAPI playThread(void *b)
35 45
 		{
36 46
 			decode_pos_ms = seek_needed - (seek_needed % 1000);
37 47
 			seek_needed = -1;
38
-			auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
48
+			auto dummyBuffer = std::vector<std::uint8_t>(576 * NumChannels * (BitsPerSample / 8));
39 49
 			xSFPlayer->Seek(static_cast<unsigned>(decode_pos_ms), nullptr, dummyBuffer, inMod.outMod);
40 50
 		}
41 51
 
... ...
@@ -51,7 +61,7 @@ DWORD WINAPI playThread(void *b)
51 61
 		}
52 62
 		else if (static_cast<unsigned>(inMod.outMod->CanWrite()) >= ((576 * NumChannels * (BitsPerSample / 8)) << (inMod.dsp_isactive() ? 1 : 0)))
53 63
 		{
54
-			auto sampleBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
64
+			auto sampleBuffer = std::vector<std::uint8_t>(576 * NumChannels * (BitsPerSample / 8));
55 65
 			unsigned samplesWritten = 0;
56 66
 			done = xSFPlayer->FillBuffer(sampleBuffer, samplesWritten);
57 67
 			if (samplesWritten)
... ...
@@ -305,7 +315,7 @@ extern "C" __declspec(dllexport) In_Module *winampGetInModule2()
305 315
 
306 316
 static eq_str eqstr;
307 317
 
308
-template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, const char *data, T *dest, size_t destlen)
318
+template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, const char *data, T *dest, std::size_t destlen)
309 319
 {
310 320
 	if (eqstr(data, "type"))
311 321
 	{
... ...
@@ -343,7 +353,7 @@ template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, c
343 353
 	}
344 354
 }
345 355
 
346
-extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
356
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, std::size_t destlen)
347 357
 {
348 358
 	try
349 359
 	{
... ...
@@ -356,7 +366,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
356 366
 	}
357 367
 }
358 368
 
359
-extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
369
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, std::size_t destlen)
360 370
 {
361 371
 	try
362 372
 	{
... ...
@@ -418,7 +428,7 @@ extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t
418 428
 	return 0;
419 429
 }
420 430
 
421
-intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
431
+std::intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> &&tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
422 432
 {
423 433
 	xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), true);
424 434
 	if (!tmpxSFPlayer->Load())
... ...
@@ -433,10 +443,10 @@ intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlay
433 443
 		*nch = NumChannels;
434 444
 	if (srate)
435 445
 		*srate = tmpxSFPlayer->GetSampleRate();
436
-	return reinterpret_cast<intptr_t>(tmpxSFPlayer.release());
446
+	return reinterpret_cast<std::intptr_t>(tmpxSFPlayer.release());
437 447
 }
438 448
 
439
-extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char *fn, int *size, int *bps, int *nch, int *srate)
449
+extern "C" __declspec(dllexport) std::intptr_t winampGetExtendedRead_open(const char *fn, int *size, int *bps, int *nch, int *srate)
440 450
 {
441 451
 	try
442 452
 	{
... ...
@@ -449,7 +459,7 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char
449 459
 	}
450 460
 }
451 461
 
452
-extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
462
+extern "C" __declspec(dllexport) std::intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
453 463
 {
454 464
 	try
455 465
 	{
... ...
@@ -464,14 +474,14 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wcha
464 474
 
465 475
 static int extendedSeekNeeded = -1;
466 476
 
467
-extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t handle, char *dest, size_t len, int *killswitch)
477
+extern "C" __declspec(dllexport) std::size_t winampGetExtendedRead_getData(std::intptr_t handle, char *dest, std::size_t len, int *killswitch)
468 478
 {
469 479
 	XSFPlayer *tmpxSFPlayer = reinterpret_cast<XSFPlayer *>(handle);
470 480
 	if (!tmpxSFPlayer)
471 481
 		return 0;
472 482
 	if (extendedSeekNeeded != -1)
473 483
 	{
474
-		auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
484
+		auto dummyBuffer = std::vector<std::uint8_t>(576 * NumChannels * (BitsPerSample / 8));
475 485
 		if (tmpxSFPlayer->Seek(static_cast<unsigned>(extendedSeekNeeded), killswitch, dummyBuffer, nullptr))
476 486
 			return 0;
477 487
 		extendedSeekNeeded = -1;
... ...
@@ -480,7 +490,7 @@ extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t h
480 490
 	bool done = false;
481 491
 	while (copied + (576 * NumChannels * (BitsPerSample / 8)) < len && !done)
482 492
 	{
483
-		auto sampleBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
493
+		auto sampleBuffer = std::vector<std::uint8_t>(576 * NumChannels * (BitsPerSample / 8));
484 494
 		unsigned samplesWritten = 0;
485 495
 		done = tmpxSFPlayer->FillBuffer(sampleBuffer, samplesWritten);
486 496
 		std::copy_n(&sampleBuffer[0], samplesWritten * NumChannels * (BitsPerSample / 8), &dest[copied]);
... ...
@@ -491,13 +501,13 @@ extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t h
491 501
 	return copied;
492 502
 }
493 503
 
494
-extern "C" __declspec(dllexport) int winampGetExtendedRead_setTime(intptr_t, int millisecs)
504
+extern "C" __declspec(dllexport) int winampGetExtendedRead_setTime(std::intptr_t, int millisecs)
495 505
 {
496 506
 	extendedSeekNeeded = millisecs;
497 507
 	return 1;
498 508
 }
499 509
 
500
-extern "C" __declspec(dllexport) void winampGetExtendedRead_close(intptr_t handle)
510
+extern "C" __declspec(dllexport) void winampGetExtendedRead_close(std::intptr_t handle)
501 511
 {
502 512
 	XSFPlayer *tmpxSFPlayer = reinterpret_cast<XSFPlayer *>(handle);
503 513
 	if (tmpxSFPlayer)
Browse code

Use std::make_unique where possible.

Naram Qashat authored on 2021/03/20 04:37:08
Showing 1 changed files
... ...
@@ -128,14 +128,14 @@ void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
128 128
 
129 129
 int infoBox(const in_char *file, HWND hwndParent)
130 130
 {
131
-	auto xSF = std::unique_ptr<XSFFile>(new XSFFile());
131
+	auto xSF = std::make_unique<XSFFile>();
132 132
 	if (!file || !*file)
133 133
 		*xSF = *xSFFile;
134 134
 	else
135 135
 	{
136 136
 		try
137 137
 		{
138
-			auto tmpxSF = std::unique_ptr<XSFFile>(new XSFFile(file));
138
+			auto tmpxSF = std::make_unique<XSFFile>(file);
139 139
 			*xSF = *tmpxSF;
140 140
 		}
141 141
 		catch (const std::exception &)
Browse code

Remove some now unnecessary codecvt lines.

Naram Qashat authored on 2021/03/20 03:57:20
Showing 1 changed files
... ...
@@ -12,11 +12,6 @@
12 12
 #include "winamp/in2.h"
13 13
 #include "winamp/wa_ipc.h"
14 14
 
15
-#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION)
16
-std::locale::id std::codecvt<char16_t, char, mbstate_t>::id;
17
-std::locale::id std::codecvt<char32_t, char, mbstate_t>::id;
18
-#endif
19
-
20 15
 extern In_Module inMod;
21 16
 static const XSFFile *xSFFile = nullptr;
22 17
 XSFFile *xSFFileInInfo = nullptr;
Browse code

Replace memcpy/memset with std::copy_n/std::fill_n.

Naram Qashat authored on 2021/03/19 16:25:21
Showing 1 changed files
... ...
@@ -488,7 +488,7 @@ extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t h
488 488
 		auto sampleBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
489 489
 		unsigned samplesWritten = 0;
490 490
 		done = tmpxSFPlayer->FillBuffer(sampleBuffer, samplesWritten);
491
-		memcpy(&dest[copied], &sampleBuffer[0], samplesWritten * NumChannels * (BitsPerSample / 8));
491
+		std::copy_n(&sampleBuffer[0], samplesWritten * NumChannels * (BitsPerSample / 8), &dest[copied]);
492 492
 		copied += samplesWritten * NumChannels * (BitsPerSample / 8);
493 493
 		if (killswitch && *killswitch)
494 494
 			break;
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
... ...
@@ -335,7 +335,7 @@ template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, c
335 335
 				return 0;
336 336
 			}
337 337
 			else if (eqstr(tagToGet, "length"))
338
-				tag = stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()));
338
+				tag = std::to_string(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()));
339 339
 			else
340 340
 				tag = file.GetTagValue(tagToGet);
341 341
 			CopyToString(tag.substr(0, destlen - 1), dest);
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 - Winamp plugin
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

update for C++17 compliance, update to latest 2sf, add WINE cross-compile makefiles

Adam Higerd authored on 2021/02/11 15:36:17
Showing 1 changed files
... ...
@@ -10,8 +10,8 @@
10 10
 #include "XSFConfig.h"
11 11
 #include "XSFCommon.h"
12 12
 #include "windowsh_wrapper.h"
13
-#include <winamp/in2.h>
14
-#include <winamp/wa_ipc.h>
13
+#include "winamp/in2.h"
14
+#include "winamp/wa_ipc.h"
15 15
 
16 16
 #if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION)
17 17
 std::locale::id std::codecvt<char16_t, char, mbstate_t>::id;
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 - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-25
4
+ * Last modification on 2014-10-05
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -93,6 +93,7 @@ void init()
93 93
 	xSFConfig = XSFConfig::Create();
94 94
 	xSFConfig->LoadConfig();
95 95
 	xSFConfig->GenerateDialogs();
96
+	xSFConfig->SetHInstance(inMod.hDllInstance);
96 97
 }
97 98
 
98 99
 void quit()
Browse code

* Small Makefile changes.

* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).

Naram Qashat authored on 2014/09/25 12:28:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
4
+ * Last modification on 2014-09-25
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -19,15 +19,15 @@ std::locale::id std::codecvt<char32_t, char, mbstate_t>::id;
19 19
 #endif
20 20
 
21 21
 extern In_Module inMod;
22
-const XSFFile *xSFFile = nullptr;
22
+static const XSFFile *xSFFile = nullptr;
23 23
 XSFFile *xSFFileInInfo = nullptr;
24
-XSFPlayer *xSFPlayer = nullptr;
24
+static XSFPlayer *xSFPlayer = nullptr;
25 25
 XSFConfig *xSFConfig = nullptr;
26
-bool paused;
27
-int seek_needed;
28
-double decode_pos_ms;
29
-HANDLE thread_handle = INVALID_HANDLE_VALUE;
30
-bool killThread = false;
26
+static bool paused;
27
+static int seek_needed;
28
+static double decode_pos_ms;
29
+static HANDLE thread_handle = INVALID_HANDLE_VALUE;
30
+static bool killThread = false;
31 31
 
32 32
 static const unsigned NumChannels = 2;
33 33
 static const unsigned BitsPerSample = 16;
... ...
@@ -374,7 +374,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *f
374 374
 	}
375 375
 }
376 376
 
377
-std::unique_ptr<XSFFile> extendedXSFFile;
377
+static std::unique_ptr<XSFFile> extendedXSFFile;
378 378
 
379 379
 int wrapperWinampSetExtendedFileInfo(const char *data, const wchar_t *val)
380 380
 {
... ...
@@ -467,7 +467,7 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wcha
467 467
 	}
468 468
 }
469 469
 
470
-int extendedSeekNeeded = -1;
470
+static int extendedSeekNeeded = -1;
471 471
 
472 472
 extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t handle, char *dest, size_t len, int *killswitch)
473 473
 {
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,17 +1,23 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-18
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
8 8
 
9 9
 #include "XSFPlayer.h"
10 10
 #include "XSFConfig.h"
11
+#include "XSFCommon.h"
11 12
 #include "windowsh_wrapper.h"
12 13
 #include <winamp/in2.h>
13 14
 #include <winamp/wa_ipc.h>
14 15
 
16
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION)
17
+std::locale::id std::codecvt<char16_t, char, mbstate_t>::id;
18
+std::locale::id std::codecvt<char32_t, char, mbstate_t>::id;
19
+#endif
20
+
15 21
 extern In_Module inMod;
16 22
 const XSFFile *xSFFile = nullptr;
17 23
 XSFFile *xSFFileInInfo = nullptr;
... ...
@@ -110,7 +116,7 @@ void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
110 116
 		catch (const std::exception &)
111 117
 		{
112 118
 			if (title)
113
-				String("").CopyToString(title);
119
+				CopyToString("", title);
114 120
 			if (length_in_ms)
115 121
 				*length_in_ms = -1000;
116 122
 			return;
... ...
@@ -118,10 +124,7 @@ void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
118 124
 		toFree = true;
119 125
 	}
120 126
 	if (title)
121
-	{
122
-		String formattedTitle = xSF->GetFormattedTitle(xSFConfig->GetTitleFormat()).Substring(0, GETFILEINFO_TITLE_LENGTH - 1);
123
-		formattedTitle.CopyToString(title);
124
-	}
127
+		CopyToString(xSF->GetFormattedTitle(xSFConfig->GetTitleFormat()).substr(0, GETFILEINFO_TITLE_LENGTH - 1), title);
125 128
 	if (length_in_ms)
126 129
 		*length_in_ms = xSF->GetLengthMS(xSFConfig->GetDefaultLength()) + xSF->GetFadeMS(xSFConfig->GetDefaultFade());
127 130
 	if (toFree)
... ...
@@ -148,17 +151,16 @@ int infoBox(const in_char *file, HWND hwndParent)
148 151
 	// TODO: Eventually make a dialog box for editing the info
149 152
 	/*xSFFileInInfo = xSF.get();
150 153
 	xSFConfig->CallInfoDialog(inMod.hDllInstance, hwndParent);*/
151
-	bool utf8 = xSF->GetTagExists("utf8");
152 154
 	auto tags = xSF->GetAllTags();
153 155
 	auto keys = tags.GetKeys();
154
-	String info;
156
+	std::wstring info;
155 157
 	for (unsigned x = 0, numTags = keys.size(); x < numTags; ++x)
156 158
 	{
157 159
 		if (x)
158
-			info += "\n";
159
-		info += String(keys[x] + "=") + String(tags[keys[x]], utf8);
160
+			info += L"\n";
161
+		info += ConvertFuncs::StringToWString(keys[x] + "=" + tags[keys[x]]);
160 162
 	}
161
-	MessageBoxW(hwndParent, info.GetWStrC(), xSF->GetFilenameWithoutPath().GetWStrC(), MB_OK);
163
+	MessageBoxW(hwndParent, info.c_str(), ConvertFuncs::StringToWString(xSF->GetFilenameWithoutPath()).c_str(), MB_OK);
162 164
 	return INFOBOX_EDITED;
163 165
 }
164 166
 
... ...
@@ -271,7 +273,7 @@ void eqSet(int, char [10], int)
271 273
 In_Module inMod =
272 274
 {
273 275
 	IN_VER,
274
-	const_cast<char *>(XSFConfig::CommonNameWithVersion().GetStrC()), /* Unsafe but Winamp's SDK requires this */
276
+	const_cast<char *>(XSFConfig::CommonNameWithVersion().c_str()), /* Unsafe but Winamp's SDK requires this */
275 277
 	nullptr, /* Filled by Winamp */
276 278
 	nullptr, /* Filled by Winamp */
277 279
 	const_cast<char *>(XSFPlayer::WinampExts), /* Unsafe but Winamp's SDK requires this */
... ...
@@ -317,9 +319,7 @@ template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, c
317 319
 		return 1;
318 320
 	}
319 321
 	else if (eqstr(data, "family"))
320
-	{
321 322
 		return 0;
322
-	}
323 323
 	else
324 324
 	{
325 325
 		try
... ...
@@ -327,6 +327,7 @@ template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, c
327 327
 			std::string tagToGet = data;
328 328
 			if (eqstr(data, "album"))
329 329
 				tagToGet = "game";
330
+			std::string tag = "";
330 331
 			if (!file.GetTagExists(tagToGet))
331 332
 			{
332 333
 				if (eqstr(tagToGet, "replaygain_track_gain"))
... ...
@@ -334,11 +335,10 @@ template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, c
334 335
 				return 0;
335 336
 			}
336 337
 			else if (eqstr(tagToGet, "length"))
337
-			{
338
-				String(stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()))).Substring(0, destlen - 1).CopyToString(dest, true);
339
-				return 1;
340
-			}
341
-			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
338
+				tag = stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()));
339
+			else
340
+				tag = file.GetTagValue(tagToGet);
341
+			CopyToString(tag.substr(0, destlen - 1), dest);
342 342
 			return 1;
343 343
 		}
344 344
 		catch (const std::exception &)
... ...
@@ -361,7 +361,6 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
361 361
 	}
362 362
 }
363 363
 
364
-#ifdef _MSC_VER
365 364
 extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
366 365
 {
367 366
 	try
... ...
@@ -374,7 +373,6 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *f
374 373
 		return 0;
375 374
 	}
376 375
 }
377
-#endif
378 376
 
379 377
 std::unique_ptr<XSFFile> extendedXSFFile;
380 378
 
... ...
@@ -388,7 +386,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, c
388 386
 {
389 387
 	try
390 388
 	{
391
-		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetStr() != fn)
389
+		if (!extendedXSFFile || extendedXSFFile->GetFilename() != fn)
392 390
 			extendedXSFFile.reset(new XSFFile(fn));
393 391
 		return wrapperWinampSetExtendedFileInfo(data, val);
394 392
 	}
... ...
@@ -398,12 +396,11 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, c
398 396
 	}
399 397
 }
400 398
 
401
-#ifdef _MSC_VER
402 399
 extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *fn, const char *data, const wchar_t *val)
403 400
 {
404 401
 	try
405 402
 	{
406
-		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetWStr() != fn)
403
+		if (!extendedXSFFile || ConvertFuncs::StringToWString(extendedXSFFile->GetFilename()) != fn)
407 404
 			extendedXSFFile.reset(new XSFFile(fn));
408 405
 		return wrapperWinampSetExtendedFileInfo(data, val);
409 406
 	}
... ...
@@ -412,7 +409,6 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
412 409
 		return 0;
413 410
 	}
414 411
 }
415
-#endif
416 412
 
417 413
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
418 414
 {
... ...
@@ -422,12 +418,10 @@ extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
422 418
 	return 1;
423 419
 }
424 420
 
425
-#ifdef _MSC_VER
426 421
 extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *)
427 422
 {
428 423
 	return 0;
429 424
 }
430
-#endif
431 425
 
432 426
 intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
433 427
 {
... ...
@@ -460,7 +454,6 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char
460 454
 	}
461 455
 }
462 456
 
463
-#ifdef _MSC_VER
464 457
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
465 458
 {
466 459
 	try
... ...
@@ -473,7 +466,6 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wcha
473 466
 		return 0;
474 467
 	}
475 468
 }
476
-#endif
477 469
 
478 470
 int extendedSeekNeeded = -1;
479 471
 
Browse code

Replaced the Makefile with one that handles things better.

* g++ compiled DLLs seem to not be seen by Winamp when the
-static-libgcc and -static-libstdc++ flags are used.
* clang++ compiled DLLs seem to cause Winamp to crash on exit.

Naram Qashat authored on 2014/09/18 20:02:22
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-09-18
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -422,10 +422,12 @@ extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
422 422
 	return 1;
423 423
 }
424 424
 
425
+#ifdef _MSC_VER
425 426
 extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *)
426 427
 {
427 428
 	return 0;
428 429
 }
430
+#endif
429 431
 
430 432
 intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
431 433
 {
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -361,6 +361,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
361 361
 	}
362 362
 }
363 363
 
364
+#ifdef _MSC_VER
364 365
 extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
365 366
 {
366 367
 	try
... ...
@@ -373,6 +374,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *f
373 374
 		return 0;
374 375
 	}
375 376
 }
377
+#endif
376 378
 
377 379
 std::unique_ptr<XSFFile> extendedXSFFile;
378 380
 
... ...
@@ -396,6 +398,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, c
396 398
 	}
397 399
 }
398 400
 
401
+#ifdef _MSC_VER
399 402
 extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *fn, const char *data, const wchar_t *val)
400 403
 {
401 404
 	try
... ...
@@ -409,6 +412,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
409 412
 		return 0;
410 413
 	}
411 414
 }
415
+#endif
412 416
 
413 417
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
414 418
 {
... ...
@@ -454,6 +458,7 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char
454 458
 	}
455 459
 }
456 460
 
461
+#ifdef _MSC_VER
457 462
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
458 463
 {
459 464
 	try
... ...
@@ -466,6 +471,7 @@ extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wcha
466 471
 		return 0;
467 472
 	}
468 473
 }
474
+#endif
469 475
 
470 476
 int extendedSeekNeeded = -1;
471 477
 
Browse code

Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

Naram Qashat authored on 2013/04/23 20:29:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-10
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -308,7 +308,7 @@ extern "C" __declspec(dllexport) In_Module *winampGetInModule2()
308 308
 
309 309
 static eq_str eqstr;
310 310
 
311
-extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
311
+template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, const char *data, T *dest, size_t destlen)
312 312
 {
313 313
 	if (eqstr(data, "type"))
314 314
 	{
... ...
@@ -324,7 +324,6 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
324 324
 	{
325 325
 		try
326 326
 		{
327
-			XSFFile file = XSFFile(fn);
328 327
 			std::string tagToGet = data;
329 328
 			if (eqstr(data, "album"))
330 329
 				tagToGet = "game";
... ...
@@ -336,7 +335,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
336 335
 			}
337 336
 			else if (eqstr(tagToGet, "length"))
338 337
 			{
339
-				strcpy(dest, stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
338
+				String(stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()))).Substring(0, destlen - 1).CopyToString(dest, true);
340 339
 				return 1;
341 340
 			}
342 341
 			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
... ...
@@ -349,44 +348,29 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
349 348
 	}
350 349
 }
351 350
 
352
-extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
351
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
353 352
 {
354
-	if (eqstr(data, "type"))
353
+	try
355 354
 	{
356
-		dest[0] = L'0';
357
-		dest[1] = 0;
358
-		return 1;
355
+		auto file = XSFFile(fn);
356
+		return wrapperWinampGetExtendedFileInfo(file, data, dest, destlen);
359 357
 	}
360
-	else if (eqstr(data, "family"))
358
+	catch (const std::exception &)
361 359
 	{
362 360
 		return 0;
363 361
 	}
364
-	else
362
+}
363
+
364
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
365
+{
366
+	try
365 367
 	{
366
-		try
367
-		{
368
-			XSFFile file = XSFFile(fn);
369
-			std::string tagToGet = data;
370
-			if (eqstr(data, "album"))
371
-				tagToGet = "game";
372
-			if (!file.GetTagExists(tagToGet))
373
-			{
374
-				if (eqstr(tagToGet, "replaygain_track_gain"))
375
-					return 1;
376
-				return 0;
377
-			}
378
-			else if (eqstr(tagToGet, "length"))
379
-			{
380
-				wcscpy(dest, wstringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
381
-				return 1;
382
-			}
383
-			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest);
384
-			return 1;
385
-		}
386
-		catch (const std::exception &)
387
-		{
388
-			return 0;
389
-		}
368
+		auto file = XSFFile(fn);
369
+		return wrapperWinampGetExtendedFileInfo(file, data, dest, destlen);
370
+	}
371
+	catch (const std::exception &)
372
+	{
373
+		return 0;
390 374
 	}
391 375
 }
392 376
 
... ...
@@ -402,7 +386,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, c
402 386
 {
403 387
 	try
404 388
 	{
405
-		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetStr() != fn)
389
+		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetStr() != fn)
406 390
 			extendedXSFFile.reset(new XSFFile(fn));
407 391
 		return wrapperWinampSetExtendedFileInfo(data, val);
408 392
 	}
... ...
@@ -416,7 +400,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
416 400
 {
417 401
 	try
418 402
 	{
419
-		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetWStr() != fn)
403
+		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetWStr() != fn)
420 404
 			extendedXSFFile.reset(new XSFFile(fn));
421 405
 		return wrapperWinampSetExtendedFileInfo(data, val);
422 406
 	}
... ...
@@ -428,7 +412,7 @@ extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *f
428 412
 
429 413
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
430 414
 {
431
-	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().empty())
415
+	if (!extendedXSFFile || extendedXSFFile->GetFilename().empty())
432 416
 		return 0;
433 417
 	extendedXSFFile->SaveFile();
434 418
 	return 1;
Browse code

* Added more interpolation methods to in_ncsf. * Cleaned up a little of the code in the Interpolate function in in_ncsf. * Made it so changes in the config can apply to a running song, depending on the player. * Slight optimization of in_ncsf's interpolation so it doesn't have as much std::vector accessing. * Stopped trying to use the slope of the points to determine points outside the sample's range, hopefully will stop some of the clipping.

Naram Qashat authored on 2013/04/10 14:39:59
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - Winamp plugin
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-02
4
+ * Last modification on 2013-04-10
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -73,6 +73,8 @@ DWORD WINAPI playThread(void *b)
73 73
 void config(HWND hwndParent)
74 74
 {
75 75
 	xSFConfig->CallConfigDialog(inMod.hDllInstance, hwndParent);
76
+	if (xSFPlayer)
77
+		xSFConfig->CopyConfigToMemory(xSFPlayer, false);
76 78
 }
77 79
 
78 80
 void about(HWND hwndParent)
Browse code

Fix crashing if a file no longer exists when Winamp tries to access it.

Naram Qashat authored on 2013/04/07 16:38:28
Showing 1 changed files
... ...
@@ -101,7 +101,18 @@ void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
101 101
 		xSF = xSFFile;
102 102
 	else
103 103
 	{
104
-		xSF = new XSFFile(file);
104
+		try
105
+		{
106
+			xSF = new XSFFile(file);
107
+		}
108
+		catch (const std::exception &)
109
+		{
110
+			if (title)
111
+				String("").CopyToString(title);
112
+			if (length_in_ms)
113
+				*length_in_ms = -1000;
114
+			return;
115
+		}
105 116
 		toFree = true;
106 117
 	}
107 118
 	if (title)
... ...
@@ -309,23 +320,30 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, c
309 320
 	}
310 321
 	else
311 322
 	{
312
-		XSFFile file = XSFFile(fn);
313
-		std::string tagToGet = data;
314
-		if (eqstr(data, "album"))
315
-			tagToGet = "game";
316
-		if (!file.GetTagExists(tagToGet))
323
+		try
317 324
 		{
318
-			if (eqstr(tagToGet, "replaygain_track_gain"))
325
+			XSFFile file = XSFFile(fn);
326
+			std::string tagToGet = data;
327
+			if (eqstr(data, "album"))
328
+				tagToGet = "game";
329
+			if (!file.GetTagExists(tagToGet))
330
+			{
331
+				if (eqstr(tagToGet, "replaygain_track_gain"))
332
+					return 1;
333
+				return 0;
334
+			}
335
+			else if (eqstr(tagToGet, "length"))
336
+			{
337
+				strcpy(dest, stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
319 338
 				return 1;
320
-			return 0;
339
+			}
340
+			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
341
+			return 1;
321 342
 		}
322
-		else if (eqstr(tagToGet, "length"))
343
+		catch (const std::exception &)
323 344
 		{
324
-			strcpy(dest, stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
325
-			return 1;
345
+			return 0;
326 346
 		}
327
-		file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
328
-		return 1;
329 347
 	}
330 348
 }
331 349
 
... ...
@@ -343,23 +361,30 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *f
343 361
 	}
344 362
 	else
345 363
 	{
346
-		XSFFile file = XSFFile(fn);
347
-		std::string tagToGet = data;
348
-		if (eqstr(data, "album"))
349
-			tagToGet = "game";
350
-		if (!file.GetTagExists(tagToGet))
364
+		try
351 365
 		{
352
-			if (eqstr(tagToGet, "replaygain_track_gain"))
366
+			XSFFile file = XSFFile(fn);
367
+			std::string tagToGet = data;
368
+			if (eqstr(data, "album"))
369
+				tagToGet = "game";
370
+			if (!file.GetTagExists(tagToGet))
371
+			{
372
+				if (eqstr(tagToGet, "replaygain_track_gain"))
373
+					return 1;
374
+				return 0;
375
+			}
376
+			else if (eqstr(tagToGet, "length"))
377
+			{
378
+				wcscpy(dest, wstringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
353 379
 				return 1;
354
-			return 0;
380
+			}
381
+			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest);
382
+			return 1;
355 383
 		}
356
-		else if (eqstr(tagToGet, "length"))
384
+		catch (const std::exception &)
357 385
 		{
358
-			wcscpy(dest, wstringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
359
-			return 1;
386
+			return 0;
360 387
 		}
361
-		file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest);
362
-		return 1;
363 388
 	}
364 389
 }
365 390
 
... ...
@@ -373,16 +398,30 @@ int wrapperWinampSetExtendedFileInfo(const char *data, const wchar_t *val)
373 398
 
374 399
 extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, const char *data, const wchar_t *val)
375 400
 {
376
-	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetStr() != fn)
377
-		extendedXSFFile.reset(new XSFFile(fn));
378
-	return wrapperWinampSetExtendedFileInfo(data, val);
401
+	try
402
+	{
403
+		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetStr() != fn)
404
+			extendedXSFFile.reset(new XSFFile(fn));
405
+		return wrapperWinampSetExtendedFileInfo(data, val);
406
+	}
407
+	catch (const std::exception &)
408
+	{
409
+		return 0;
410
+	}
379 411
 }
380 412
 
381 413
 extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *fn, const char *data, const wchar_t *val)
382 414
 {
383
-	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetWStr() != fn)
384
-		extendedXSFFile.reset(new XSFFile(fn));
385
-	return wrapperWinampSetExtendedFileInfo(data, val);
415
+	try
416
+	{
417
+		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetWStr() != fn)
418
+			extendedXSFFile.reset(new XSFFile(fn));
419
+		return wrapperWinampSetExtendedFileInfo(data, val);
420
+	}
421
+	catch (const std::exception &)
422
+	{
423
+		return 0;
424
+	}
386 425
 }
387 426
 
388 427
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
... ...
@@ -418,14 +457,28 @@ intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlay
418 457
 
419 458
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char *fn, int *size, int *bps, int *nch, int *srate)
420 459
 {
421
-	auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
422
-	return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
460
+	try
461
+	{
462
+		auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
463
+		return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
464
+	}
465
+	catch (const std::exception &)
466
+	{
467
+		return 0;
468
+	}
423 469
 }
424 470
 
425 471
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
426 472
 {
427
-	auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
428
-	return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
473
+	try
474
+	{
475
+		auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
476
+		return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
477
+	}
478
+	catch (const std::exception &)
479
+	{
480
+		return 0;
481
+	}
429 482
 }
430 483
 
431 484
 int extendedSeekNeeded = -1;
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 - Winamp plugin
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
  */
... ...
@@ -258,7 +258,7 @@ void eqSet(int, char [10], int)
258 258
 In_Module inMod =
259 259
 {
260 260
 	IN_VER,
261
-	const_cast<char *>(XSFPlayer::WinampDescription), /* Unsafe but Winamp's SDK requires this */
261
+	const_cast<char *>(XSFConfig::CommonNameWithVersion().GetStrC()), /* Unsafe but Winamp's SDK requires this */
262 262
 	nullptr, /* Filled by Winamp */
263 263
 	nullptr, /* Filled by Winamp */
264 264
 	const_cast<char *>(XSFPlayer::WinampExts), /* Unsafe but Winamp's SDK requires this */
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 - Winamp plugin
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
  */
... ...
@@ -13,10 +13,10 @@
13 13
 #include <winamp/wa_ipc.h>
14 14
 
15 15
 extern In_Module inMod;
16
-const XSFFile *xSFFile = NULL;
17
-XSFFile *xSFFileInInfo = NULL;
18
-XSFPlayer *xSFPlayer = NULL;
19
-XSFConfig *xSFConfig = NULL;
16
+const XSFFile *xSFFile = nullptr;
17
+XSFFile *xSFFileInInfo = nullptr;
18
+XSFPlayer *xSFPlayer = nullptr;
19
+XSFConfig *xSFConfig = nullptr;
20 20
 bool paused;
21 21
 int seek_needed;
22 22
 double decode_pos_ms;
... ...
@@ -36,7 +36,7 @@ DWORD WINAPI playThread(void *b)
36 36
 			decode_pos_ms = seek_needed - (seek_needed % 1000);
37 37
 			seek_needed = -1;
38 38
 			auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
39
-			xSFPlayer->Seek(static_cast<unsigned>(decode_pos_ms), NULL, dummyBuffer, inMod.outMod);
39
+			xSFPlayer->Seek(static_cast<unsigned>(decode_pos_ms), nullptr, dummyBuffer, inMod.outMod);
40 40
 		}
41 41
 
42 42
 		if (done)
... ...
@@ -149,7 +149,7 @@ int infoBox(const in_char *file, HWND hwndParent)
149 149
 	return INFOBOX_EDITED;
150 150
 }
151 151
 
152
-int isOurFile(const in_char *fn)
152
+int isOurFile(const in_char *)
153 153
 {
154 154
 	return 0;
155 155
 }
... ...
@@ -178,7 +178,7 @@ int play(const in_char *fn)
178 178
 
179 179
 		xSFPlayer = tmpxSFPlayer.release();
180 180
 		killThread = false;
181
-		thread_handle = CreateThread(NULL, 0, playThread, &killThread, 0, NULL);
181
+		thread_handle = CreateThread(nullptr, 0, playThread, &killThread, 0, nullptr);
182 182
 		return 0;
183 183
 	}
184 184
 	catch (const std::exception &)
... ...
@@ -220,8 +220,8 @@ void stop()
220 220
 	inMod.outMod->Close();
221 221
 	inMod.SAVSADeInit();
222 222
 	delete xSFPlayer;
223
-	xSFPlayer = NULL;
224
-	xSFFile = NULL;
223
+	xSFPlayer = nullptr;
224
+	xSFFile = nullptr;
225 225
 }
226 226
 
227 227
 int getLength()
... ...
@@ -251,7 +251,7 @@ void setPan(int pan)
251 251
 	inMod.outMod->SetPan(pan);
252 252
 }
253 253
 
254
-void eqSet(int on, char data[10], int preamp)
254
+void eqSet(int, char [10], int)
255 255
 {
256 256
 }
257 257
 
... ...
@@ -259,8 +259,8 @@ In_Module inMod =
259 259
 {
260 260
 	IN_VER,
261 261
 	const_cast<char *>(XSFPlayer::WinampDescription), /* Unsafe but Winamp's SDK requires this */
262
-	NULL, /* Filled by Winamp */
263
-	NULL, /* Filled by Winamp */
262
+	nullptr, /* Filled by Winamp */
263
+	nullptr, /* Filled by Winamp */
264 264
 	const_cast<char *>(XSFPlayer::WinampExts), /* Unsafe but Winamp's SDK requires this */
265 265
 	1,
266 266
 	IN_MODULE_FLAG_USES_OUTPUT_PLUGIN | IN_MODULE_FLAG_REPLAYGAIN,
... ...
@@ -281,11 +281,11 @@ In_Module inMod =
281 281
 	setOutputTime,
282 282
 	setVolume,
283 283
 	setPan,
284
-	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* Vis stuff, filled by Winamp */
285
-	NULL, NULL, /* DSP stuff, filled by Winamp */
284
+	nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, /* Vis stuff, filled by Winamp */
285
+	nullptr, nullptr, /* DSP stuff, filled by Winamp */
286 286
 	eqSet,
287
-	NULL, /* Filled by Winamp */
288
-	NULL /* Filled by Winamp */
287
+	nullptr, /* Filled by Winamp */
288
+	nullptr /* Filled by Winamp */
289 289
 };
290 290
 
291 291
 extern "C" __declspec(dllexport) In_Module *winampGetInModule2()
... ...
@@ -393,7 +393,7 @@ extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
393 393
 	return 1;
394 394
 }
395 395
 
396
-extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *fn)
396
+extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *)
397 397
 {
398 398
 	return 0;
399 399
 }
... ...
@@ -438,7 +438,7 @@ extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t h
438 438
 	if (extendedSeekNeeded != -1)
439 439
 	{
440 440
 		auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
441
-		if (tmpxSFPlayer->Seek(static_cast<unsigned>(extendedSeekNeeded), killswitch, dummyBuffer, NULL))
441
+		if (tmpxSFPlayer->Seek(static_cast<unsigned>(extendedSeekNeeded), killswitch, dummyBuffer, nullptr))
442 442
 			return 0;
443 443
 		extendedSeekNeeded = -1;
444 444
 	}
... ...
@@ -457,7 +457,7 @@ extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t h
457 457
 	return copied;
458 458
 }
459 459
 
460
-extern "C" __declspec(dllexport) int winampGetExtendedRead_setTime(intptr_t handle, int millisecs)
460
+extern "C" __declspec(dllexport) int winampGetExtendedRead_setTime(intptr_t, int millisecs)
461 461
 {
462 462
 	extendedSeekNeeded = millisecs;
463 463
 	return 1;
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
... ...
@@ -117,13 +117,20 @@ void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
117 117
 
118 118
 int infoBox(const in_char *file, HWND hwndParent)
119 119
 {
120
-	auto xSF = std::auto_ptr<XSFFile>(new XSFFile());
120
+	auto xSF = std::unique_ptr<XSFFile>(new XSFFile());
121 121
 	if (!file || !*file)
122 122
 		*xSF = *xSFFile;
123 123
 	else
124 124
 	{
125
-		auto tmpxSF = std::auto_ptr<XSFFile>(new XSFFile(file));
126
-		*xSF = *tmpxSF;
125
+		try
126
+		{
127
+			auto tmpxSF = std::unique_ptr<XSFFile>(new XSFFile(file));
128
+			*xSF = *tmpxSF;
129
+		}
130
+		catch (const std::exception &)
131
+		{
132
+			return INFOBOX_UNCHANGED;
133
+		}
127 134
 	}
128 135
 	// TODO: Eventually make a dialog box for editing the info
129 136
 	/*xSFFileInInfo = xSF.get();
... ...
@@ -151,7 +158,7 @@ int play(const in_char *fn)
151 158
 {
152 159
 	try
153 160
 	{
154
-		auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
161
+		auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
155 162
 		xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), true);
156 163
 		if (!tmpxSFPlayer->Load())
157 164
 			return 1;
... ...
@@ -356,7 +363,7 @@ extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *f
356 363
 	}
357 364
 }
358 365
 
359
-std::auto_ptr<XSFFile> extendedXSFFile;
366
+std::unique_ptr<XSFFile> extendedXSFFile;
360 367
 
361 368
 int wrapperWinampSetExtendedFileInfo(const char *data, const wchar_t *val)
362 369
 {
... ...
@@ -391,7 +398,7 @@ extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t
391 398
 	return 0;
392 399
 }
393 400
 
394
-intptr_t wrapperWinampGetExtendedRead_open(std::auto_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
401
+intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
395 402
 {
396 403
 	xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), true);
397 404
 	if (!tmpxSFPlayer->Load())
... ...
@@ -411,14 +418,14 @@ intptr_t wrapperWinampGetExtendedRead_open(std::auto_ptr<XSFPlayer> tmpxSFPlayer
411 418
 
412 419
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char *fn, int *size, int *bps, int *nch, int *srate)
413 420
 {
414
-	auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
415
-	return wrapperWinampGetExtendedRead_open(tmpxSFPlayer, size, bps, nch, srate);
421
+	auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
422
+	return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
416 423
 }
417 424
 
418 425
 extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
419 426
 {
420
-	auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
421
-	return wrapperWinampGetExtendedRead_open(tmpxSFPlayer, size, bps, nch, srate);
427
+	auto tmpxSFPlayer = std::unique_ptr<XSFPlayer>(XSFPlayer::Create(fn));
428
+	return wrapperWinampGetExtendedRead_open(std::move(tmpxSFPlayer), size, bps, nch, srate);
422 429
 }
423 430
 
424 431
 int extendedSeekNeeded = -1;
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,464 @@
1
+/*
2
+ * xSF - Winamp plugin
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
+#include "XSFPlayer.h"
10
+#include "XSFConfig.h"
11
+#include "windowsh_wrapper.h"
12
+#include <winamp/in2.h>
13
+#include <winamp/wa_ipc.h>
14
+
15
+extern In_Module inMod;
16
+const XSFFile *xSFFile = NULL;
17
+XSFFile *xSFFileInInfo = NULL;
18
+XSFPlayer *xSFPlayer = NULL;
19
+XSFConfig *xSFConfig = NULL;
20
+bool paused;
21
+int seek_needed;
22
+double decode_pos_ms;
23
+HANDLE thread_handle = INVALID_HANDLE_VALUE;
24
+bool killThread = false;
25
+
26
+static const unsigned NumChannels = 2;
27
+static const unsigned BitsPerSample = 16;
28
+
29
+DWORD WINAPI playThread(void *b)
30
+{
31
+	bool done = false;
32
+	while (!*static_cast<bool *>(b))
33
+	{
34
+		if (seek_needed != -1)
35
+		{
36
+			decode_pos_ms = seek_needed - (seek_needed % 1000);
37
+			seek_needed = -1;
38
+			auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
39
+			xSFPlayer->Seek(static_cast<unsigned>(decode_pos_ms), NULL, dummyBuffer, inMod.outMod);
40
+		}
41
+
42
+		if (done)
43
+		{
44
+			inMod.outMod->CanWrite();
45
+			if (!inMod.outMod->IsPlaying())
46
+			{
47
+				PostMessage(inMod.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
48
+				return 0;
49
+			}
50
+			Sleep(10);
51
+		}
52
+		else if (static_cast<unsigned>(inMod.outMod->CanWrite()) >= ((576 * NumChannels * (BitsPerSample / 8)) << (inMod.dsp_isactive() ? 1 : 0)))
53
+		{
54
+			auto sampleBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
55
+			unsigned samplesWritten = 0;
56
+			done = xSFPlayer->FillBuffer(sampleBuffer, samplesWritten);
57
+			if (samplesWritten)
58
+			{
59
+				inMod.SAAddPCMData(reinterpret_cast<char *>(&sampleBuffer[0]), NumChannels, BitsPerSample, static_cast<int>(decode_pos_ms));
60
+				inMod.VSAAddPCMData(reinterpret_cast<char *>(&sampleBuffer[0]), NumChannels, BitsPerSample, static_cast<int>(decode_pos_ms));
61
+				if (inMod.dsp_isactive())
62
+					samplesWritten = inMod.dsp_dosamples(reinterpret_cast<short *>(&sampleBuffer[0]), samplesWritten, BitsPerSample, NumChannels, xSFPlayer->GetSampleRate());
63
+				decode_pos_ms += samplesWritten * 1000.0 / xSFPlayer->GetSampleRate();
64
+				inMod.outMod->Write(reinterpret_cast<char *>(&sampleBuffer[0]), samplesWritten * NumChannels * (BitsPerSample / 8));
65
+			}
66
+		}
67
+		else
68
+			Sleep(20);
69
+	}
70
+	return 0;
71
+}
72
+
73
+void config(HWND hwndParent)
74
+{
75
+	xSFConfig->CallConfigDialog(inMod.hDllInstance, hwndParent);
76
+}
77
+
78
+void about(HWND hwndParent)
79
+{
80
+	xSFConfig->About(hwndParent);
81
+}
82
+
83
+void init()
84
+{
85
+	xSFConfig = XSFConfig::Create();
86
+	xSFConfig->LoadConfig();
87
+	xSFConfig->GenerateDialogs();
88
+}
89
+
90
+void quit()
91
+{
92
+	delete xSFPlayer;
93
+	delete xSFConfig;
94
+}
95
+
96
+void getFileInfo(const in_char *file, in_char *title, int *length_in_ms)
97
+{
98
+	const XSFFile *xSF;
99
+	bool toFree = false;
100
+	if (!file || !*file)
101
+		xSF = xSFFile;
102
+	else
103
+	{
104
+		xSF = new XSFFile(file);
105
+		toFree = true;
106
+	}
107
+	if (title)
108
+	{
109
+		String formattedTitle = xSF->GetFormattedTitle(xSFConfig->GetTitleFormat()).Substring(0, GETFILEINFO_TITLE_LENGTH - 1);
110
+		formattedTitle.CopyToString(title);
111
+	}
112
+	if (length_in_ms)
113
+		*length_in_ms = xSF->GetLengthMS(xSFConfig->GetDefaultLength()) + xSF->GetFadeMS(xSFConfig->GetDefaultFade());
114
+	if (toFree)
115
+		delete xSF;
116
+}
117
+
118
+int infoBox(const in_char *file, HWND hwndParent)
119
+{
120
+	auto xSF = std::auto_ptr<XSFFile>(new XSFFile());
121
+	if (!file || !*file)
122
+		*xSF = *xSFFile;
123
+	else
124
+	{
125
+		auto tmpxSF = std::auto_ptr<XSFFile>(new XSFFile(file));
126
+		*xSF = *tmpxSF;
127
+	}
128
+	// TODO: Eventually make a dialog box for editing the info
129
+	/*xSFFileInInfo = xSF.get();
130
+	xSFConfig->CallInfoDialog(inMod.hDllInstance, hwndParent);*/
131
+	bool utf8 = xSF->GetTagExists("utf8");
132
+	auto tags = xSF->GetAllTags();
133
+	auto keys = tags.GetKeys();
134
+	String info;
135
+	for (unsigned x = 0, numTags = keys.size(); x < numTags; ++x)
136
+	{
137
+		if (x)
138
+			info += "\n";
139
+		info += String(keys[x] + "=") + String(tags[keys[x]], utf8);
140
+	}
141
+	MessageBoxW(hwndParent, info.GetWStrC(), xSF->GetFilenameWithoutPath().GetWStrC(), MB_OK);
142
+	return INFOBOX_EDITED;
143
+}
144
+
145
+int isOurFile(const in_char *fn)
146
+{
147
+	return 0;
148
+}
149
+
150
+int play(const in_char *fn)
151
+{
152
+	try
153
+	{
154
+		auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
155
+		xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), true);
156
+		if (!tmpxSFPlayer->Load())
157
+			return 1;
158
+		xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), false);
159
+		xSFFile = tmpxSFPlayer->GetXSFFile();
160
+		paused = false;
161
+		seek_needed = -1;
162
+		decode_pos_ms = 0.0;
163
+
164
+		int maxlatency = inMod.outMod->Open(tmpxSFPlayer->GetSampleRate(), NumChannels, BitsPerSample, -1, -1);
165
+		if (maxlatency < 0)
166
+			return 1;
167
+		inMod.SetInfo((tmpxSFPlayer->GetSampleRate() * NumChannels * BitsPerSample) / 1000, tmpxSFPlayer->GetSampleRate() / 1000, NumChannels, 1);
168
+		inMod.SAVSAInit(maxlatency, tmpxSFPlayer->GetSampleRate());
169
+		inMod.VSASetInfo(tmpxSFPlayer->GetSampleRate(), NumChannels);
170
+		inMod.outMod->SetVolume(-666);
171
+
172
+		xSFPlayer = tmpxSFPlayer.release();
173
+		killThread = false;
174
+		thread_handle = CreateThread(NULL, 0, playThread, &killThread, 0, NULL);
175
+		return 0;
176
+	}
177
+	catch (const std::exception &)
178
+	{
179
+		return 1;
180
+	}
181
+}
182
+
183
+void pause()
184
+{
185
+	paused = true;
186
+	inMod.outMod->Pause(1);
187
+}
188
+
189
+void unPause()
190
+{
191
+	paused = false;
192
+	inMod.outMod->Pause(0);
193
+}
194
+
195
+int isPaused()
196
+{
197
+	return paused;
198
+}
199
+
200
+void stop()
201
+{
202
+	if (thread_handle != INVALID_HANDLE_VALUE)
203
+	{
204
+		killThread = true;
205
+		if (WaitForSingleObject(thread_handle, 2000) == WAIT_TIMEOUT)
206
+		{
207
+			MessageBoxW(inMod.hMainWindow, L"error asking thread to die!", L"error killing decode thread", 0);
208
+			TerminateThread(thread_handle, 0);
209
+		}
210
+		CloseHandle(thread_handle);
211
+		thread_handle = INVALID_HANDLE_VALUE;
212
+	}
213
+	inMod.outMod->Close();
214
+	inMod.SAVSADeInit();
215
+	delete xSFPlayer;
216
+	xSFPlayer = NULL;
217
+	xSFFile = NULL;
218
+}
219
+
220
+int getLength()
221
+{
222
+	if (!xSFFile->HasFile())
223
+		return -1000;
224
+	return xSFFile->GetLengthMS(xSFConfig->GetDefaultLength()) + xSFFile->GetFadeMS(xSFConfig->GetDefaultFade());
225
+}
226
+
227
+int getOutputTime()
228
+{
229
+	return inMod.outMod->GetOutputTime();
230
+}
231
+
232
+void setOutputTime(int time_in_ms)
233
+{
234
+	seek_needed = time_in_ms;
235
+}
236
+
237
+void setVolume(int volume)
238
+{
239
+	inMod.outMod->SetVolume(volume);
240
+}
241
+
242
+void setPan(int pan)
243
+{
244
+	inMod.outMod->SetPan(pan);
245
+}
246
+
247
+void eqSet(int on, char data[10], int preamp)
248
+{
249
+}
250
+
251
+In_Module inMod =
252
+{
253
+	IN_VER,
254
+	const_cast<char *>(XSFPlayer::WinampDescription), /* Unsafe but Winamp's SDK requires this */
255
+	NULL, /* Filled by Winamp */
256
+	NULL, /* Filled by Winamp */
257
+	const_cast<char *>(XSFPlayer::WinampExts), /* Unsafe but Winamp's SDK requires this */
258
+	1,
259
+	IN_MODULE_FLAG_USES_OUTPUT_PLUGIN | IN_MODULE_FLAG_REPLAYGAIN,
260
+	config,
261
+	about,
262
+	init,
263
+	quit,
264
+	getFileInfo,
265
+	infoBox,
266
+	isOurFile,
267
+	play,
268
+	pause,
269
+	unPause,
270
+	isPaused,
271
+	stop,
272
+	getLength,
273
+	getOutputTime,
274
+	setOutputTime,
275
+	setVolume,
276
+	setPan,
277
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* Vis stuff, filled by Winamp */
278
+	NULL, NULL, /* DSP stuff, filled by Winamp */
279
+	eqSet,
280
+	NULL, /* Filled by Winamp */
281
+	NULL /* Filled by Winamp */
282
+};
283
+
284
+extern "C" __declspec(dllexport) In_Module *winampGetInModule2()
285
+{
286
+	return &inMod;
287
+}
288
+
289
+static eq_str eqstr;
290
+
291
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
292
+{
293
+	if (eqstr(data, "type"))
294
+	{
295
+		dest[0] = '0';
296
+		dest[1] = 0;
297
+		return 1;
298
+	}
299
+	else if (eqstr(data, "family"))
300
+	{
301
+		return 0;
302
+	}
303
+	else
304
+	{
305
+		XSFFile file = XSFFile(fn);
306
+		std::string tagToGet = data;
307
+		if (eqstr(data, "album"))
308
+			tagToGet = "game";
309
+		if (!file.GetTagExists(tagToGet))
310
+		{
311
+			if (eqstr(tagToGet, "replaygain_track_gain"))
312
+				return 1;
313
+			return 0;
314
+		}
315
+		else if (eqstr(tagToGet, "length"))
316
+		{
317
+			strcpy(dest, stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
318
+			return 1;
319
+		}
320
+		file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
321
+		return 1;
322
+	}
323
+}
324
+
325
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
326
+{
327
+	if (eqstr(data, "type"))
328
+	{
329
+		dest[0] = L'0';
330
+		dest[1] = 0;
331
+		return 1;
332
+	}
333
+	else if (eqstr(data, "family"))
334
+	{
335
+		return 0;
336
+	}
337
+	else
338
+	{
339
+		XSFFile file = XSFFile(fn);
340
+		std::string tagToGet = data;
341
+		if (eqstr(data, "album"))
342
+			tagToGet = "game";
343
+		if (!file.GetTagExists(tagToGet))
344
+		{
345
+			if (eqstr(tagToGet, "replaygain_track_gain"))
346
+				return 1;
347
+			return 0;
348
+		}
349
+		else if (eqstr(tagToGet, "length"))
350
+		{
351
+			wcscpy(dest, wstringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
352
+			return 1;
353
+		}
354
+		file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest);
355
+		return 1;
356
+	}
357
+}
358
+
359
+std::auto_ptr<XSFFile> extendedXSFFile;
360
+
361
+int wrapperWinampSetExtendedFileInfo(const char *data, const wchar_t *val)
362
+{
363
+	extendedXSFFile->SetTag(data, val);
364
+	return 1;
365
+}
366
+
367
+extern "C" __declspec(dllexport) int winampSetExtendedFileInfo(const char *fn, const char *data, const wchar_t *val)
368
+{
369
+	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetStr() != fn)
370
+		extendedXSFFile.reset(new XSFFile(fn));
371
+	return wrapperWinampSetExtendedFileInfo(data, val);
372
+}
373
+
374
+extern "C" __declspec(dllexport) int winampSetExtendedFileInfoW(const wchar_t *fn, const char *data, const wchar_t *val)
375
+{
376
+	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetWStr() != fn)
377
+		extendedXSFFile.reset(new XSFFile(fn));
378
+	return wrapperWinampSetExtendedFileInfo(data, val);
379
+}
380
+
381
+extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
382
+{
383
+	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().empty())
384
+		return 0;
385
+	extendedXSFFile->SaveFile();
386
+	return 1;
387
+}
388
+
389
+extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *fn)
390
+{
391
+	return 0;
392
+}
393
+
394
+intptr_t wrapperWinampGetExtendedRead_open(std::auto_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
395
+{
396
+	xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), true);
397
+	if (!tmpxSFPlayer->Load())
398
+		return 0;
399
+	tmpxSFPlayer->IgnoreVolume();
400
+	xSFConfig->CopyConfigToMemory(tmpxSFPlayer.get(), false);
401
+	if (size)
402
+		*size = tmpxSFPlayer->GetLengthInSamples() * NumChannels * (BitsPerSample / 8);
403
+	if (bps)
404
+		*bps = BitsPerSample;
405
+	if (nch)
406
+		*nch = NumChannels;
407
+	if (srate)
408
+		*srate = tmpxSFPlayer->GetSampleRate();
409
+	return reinterpret_cast<intptr_t>(tmpxSFPlayer.release());
410
+}
411
+
412
+extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_open(const char *fn, int *size, int *bps, int *nch, int *srate)
413
+{
414
+	auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
415
+	return wrapperWinampGetExtendedRead_open(tmpxSFPlayer, size, bps, nch, srate);
416
+}
417
+
418
+extern "C" __declspec(dllexport) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate)
419
+{
420
+	auto tmpxSFPlayer = std::auto_ptr<XSFPlayer>(XSFPlayer::Create(fn));
421
+	return wrapperWinampGetExtendedRead_open(tmpxSFPlayer, size, bps, nch, srate);
422
+}
423
+
424
+int extendedSeekNeeded = -1;
425
+
426
+extern "C" __declspec(dllexport) size_t winampGetExtendedRead_getData(intptr_t handle, char *dest, size_t len, int *killswitch)
427
+{
428
+	XSFPlayer *tmpxSFPlayer = reinterpret_cast<XSFPlayer *>(handle);
429
+	if (!tmpxSFPlayer)
430
+		return 0;
431
+	if (extendedSeekNeeded != -1)
432
+	{
433
+		auto dummyBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
434
+		if (tmpxSFPlayer->Seek(static_cast<unsigned>(extendedSeekNeeded), killswitch, dummyBuffer, NULL))
435
+			return 0;
436
+		extendedSeekNeeded = -1;
437
+	}
438
+	unsigned copied = 0;
439
+	bool done = false;
440
+	while (copied + (576 * NumChannels * (BitsPerSample / 8)) < len && !done)
441
+	{
442
+		auto sampleBuffer = std::vector<uint8_t>(576 * NumChannels * (BitsPerSample / 8));
443
+		unsigned samplesWritten = 0;
444
+		done = tmpxSFPlayer->FillBuffer(sampleBuffer, samplesWritten);
445
+		memcpy(&dest[copied], &sampleBuffer[0], samplesWritten * NumChannels * (BitsPerSample / 8));
446
+		copied += samplesWritten * NumChannels * (BitsPerSample / 8);
447
+		if (killswitch && *killswitch)
448
+			break;
449
+	}
450
+	return copied;
451
+}
452
+
453
+extern "C" __declspec(dllexport) int winampGetExtendedRead_setTime(intptr_t handle, int millisecs)
454
+{
455
+	extendedSeekNeeded = millisecs;
456
+	return 1;
457
+}
458
+
459
+extern "C" __declspec(dllexport) void winampGetExtendedRead_close(intptr_t handle)
460
+{
461
+	XSFPlayer *tmpxSFPlayer = reinterpret_cast<XSFPlayer *>(handle);
462
+	if (tmpxSFPlayer)
463
+		delete tmpxSFPlayer;
464
+}