1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
|
//#define PLUGIN_NAME "Nullsoft CD Plug-in"
#define PLUGIN_VERSION L"4.7"
#include "main.h"
#include "cddb.h"
#include "CDPlay.h"
#include "DAEPlay.h"
#include "MCIPlay.h"
#include "WindacPlay.h"
#include "PlayStatus.h"
#include "../nu/AutoWide.h"
#include "../nu/AutoChar.h"
#include "../Winamp/strutil.h"
#include "../winamp/wa_ipc.h"
#include <shlwapi.h>
#include "api__in_cdda.h"
#include "workorder.h"
#include <strsafe.h>
using namespace Nullsoft::Utility;
Nullsoft::Utility::LockGuard *playDeviceGuard = 0;
char * s_last_error = NULL;
static wchar_t playDriveLetter;
//extern int config_maxextractspeed;
api_config *AGAVE_API_CONFIG=0;
#ifndef _DEBUG
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
DisableThreadLibraryCalls(hInst);
return TRUE;
}
#endif
#ifdef IGNORE_API_GRACENOTE
static DINFO g_ps;
#endif
int g_ps_inuse = 0;
int g_playtrack, g_playlength;
wchar_t lastfn[1024] = {0};
int paused;
void _setvolume();
DWORD MainThreadId;
extern char INI_FILE[];
extern char app_name[];
int DoAboutMessageBox(HWND parent, wchar_t* title, wchar_t* message)
{
MSGBOXPARAMS msgbx = {sizeof(MSGBOXPARAMS),0};
msgbx.lpszText = message;
msgbx.lpszCaption = title;
msgbx.lpszIcon = MAKEINTRESOURCE(102);
msgbx.hInstance = GetModuleHandle(0);
msgbx.dwStyle = MB_USERICON;
msgbx.hwndOwner = parent;
return MessageBoxIndirect(&msgbx);
}
void about(HWND hwndParent)
{
wchar_t message[1024] = {0}, text[1024] = {0};
WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_CD_PLUGIN_OLD,text,1024);
StringCchPrintf(message, 1024, WASABI_API_LNGSTRINGW(IDS_ABOUT_TEXT),
line.description, TEXT(__DATE__));
DoAboutMessageBox(hwndParent,text,message);
}
void quit();
int init();
int isourfile(const in_char *fn)
{
if (!_wcsnicmp(fn, L"cda://", 6)) return 1;
return 0;
}
volatile int done = 0;
int g_lastpos = 0;
C_CDPlay *g_cdplay = 0;
const wchar_t *filename(const wchar_t *fn)
{
const wchar_t *s = scanstr_backcW(fn, L"\\/", 0);
if (!s) return fn;
return (s + 1);
}
bool ParseName(const wchar_t *fn, wchar_t &device, int &trackNum)
{
wchar_t track[16] = L"1";
if (!_wcsnicmp(fn, L"cda://", 6))
{
fn += 6;
wchar_t d[16] = {0};
wchar_t *p = d;
while (fn && *fn && *fn != L',' && (p - d < 15)) *p++ = *fn++;
if (p) *p = 0;
device = toupper(d[0]);
if (*fn == L',') fn++;
lstrcpyn(track, fn, ARRAYSIZE(track));
trackNum = _wtoi(track);
return true;
}
else if (!_wcsicmp(extensionW(fn), L"cda"))
{
const wchar_t *f = filename(fn);
if (!_wcsnicmp(f, L"track", 5)) f += 5;
wchar_t t[16] = {0};
wchar_t *p = t;
while (f && *f && *f != L'.' && (p - t < 15)) *p++ = *f++;
lstrcpyn(track, t, ARRAYSIZE(track));
device = toupper(fn[0]);
trackNum = _wtoi(track);
return true;
}
return false;
}
WindacPlay *windacPlayer = 0;
DAEPlay *daePlayer = 0;
MciPlay *mciPlayer = 0;
int play(const in_char *fn)
{
done = 0;
lstrcpyn(lastfn, fn, 1024);
line.is_seekable = 0;
g_lastpos = 0;
int track = -1;
if (!ParseName(fn, playDriveLetter, track))
return 1;
if (playStatus[playDriveLetter].IsRipping() || (g_cdplay && g_cdplay->IsPlaying(playDriveLetter)))
{
wchar_t title[32] = {0};
MessageBoxW(NULL, WASABI_API_LNGSTRINGW(IDS_CD_CURRENTLY_IN_USE),
WASABI_API_LNGSTRINGW_BUF(IDS_DRIVE_IN_USE,title,32), MB_OK);
return 1;
}
if (g_cdplay) delete g_cdplay; g_cdplay = NULL;
//first, try DAE
if (!daePlayer) daePlayer = new DAEPlay;
g_cdplay = daePlayer;
int ret = (g_cdplay ? g_cdplay->play(playDriveLetter, track) : 0);
if (ret != 0)
{
if (g_cdplay) delete g_cdplay; g_cdplay = daePlayer = NULL;
//second, try Windac
if (!windacPlayer) windacPlayer = new WindacPlay;
g_cdplay = windacPlayer;
ret = (g_cdplay ? g_cdplay->play(playDriveLetter, track) : 0);
if (ret != 0)
{
if (g_cdplay) delete g_cdplay; g_cdplay = windacPlayer = NULL;
//try MCI
if (!mciPlayer) mciPlayer = new MciPlay;
g_cdplay = mciPlayer;
int ret = (g_cdplay ? g_cdplay->play(playDriveLetter, track) : 1);
if (ret != 0)
{
//no luck
if (g_cdplay) delete g_cdplay; g_cdplay = mciPlayer = NULL;
return ret;
}
}
}
paused = 0;
return 0;
}
void pause()
{
if (g_cdplay) g_cdplay->pause();
paused = 1;
}
void unpause()
{
if (g_cdplay) g_cdplay->unpause();
paused = 0;
}
int ispaused()
{
return paused;
}
void stop()
{
if (g_cdplay)
{
g_cdplay->stop();
g_cdplay = NULL;
}
done = 0;
line.SAVSADeInit();
}
int getlength()
{
if (g_cdplay) return g_cdplay->getlength();
return -1000;
}
int getoutputtime()
{
if (g_cdplay) return g_cdplay->getoutputtime();
return 0;
//return audioGetPos();
}
void setoutputtime(int time_in_ms)
{
if (g_cdplay) g_cdplay->setoutputtime(time_in_ms);
}
void setvolume(int volume)
{
if (volume != -666)
{
a_v = volume;
}
if (g_cdplay) g_cdplay->setvolume(a_v, a_p);
}
void setpan(int pan)
{
a_p = pan;
if (g_cdplay) g_cdplay->setvolume(a_v, a_p);
}
int infoDlg(const in_char *fn, HWND hwnd)
{
return 0;
#if 0 // switched to unified file info dialog in 5.53
if (!_stricmp(extension(fn), "cda") || !_strnicmp(fn, "cda://", 6))
{
if (!g_ps_inuse)
{
char device;
int res=1;
MCIDEVICEID d = 0;
g_ps_inuse = 1;
device = fn[_strnicmp(fn, "cda://", 6) ? 0 : 6];
if (device >= 'a' && device <= 'z') device += 'A' -'a';
CDOpen(&d, device, L"infoDlg");
memset(&g_ps, 0, sizeof(g_ps));
res = GetDiscID(d, &g_ps);
CDClose(&d);
if (!res)
res = GetCDDBInfo(&g_ps, device);
//if (!res) DBEdit(&g_ps, hwnd, 0, device);
//if (!res)
{
if (CDEdit(device, &g_ps, hwnd))
{
g_ps_inuse = 0;
return INFOBOX_EDITED;
}
}
g_ps_inuse = 0;
}
}
return INFOBOX_UNCHANGED;
#endif
}
void getfileinfo(const in_char *filename, in_char *title, int *length_in_ms)
{
#if 0
int track;
char device;
MCIDEVICEID dev2 = 0;
if (length_in_ms) *length_in_ms = -1000;
if (!filename || !*filename) // currently playing
{
if (!_stricmp(extension(lastfn), "cda") || !_strnicmp(lastfn, "cda://", 6))
{
#ifdef IGNORE_API_GRACENOTE
if (title)
{
lstrcpynA(title, "CD Track", GETFILEINFO_TITLE_LENGTH);
if (!g_ps_inuse)
{
g_ps_inuse = 1;
memset(&g_ps, 0, sizeof(g_ps));
if (CDOpen(&dev2, playDriveLetter, L"getfileinfo"))
{
wchar_t wtitle[256] = {0};
int ret = GetDiscID(dev2, &g_ps);
CDClose(&dev2);
if (!ret && GetCDDBInfo(&g_ps, 0)) // TODO: get device letter
PostMessage(line.hMainWindow, WM_USER, (WPARAM) L"cda://", 247/*IPC_REFRESHPLCACHE*/);
if (wtitle[0])
lstrcpynA(title, AutoChar(wtitle), GETFILEINFO_TITLE_LENGTH);
}
g_ps_inuse = 0;
}
}
if (length_in_ms) *length_in_ms = g_playlength;
#endif
}
return ;
}
if (title)
{
const char *p = filename + strlen(filename);
while (p >= filename && *p != '\\') p--;
lstrcpynA(title, ++p, GETFILEINFO_TITLE_LENGTH);
}
track = 0;
if (!_strnicmp(filename, "cda://", 6)) // determine length of cd track via MCI
{
track = atoi(filename + 8);
device = filename[6];
if (device >= 'a' && device <= 'z') device += 'A' -'a';
if (length_in_ms)
{
if (CDOpen(&dev2, device, L"getfileinfo"))
{
MCI_SET_PARMS sMCISet;
sMCISet.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
MCISendCommand(dev2, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)(LPVOID) &sMCISet);
*length_in_ms = CDGetTrackLength(dev2, track);
sMCISet.dwTimeFormat = MCI_FORMAT_TMSF;
MCISendCommand(dev2, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)(LPVOID) &sMCISet);
}
}
}
else // determine from RIFF structure of .CDA
{
HMMIO hmmio;
hmmio = mmioOpenA((char *)filename, NULL, MMIO_READ | MMIO_ALLOCBUF);
device = filename[0];
if (device >= 'a' && device <= 'z') device += 'A' -'a';
if (hmmio)
{
MMCKINFO mmckinfoParent; // parent chunk information
mmckinfoParent.fccType = mmioFOURCC('C', 'D', 'D', 'A');
if (mmioDescend(hmmio, (LPMMCKINFO) &mmckinfoParent, NULL, MMIO_FINDRIFF) == MMSYSERR_NOERROR)
{
MMCKINFO mmckinfoSubchunk; // subchunk information structure
mmckinfoSubchunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent, MMIO_FINDCHUNK) == MMSYSERR_NOERROR)
{
char *format;
DWORD dwFmtSize; // size of "FMT" chunk
dwFmtSize = mmckinfoSubchunk.cksize;
format = (char *) GlobalAlloc(GPTR, dwFmtSize);
if (mmioRead(hmmio, (HPSTR) format, dwFmtSize) == (int)dwFmtSize)
{
mmioAscend(hmmio, &mmckinfoSubchunk, 0);
track = *((short int *)format + 1);
if (length_in_ms)
{
int length = *((int *)format + 3);
int l = length % 75;
length /= 75;
length *= 1000;
length += (l * 1000) / 75;
*length_in_ms = length;
}
}
GlobalFree(format);
}
}
mmioClose(hmmio, 0);
}
}
#ifdef IGNORE_API_GRACENOTE
if (title && track)
{
if (0 && !g_ps_inuse)
{
g_ps_inuse = 1;
memset(&g_ps, 0, sizeof(g_ps));
if (!dev2)
{
CDOpen(&dev2, device, L"getfileinfo");
}
if (dev2)
{
StringCchPrintfA(title, GETFILEINFO_TITLE_LENGTH, "CD Track %d", track);
wchar_t wtitle[256] = L"";
int ret = GetDiscID(dev2, &g_ps);
CDClose(&dev2);
dev2=0;
if (!ret && GetCDDBInfo(&g_ps, device))
PostMessage(line.hMainWindow, WM_USER, (WPARAM) L"cda://", 247 /*IPC_REFRESHPLCACHE*/);
if (wtitle[0])
lstrcpynA(title, AutoChar(wtitle), GETFILEINFO_TITLE_LENGTH);
}
g_ps_inuse = 0;
}
}
#endif
if (dev2) CDClose(&dev2);
#endif
}
void eq_set(int on, char data[10], int preamp)
{}
In_Module line =
{
IN_VER_RET,
"nullsoft(in_cdda.dll)",
0, // hMainWindow
0, // hDllInstance
0,
0, // is_seekable
1, // uses output plugins
about,//config,
about,
init,
quit,
getfileinfo,
infoDlg,
isourfile,
play,
pause,
unpause,
ispaused,
stop,
getlength,
getoutputtime,
setoutputtime,
setvolume,
setpan,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, // dsp shit
eq_set,
NULL, // setinfo
NULL // out_mod
};
int m_nblock = 0;
extern "C"
{
__declspec(dllexport) In_Module * winampGetInModule2()
{
s_last_error = NULL;
return &line;
}
#if 0 // TODO?
__declspec(dllexport) int winampWriteExtendedFileInfo()
{
s_last_error = NULL;
// write it out
if (m_eiw_lastdrive)
{
AddToDatabase(&setInfo);
m_eiw_lastdrive = 0;
return 1;
}
return 0;
}
#endif
};
// wasabi based services for localisation support
api_language *WASABI_API_LNG = 0;
HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
#ifndef IGNORE_API_GRACENOTE
api_gracenote *AGAVE_API_GRACENOTE = 0;
#endif
api_application *WASABI_API_APP = 0;
void SetFileExtensions(void)
{
static char fileExtensionsString[1200] = {0}; // "CDA\0CDDA Audio Tracks (*.CDA)\0"
char* end = 0;
StringCchCopyExA(fileExtensionsString, 1200, "CDA", &end, 0, 0);
StringCchCopyExA(end+1, 1200, WASABI_API_LNGSTRING(IDS_CDDA_AUDIO_TRACKS), 0, 0, 0);
line.FileExtensions = fileExtensionsString;
}
int init()
{
if (!IsWindow(line.hMainWindow))
return IN_INIT_FAILURE;
//CoInitialize(0);
#ifndef IGNORE_API_GRACENOTE
Cddb_Initialize();
InitializeCddbCache();
#endif
// loader so that we can get the localisation service api for use
waServiceFactory *sf = line.service->service_getServiceByGuid(languageApiGUID);
if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
sf = line.service->service_getServiceByGuid(AgaveConfigGUID);
if (sf) AGAVE_API_CONFIG = reinterpret_cast<api_config*>(sf->getInterface());
#ifndef IGNORE_API_GRACENOTE
sf = line.service->service_getServiceByGuid(gracenoteApiGUID);
if (sf) AGAVE_API_GRACENOTE = reinterpret_cast<api_gracenote*>(sf->getInterface());
#endif
sf = line.service->service_getServiceByGuid(applicationApiServiceGuid);
if (sf) WASABI_API_APP = reinterpret_cast<api_application*>(sf->getInterface());
// need to have this initialised before we try to do anything with localisation features
WASABI_API_START_LANG(line.hDllInstance,InCDDALangGUID);
static wchar_t szDescription[256];
StringCchPrintfW(szDescription,256,WASABI_API_LNGSTRINGW(IDS_NULLSOFT_CD_PLUGIN),PLUGIN_VERSION);
line.description = (char*)szDescription;
SetFileExtensions();
playDeviceGuard = new Nullsoft::Utility::LockGuard;
playStatusGuard = new Nullsoft::Utility::LockGuard;
MainThreadId = GetCurrentThreadId();
config_read();
return IN_INIT_SUCCESS;
}
void quit()
{
#ifndef IGNORE_API_GRACENOTE
ShutdownMusicIDWorkOrder();
#endif
if (playStatusGuard)
{
delete playStatusGuard;
playStatusGuard = 0;
}
if (windacPlayer)
{
delete windacPlayer;
windacPlayer = NULL;
}
if (daePlayer)
{
delete daePlayer;
daePlayer = NULL;
}
if (mciPlayer)
{
delete mciPlayer;
mciPlayer = NULL;
}
#ifndef IGNORE_API_GRACENOTE
ShutDownCDDB();
#endif
waServiceFactory *sf = line.service->service_getServiceByGuid(languageApiGUID);
if (sf) sf->releaseInterface(WASABI_API_LNG);
sf = line.service->service_getServiceByGuid(AgaveConfigGUID);
if (sf) sf->releaseInterface(AGAVE_API_CONFIG);
#ifndef IGNORE_API_GRACENOTE
sf = line.service->service_getServiceByGuid(gracenoteApiGUID);
if (sf) sf->releaseInterface(AGAVE_API_GRACENOTE);
Cddb_Uninitialize();
UninitializeCddbCache();
#endif
CloseTables();
//CoUninitialize();
}
|