Results.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "main.h"
  2. #include "resource.h"
  3. #include "../nu/listview.h"
  4. #include "api__ml_rg.h"
  5. #include <shlwapi.h>
  6. #include <strsafe.h>
  7. // this isn't nice but it localises the values for display as they're saved in "C" locale
  8. enum { GAIN_MODE=0, PEAK_MODE };
  9. wchar_t* LocaliseNumericText(wchar_t str[64], int mode){
  10. static wchar_t tmp[64];
  11. double value;
  12. tmp[0]=0;
  13. value = _wtof_l(str,WASABI_API_LNG->Get_C_NumericLocale());
  14. StringCchPrintfW(tmp,64,(mode==GAIN_MODE?L"%-+.2f dB":L"%-.9f"),value);
  15. return tmp;
  16. }
  17. static void AddQueueToListView(W_ListView *listView, WorkQueue::RGWorkQueue *queue)
  18. {
  19. int i=listView->GetCount();
  20. for(WorkQueue::RGWorkQueue::iterator itr = queue->begin(); itr!= queue->end(); itr++)
  21. {
  22. listView->InsertItem(i, PathFindFileNameW(itr->filename), (int)&*itr);
  23. listView->SetItemText(i, 1, LocaliseNumericText(itr->track_gain,GAIN_MODE));
  24. listView->SetItemText(i, 2, LocaliseNumericText(itr->track_peak,PEAK_MODE));
  25. listView->SetItemText(i, 3, LocaliseNumericText(itr->album_gain,GAIN_MODE));
  26. listView->SetItemText(i, 4, LocaliseNumericText(itr->album_peak,PEAK_MODE));
  27. i++;
  28. }
  29. }
  30. INT_PTR WINAPI ReplayGainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  31. {
  32. switch(msg)
  33. {
  34. case WM_INITDIALOG:
  35. {
  36. W_ListView listView(GetDlgItem(hwndDlg, IDC_RGLIST));
  37. listView.setwnd(GetDlgItem(hwndDlg, IDC_RGLIST));
  38. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_FILENAME), 200);
  39. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_TRACK_GAIN), 65);
  40. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_TRACK_PEAK), 80);
  41. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_ALBUM_GAIN), 65);
  42. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_ALBUM_PEAK), 80);
  43. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  44. WorkQueue::RGWorkQueue *queue = (WorkQueue::RGWorkQueue *)lParam;
  45. AddQueueToListView(&listView, queue);
  46. POINT pt = {(LONG)GetPrivateProfileIntA("ml_rg", "res_x", -1, iniFile),
  47. (LONG)GetPrivateProfileIntA("ml_rg", "res_y", -1, iniFile)};
  48. if (!windowOffScreen(hwndDlg, pt))
  49. SetWindowPos(hwndDlg, HWND_TOP, pt.x, pt.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOSENDCHANGING);
  50. }
  51. break;
  52. case WM_COMMAND:
  53. switch(LOWORD(wParam))
  54. {
  55. case IDOK:
  56. {
  57. WorkQueue::RGWorkQueue *queue = (WorkQueue::RGWorkQueue *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  58. WriteAlbum(*queue);
  59. }
  60. case IDCANCEL:
  61. {
  62. RECT rect = {0};
  63. GetWindowRect(hwndDlg, &rect);
  64. char buf[16] = {0};
  65. StringCchPrintfA(buf, 16, "%d", rect.left);
  66. WritePrivateProfileStringA("ml_rg", "res_x", buf, iniFile);
  67. StringCchPrintfA(buf, 16, "%d", rect.top);
  68. WritePrivateProfileStringA("ml_rg", "res_y", buf, iniFile);
  69. EndDialog(hwndDlg, 0);
  70. }
  71. break;
  72. case IDC_SAVETRACK:
  73. {
  74. WorkQueue::RGWorkQueue *queue = (WorkQueue::RGWorkQueue *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  75. WriteTracks(*queue);
  76. EndDialog(hwndDlg, 0);
  77. }
  78. break;
  79. }
  80. }
  81. return 0;
  82. }
  83. INT_PTR WINAPI ReplayGainDialogProcAll(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  84. {
  85. switch(msg)
  86. {
  87. case WM_INITDIALOG:
  88. {
  89. W_ListView listView(GetDlgItem(hwndDlg, IDC_RGLIST));
  90. listView.setwnd(GetDlgItem(hwndDlg, IDC_RGLIST));
  91. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_FILENAME), 200);
  92. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_TRACK_GAIN), 65);
  93. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_TRACK_PEAK), 80);
  94. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_ALBUM_GAIN), 65);
  95. listView.AddCol(WASABI_API_LNGSTRINGW(IDS_COL_ALBUM_PEAK), 80);
  96. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  97. WorkQueue *queue = (WorkQueue *)lParam;
  98. AddQueueToListView(&listView, &queue->unclassified);
  99. for (WorkQueue::AlbumMap::iterator mapItr=queue->albums.begin();mapItr!=queue->albums.end();mapItr++)
  100. {
  101. AddQueueToListView(&listView, &mapItr->second);
  102. }
  103. POINT pt = {(LONG)GetPrivateProfileIntA("ml_rg", "res_x", -1, iniFile),
  104. (LONG)GetPrivateProfileIntA("ml_rg", "res_y", -1, iniFile)};
  105. if (!windowOffScreen(hwndDlg, pt))
  106. SetWindowPos(hwndDlg, HWND_TOP, pt.x, pt.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOSENDCHANGING);
  107. }
  108. break;
  109. case WM_COMMAND:
  110. switch(LOWORD(wParam))
  111. {
  112. case IDOK:
  113. {
  114. WorkQueue *queue = (WorkQueue *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  115. WriteAlbum(queue->unclassified);
  116. for (WorkQueue::AlbumMap::iterator mapItr=queue->albums.begin();mapItr!=queue->albums.end();mapItr++)
  117. {
  118. WriteAlbum(mapItr->second);
  119. }
  120. }
  121. case IDCANCEL:
  122. {
  123. RECT rect = {0};
  124. GetWindowRect(hwndDlg, &rect);
  125. char buf[16] = {0};
  126. StringCchPrintfA(buf, 16, "%d", rect.left);
  127. WritePrivateProfileStringA("ml_rg", "res_x", buf, iniFile);
  128. StringCchPrintfA(buf, 16, "%d", rect.top);
  129. WritePrivateProfileStringA("ml_rg", "res_y", buf, iniFile);
  130. EndDialog(hwndDlg, 0);
  131. }
  132. break;
  133. case IDC_SAVETRACK:
  134. {
  135. WorkQueue *queue = (WorkQueue *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  136. WriteTracks(queue->unclassified);
  137. for (WorkQueue::AlbumMap::iterator mapItr=queue->albums.begin();mapItr!=queue->albums.end();mapItr++)
  138. {
  139. WriteTracks(mapItr->second);
  140. }
  141. EndDialog(hwndDlg, 0);
  142. }
  143. break;
  144. }
  145. }
  146. return 0;
  147. }
  148. void DoResults(WorkQueue::RGWorkQueue &queue)
  149. {
  150. if (!queue.empty())
  151. WASABI_API_DIALOGBOXPARAM(IDD_RESULTS, GetDialogBoxParent(), ReplayGainDialogProc, (LPARAM)&queue);
  152. }
  153. void DoResults(WorkQueue &queue)
  154. {
  155. WASABI_API_DIALOGBOXPARAM(IDD_RESULTS, GetDialogBoxParent(), ReplayGainDialogProcAll, (LPARAM)&queue);
  156. }