1
0

main.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef NULLSOFT_ML_RG_MAIN_H
  2. #define NULLSOFT_ML_RG_MAIN_H
  3. #include <windows.h>
  4. #include "../../General/gen_ml/ml.h"
  5. #include <windowsx.h>
  6. #include "../winamp/wa_ipc.h"
  7. #include "../../General/gen_ml/ml.h"
  8. #include "resource.h"
  9. #include <string>
  10. #include <vector>
  11. #include <map>
  12. extern winampMediaLibraryPlugin plugin;
  13. extern char *iniFile;
  14. LRESULT SetFileInfo(const wchar_t *filename, const wchar_t *metadata, const wchar_t *data);
  15. int GetFileInfo(const wchar_t *filename, const wchar_t *metadata, wchar_t *dest, int len);
  16. void WriteFileInfo();
  17. void TagUpdated(const wchar_t *filename);
  18. struct RGWorkFile
  19. {
  20. RGWorkFile(const wchar_t *_filename=0)
  21. {
  22. if (_filename)
  23. lstrcpynW(filename, _filename, MAX_PATH);
  24. else
  25. filename[0]=0;
  26. track_gain[0]=0;
  27. track_peak[0]=0;
  28. album_gain[0]=0;
  29. album_peak[0]=0;
  30. }
  31. wchar_t filename[MAX_PATH];
  32. wchar_t track_gain[64];
  33. wchar_t track_peak[64];
  34. wchar_t album_gain[64];
  35. wchar_t album_peak[64];
  36. };
  37. class ProgressCallback;
  38. class WorkQueue
  39. {
  40. public:
  41. WorkQueue() : totalFiles(0){}
  42. void Add(const wchar_t *filename);
  43. void Calculate(ProgressCallback *callback, int *killSwitch);
  44. typedef std::vector<RGWorkFile> RGWorkQueue;
  45. typedef std::map<std::wstring, RGWorkQueue> AlbumMap;
  46. AlbumMap albums;
  47. RGWorkQueue unclassified;
  48. size_t totalFiles;
  49. };
  50. constexpr auto TIME_SPAN_MS = 10;
  51. class ProgressCallback
  52. {
  53. public:
  54. ProgressCallback(HWND _c)
  55. : callback(_c),
  56. totalReceived(0)
  57. {
  58. ticks = GetTickCount64();
  59. }
  60. void InformSize(size_t bytes)
  61. {
  62. if (!PostMessage(callback, WM_USER + 3, 0, bytes))
  63. {
  64. // LOG the error
  65. DWORD e = GetLastError();
  66. }
  67. }
  68. /// <summary>
  69. /// This function may fire an "ERROR_NOT_ENOUGH_QUOTA" 1816 (0x718) error when the limit is hit!
  70. /// Put some throttle here, post message every 10 ms, not each time we receive a progress.
  71. /// </summary>
  72. /// <param name="bytes"></param>
  73. void Progress(size_t bytes)
  74. {
  75. totalReceived += bytes;
  76. ULONGLONG currentTicks = GetTickCount64();
  77. if (currentTicks - ticks >= TIME_SPAN_MS)
  78. {
  79. ticks = currentTicks;
  80. if (!PostMessage(callback, WM_USER + 4, 0, totalReceived))
  81. {
  82. // LOG the error
  83. DWORD e = GetLastError();
  84. }
  85. totalReceived = 0;
  86. }
  87. }
  88. void FileFinished()
  89. {
  90. // notify remaining bytes
  91. if (totalReceived)
  92. {
  93. PostMessage(callback, WM_USER + 4, 0, totalReceived);
  94. totalReceived = 0;
  95. }
  96. if(!PostMessage(callback, WM_USER, 0, 0))
  97. {
  98. // LOG the error
  99. DWORD e = GetLastError();
  100. }
  101. }
  102. void AlbumFinished(WorkQueue::RGWorkQueue *album)
  103. {
  104. if(!PostMessage(callback, WM_USER + 1, 0, (LPARAM)album))
  105. {
  106. // LOG the error
  107. DWORD e = GetLastError();
  108. }
  109. }
  110. HWND callback;
  111. ULONGLONG ticks;
  112. size_t totalReceived;
  113. };
  114. void CopyAlbumData(WorkQueue::RGWorkQueue &workQueue, const wchar_t *album_gain, const wchar_t *album_peak);
  115. void WriteAlbum(WorkQueue::RGWorkQueue &workQueue);
  116. void WriteTracks(WorkQueue::RGWorkQueue &workQueue);
  117. void DoResults(WorkQueue::RGWorkQueue &queue);
  118. void DoResults(WorkQueue &queue);
  119. void DoProgress(WorkQueue &workQueue);
  120. void DestroyRG(void *context);
  121. void *CreateRG();
  122. void CalculateAlbumRG(void *context, wchar_t album_gain[64], wchar_t album_peak[64], float &albumPeak);
  123. void StartRG(void *context);
  124. void CalculateRG(void *context, const wchar_t *filename, wchar_t track_gain[64], wchar_t track_peak[64], ProgressCallback *callback, int *killSwitch, float &albumPeak);
  125. HWND GetDialogBoxParent();
  126. BOOL windowOffScreen(HWND hwnd, POINT pt);
  127. extern int config_ask, config_ask_each_album, config_ignore_gained_album;
  128. INT_PTR WINAPI RGConfig(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  129. #endif