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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
#include "api.h"
extern "C" {
#include "main.h"
}
#include "log.h"
#include "../../winamp/wa_ipc.h"
#include "../nu/AutoWide.h"
#include "../nu/AutoCharFn.h"
#include <shlwapi.h>
#include <commdlg.h>
extern "C" MMSTREAM *_mm_fopen_rf(const CHAR *fname); //rf_wrapper.c
//
// data types and stuff
//
#define SU_POSITION 1
#define SU_TIME 2
#define PPF_CONT_LOOP 1
#define PPF_LOOPALL 2
#define PPF_ADD_TITLE 4
typedef struct
{
const char *cmd;
const char *file;
const char *title;
int titleLength;
int start;
int startUnit;
int loops;
int flags;
} PlayParams;
// Public Globals!
// ---------------
extern "C"
{
UNIMOD *mf;
MPLAYER *mp;
int paused;
int decode_pos; // in 1/64th of millisecond
extern char cfg_format[];
}
void infobox_setmodule(HWND hwnd);
// Static Globals!
// ---------------
#define SILENCE_THRESHOLD 10800
extern "C" int GetSampleSizeFlag();
static char ERROR_TITLE[64];
static int is_tempfile = 0;
static char cmdName[2048], saveName[MAX_PATH];
static char songTitle[400]; // as in Winamp
static PlayParams currParams;
static HANDLE thread_handle = INVALID_HANDLE_VALUE;
static volatile int killDecodeThread;
static volatile int seek_needed;
// wasabi based services for localisation support
api_application *WASABI_API_APP = 0;
api_language *WASABI_API_LNG = 0;
HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
extern "C" DWORD WINAPI decodeThread(void *b);
void __cdecl setoutputtime(int time_in_ms);
// =====================================================================================
// error handling shiz
// =====================================================================================
static int lastError = 0;
__inline void mm_clearerror() { lastError = 0; }
static void mmerr(int crap, const CHAR *crud)
{
char tmp[128] = {0};
if (lastError==crap || crap==MMERR_OPENING_FILE)
return;
else
{
if(!lstrcmpi(crud,"Corrupt file or unsupported module type."))
{
WASABI_API_LNGSTRING_BUF(IDS_CORRUPT_UNSUPPORTED_TYPE,tmp,128);
}
else
tmp[0] = 0;
}
MessageBox(mikmod.hMainWindow, (tmp[0]?tmp:crud), ERROR_TITLE, MB_ICONERROR);
lastError = crap;
}
// =====================================================================================
static int __cdecl init(void)
// =====================================================================================
{
if (!IsWindow(mikmod.hMainWindow))
return IN_INIT_FAILURE;
waServiceFactory *sf = mikmod.service->service_getServiceByGuid(languageApiGUID);
if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
sf = mikmod.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(mikmod.hDllInstance,InModLangGUID);
static wchar_t szDescription[256];
swprintf(szDescription,256,WASABI_API_LNGSTRINGW(IDS_NULLSOFT_MODULE_DECODER),PLUGIN_VER);
mikmod.description = (char*)szDescription;
WASABI_API_LNGSTRING_BUF(IDS_MOD_PLUGIN_ERROR,ERROR_TITLE,64);
_mmerr_sethandler(&mmerr);
config_read();
Mikmod_RegisterAllLoaders();
Mikmod_RegisterDriver(drv_amp);
//Mikmod_RegisterDriver(drv_buffer);
return IN_INIT_SUCCESS;
}
// =====================================================================================
static void __cdecl quit()
// =====================================================================================
{
//LOG log_exit();
SL_Cleanup();
}
static MDRIVER *md;
// =====================================================================================
// file open shiz
// =====================================================================================
#define IPC_GETHTTPGETTER 240
__inline char *GetFileName(const char *fullname)
{
const char *c = fullname + strlen(fullname) - 1;
while (c > fullname)
{
if (*c=='\\' || *c=='/')
{
c++;
break;
}
c--;
}
return (char*)c;
}
char* BuildFilterString(void)
{
static char filterStr[128] = {0};
if(!filterStr[0])
{
char* temp = filterStr;
WASABI_API_LNGSTRING_BUF(IDS_ALL_FILES,filterStr,128);
temp += lstrlen(filterStr)+1;
lstrcpy(temp, "*.*");
*(temp = temp + lstrlen(temp) + 1) = 0;
}
return filterStr;
}
BOOL GetPlayParams(const char *fileName, BOOL open, PlayParams *params)
{
mm_clearerror();
// fill params
params->cmd = fileName;
params->start = 0;
params->loops = config_loopcount;
params->titleLength = 0;
params->flags = 0;
if (config_playflag & CPLAYFLG_CONT_LOOP)
params->flags |= PPF_CONT_LOOP;
if (config_playflag & CPLAYFLG_LOOPALL)
params->flags |= PPF_LOOPALL;
if (params->loops == -1)
params->flags &= ~PPF_CONT_LOOP;
// check for mod:// prefix
if (!strncmp(fileName, "mod://", 6))
{
const char *c = fileName += 6;
while (c && *c && *c!=':')
{
// jump to
if (!strncmp(c, "jmp=", 4))
{
// jump units
switch (*(c + 4))
{
// position
case 'p':
params->startUnit = SU_POSITION;
params->flags &= ~PPF_CONT_LOOP;
break;
// time
case 't':
params->startUnit = SU_TIME;
break;
// invalid
default:
return FALSE;
}
params->start = atoi(c + 5);
}
// loops
else if (!strncmp(c, "lop=", 4))
{
if (*(c+4) == 'u')
{
params->flags |= PPF_LOOPALL;
c++;
}
params->loops = atoi(c + 4);
params->loops = _mm_boundscheck(params->loops, -1, 64);
if (params->loops == -1)
params->flags &= ~PPF_CONT_LOOP;
}
// continue after loop
else if (!strncmp(c, "con=", 4))
{
if (atoi(c + 4))
params->flags |= PPF_CONT_LOOP;
else params->flags &= ~PPF_CONT_LOOP;
}
// title
else if (!strncmp(c, "tit=", 4))
{
// find string
const char *p = c + 4;
if (*p == '+')
{
params->flags |= PPF_ADD_TITLE;
c++;
p++;
}
if (*p++ != '"') return FALSE;
while (p && *p && *p!='"')
p++;
if (*p != '"') return FALSE;
// set
params->title = c + 5;
params->titleLength = p - c - 5;
c = p - 3;
}
// invalid
else return FALSE;
// skip
c += 4;
while (c && *c && *c!=',' && *c!=':')
c++;
if (*c == ',') c++;
}
if (!*c) return FALSE;
fileName = c + 1;
}
params->file = fileName;
// check for URLs
if (open)
{
saveName[0] = 0;
is_tempfile = 0;
if (!_strnicmp(fileName, "http://", 7) || !_strnicmp(fileName, "https://", 8) ||
!_strnicmp(fileName, "ftp://", 6)) // FTP is now currently supported, but still...
{
typedef int (__cdecl *HttpRetrieveFile)(HWND hwnd, const char *url, const char *file, const char *dlgtitle);
HttpRetrieveFile fileGetter;
int t = SendMessage(mikmod.hMainWindow,WM_USER,0,IPC_GETHTTPGETTER);
// try to get httpGetter
if (!t || t==1)
{
MessageBox(mikmod.hMainWindow,
WASABI_API_LNGSTRING(IDS_URLS_ONLY_SUPPORTED_IN_2_10_PLUS),
ERROR_TITLE, MB_ICONERROR);
return FALSE;
}
fileGetter = (HttpRetrieveFile)t;
// save stream if required
if (config_savestr)
{
OPENFILENAME l = {0};
lstrcpyn(saveName, GetFileName(fileName), MAX_PATH);
l.lStructSize = sizeof(l);
l.hwndOwner = mikmod.hMainWindow;
l.hInstance = NULL;
l.lpstrFilter = BuildFilterString();
l.lpstrCustomFilter = NULL;
l.nMaxCustFilter = 0;
l.nFilterIndex = 0;
l.lpstrFile = saveName;
l.nMaxFile = sizeof(saveName);
l.lpstrFileTitle = 0;;
l.nMaxFileTitle = 0;
l.lpstrInitialDir = NULL;
l.lpstrTitle = WASABI_API_LNGSTRING(IDS_SAVE_MODULE);
l.lpstrDefExt = "mod";
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&l))
saveName[0] = 0;
}
// generate temp name, if not saving
if (!saveName[0])
{
char p[MAX_PATH] = {0};
GetTempPath(sizeof(p), p);
GetTempFileName(p, "mod", 0, saveName);
is_tempfile = 1;
}
// get file
if (fileGetter(mikmod.hMainWindow, fileName, saveName, WASABI_API_LNGSTRING(IDS_RETRIEVING_MODULE)))
{
is_tempfile = 0;
saveName[0] = 0;
return FALSE;
}
params->file = saveName;
}
}
else
{
if (saveName[0] && !_stricmp(fileName, cmdName))
params->file = saveName;
}
return TRUE;
}
static void CleanupTemp()
{
if (is_tempfile && saveName[0])
{
DeleteFile(saveName);
is_tempfile = 0;
}
saveName[0] = 0;
}
BOOL InitPlayer(UNIMOD *mf, MPLAYER **ps, const PlayParams *params, BOOL quick)
{
int flags;
// strip silence
if (config_playflag & CPLAYFLG_STRIPSILENCE)
Unimod_StripSilence(mf, SILENCE_THRESHOLD);
// set flags
flags = PF_TIMESEEK;
if (params->flags & PPF_CONT_LOOP) flags |= PF_CONT_LOOP;
// init player
if (quick)
*ps = Player_Create(mf, flags);
else *ps = Player_InitSong(mf, NULL, flags, config_voices);
if (!*ps) return FALSE;
// position seek
if (params->start && params->startUnit==SU_POSITION)
Player_SetStartPosition(*ps, params->start);
// looping
Player_SetLoopStatus(*ps, params->flags & PPF_LOOPALL, params->loops);
if (quick || config_playflag&CPLAYFLG_SEEKBYORDERS)
Player_PredictSongLength(*ps);
else
{
// time calculation & seeking-lookups creation
Player_BuildQuickLookups(*ps);
// fade (needs results of Player_BuildQuickLookups)
if (config_playflag & CPLAYFLG_FADEOUT)
Player_VolumeFadeEx(*ps, MP_VOLUME_CUR, 0, config_fadeout, MP_SEEK_END, config_fadeout);
}
// remember song length
mf->songlen = (*ps)->songlen;
return TRUE;
}
static UNIMOD *GetModuleInfo(const PlayParams *params)
{
UNIMOD *m = mf;
// check against the current one
if (!m || _stricmp(cmdName, params->cmd)) // check the whole string, not just file name
{
MPLAYER *ps;
MMSTREAM * fp;
// load module
mm_clearerror();
fp = _mm_fopen_rf(params->file);
if (!fp) return NULL;
m = Unimod_LoadInfo_FP(params->file,fp);
_mm_fclose(fp);
if (!m) return NULL;
// get info and clean up
if (!InitPlayer(m, &ps, params, TRUE))
{
Unimod_Free(m);
return NULL;
}
Player_Free(ps);
}
return m;
}
static int __cdecl isourfile(const char *fn)
{
return !_strnicmp(fn, "mod://", 6);
}
// =====================================================================================
// helpers
// =====================================================================================
static UNIMOD *FindInfoBox(const char *fileName, HWND *hwnd)
{
INFOBOX *cruise;
for (cruise=infobox_list; cruise; cruise=cruise->next)
if (!_stricmp(cruise->dlg.module->filename, fileName))
{
if (hwnd) *hwnd = cruise->hwnd;
return cruise->dlg.module;
}
return NULL;
}
static BOOL FindInfoBoxPtr(const UNIMOD *mf)
{
INFOBOX *cruise;
for (cruise=infobox_list; cruise; cruise=cruise->next)
if (cruise->dlg.module == mf)
return TRUE;
return FALSE;
}
// =====================================================================================
static int __cdecl play(const char *fileName)
// =====================================================================================
{
PlayParams params;
uint md_mode = 0;
// parse parameters
if (!GetPlayParams(fileName, TRUE, ¶ms))
return 1;
// save strings locally
lstrcpyn(cmdName, params.cmd, 2048);
if (params.titleLength)
lstrcpyn(songTitle, params.title, min(params.titleLength+1, sizeof(songTitle)));
else songTitle[0] = 0;
// save current values
currParams = params;
currParams.cmd = params.cmd;
currParams.title = songTitle;
// Initialize MDRVER
// -----------------
if (config_interp & 1) md_mode |= DMODE_INTERP;
if (config_interp & 2) md_mode |= DMODE_NOCLICK;
if (config_interp & 4) md_mode |= DMODE_FIR;
md_mode |= GetSampleSizeFlag();
if (AllowSurround()) md_mode |= DMODE_SURROUND;
if (config_panrev) md_mode |= DMODE_REVERSE;
if (config_resonance) md_mode |= DMODE_RESONANCE;
md = Mikmod_Init(config_srate, 1000, NULL, GetNumChannels()==1 ? MD_MONO : MD_STEREO, config_cpu, md_mode, &drv_amp);
if (!md)
{
CleanupTemp();
return 1;
}
md->pansep = config_pansep;
// Register non-interpolation mixers
// ---------------------------------
// if the user has disabled interpolation...
if(!(config_interp & 1))
{
VC_RegisterMixer(md->device.vc, &RF_M8_MONO);
VC_RegisterMixer(md->device.vc, &RF_M16_MONO);
VC_RegisterMixer(md->device.vc, &RF_M8_STEREO);
VC_RegisterMixer(md->device.vc, &RF_M16_STEREO);
VC_RegisterMixer(md->device.vc, &M8_MONO);
VC_RegisterMixer(md->device.vc, &M16_MONO);
VC_RegisterMixer(md->device.vc, &M8_STEREO);
VC_RegisterMixer(md->device.vc, &M16_STEREO);
}
else if (config_interp&4)
{
/*
VC_RegisterMixerHack(md->device.vc, &M16_MONO_CUBIC);
VC_RegisterMixerHack(md->device.vc, &M16_STEREO_CUBIC);
VC_RegisterMixerHack(md->device.vc, &M8_MONO_CUBIC);
VC_RegisterMixerHack(md->device.vc, &M8_STEREO_CUBIC);
*/
VC_RegisterMixerHack(md->device.vc, &M16_MONO_FIR);
VC_RegisterMixerHack(md->device.vc, &M16_STEREO_FIR);
VC_RegisterMixerHack(md->device.vc, &M8_MONO_FIR);
VC_RegisterMixerHack(md->device.vc, &M8_STEREO_FIR);
}
// LOADING THE SONG
// ----------------
// Check through the list of active info boxes for a matching filename. If found,
// then we use the already-loaded module information instead!
{
HWND hwnd;
if ((mf=FindInfoBox(params.file, &hwnd)) != NULL)
{
MMSTREAM *smpfp;
// prepare for reloading
info_killseeker(hwnd);
// reload samples
smpfp = _mm_fopen_rf(params.file);
Unimod_LoadSamples(mf, md, smpfp);
_mm_fclose(smpfp);
}
// not already loaded
else
{
MMSTREAM *fp;
fp = _mm_fopen_rf(params.file);
if (!fp)
{
Mikmod_Exit(md);
CleanupTemp();
return -1;
}
//MMEXPORT UNIMOD *Unimod_LoadFP(MDRIVER *md, MMSTREAM *modfp, MMSTREAM *smpfp, int mode);
//MMEXPORT UNIMOD *Unimod_Load(MDRIVER *md, const CHAR *filename);
mf=Unimod_Load_FP(md, params.file,fp);
_mm_fclose(fp);
if (mf==NULL)
{
Mikmod_Exit(md);
CleanupTemp();
return -1;
}
}
}
// file name is stored in module now
if (!saveName[0])
params.file = mf->filename;
// init player
if (!InitPlayer(mf, &mp, ¶ms, FALSE))
{
CleanupTemp();
return -1;
}
Player_Start(mp);
// set start time
seek_needed = -1;
decode_pos = 0;
if (params.start && params.startUnit==SU_TIME)
setoutputtime(params.start*1000);
// init output & info
mikmod.outMod->SetVolume(-666);
mikmod.SetInfo(MulDiv(mf->filesize, 8, mf->songlen), config_srate/1000, GetNumChannels(), 1);
// init decoding thread
{
DWORD threadid;
killDecodeThread = 0;
paused = 0;
thread_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)decodeThread, NULL, 0, &threadid);
set_priority();
}
return 0;
}
// =====================================================================================
static void __cdecl stop(void)
// =====================================================================================
{
if (thread_handle != INVALID_HANDLE_VALUE)
{
killDecodeThread = 1;
if (WaitForSingleObject(thread_handle, 2000) == WAIT_TIMEOUT)
{
MessageBox(mikmod.hMainWindow,
WASABI_API_LNGSTRING(IDS_ERROR_KILLING_DECODING_THREAD),
ERROR_TITLE, MB_ICONWARNING);
TerminateThread(thread_handle, 0);
}
CloseHandle(thread_handle);
thread_handle = INVALID_HANDLE_VALUE;
CleanupTemp();
}
Player_Free(mp);
mp = NULL;
// We need to see if mf is in use. If so, then we can't unload it.
// Bute we *do* have to unload its samples, because those are not needed.
if (FindInfoBoxPtr(mf))
Unimod_UnloadSamples(mf);
else Unimod_Free(mf);
mf = NULL;
Mikmod_Exit(md); md = NULL;
mikmod.SAVSADeInit();
}
// =====================================================================================
// pausing stuff
// =====================================================================================
static void __cdecl pause(void) { paused=1; mikmod.outMod->Pause(1); }
static void __cdecl unpause(void) { paused=0; mikmod.outMod->Pause(0); }
static int __cdecl ispaused(void) { return paused; }
// =====================================================================================
// seeking/timing related stuff
// =====================================================================================
static int __cdecl getlength(void)
{
if (mp)
{
if (!(config_playflag & CPLAYFLG_SEEKBYORDERS))
return mp->songlen;
else return mf->numpos * 1000;
}
else return 0;
}
static int __cdecl getoutputtime(void)
{
if (!(config_playflag & CPLAYFLG_SEEKBYORDERS))
return decode_pos/64 + (mikmod.outMod->GetOutputTime() - mikmod.outMod->GetWrittenTime());
else return mp ? mp->state.sngpos * 1000 : 0;
}
static void __cdecl setoutputtime(int time_in_ms)
{
seek_needed = time_in_ms;
}
// =====================================================================================
static int __cdecl infobox(const char *fileName, HWND hwnd)
// =====================================================================================
{
PlayParams params;
// parse params
if (!GetPlayParams(fileName, FALSE, ¶ms))
return 1;
// First we check our array of loaded dialog boxes. If there are any filename matches,
// then we just bring that window to the foreground!
if (FindInfoBox(params.file, &hwnd) != NULL)
{
SetForegroundWindow(hwnd);
return 0;
}
infoDlg(hwnd, GetModuleInfo(¶ms), TRUE, TRUE);
return 0;
}
/*extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, int destlen)
{
UNIMOD *m=0;
PlayParams params;
const char *ret=0;
if (!_stricmp(data,"TYPE"))
{
dest[0] = '0';
dest[1] = 0x00;
return 1;
}
if (!_stricmp(data,"FAMILY"))
{
LPCTSTR e;
e = PathFindExtension(fn);
if (L'.' != *e) return 0;
e++;
return GetTypeInfo(e, dest, destlen);
}
if (!GetPlayParams(fn, FALSE, ¶ms))
return 0;
m=GetModuleInfo(¶ms);
if (!m)
return 0;
if (!_stricmp(data,"TITLE"))
{
if (!params.titleLength || params.flags&PPF_ADD_TITLE)
ret = m->songname;
else
ret=params.title;
}
else if (!_stricmp(data,"PART"))
{
if (params.titleLength && params.flags&PPF_ADD_TITLE)
ret=params.title;
}
else if (!_stricmp(data,"ARTIST") )
ret=m->composer;
else if (!_stricmp(data,"COMPOSER"))
ret=m->composer;
else if (!_stricmp(data,"COMMENT"))
ret=m->comment;
else if (!_stricmp(data,"FORMAT") || !_stricmp(data,"MODTYPE"))
ret=m->modtype;
else if (!_stricmp(data,"LENGTH"))
{
_itoa(m->songlen, dest, 10);
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 1;
}
else
{
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 0;
}
if (ret)
lstrcpyn(dest, ret, destlen);
else
dest[0]=0;
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 1;
}*/
extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, int destlen)
{
UNIMOD *m=0;
PlayParams params;
const char *ret=0;
if (!_stricmp(data,"TYPE"))
{
dest[0] = L'0';
dest[1] = 0x00;
return 1;
}
if (!_stricmp(data,"FAMILY"))
{
LPCWSTR e;
e = PathFindExtensionW(fn);
if (L'.' != *e) return 0;
e++;
return GetTypeInfo(e, dest, destlen);
}
if (!GetPlayParams(AutoCharFn(fn), FALSE, ¶ms))
return 0;
m=GetModuleInfo(¶ms);
if (!m)
return 0;
if (!_stricmp(data,"TITLE"))
{
if (!params.titleLength || params.flags&PPF_ADD_TITLE)
ret = m->songname;
else
ret=params.title;
}
else if (!_stricmp(data,"PART"))
{
if (params.titleLength && params.flags&PPF_ADD_TITLE)
ret=params.title;
}
else if (!_stricmp(data,"ARTIST") )
ret=m->composer;
else if (!_stricmp(data,"COMPOSER"))
ret=m->composer;
else if (!_stricmp(data,"COMMENT"))
ret=m->comment;
else if (!_stricmp(data,"FORMAT") || !_stricmp(data,"MODTYPE"))
ret=m->modtype;
else if (!_stricmp(data,"LENGTH"))
{
_itow(m->songlen, dest, 10);
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 1;
}
else
{
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 0;
}
if (ret)
lstrcpynW(dest, AutoWide(ret), destlen);
else
dest[0]=0;
if (m!=mf) // make sure it's not the currently playing file
Unimod_Free(m); // in theory this is a race condition
return 1;
}
// =====================================================================================
static void __cdecl getfileinfo(const char *fileName, char *title, int *length_in_ms)
// =====================================================================================
{
PlayParams params;
UNIMOD *m;
BOOL unload = FALSE;
// empty string stands for the current file
if (fileName!=NULL && *fileName)
{
if (!GetPlayParams(fileName, FALSE, ¶ms))
{
lstrcpyn(title, fileName, GETFILEINFO_TITLE_LENGTH);
if (length_in_ms)
*length_in_ms = -1;
return;
}
}
else
params = currParams;
// module loaded
if ((m=FindInfoBox(params.file, NULL))!=NULL || (unload=1, m=GetModuleInfo(¶ms))!=NULL)
{
if (title)
{
if (!params.titleLength || params.flags&PPF_ADD_TITLE)
lstrcpyn(title, m->songname, GETFILEINFO_TITLE_LENGTH);
else
lstrcpyn(title, params.title, GETFILEINFO_TITLE_LENGTH);
}
// set playing time
if (length_in_ms)
*length_in_ms = m->songlen;
// clean up
if (unload && m!=mf)
Unimod_Free(m);
}
// invalid module or smth else
else
{
lstrcpyn(title, GetFileName(params.file), GETFILEINFO_TITLE_LENGTH);
if (length_in_ms)
*length_in_ms = -1;
}
}
// =====================================================================================
// misc stuff
// =====================================================================================
static void __cdecl setvolume(int volume) { mikmod.outMod->SetVolume(volume); }
static void __cdecl setpan(int pan) { mikmod.outMod->SetPan(pan); }
static void __cdecl eq_set(int on, char data[10], int preamp) {}
static CHAR capnstupid[4096];
// =====================================================================================
In_Module mikmod =
// =====================================================================================
{
IN_VER_RET,
"nullsoft(in_mod.dll)", // need to set this to some form of valid buffer otherwise in_bass crashes (why it's looking at this i don't know!!)
0, // hMainWindow
0, // hDllInstance
capnstupid,
1, // is_seekable
1, // uses_output_plug
config,
about,
init,
quit,
getfileinfo,
infobox,
isourfile,
play,
pause,
unpause,
ispaused,
stop,
getlength,
getoutputtime,
setoutputtime,
setvolume,
setpan,
0,0,0,0,0,0,0,0,0, // vis stuff
0,0, // dsp shit
eq_set,
NULL, // setinfo
NULL // outmod
};
// =====================================================================================
extern "C" __declspec(dllexport) In_Module *__cdecl winampGetInModule2()
// input module getter. the only thing exported from here.
// =====================================================================================
{
return &mikmod;
}
// =====================================================================================
static DWORD WINAPI decodeThread(void *unused)
// =====================================================================================
{
int has_flushed = 0;
while (!killDecodeThread)
{
if (seek_needed >= 0)
{
int ms = seek_needed;
seek_needed = -1;
if (!(config_playflag & CPLAYFLG_SEEKBYORDERS))
{
Player_SetPosTime(mp, ms);
decode_pos = ms * 64;
}
else Player_SetPosition(mp, ms/1000, TRUE);
mikmod.outMod->Flush(ms);
if (paused) mikmod.outMod->Pause(1);
}
if (!Player_Active(mp))
{
// check for infinite looping
// infinite looping is done manually (only here). we check if
// it was requested and if the loop is required (song ended
// with loop or unconditional looping is on)
if (mp->loopcount!=-1 || !(mp->flags&PF_LOOP || mp->state.looping<0))
{
if (!has_flushed)
{
has_flushed = 1;
mikmod.outMod->Write(NULL, 0); // write all samples into buffer queue
}
if (!mikmod.outMod->IsPlaying())
{
PostMessage(mikmod.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
return 0;
}
else mikmod.outMod->CanWrite(); // make sure plug-in can do any extra processing needed
Sleep(20);
}
else
{
Player_Restart(mp, TRUE);
decode_pos = mp->state.curtime;
}
}
else
{
Mikmod_Update(md);
Sleep(8);
}
}
return 0;
}
// =====================================================================================
void set_priority(void) // also used in config.c
// =====================================================================================
{
if (thread_handle != INVALID_HANDLE_VALUE)
SetThreadPriority(thread_handle, GetThreadPriorityConfig());
}
BOOL WINAPI DllMain(HANDLE h, DWORD r, void *z)
{
if (r == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls((HMODULE)h);
}
return 1;
}
|