1 #include "All.h"
2 #include "APEInfo.h"
3 using namespace APE;
4
5 #include "APEInfoDialog.h"
6 #include "APECompress.h"
7 #include "CharacterHelper.h"
8
9 /***************************************************************************************
10 The dialog component ID's
11 ***************************************************************************************/
12 #define FILE_NAME_EDIT 1000
13
14 #define ENCODER_VERSION_STATIC 2000
15 #define COMPRESSION_LEVEL_STATIC 2001
16 #define FORMAT_FLAGS_STATIC 2002
17 #define HAS_TAG_STATIC 2003
18
19 #define SAMPLE_RATE_STATIC 3000
20 #define CHANNELS_STATIC 3001
21 #define BITS_PER_SAMPLE_STATIC 3002
22 #define PEAK_LEVEL_STATIC 3003
23
24 #define TRACK_LENGTH_STATIC 4000
25 #define WAV_SIZE_STATIC 4001
26 #define APE_SIZE_STATIC 4002
27 #define COMPRESSION_RATIO_STATIC 4003
28
29 #define TITLE_EDIT 5000
30 #define ARTIST_EDIT 5001
31 #define ALBUM_EDIT 5002
32 #define COMMENT_EDIT 5003
33 #define YEAR_EDIT 5004
34 #define GENRE_COMBOBOX 5005
35 #define TRACK_EDIT 5006
36
37 #define SAVE_TAG_BUTTON 6000
38 #define REMOVE_TAG_BUTTON 6001
39 #define CANCEL_BUTTON 6002
40
41 /***************************************************************************************
42 Global pointer to this instance
43 ***************************************************************************************/
44 CAPEInfoDialog * g_pAPEDecompressDialog = NULL;
45
46 /***************************************************************************************
47 Construction / destruction
48 ***************************************************************************************/
CAPEInfoDialog()49 CAPEInfoDialog::CAPEInfoDialog()
50 {
51 g_pAPEDecompressDialog = NULL;
52 }
53
~CAPEInfoDialog()54 CAPEInfoDialog::~CAPEInfoDialog()
55 {
56 }
57
58 /***************************************************************************************
59 Display the file info dialog
60 ***************************************************************************************/
ShowAPEInfoDialog(const str_utfn * pFilename,HINSTANCE hInstance,const str_utfn * lpszTemplateName,HWND hWndParent)61 int CAPEInfoDialog::ShowAPEInfoDialog(const str_utfn * pFilename, HINSTANCE hInstance, const str_utfn * lpszTemplateName, HWND hWndParent)
62 {
63 // only allow one instance at a time
64 if (g_pAPEDecompressDialog != NULL) { return -1; }
65
66 // open the file
67 int nErrorCode = ERROR_SUCCESS;
68 m_pAPEDecompress = CreateIAPEDecompress(pFilename, &nErrorCode);
69 if (m_pAPEDecompress == NULL || nErrorCode != ERROR_SUCCESS)
70 return nErrorCode;
71
72 g_pAPEDecompressDialog = this;
73
74 DialogBoxParam(hInstance, lpszTemplateName, hWndParent, (DLGPROC) DialogProc, 0);
75
76 // clean up
77 SAFE_DELETE(m_pAPEDecompress);
78 g_pAPEDecompressDialog = NULL;
79
80 return 0;
81 }
82
83 /***************************************************************************************
84 Fill the genre combobox
85 ***************************************************************************************/
FillGenreComboBox(HWND hDlg,int nComboBoxID,char * pSelectedGenre)86 int CAPEInfoDialog::FillGenreComboBox(HWND hDlg, int nComboBoxID, char *pSelectedGenre)
87 {
88 // declare the variables
89 int nRetVal;
90 HWND hGenreComboBox = GetDlgItem(hDlg, nComboBoxID);
91
92 // reset the contents of the combobox
93 SendMessage(hGenreComboBox, CB_RESETCONTENT, 0, 0);
94
95 // propagate the combobox (0 to 126 so "Undefined" isn't repeated)
96 for (int z = 0; z < CAPETag::s_nID3GenreCount; z++)
97 {
98 //add the genre string
99 nRetVal = SendMessage(hGenreComboBox, CB_ADDSTRING, 0, (intn) CAPETag::s_aryID3GenreNames[z]);
100 if (nRetVal == CB_ERR) { return -1; }
101 }
102
103 // add the 'Undefined' genre
104 nRetVal = SendMessage(hGenreComboBox, CB_ADDSTRING, 0, (intn) "Undefined");
105 if (nRetVal == CB_ERR) { return -1; }
106
107 // set the genre id (if it's specified)
108 if (pSelectedGenre)
109 {
110 if (strlen(pSelectedGenre) > 0)
111 SendMessage(hGenreComboBox, CB_SELECTSTRING, -1, (intn) pSelectedGenre);
112 }
113
114 return 0;
115 }
116
117 /***************************************************************************************
118 The dialog procedure
119 ***************************************************************************************/
DialogProc(HWND hDlg,UINT message,intn wParam,intn lParam)120 LRESULT CALLBACK CAPEInfoDialog::DialogProc(HWND hDlg, UINT message, intn wParam, intn lParam)
121 {
122 // get the class
123 IAPEDecompress * pAPEDecompress = g_pAPEDecompressDialog->m_pAPEDecompress;
124
125 int wmID, wmEvent;
126
127 switch (message)
128 {
129 case WM_INITDIALOG:
130 {
131 // variable declares
132 TCHAR cTemp[1024] = { 0 };
133
134 // set info
135 wchar_t cFilename[MAX_PATH + 1] = {0};
136 GET_IO(pAPEDecompress)->GetName(&cFilename[0]);
137
138 SetDlgItemText(hDlg, FILE_NAME_EDIT, cFilename);
139
140 switch (pAPEDecompress->GetInfo(APE_INFO_COMPRESSION_LEVEL))
141 {
142 case COMPRESSION_LEVEL_FAST: _stprintf_s(cTemp, 1024, _T("Mode: Fast")); break;
143 case COMPRESSION_LEVEL_NORMAL: _stprintf_s(cTemp, 1024, _T("Mode: Normal")); break;
144 case COMPRESSION_LEVEL_HIGH: _stprintf_s(cTemp, 1024, _T("Mode: High")); break;
145 case COMPRESSION_LEVEL_EXTRA_HIGH: _stprintf_s(cTemp, 1024, _T("Mode: Extra High")); break;
146 case COMPRESSION_LEVEL_INSANE: _stprintf_s(cTemp, 1024, _T("Mode: Insane")); break;
147 default: _stprintf_s(cTemp, 1024, _T("Mode: Unknown")); break;
148 }
149 SetDlgItemText(hDlg, COMPRESSION_LEVEL_STATIC, cTemp);
150
151 _stprintf_s(cTemp, 1024, _T("Version: %.2f"), float(pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION)) / float(1000));
152 SetDlgItemText(hDlg, ENCODER_VERSION_STATIC, cTemp);
153
154 _stprintf_s(cTemp, 1024, _T("Format Flags: %d"), (int) pAPEDecompress->GetInfo(APE_INFO_FORMAT_FLAGS));
155 SetDlgItemText(hDlg, FORMAT_FLAGS_STATIC, cTemp);
156
157 _stprintf_s(cTemp, 1024, _T("Sample Rate: %d"), (int) pAPEDecompress->GetInfo(APE_INFO_SAMPLE_RATE));
158 SetDlgItemText(hDlg, SAMPLE_RATE_STATIC, cTemp);
159
160 _stprintf_s(cTemp, 1024, _T("Channels: %d"), (int) pAPEDecompress->GetInfo(APE_INFO_CHANNELS));
161 SetDlgItemText(hDlg, CHANNELS_STATIC, cTemp);
162
163 _stprintf_s(cTemp, 1024, _T("Bits Per Sample: %d"), (int) pAPEDecompress->GetInfo(APE_INFO_BITS_PER_SAMPLE));
164 SetDlgItemText(hDlg, BITS_PER_SAMPLE_STATIC, cTemp);
165
166 int nSeconds = pAPEDecompress->GetInfo(APE_INFO_LENGTH_MS) / 1000; int nMinutes = nSeconds / 60; nSeconds = nSeconds % 60; int nHours = nMinutes / 60; nMinutes = nMinutes % 60;
167 if (nHours > 0) _stprintf_s(cTemp, 1024, _T("Length: %d:%02d:%02d"), nHours, nMinutes, nSeconds);
168 else if (nMinutes > 0) _stprintf_s(cTemp, 1024, _T("Length: %d:%02d"), nMinutes, nSeconds);
169 else _stprintf_s(cTemp, 1024, _T("Length: 0:%02d"), nSeconds);
170 SetDlgItemText(hDlg, TRACK_LENGTH_STATIC, cTemp);
171
172 int nPeakLevel = pAPEDecompress->GetInfo(APE_INFO_PEAK_LEVEL);
173 if (nPeakLevel >= 0) _stprintf_s(cTemp, 1024, _T("Peak Level: %d"), nPeakLevel);
174 else _stprintf_s(cTemp, 1024, _T("Peak Level: ?"));
175 SetDlgItemText(hDlg, PEAK_LEVEL_STATIC, cTemp);
176
177 // the file size
178 _stprintf_s(cTemp, 1024, _T("APE: %.2f MB"), float(pAPEDecompress->GetInfo(APE_INFO_APE_TOTAL_BYTES)) / float(1048576));
179 SetDlgItemText(hDlg, APE_SIZE_STATIC, cTemp);
180
181 _stprintf_s(cTemp, 1024, _T("WAV: %.2f MB"), float(pAPEDecompress->GetInfo(APE_INFO_WAV_TOTAL_BYTES)) / float(1048576));
182 SetDlgItemText(hDlg, WAV_SIZE_STATIC, cTemp);
183
184 // the compression ratio
185 _stprintf_s(cTemp, 1024, _T("Compression: %.2f%%"), float(pAPEDecompress->GetInfo(APE_INFO_AVERAGE_BITRATE) * 100) / float(pAPEDecompress->GetInfo(APE_INFO_DECOMPRESSED_BITRATE)));
186 SetDlgItemText(hDlg, COMPRESSION_RATIO_STATIC, cTemp);
187
188 // the has tag
189 BOOL bHasID3Tag = GET_TAG(pAPEDecompress)->GetHasID3Tag();
190 BOOL bHasAPETag = GET_TAG(pAPEDecompress)->GetHasAPETag();
191
192 if (!bHasID3Tag && !bHasAPETag)
193 _stprintf_s(cTemp, 1024, _T("Tag: None"));
194 else if (bHasID3Tag && !bHasAPETag)
195 _stprintf_s(cTemp, 1024, _T("Tag: ID3v1.1"));
196 else if (!bHasID3Tag && bHasAPETag)
197 _stprintf_s(cTemp, 1024, _T("Tag: APE Tag"));
198 else
199 _stprintf_s(cTemp, 1024, _T("Tag: Corrupt"));
200 SetDlgItemText(hDlg, HAS_TAG_STATIC, cTemp);
201
202 wchar_t cBuffer[256];
203 int nBufferBytes = 256;
204
205 nBufferBytes = 256;
206 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_TITLE, cBuffer, &nBufferBytes);
207 SetDlgItemText(hDlg, TITLE_EDIT, cBuffer);
208
209 nBufferBytes = 256;
210 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_ARTIST, cBuffer, &nBufferBytes);
211 SetDlgItemText(hDlg, ARTIST_EDIT, cBuffer);
212
213 nBufferBytes = 256;
214 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_ALBUM, cBuffer, &nBufferBytes);
215 SetDlgItemText(hDlg, ALBUM_EDIT, cBuffer);
216
217 nBufferBytes = 256;
218 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_COMMENT, cBuffer, &nBufferBytes);
219 SetDlgItemText(hDlg, COMMENT_EDIT, cBuffer);
220
221 nBufferBytes = 256;
222 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_YEAR, cBuffer, &nBufferBytes);
223 SetDlgItemText(hDlg, YEAR_EDIT, cBuffer);
224
225 nBufferBytes = 256;
226 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_TRACK, cBuffer, &nBufferBytes);
227 SetDlgItemText(hDlg, TRACK_EDIT, cBuffer);
228
229 g_pAPEDecompressDialog->FillGenreComboBox(hDlg, GENRE_COMBOBOX, NULL);
230
231 nBufferBytes = 256;
232 GET_TAG(pAPEDecompress)->GetFieldString(APE_TAG_FIELD_GENRE, cBuffer, &nBufferBytes);
233 SetDlgItemText(hDlg, GENRE_COMBOBOX, cBuffer);
234
235 return TRUE;
236 break;
237 }
238 case WM_COMMAND:
239 wmID = LOWORD(wParam);
240 wmEvent = HIWORD(wParam);
241
242 switch (wmID)
243 {
244 case IDCANCEL:
245 // traps the [esc] key
246 EndDialog(hDlg, 0);
247 return TRUE;
248 break;
249 case CANCEL_BUTTON:
250 EndDialog(hDlg, 0);
251 return TRUE;
252 break;
253 case REMOVE_TAG_BUTTON:
254 {
255 // make sure you really wanted to
256 int nRetVal = ::MessageBox(hDlg, _T("Are you sure you want to permanently remove the tag?"), _T("Are You Sure?"), MB_YESNO | MB_ICONQUESTION);
257 if (nRetVal == IDYES)
258 {
259 // remove the ID3 tag...
260 if (GET_TAG(pAPEDecompress)->Remove() != 0)
261 {
262 MessageBox(hDlg, _T("Error removing tag. (could the file be read-only?)"), _T("Error Removing Tag"), MB_OK | MB_ICONEXCLAMATION);
263 return TRUE;
264 }
265 else
266 {
267 EndDialog(hDlg, 0);
268 return TRUE;
269 }
270 }
271 break;
272 }
273 case SAVE_TAG_BUTTON:
274
275 // make the id3 tag
276 TCHAR cBuffer[256]; int z;
277
278 #define SAVE_FIELD(ID, Field) \
279 for (z = 0; z < 256; z++) { cBuffer[z] = 0; } \
280 GetDlgItemText(hDlg, ID, cBuffer, 256); \
281 GET_TAG(pAPEDecompress)->SetFieldString(Field, cBuffer);
282
283 SAVE_FIELD(TITLE_EDIT, APE_TAG_FIELD_TITLE)
284 SAVE_FIELD(ARTIST_EDIT, APE_TAG_FIELD_ARTIST)
285 SAVE_FIELD(ALBUM_EDIT, APE_TAG_FIELD_ALBUM)
286 SAVE_FIELD(COMMENT_EDIT, APE_TAG_FIELD_COMMENT)
287 SAVE_FIELD(TRACK_EDIT, APE_TAG_FIELD_TRACK)
288 SAVE_FIELD(YEAR_EDIT, APE_TAG_FIELD_YEAR)
289 SAVE_FIELD(GENRE_COMBOBOX, APE_TAG_FIELD_GENRE)
290
291 if (GET_TAG(pAPEDecompress)->Save() != 0)
292 {
293 MessageBox(hDlg, _T("Error saving tag. (could the file be read-only?)"), _T("Error Saving Tag"), MB_OK | MB_ICONEXCLAMATION);
294 return TRUE;
295 }
296
297 EndDialog(hDlg, 0);
298 break;
299 }
300 break;
301 case WM_CLOSE:
302 EndDialog(hDlg, 0);
303 return TRUE;
304 break;
305 }
306
307 return FALSE;
308 }