-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubeview.cpp
6676 lines (6098 loc) · 201 KB
/
Cubeview.cpp
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
#include "extern.h"
#include "stdafx.h"
#include "cube.h"
#include "cubedoc.h"
#include "cubeview.h"
#include "mainfrm.h"
#include <gl\GL.h>
#include "strgrp.h"
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#include <math.h>
#include <time.h>
#include <omp.h>
#include <io.h>
#include "resource.h"
#include "csettings.h"
#include "soundfont.h"
#include "gm.h"
#include <gdiplus.h>
#include <mmsystem.h>
#include <locale.h>
#include <assert.h>
#pragma comment(lib,"Gdiplus.lib")
#pragma comment(lib,"winmm")
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#ifndef printf
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
void CCubeView::AssertValid() const
{
CView::AssertValid();
}
void CCubeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCubeDoc* CCubeView::GetDocument() // non-debug version is inline
{
return STATIC_DOWNCAST(CCubeDoc, m_pDocument);
}
#endif
#define del 0
#define MIN(a,b) (a<b)?a:b
#define MAX(a,b) (a>b)?a:b
#define getr(x) ((x&0x00FF0000) >> 0x10)
#define getg(x) ((x&0x0000FF00) >> 0x08)
#define getb(x) ((x&0x000000FF))
#define wjputs(f) fwrite(opbuf, 1, opbufcnt, f)
#define cc(x,lv) ((lv != 0) ? x + (1 - x) / (float)(lv + 1):x)
#define print2st(val) (((CMainFrame*)AfxGetApp()->m_pMainWnd)->m_wndStatusBar).SetPaneText(0, val);
#define glBegin2(id) (glcounter[id]=0)
#define glBegin3(id) (glVertexPointer(3, GL_FLOAT, 0, glbuffer[id]))
#define glBegin_common2() glEnableClientState(GL_VERTEX_ARRAY)
#define glVertex3f2(x,y,z,id) (glbt=(float*)glbuffer[id][glcounter[id]++],glbt[0]=x,glbt[1]=y,glbt[2]=z)
#define glEnd2(id) glDrawArrays(GL_QUADS,0,glcounter[id])
#define glEnd_common2() glDisableClientState(GL_VERTEX_ARRAY)
inline void pauseall();
void DrawScene();
int exit2(int iex);
void mtinit2();
struct chbuf { char c[8000]; char cb; };
struct wavFileHeader
{
long chunkId; //"RIFF" (0x52,0x49,0x46,0x46)
long chunkSize; // (fileSize - 8) - could also be thought of as bytes of data in file following this field (bytesRemaining)
long riffType; // "WAVE" (0x57415645)
};
struct fmtChunk
{
long chunkId; // "fmt " - (0x666D7420)
long chunkDataSize; // 16 + extra format bytes
short compressionCode; // 1 - 65535
short numChannels; // 1 - 65535
long sampleRate; // 1 - 0xFFFFFFFF
long avgBytesPerSec; // 1 - 0xFFFFFFFF
short blockAlign; // 1 - 65535
short significantBitsPerSample; // 2 - 65535
short extraFormatBytes; // 0 - 65535
};
struct wavChunk
{
long chunkId;
long chunkDataSize;
};
union int642char { unsigned long long i = 0; char c[8]; };
union int2char { unsigned int i = 0; char c[4]; };
union _playmidit { unsigned char bf[4]; int me; };
char mdtmpvel[2048];
char mdtmpvel8[2048];
char mdtmpoff[2048];
char mdtmpwrite[12288];
int mdtmpsize;
void mdtmpreset() {
mdtmpsize = 0;
memset(mdtmpvel, 0, 2048);
memset(mdtmpvel8, 0, 2048);
memset(mdtmpoff, 0, 2048);
}
void mdtmpsort() {
mdtmpsize = 0;
for (int i = 0; i < 2048; i++) {
if (mdtmpoff[i]) {
mdtmpwrite[mdtmpsize++] = mdtmpoff[i] + (i >> 7);
mdtmpwrite[mdtmpsize++] = (i & 127);
mdtmpwrite[mdtmpsize++] = 0;
}
}
for (int i = 0; i < 2048; i++) {
if (mdtmpvel[i] > 80) {
mdtmpwrite[mdtmpsize++] = mdtmpvel8[i] + (i >> 7);
mdtmpwrite[mdtmpsize++] = (i & 127);
mdtmpwrite[mdtmpsize++] = mdtmpvel[i];
}
}
for (int i = 0; i < 2048; i++) {
if (mdtmpvel[i] > 40&&80>= mdtmpvel[i]) {
mdtmpwrite[mdtmpsize++] = mdtmpvel8[i] + (i >> 7);
mdtmpwrite[mdtmpsize++] = (i & 127);
mdtmpwrite[mdtmpsize++] = mdtmpvel[i];
}
}
for (int i = 0; i < 2048; i++) {
if ( 40 >= mdtmpvel[i] && mdtmpvel[i]) {
mdtmpwrite[mdtmpsize++] = mdtmpvel8[i] + (i >> 7);
mdtmpwrite[mdtmpsize++] = (i & 127);
mdtmpwrite[mdtmpsize++] = mdtmpvel[i];
}
}
}
class AUX_RGBImageRec {
void convertBGRtoRGB()
{
const DWORD BitmapLength = sizeX * sizeY * 3;
byte Temp;
for (DWORD i = 0; i< BitmapLength; i += 3)
{
Temp = data[i];
data[i] = data[i + 2];
data[i + 2] = Temp;
}
}
public:
byte *data;
DWORD sizeX;
DWORD sizeY;
bool NoErrors;
AUX_RGBImageRec() : NoErrors(false), data(NULL) {};
AUX_RGBImageRec(const char *FileName) : data(NULL), NoErrors(false)
{
loadFile(FileName);
}
~AUX_RGBImageRec()
{
if (data != NULL) delete data;
data = NULL;
}
bool loadFile(const char* Filename)
{
BITMAPINFO BMInfo; // need the current OpenGL device contexts in order to make use of windows DIB utilities
const HDC gldc = wglGetCurrentDC(); // a handle for the current OpenGL Device Contexts
// assume there are errors until file is loaded successfully into memory
NoErrors = false; // release old data since this object could be used to load multiple Textures
if (data != NULL) delete data; // windows needs this info to determine what header info we are looking for
BMInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // Get windows to determine color bit depth in the file for us
BMInfo.bmiHeader.biBitCount = 0; // Get windows to open and load the BMP file and handle the messy decompression if the file is compressed
// assume perfect world and no errors in reading file, Ha Ha
HANDLE DIBHandle = LoadImage(0, Filename, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); // use windows to get header info of bitmap - assume no errors in header format
GetDIBits(gldc, (HBITMAP)DIBHandle, 0, 0, NULL, &BMInfo, DIB_RGB_COLORS);
sizeX = BMInfo.bmiHeader.biWidth;
sizeY = BMInfo.bmiHeader.biHeight; // change color depth to 24 bits (3 bytes (BGR) / pixel)
BMInfo.bmiHeader.biBitCount = 24; // don't want the data compressed
BMInfo.bmiHeader.biCompression = BI_RGB;
const DWORD BitmapLength = sizeX * sizeY * 3; // 3 bytes (BGR) per pixel (24bp)
// allocate enough memory to hold the pixel data in client memory
data = new byte[BitmapLength]; // Get windows to do the dirty work of converting the BMP into the format needed by OpenGL
// if file is already 24 bit color then this is a waste of time but makes for short code
// Get the actual Texel data from the BMP object
if (GetDIBits(gldc, (HBITMAP)DIBHandle, 0, sizeY, data, &BMInfo, DIB_RGB_COLORS))
{
NoErrors = true;
convertBGRtoRGB(); // NOTE: BMP is in BGR format but OpenGL needs RGB unless you use GL_BGR_EXT
}
DeleteObject(DIBHandle); // don't need the BMP Object anymore
return NoErrors;
}
friend AUX_RGBImageRec *auxDIBImageLoad(const char *FileName);
};
AUX_RGBImageRec *pTextureImage;
wavChunk mDataChunk;
WAVEFORMATEX wf;
_playmidit playmidit;
WAVEHDR wh;
HWAVEOUT hWaveOut;
int642char offs;
HANDLE thread1;
HMIDIOUT playmidiout;
csettings4 st4;
int2char wjct2;
chbuf *chbuffer;
FILE *wj, *wj2, *wj3, *wj6, *wj7, *i, *wj4, *ch, *lrcf, *playmidif, *playmidig;
int fp2,speedupdate=0;
char afqwfq[384] = { 0 };
bool ab=0,bt, gtmp, gmea, mov, dbc, lrcb, ps, fs, skip, ppmy, txtoff, playrd100t, playrd100t2, *buf, keysig2, stop, damppad[16], softpad[16], sti3, stop2, g3446 = true, atmod, wjaa, updta, vol, strclrc, ply = true, f, fnm, pb, quit, htit, mmp, forcenomidi, sdfsdf, exbl;
char t[10000], filename1[10000], filename[10000], filename2[10000], filename3[10000], filename4[10000], filename6[10000], filename5[10000], filename8[1025], filename9[400], *buffer, opbuf[8000], mdstrings[2000], chrinp[100], ktemp[1056], ktt, lrcc1[2000], lrcc2[2000], lrcc3[2000], filename7[10000], argv[1000], tj[1000], imgname[1000], mdt[500][268][16], p[100], *midname, *midname2, str[10000], midstr[1000], ofilename2[1000], filename0[1000];
short pc2[16], *key5[128], stm, midipan;
int windh, windv, ox, oy, frqt, gmetmp2, midipitchbend[16][2], mdtpnt2, owindx, owindy, monce, onelp, pitchint[16], q, ips, ro, midipitchbend2[16], midipitchbend_[16], pitchint2[16], midipitch, tmpmode, lt, glcounter[8], wavestate, windx, windy, ocl, bfps, fps, txtys, key3[128][16], keysust[128][16], *oldstate, midibx[128][16], playrd10, chn = -1, yryer, opbufcnt, oks, ipaused[16], bpaused[16], cpaused[16], rpaused[16], mpaused[16], j5gyj, chrcnt, bth = 4, btl = 4, keysig = 8, *chbuffercnt, textmode, windowx, windowy, mode, ii, stringcount, mdtpnt, brebe, txtmd2, tpi, knamei, kfreqi, hortxti, mirror, reverse, trand, asfaq, mpoffset, setmidivol, fspace = 100, isplay, midibank[16], fmbank[16], midipreset[16], fmpreset[16], ombank[16], ompreset[16], bpshf;
unsigned int tex, playrate = 22050, tempo = 120, deltatime;
long gtc, ldpdt, oldpdt, doldpdt, playrd100, modulationwheel[16], fmodulationwheel[16], fchorus[16], freverb[16], pbendratio[16], chnvolt[16], footcontr[16], breathcontr[16], pan[16], owptr, owptr6, chorus[16], reverb[16];
unsigned long thread1d, thread1e, clock_start;
float glbuffer[8][2008][3], *glbt, h45h7 , gasfw , hg4h5, stretchx = 1.0f, stretchy = 1.0f, stretchz = 1.0f, x , y, turfreq = 440, strclr[4], j5jgj = 1, or , og, tr = 0.5, tg = 0.5, tb = 0.5, ta = 1, mdtpnt3, upbl = 0.1, dwbl = 0.3, erhwh[16], iyybt[16], trity[16], sadae[16], erhwhw2[16][8], iyybts2[16][8], trityu2[16][8];
long long offs2, lrct3, lrct4, midisize, pnote, wptr, owptr4, owptr5, mptr, *le, *le2, *chlnt, *fileptr, nplayoffset, playoffset, onp1;
unsigned long long oplaymidii, gmeo, lud, playmidin0, playlength, wj6startpos2, playmidii, playmidij, playmidini, playmidinj, note, owptr2;
double lrct1, lrct2, _clock2, clocks, clocks2, f346h = 1., playvolume = 1.0f, pitcherror[16][128], chvol[16], key[128][16], dchorus[16], dreverb[16], rmodulationwheel[16], volume2[16], spd2=100,spd = 100, loop = 0., pitch[16], rpitch[16], pc3[16], dwp, mdvol2[3][16], mdvol3[128][16], dplayrate, pitcherr[128][16], pdt, dpdt, wjct, wjcid2[128], wjca;
volatile unsigned long long gmeaptr, gmeaptr2;
AUX_RGBImageRec *auxDIBImageLoad(const char *FileName)
{
return new AUX_RGBImageRec(FileName);
}
AUX_RGBImageRec * LoadBMPFile(char *filename)
{
FILE *hFile = NULL;
if (!filename) return NULL;
hFile = fopen(filename, "r");
if (hFile) {
fclose(hFile);
return auxDIBImageLoad(filename);
}
return NULL;
}
inline void revfile(char* filename) {
char y[10000];
FILE *r, *w;
strcpy(y, filename);
r = fopen(y, "rb");
sprintf(y, "%st", filename);
w = fopen(y, "wb");
for (int i = 0; i < 4; i++) {
fputc(fgetc(r), w);
}
fputc(fgetc(r) == 1 ? 0 : 1, w);
unsigned long long t;
_fseeki64(r, -8, SEEK_END);
fread(&t, 8, 1, r);
_fseeki64(r, t, SEEK_SET);
long long rt = t;
_fseeki64(r, -1056, SEEK_CUR); rt -= 1056;
while (1) {
fread(y, 1, 1056, r);
rt += 1056;
fwrite(y, 1, 1056, w);
_fseeki64(r, -2112, SEEK_CUR);
rt -= 2112;
if (rt<0)break;
}
//("?");
_fseeki64(r, -12, SEEK_END);
rt = _ftelli64(r);
while (1) {
int ti = 0, ti2 = 0;
while (1) {
//_fseeki64(r, -1, SEEK_CUR);
if (rt < t) break;
rt++;
if (fgetc(r) == 0x0A) ti++;
if (ti == 6) break;
//
rt -= 2;
_fseeki64(r, -2, SEEK_CUR);
ti2++;
}
fread(y, 1, ti2, r);
fwrite(y, 1, ti2, w);
_fseeki64(r, -ti2 - 1, SEEK_CUR);
rt--;
if (_ftelli64(r) < t) break;
}
fputc(0x0a, w);
fwrite("eof", 1, 3, w);
fwrite(&t, 8, 1, w);
fclose(r);
fclose(w);
sprintf(y, "del \"%s\"", filename);
system(y);
Sleep(100);
char *t2;
for (int i = strlen(filename); i >= 0; i--) {
if (filename[i] == '\\') {
t2 = &(filename[i + 1]);
break;
}
}
sprintf(y, "ren \"%st\" \"%s\"", t2, t2);
//("%s", y);
system(y);
}
inline void revfile2(char* filename) {
char y[10000];
FILE *r, *w;
strcpy(y, filename);
r = fopen(y, "rb");
sprintf(y, "%st", filename);
w = fopen(y, "wb");
for (int i = 0; i < 0x2c; i++) {
fputc(fgetc(r), w);
}
fseek(r, -2, SEEK_END);
while (1) {
fputc(fgetc(r), w);
fputc(fgetc(r), w);
fseek(r, -4, SEEK_CUR);
if (ftell(r) < 0x2c) break;
}
fclose(r);
fclose(w);
sprintf(y, "del \"%s\"", filename);
system(y);
Sleep(100);
char *t2;
for (int i = strlen(filename); i >= 0; i--) {
if (filename[i] == '\\') {
t2 = &(filename[i + 1]);
break;
}
}
sprintf(y, "ren \"%st\" \"%s\"", t2, t2);
system(y);
}
void putini() {
FILE *ini;
intfloat t[16];
t[0].a = h45h7;
t[1].a = gasfw;
t[2].a = hg4h5;
t[3].a = tr;
t[4].a = tg;
t[5].a = tb;
t[6].a = ta;
t[7].a = turfreq;
t[8].a = x;
t[9].a = y;
t[10].a = stretchx;
t[11].a = stretchy;
t[12].a = stretchz;
t[13].a = upbl;
t[14].a = dwbl;
t[15].a = j5jgj;
char stf[1000];
GetModuleFileNameA(NULL, stf, 1000);
for (int i = strlen(stf) - 1; i >= 0; i--)
if (stf[i] == '\\') { stf[i] = 0; break; }
strcat(stf, "\\hmp6.ini");
if ((ini = fopen(stf, "w")) != NULL) {
sprintf(recentfilelist[12], "%d %d %d %d %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", windowx, windowy, windh, windv, mmp, t[0].b, t[1].b, t[2].b, t[3].b, t[4].b, t[5].b, t[6].b, asfaq, brebe, textmode, h54ui, jhj56, ghkj6, j65j8, trand, mirror, reverse, knamei, kfreqi, hortxti, t[7].b, t[8].b, t[9].b, t[10].b, fsize, fspace, t[11].b, t[12].b, t[13].b, t[14].b, txtmd2, t[15].b);
for (int i = 0; i < 13; i++) { fprintf(ini, "%s_\n", recentfilelist[i]); }
fprintf(ini, "%d\n", j5gyj);
for (int i = 0; i < 16; i++) { t[0].a = erhwh[i]; t[1].a = iyybt[i]; t[2].a = trity[i]; t[3].a = sadae[i]; fprintf(ini, "%x %x %x %x\n", t[0].b, t[1].b, t[2].b, t[3].b); }
fprintf(ini, "%s_\n", recentfilelist[13]);
fclose(ini);
}
}
inline void getini() {
FILE *ini;
char stf[1000];
GetModuleFileNameA(NULL, stf, 1000);
for (int i = strlen(stf) - 1; i >= 0; i--)
if (stf[i] == '\\') { stf[i] = 0; break; }
strcat(stf, "\\hmp6.ini");
if (access(stf, 0) != 0) {
st4.ShowWindow(SW_SHOW);
windh = 1024;
windv = 768;
turfreq = 440.0f;
fsize = 20; fspace = 100;
strcpy(recentfilelist[13], "Arial");
ini = fopen(stf, "w");
fprintf(ini, "_\n_\n_\n_\n_\n_\n_\n_\n_\n_\n_\n_\n100 100 1024 768 0 0 0 0 3f000000 3f000000 3f000000 3f800000 15e 64 0 0 2 0 64 0 0 0 0 0 0 43dc0000 0 0 3f800000 14 64 3f800000 3f800000 3dcccccd 3e99999a 0 3f800000_\n1\n3f7f0000 0 3efe0000 3f7f0000\n3eee0000 3f350000 3f7e0000 3f7f0000\n3f7f0000 3f5f0000 0 3f7f0000\n3f3f0000 3f7f0000 0 3f7f0000\n3efe0000 0 3f7f0000 3f7f0000\n0 3f7f0000 3f7f0000 3f7f0000\n3f600000 3f300000 3f7f0000 3f7f0000\n3f7f0000 3f650000 3f340000 3f7f0000\n3f230000 3f410000 3f2d0000 3f7f0000\n3f400000 3f400000 3f400000 3f7f0000\n3f410000 3f1a0000 3ed60000 3f7f0000\n3f7e0000 3e9c0000 3f5a0000 3f7f0000\n3f700000 3f7f0000 3f700000 3f7f0000\n3ea00000 3f480000 3ef00000 3f7f0000\n3f7d0000 3f7f0000 0 3f7f0000\n3f670000 3f7e0000 3f7f0000 3f7f0000\nArial_");
fclose(ini);
Sleep(10);
ini = fopen(stf, "r");
}
if ((ini = fopen(stf, "r")) == NULL) return;
for (int i = 0; i < 13; i++) {
fscanf(ini, " %[^\n]", recentfilelist[i]);
recentfilelist[i][strlen(recentfilelist[i]) - 1] = 0;
}
fscanf(ini, " %d", &j5gyj);
intfloat t[16];
if (j5gyj == 1) {
for (int i = 0; i < 16; i++) {
fscanf(ini, " %x %x %x %x", &t[0].b, &t[1].b, &t[2].b, &t[3].b); erhwh[i] = t[0].a; iyybt[i] = t[1].a; trity[i] = t[2].a; sadae[i] = t[3].a;
}
}
else {
int j;
for (int i = 0; i < 16; i++) {
fscanf(ini, " %*x %*x %*x %*x");
}
}
fscanf(ini, " %[^\n]", recentfilelist[13]);
recentfilelist[13][strlen(recentfilelist[13]) - 1] = 0;
FILE *tmp;
int a = 0;
for (int i = 0; i < 12; i++) {
if ((tmp = fopen(recentfilelist[i], "r")) == NULL) {
a = 1;
recentfilelist[i][0] = 0;
}
else fclose(tmp);
}
fclose(ini);
fsize = 0; fspace = 0;
sscanf(recentfilelist[12], " %d %d %d %d %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", &windowx, &windowy, &windh, &windv, &mmp, &t[0].b, &t[1].b, &t[2].b, &t[3].b, &t[4].b, &t[5].b, &t[6].b, &asfaq, &brebe, &textmode, &h54ui, &jhj56, &ghkj6, &j65j8, &trand, &mirror, &reverse, &knamei, &kfreqi, &hortxti, &t[7].b, &t[8].b, &t[9].b, &t[10].b, &fsize, &fspace, &t[11].b, &t[12].b, &t[13].b, &t[14].b, &txtmd2, &t[15].b);
if (a)putini();
h45h7 = t[0].a;
gasfw = t[1].a;
hg4h5 = t[2].a;
tr = t[3].a;
tg = t[4].a;
tb = t[5].a;
ta = t[6].a;
turfreq = t[7].a;
x = t[8].a;
y = t[9].a;
stretchx = t[10].a;
stretchy = t[11].a;
stretchz = t[12].a;
upbl = t[13].a;
dwbl = t[14].a;
j5jgj = t[15].a;
if (stretchx < 0.00099 || stretchx >1001. || stretchy < 0.00099 || stretchy >1001.|| stretchz < 0.00099 || stretchz >1001.) {
Sleep(10);
char p[1000];
sprintf(p, "del \"%s\"", stf);
system(p);
Sleep(100);
getini();
}
}
inline int LoadGLTextures(void) {
AUX_RGBImageRec *texRec; //<1>
if ((texRec = LoadBMPFile(imgname))) {
glGenTextures(3, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //<7>
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texRec->sizeX, texRec->sizeY, 0,GL_RGB, GL_UNSIGNED_BYTE, texRec->data); //<9>
}
else return FALSE;
if (texRec) {
if (texRec->data) free(texRec->data);
free(texRec);
}
else return FALSE;
glEnable(GL_TEXTURE_2D);
return TRUE;
}
inline void wjput(char* g, FILE *f) {
opbuf[opbufcnt++] = g[2];
opbuf[opbufcnt++] = g[3];
if (opbufcnt == 8000) {
opbufcnt = 0; fwrite(opbuf, 1, 8000, f);
}
}
inline int sjgf(FILE* file, int id) {
int temp;
if (chbuffercnt[id] >= 0) temp = chbuffer[id].c[chbuffercnt[id]];
else if (chbuffercnt[id] == -1) temp = chbuffer[id].cb;
else {
_fseeki64(file, fileptr[id], SEEK_SET);
long long loadsize = midisize - fileptr[id];
if (loadsize > 8000)loadsize = 8000;
fread(chbuffer[id].c, 1, loadsize, file);
fileptr[id] += loadsize;
chbuffercnt[id] = 0;
temp = chbuffer[id].c[0] & 0x00FF;
}
if (chbuffercnt[id] == 7999) {
chbuffercnt[id] = -1;
chbuffer[id].cb = chbuffer[id].c[7999]; _fseeki64(file, fileptr[id], SEEK_SET);
long long loadsize = midisize - fileptr[id];
if (loadsize > 8000)loadsize = 8000;
fread(chbuffer[id].c, 1, loadsize, file);
fileptr[id] += loadsize;
}
chbuffercnt[id]++;
chlnt[id]--;
if (chlnt[id] < 0) buf[id] = true;
temp &= 0x00FF;
return temp;
}
inline double freq2(int a) {
int b = a - 0x45;
double c = 440;
while (1) {
if (b > 12) { b -= 12; c *= 2; }
else if (b < -12) { b += 12; c /= 2; }
else if (b > 4) { b -= 4; c *= 1.2599210498948731647672106072782; }
else if (b < -4) { b += 4; c /= 1.2599210498948731647672106072782; }
else if (b > 0) { b--; c *= 1.0594630943592952645618252949463; }
else if (b < 0) { b++; c /= 1.0594630943592952645618252949463; }
else break;
}
return c;
}
inline double freq(int a) {
if (jhj56 == 2 || jhj56 == 4) atmod = true;
else atmod = false;
if (jhj56 == 0) {
int b = a - 0x45;
double c = 440.;
while (1) {
if (b > 12) { b -= 12; c *= 2; }
else if (b < -12) { b += 12; c /= 2; }
else if (b > 4) { b -= 4; c *= 1.2599210498948731647672106072782; }
else if (b < -4) { b += 4; c /= 1.2599210498948731647672106072782; }
else if (b > 0) { b--; c *= 1.0594630943592952645618252949463; }
else if (b < 0) { b++; c /= 1.0594630943592952645618252949463; }
else break;
}
return c*turfreq / 440.;
}
else if (jhj56>2) {
frqt = a % 12;
if (frqt == 9) {
int b = a - 69;
double c = pure[0][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 10) {
int b = a - 70;
double c = pure[1][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 11) {
int b = a - 71;
double c = pure[2][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 0) {
int b = a - 72;
double c = pure[3][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 1) {
int b = a - 73;
double c = pure[4][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 2) {
int b = a - 74;
double c = pure[5][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 3) {
int b = a - 75;
double c = pure[6][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 4) {
int b = a - 76;
double c = pure[7][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 5) {
int b = a - 77;
double c = pure[8][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 6) {
int b = a - 78;
double c = pure[9][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 7) {
int b = a - 79;
double c = pure[10][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else {
int b = a - 80;
double c = pure[11][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
//
}
else {//69번키가 라
frqt = a % 12;
if (frqt == 9) {
int b = a - 69;
double c = pyt[0][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 10) {
int b = a - 70;
double c = pyt[1][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 11) {
int b = a - 71;
double c = pyt[2][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 0) {
int b = a - 72;
double c = pyt[3][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 1) {
int b = a - 73;
double c = pyt[4][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 2) {
int b = a - 74;
double c = pyt[5][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 3) {
int b = a - 75;
double c = pyt[6][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 4) {
int b = a - 76;
double c = pyt[7][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 5) {
int b = a - 77;
double c = pyt[8][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 6) {
int b = a - 78;
double c = pyt[9][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else if (frqt == 7) {
int b = a - 79;
double c = pyt[10][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
else {
int b = a - 80;
double c = pyt[11][(atmod == true) ? keysig : 8];
while (1) {
if (b >= 12) { b -= 12; c *= 2; }
else if (b <= -12) { b += 12; c /= 2; }
else break;
}
return c*turfreq / 440.;
}
//
}
}
inline void sppmy() {
for (int i = 0; i < 16; i++) {
for (int k = 0; k < 128; k++) {
pitcherr[k][i] = freq(k)*rpitch[i] / freq2(k);
}
}
}
inline void noteoff(int wyr, int midichennel) {
if (mirror)wyr = 0x7F - wyr;
if (midichennel != 9)releasenote(midichennel, wyr);
key3[wyr][midichennel] = 0;
}
inline void noteon(int wyr, int vel, int chennel, int midichennel) {
ombank[midichennel] = 1;
if (mirror)wyr = 0x7F - wyr;
note++;
setnote(midichennel, wyr, vel, (double)vel / 128.*mdvol3[wyr][midichennel]);
key3[wyr][midichennel] = ((chennel & 7) != 0) ? (chennel & 7) : 7;
}
inline void noteon2(int wyr, int midichennel) {
if (mirror)wyr = 0x7F - wyr;
key3[wyr][midichennel] = 0;
}
inline void getmidieventacc() {
for (int j = 0; j < chn; j++) {
unsigned int tmp2;
unsigned int tmp = 0, b = 0;
unsigned int c = 0,e=0;
unsigned long long d = 0;
if (mptr == le[j] + le2[j] && buf[j] == false) {
le[j] += le2[j];
tmp = sjgf(ch, j);
C2:
gmetmp2 = tmp & 15;
if (tmp <= 0x7F) { //("!");
chbuffercnt[j]--; chlnt[j]++; tmp = oldstate[j]; goto C2;
}
else if (tmp >= 0x80 && tmp <= 0x8F) {
oldstate[j] = tmp;
b = sjgf(ch, j);
c = sjgf(ch, j);
if (keysust[b][gmetmp2] == 0) noteoff(b, gmetmp2);
else noteon2(b, gmetmp2);
}
else if (tmp >= 0x90 && tmp <= 0x9F) {
oldstate[j] = tmp;
b = sjgf(ch, j);
c = sjgf(ch, j);
if (c) noteon(b, softpad[gmetmp2] ? (c >> 1) : c, j, gmetmp2);
else if (damppad[gmetmp2] || keysust[b][gmetmp2] == 1)
noteon2(b, gmetmp2);
else noteoff(b, gmetmp2);
}
else if (tmp >= 0xF0 && tmp <= 0xFE) {
if (tmp == 0xF0) {
while (tmp != 0xF7) tmp = sjgf(ch, j);
}
else if (tmp == 0xF7) {
while (tmp != 0xF7) { tmp = sjgf(ch, j); }
}
else if (tmp == 0xF6) {
}
else if (tmp >= 0xF1 || tmp <= 0xF3) {
tmp = sjgf(ch, j);
}
}
else if (tmp >= 0xE0 && tmp <= 0xEF) {
oldstate[j] = tmp;
b = sjgf(ch, j);
c = sjgf(ch, j);
//midipitchbend[gmetmp2][0] = b; midipitchbend[gmetmp2][1] = c;
int t = ((((int)c << 7) + (int)b) - 8192);
rpitch[gmetmp2] = pow(2, (double)t / (12.*4096. * 256. / (double)pbendratio[gmetmp2]))*pc3[gmetmp2];
pc2[gmetmp2] = (int)(12 * log2(rpitch[gmetmp2]));
sppmy();
}
else if (tmp >= 0xC0 && tmp <= 0xCF) {
oldstate[j] = tmp;
e = sjgf(ch, j);
if ((fmpreset[gmetmp2] == 128 || ombank[gmetmp2] == 1))
midipreset[gmetmp2] = e;
if (midiout)reparsesf(gmetmp2, midibank[gmetmp2], midipreset[gmetmp2], playrate);
}
else if (tmp >= 0xD0 && tmp <= 0xDF) {
oldstate[j] = tmp;
b = sjgf(ch, j);
}
else if (tmp >= 0xB0 && tmp <= 0xBF) {
oldstate[j] = tmp;
c = sjgf(ch, j);
b = sjgf(ch, j);
if (c == 0x00 && (fmbank[gmetmp2] == -1||ombank[gmetmp2]==1)) {
midibank[gmetmp2] = b;
//system("pause");
if (midiout)reparsesf(gmetmp2, midibank[gmetmp2], midipreset[gmetmp2], playrate);
}
else if (c == 0x01) {
modulationwheel[gmetmp2] = (b << 7) + (modulationwheel[gmetmp2] & 0x7F); rmodulationwheel[gmetmp2] = (double)(modulationwheel[gmetmp2] + fmodulationwheel[gmetmp2]) / 16384.; if (rmodulationwheel[gmetmp2]>1) rmodulationwheel[gmetmp2] = 1; if (rmodulationwheel[gmetmp2]<0) rmodulationwheel[gmetmp2] = 0;
}
else if (c == 0x02) {
breathcontr[gmetmp2] = (b << 7) + (breathcontr[gmetmp2] & 0x7F);
}
else if (c == 0x04) {
footcontr[gmetmp2] = (b << 7) + (footcontr[gmetmp2] & 0x7F);
}
else if (c == 0x06) {
pbendratio[gmetmp2] = (b << 7) + (pbendratio[gmetmp2] & 0x7F);
}
else if (c == 0x07) {
chnvolt[gmetmp2] = (b << 7) + (chnvolt[gmetmp2] & 0x7F);
chvol[gmetmp2] = volume2[gmetmp2] * chnvolt[gmetmp2] / 16383.;
}
else if (c == 0x08 || c == 0x0A) {
pan[gmetmp2] = (b << 7) + (pan[gmetmp2] & 0x7F);
}
else if (c == 0x20 && (fmbank[gmetmp2] == -1||ombank[gmetmp2]==1)) {
////midibank[gmetmp2] = b + (midibank[gmetmp2] & 0x3F80);
//system("pause");
//if (midiout)reparsesf(gmetmp2, midibank[gmetmp2], midipreset[gmetmp2], playrate);
}
else if (c == 0x21) {
modulationwheel[gmetmp2] = b + (modulationwheel[gmetmp2] & 0x3F80); rmodulationwheel[gmetmp2] = (double)(modulationwheel[gmetmp2] + fmodulationwheel[gmetmp2]) / 16384.; if (rmodulationwheel[gmetmp2]>1) rmodulationwheel[gmetmp2] = 1; if (rmodulationwheel[gmetmp2]<0) rmodulationwheel[gmetmp2] = 0;
}
else if (c == 0x22) {
breathcontr[gmetmp2] = b + (breathcontr[gmetmp2] & 0x3F80);
}
else if (c == 0x24) {
footcontr[gmetmp2] = b + (footcontr[gmetmp2] & 0x3F80);
}
else if (c == 0x26) {
pbendratio[gmetmp2] = b + (pbendratio[gmetmp2] & 0x3F80);
}
else if (c == 0x27) {
chnvolt[gmetmp2] = b + (chnvolt[gmetmp2] & 0x3F80);
chvol[gmetmp2] = volume2[gmetmp2] * chnvolt[gmetmp2] / 16383.;
}
else if (c == 0x28 || c == 0x2A) {
pan[gmetmp2] = b + (pan[gmetmp2] & 0x3F80);
}
else if (c == 0x40) {
if (b > 64) damppad[gmetmp2] = true;
else {
damppad[gmetmp2] = false;
if (gmetmp2 != 9)
for (int dj = 0; dj < 128; dj++) {
if (!key3[dj][gmetmp2])releasenote(gmetmp2, dj);
}
}
}
else if (c == 0x41) {
if (b > 64);
else pbendratio[gmetmp2] = 256;
}
else if (c == 0x42) {
if (b > 64) {
for (int dj = 0; dj < 128; dj++)keysust[gmetmp2][dj] = (key3[gmetmp2][dj] != 0);
}
else {
for (int dj = 0; dj < 128; dj++)
if (keysust[gmetmp2][dj] == 1) {