aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Input/in_midi/wa2.cpp
blob: 71e39ff2dae15ba0df3eb189c0304f1589e507e1 (plain) (blame)
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
#include "main.h"
#include "resource.h"
#include <shlwapi.h>
#include <api/service/waServiceFactory.h>
#include "../winamp/wa_ipc.h"
#include "../Agave/language/api_language.h"
#include "CompressionUtility.h"
#include "minizip/unzip.h"

static bool paused;
static int volume=255;
static int pan=0;
static string cur_file;
static HANDLE thread;
static HINSTANCE hRFdll;
static reader_source * pRF;

// wasabi based services for localisation support
api_language *WASABI_API_LNG = 0;
HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;

#define IPC_GETHTTPGETTER 240

typedef int (*t_getf)(HWND hwnd, char *url, char *file, char *dlgtitle);

static WReader * get_reader(const char * fn);//wa2 hack


static int reader_process_file(WReader * r,const char * fn,void * &out_data, size_t &out_size)
{
	void * data=0;
	int size=0;
	char ks=0;
	if (r->Open((char*)fn,&ks)) 
		return 0;

	size = r->GetLength();
	
	if (size==-1 || size<0x20) 
		return 0;
	
	data=malloc(size);//scan funcs assume that theres at least 256 data
	
	if (!data) 
		return 0;
	
	if (r->Read((char*)data,size,&ks)!=size) 
	{
		free(data);
		return 0;
	}

	void* pvOut;
	size_t nSizeOut = 0;
	// GZIP
	if (((*(DWORD*)data) & 0xFFFFFF) == 0x088b1f)
	{
		if (CompressionUtility::DecompressGZip(data, size, &pvOut, nSizeOut) >= 0)
		{
			out_data = pvOut;
			out_size = nSizeOut;
			return 1;
		}
		else
		{
			return 0;
		}
	}
	// PKZIP
	else if (*(DWORD*)data == 0x04034B50)
	{
		if (CompressionUtility::DecompressPKZip(fn, &pvOut, nSizeOut) >= 0)
		{
			out_data = pvOut;
			out_size = nSizeOut;
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	out_size = size;
	out_data = data;
	return 1;
}

MIDI_file * wa2_open_file(const char * url)
{
	WReader * r=get_reader(url);
	if (!r) return 0;
	void * data=0;
	size_t size=0;
	MIDI_file* mf=0;
	if (reader_process_file(r,url,data,size))
	{
		mf=MIDI_file::Create(url,data,size);
		free(data);
	}
	delete r;
	return mf;
}

static void build_fmtstring();

static cfg_int cfg_mod_output("dev_output",1);

static void wa2_onCfgUpdate()
{
	MIDI_device * dev = MIDI_driver::find_device(cfg_driver,cfg_device);
	if (!dev)
	{
		dev = MIDI_driver::find_device_default();
	}

	//hack for wa2input.wac in wa3
	mod.UsesOutputPlug=(dev->has_output() || (cfg_smp && cfg_sampout)) ? 1 : 0x8001;
	cfg_mod_output=mod.UsesOutputPlug;
	build_fmtstring();
}

static char fmts_string[1024];

#define NSEEK(a) {while(!(cfg_ext_mask&(1<<a)) && a<n_exts) a++;}
static void build_fmtstring()
{
	UINT n_exts = MIDI_core::FileTypes_GetNum();
	if (!cfg_ext_mask)
	{
		fmts_string[1]=fmts_string[0]=0;
		return;
	}
	UINT n=0;
	NSEEK(n);
	const char* d=MIDI_core::FileTypes_GetDescription(n);
	char* o=fmts_string;
	while(1)
	{
		UINT f=n;
		while(n<n_exts && d==MIDI_core::FileTypes_GetDescription(n))
		{
			const char * e=MIDI_core::FileTypes_GetExtension(n);
			while(e && *e) *(o++)=*(e++);
			n++;
			NSEEK(n);
			*(o++)=';';
		}
		o[-1]=0;
		while(d && *d) *(o++)=*(d++);
		*(o++)=' ';
		*(o++)='(';
		while(f<n)
		{
			const char * e=MIDI_core::FileTypes_GetExtension(f);
			while(e && *e) *(o++)=*(e++);
			f++;
			NSEEK(f);
			*(o++)=',';			
		}
		o[-1]=')';
		*(o++)=0;
		if (n>=n_exts) break;
		d=MIDI_core::FileTypes_GetDescription(n);
	}
	if (cfg_extra_exts.get_string().length()>0)
	{
		d=cfg_extra_exts;
		while(d && *d) *(o++)=*(d++);
		*(o++)=0;
		d=WASABI_API_LNGSTRING(STRING_FILES_OTHER);
		while(d && *d) *(o++)=*(d++);
		d=cfg_extra_exts;
		while(d && *d)
		{
			if (*d==';') *o=',';
			else *o=*d;
			o++;
			d++;
		}
		*(o++)=')';
		*(o++)=0;
	}
	*(o++)=0;
}
#undef NSEEK


static void Config(HWND p)
{
	if (MIDI_core::Config(p))
	{
		MIDI_core::WriteConfig();
		wa2_onCfgUpdate();
	}
}

void About(HWND);

class CMemReader : public WReader
{
public:
	BYTE* mem;
	UINT sz;
	UINT pos;
	int Open(char *url, char *killswitch);
	int Read(char *buffer, int length, char* killswitch) {if (!mem) return 0;if (length+pos>sz) length=sz-pos;memcpy(buffer,mem+pos,length);pos+=length;return length;}
	int GetLength(void) {return sz;} 
	int CanSeek(void) {return 1;};
	int Seek(int position, char*killswitch) {pos=position;return 0;};
	
	CMemReader() {mem=0;sz=0;pos=0;}
	~CMemReader() {if (mem) free(mem);}

};

static int Download(char* url,UINT* f_size,BYTE** m_buf)
{
	typedef int (*t_getf)(HWND hwnd, char *url, char *file, char *dlgtitle);

	t_getf getf;

	int t=SendMessage(mod.hMainWindow,WM_USER,0,IPC_GETHTTPGETTER);
	if (!t || t==1)
	{
#ifndef WINAMPX
    MessageBoxA(mod.hMainWindow,WASABI_API_LNGSTRING(STRING_URL_ERROR),ERROR,MB_ICONERROR);
#endif
		return 0;
	}
	else
	{
		int rv=0;
		char tmp[MAX_PATH] = {0};
		get_temp_file(tmp);
		HANDLE f;
		DWORD br = 0,s = 0;
		void* b;
		getf=(t_getf)t;
		if (getf(mod.hMainWindow,url,tmp,WASABI_API_LNGSTRING(STRING_RETRIEVING_FILE))) goto fail;
		f=CreateFileA(tmp,GENERIC_READ,0,0,OPEN_EXISTING,0,0);
		if (f==INVALID_HANDLE_VALUE) goto fail;
		br=0;
		s=GetFileSize(f,0);
		if (!s) goto fail;
		b=malloc(s);
		if (!b) goto fail;
		ReadFile(f,b,s,&br,0);
		rv=1;
		*f_size=br;
		*m_buf=(BYTE*)b;
fail:
		CloseHandle(f);
		DeleteFileA(tmp);
		return rv;
	}
}


int CMemReader::Open(char* url,char*)
{
	sz=pos=0;
	if (mem) {free(mem);mem=0;}
	HANDLE f=CreateFileA(url,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
	if (f!=INVALID_HANDLE_VALUE)
	{
		sz=GetFileSize(f,0);
		mem=(BYTE*)malloc(sz);
		if (!mem) {CloseHandle(f);return 1;}
		ReadFile(f,mem,sz,(DWORD*)&sz,0);
		CloseHandle(f);
		return 0;
	}
	return !Download(url,&sz,&mem);
}

class CFileReader : public WReader
{
  public:
	HANDLE f;
	CFileReader() {f=0;};
	~CFileReader() {if (f) CloseHandle(f);}
	int Open(char *url, char*killswitch) {f=CreateFileA(url,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);return f==INVALID_HANDLE_VALUE;}
	int Read(char *buffer, int length, char*killswitch) {DWORD br=0;ReadFile(f,buffer,length,&br,0);return br;}
	int GetLength(void) {return GetFileSize(f,0);} 
	int CanSeek(void) {return 1;};
	int Seek(int position, char*killswitch) {SetFilePointer(f,position,0,FILE_BEGIN);return 0;}
	
};

static WReader *get_reader(const char* url)
{
	if (!_strnicmp(url,"file://",7)) url+=7;
	WReader* ret=0;
	if (pRF && pRF->ismine((char*)url)) ret=pRF->create();
	if (ret)
	{
		ret->m_player=0;
		return ret;
	}

	if (_strnicmp(url,"http://",7)==0 || _strnicmp(url,"ftp://",6)==0 || _strnicmp(url,"https://",8)==0) return new CMemReader;
	return new CFileReader();
}

int Init()
{
	if (!IsWindow(mod.hMainWindow))
		return IN_INIT_FAILURE;

	// loader so that we can get the localisation service api for use
	waServiceFactory *sf = mod.service->service_getServiceByGuid(languageApiGUID);
	if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());

	// need to have this initialised before we try to do anything with localisation features
	WASABI_API_START_LANG(mod.hDllInstance,InMidiLangGUID);

	static wchar_t szDescription[256];
	swprintf(szDescription,256,WASABI_API_LNGSTRINGW(IDS_NULLSOFT_MIDI_PLAYER),VER);
	mod.description = (char*)szDescription;

	MIDI_core::GlobalInit();
	mod.UsesOutputPlug=cfg_mod_output;
	build_fmtstring();
	return IN_INIT_SUCCESS;
}

void Quit()
{
	MIDI_core::GlobalQuit();
}

void GetFileInfo(const char *url, char *title, int *len)
{
	if (!url || !*url)
	{
		url=cur_file;
	}
	if (len) *len=0;
	if (title) *title=0;

	char ks=0;

	bool file_local=0;
	MIDI_file * file=0;
	if (MIDI_core::getFile() && !_stricmp(url,MIDI_core::getFile()->path))
	{
		file = MIDI_core::getFile()->AddRef();
	}

	if (!file)
	{
		file = wa2_open_file(url);
    if (!file) {
      return;
    }
		file_local=1;
	}

	if (len) 
		*len=file->GetLength();
	if (title) 
		file->GetTitle(title,256);

	file->Free();
}

BOOL CALLBACK InfoProc(HWND,UINT,WPARAM,LPARAM);

int show_rmi_info(HWND w,MIDI_file* mf);

int infoDlg(const char *fn, HWND hwnd)
{
	int rv=1;
	MIDI_file *mf=wa2_open_file(fn);

	if (!mf) return INFOBOX_UNCHANGED;
	
	if (cfg_rmi_def) rv=show_rmi_info(hwnd,mf);
	else
	{
	    rv = WASABI_API_DIALOGBOXPARAM(IDD_INFO,hwnd,InfoProc,(LPARAM)mf);
	}
	if (!rv && !_stricmp(mf->path,cur_file))
	{
		PostMessage(mod.hMainWindow,WM_USER,0,243);
	}
	mf->Free();
	return rv;
}

int InfoBox(const char *file, HWND parent)
{
	if (!file) file=cur_file;
	return infoDlg(file,parent);
}

static char kill;
static int pos_ms;
static int seek_to;
static bool out_open;

DWORD WINAPI PlayThread(void*)
{
#ifdef USE_LOG
	log_write("PlayThread");
#endif
	short * visbuf;

	char *sample_buf;
	int sr,bps,nch;
	pos_ms=0;
	int pos_base=0;
	int samp_wr=0;
	int max_l=0;
	MIDI_core::GetPCM(&sr,&nch,&bps);
	int s_size=576 * (bps/8) * nch;
	if (bps>16)
	{
		visbuf=(short*)malloc(576*2*nch);
	}
	else visbuf=0;

	sample_buf = (char*)malloc(576 * 2 * (bps/8) * nch);

	bool done=0;
	while(!(kill&1))
	{
#ifdef USE_LOG
		log_write("main loop");
#endif
		if (paused) {
#ifdef USE_LOG
			log_write("paused");
#endif
			Sleep(10);
			continue;
		}
		if (seek_to!=-1)
		{
#ifdef USE_LOG
			log_write("seeking");
#endif
			if (MIDI_core::SetPosition(seek_to))
			{
				pos_ms=seek_to;
				if (out_open)
				{
					mod.outMod->Flush(pos_ms);
				}
				pos_base=pos_ms;
				samp_wr=0;
				done=0;
			}
			kill&=~2;
			seek_to=-1;
		}
		if (done)
		{
#ifdef USE_LOG
			log_write("done");
#endif
			if (!mod.outMod->IsPlaying())
			{
				PostMessage(mod.hMainWindow,WM_WA_MPEG_EOF,0,0);
				break;
			}
			Sleep(10);continue;
		}
#ifdef USE_LOG
		log_write("calling GetSamples");
#endif
		int l=MIDI_core::GetSamples(sample_buf,s_size,&kill);
		if (kill&1) {
#ifdef USE_LOG
			log_write("kill&1");
#endif
			break;
		}
		if (kill&2) {
#ifdef USE_LOG
			log_write("kill&2");
#endif
			continue;
		}
		if (l<=0 && !paused)
		{
#ifdef USE_LOG
			log_write("done(?)");
#endif
			done=1;
			if (out_open)
			{
				mod.outMod->Write(sample_buf,0);
				continue;
			}
			else
			{
				PostMessage(mod.hMainWindow,WM_WA_MPEG_EOF,0,0);
				break;
			}
		}
		if (mod.dsp_isactive())
		{
#ifdef USE_LOG
			log_write("DSP");
#endif
			l=(8*l)/(bps*nch);
			l=mod.dsp_dosamples((short*)sample_buf,l,bps,nch,sr);
			l*=(nch*bps)/8;
		}
		if (out_open)
		{
#ifdef USE_LOG
			log_write("sending to output");
#endif
			if (kill&1) break;
			while(mod.outMod->CanWrite()<l && !kill) Sleep(2);
			if (kill&1) break;

			if (!kill) mod.outMod->Write((char*)sample_buf,l);
		}
		{
			char * vis=sample_buf;
			UINT vis_bps=bps;
			if (bps>16)
			{
				int n;
				UINT d=bps>>3;
				char * foo=sample_buf+d-2;
				for(n=0;n<576*nch;n++)
				{
					visbuf[n]=*(short*)foo;
					foo+=d;
				}
				vis=(char*)visbuf;
				vis_bps=16;
			}
#ifdef USE_LOG
			log_write("doing vis");
#endif
			mod.SAAddPCMData(vis,nch,vis_bps,pos_ms);
			mod.VSAAddPCMData(vis,nch,vis_bps,pos_ms);

		}
		samp_wr+=(8*l)/(bps*nch);
		pos_ms=pos_base+MulDiv(1000,samp_wr,sr);
	}

	free(sample_buf);
	if (visbuf) free(visbuf);
	return 0;
}

int initDefaultDeviceShit()
{
  //CT> find default device if no device set
	MIDI_device * dev = MIDI_driver::find_device(cfg_driver,cfg_device);
  if(dev) return 1;

  //reinit to default
  MIDI_driver *driver=MIDI_driver::driver_enumerate(0);
  if(!driver) return 0;
  MIDI_device *device=driver->device_enumerate(0);
  if(!device) return 0;
  cfg_driver=driver->get_guid();
  cfg_device=device->get_guid();
	return 1;
}

int Play(const char *fn)
{
  if(!initDefaultDeviceShit()) return 0;

	paused=0;
	seek_to=-1;
	kill=0;

	if (!MIDI_core::Init()) return 0;

	if (!MIDI_core::UsesOutput())
	{
		MIDI_core::SetVolume(volume);
		MIDI_core::SetPan(pan);
	}
	else
	{
		MIDI_core::SetVolume(255);
		MIDI_core::SetPan(0);
	}

	MIDI_file * file = wa2_open_file(fn);
	if (!file) return -1;

	int rv=MIDI_core::OpenFile(file);
	
	file->Free();

	if (rv==0)
	{
		MIDI_core::Close();
		return 1;
	}
	cur_file=fn;
	int sr,nch,bps;
	MIDI_core::GetPCM(&sr,&nch,&bps);

	{
		MIDI_file * mf=MIDI_core::getFile();
		UINT nc=0;
		if (mf) nc=mf->info.channels;
		mod.SetInfo(nc*10000,sr/1000,2,1);
	}

	if (MIDI_core::HavePCM())
	{
		int max_l=0;
		MIDI_core::GetPCM(&sr,&nch,&bps);
		if (MIDI_core::UsesOutput())
		{
#ifdef USE_LOG
			log_write("output init");
#endif
			max_l=mod.outMod->Open(sr,nch,bps,-1,-1);
			if (max_l<0)
			{
				MIDI_core::Close();
				return 1;
			}
			out_open=1;
			mod.outMod->SetVolume(volume);
			mod.outMod->SetPan(pan);
		}
		mod.SAVSAInit(max_l,sr);
		mod.VSASetInfo(sr,nch);
#ifdef USE_LOG
		log_write("Creating thread");
#endif
		DWORD id;
		thread=CreateThread(0,0,PlayThread,0,CREATE_SUSPENDED,&id);
#ifndef _DEBUG
		SetThreadPriority(thread,THREAD_PRIORITY_TIME_CRITICAL);
#endif
		ResumeThread(thread);

	}
	else
	{
#ifdef USE_LOG
		log_write("threadless mode");
#endif
		thread=0;
	}
	
	return 0;
}

void Pause()
{
	if (MIDI_core::HavePlayer() && !paused)
	{
		MIDI_core::Pause(paused=1);
		if (MIDI_core::UsesOutput()) mod.outMod->Pause(1);
	}
}

void UnPause()
{
	if (MIDI_core::HavePlayer() && paused)
	{
		MIDI_core::Pause(paused=0);
		if (MIDI_core::UsesOutput())
		{
			mod.outMod->Flush(0);
			mod.outMod->Pause(0);
		}
	}
}

int IsPaused()
{
	return paused;
}

void Stop()
{
	if (thread)
	{
		kill|=1;
		WaitForSingleObject(thread,INFINITE);
		CloseHandle(thread);
		thread=0;
		mod.SAVSADeInit();

		if (out_open)
		{
			out_open=0;
			mod.outMod->Close();
		}
	}

	MIDI_core::Close();
}

void EQSet(int on, char data[10], int preamp)
{
}

int GetLength()
{
	return MIDI_core::GetLength();
}

int GetOutputTime()
{
	if (seek_to!=-1) return seek_to;

	if (thread && MIDI_core::UsesOutput()) return pos_ms+mod.outMod->GetOutputTime()-mod.outMod->GetWrittenTime();
	else return MIDI_core::GetPosition();
}

void SetOutputTime(int t)
{
	if (thread)
	{
		seek_to=t;
		kill|=2;
	}
	else MIDI_core::SetPosition(t);
}

void SetVolume(int v)
{
	volume=v;
	if (MIDI_core::UsesOutput()) mod.outMod->SetVolume(v);
	else MIDI_core::SetVolume(v);
}

void SetPan(int p)
{
	pan=p;
	if (MIDI_core::UsesOutput()) mod.outMod->SetPan(p);
	else MIDI_core::SetPan(p);
}

In_Module mod=
{
	IN_VER_RET,
	"nullsoft(in_midi.dll)",
	0,0,
	
	fmts_string,
	
	1,
	1,

	Config,
	About,

	Init,
	Quit,

	GetFileInfo,
	InfoBox,
	
	MIDI_core::IsOurFile,
	Play,
	Pause,
	UnPause,
	IsPaused,
	Stop,

	GetLength,
	GetOutputTime,
	SetOutputTime,

	SetVolume,
	SetPan,
	
	0,0,0,0,0,0,0,0,0,0,0,
	EQSet,

	0,
	0,
};

extern "C"
{
	__declspec( dllexport ) In_Module * winampGetInModule2()
	{
		return &mod;
	}
}

void MIDI_callback::NotifyEOF() {PostMessage(mod.hMainWindow,WM_WA_MPEG_EOF,0,0);}
HWND MIDI_callback::GetMainWindow() {return mod.hMainWindow;}
HINSTANCE MIDI_callback::GetInstance() {return mod.hDllInstance;}

void MIDI_callback::Error(const char * tx)
{
#ifndef WINAMPX
  MessageBoxA(mod.hMainWindow,tx,0,MB_ICONERROR);
#endif
}

BOOL APIENTRY DllMain(HANDLE hMod,DWORD r,void*)
{
    if (r==DLL_PROCESS_ATTACH)
	{
		DisableThreadLibraryCalls((HMODULE)hMod);
	}
	return 1;
	
}

void MIDI_callback::Idle(int ms)
{
	int start = timeGetTime();
	do Sleep(1); while( (int)timeGetTime() - start < ms);
}