-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKernel.cpp
1475 lines (1188 loc) · 46.4 KB
/
Kernel.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
// Copyright 2004/2006 Marko Mihovilic
#include "Globals.h"
#include "PowerSpectrum.h"
#include "AnalyzerRedesigned.h"
#include "LazySpectrum.h"
#include "Scope.h"
#include "DoubleScope.h"
#include "AmoebaScope.h"
#include "VuMeter.h"
#include "Kernel.h"
#include "TransitionEffects.h"
#include "Configuration.h"
#include "Resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Our main entry point
INT WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, INT /*nCmdShow*/)
{
// Create a system wide mutex
HANDLE mutex = CreateMutex(NULL,FALSE,ANALYZER_MUTEXSTRING);
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
//MessageBox(GetDesktopWindow(),L"A instance of " ANALYZER_WINDOWTITLE L" is already running.\n\nPlease close it before running again.",L"Already running",MB_OK|MB_ICONEXCLAMATION);
HWND hWnd = FindWindow(ANALYZER_CLASSNAME,ANALYZER_WINDOWTITLE);
ShowWindow(hWnd,SW_RESTORE);
SetForegroundWindow(hWnd);
return 0;
}
// Initialize com
CoInitialize(NULL);
// Randomize the random seed
srand((unsigned long)GetCurrentTime());
// Increase system timer resolution
timeBeginPeriod(1);
//InitCommoControls();
// Call our main frame's main function that will block until the app exits
int ret = GetKernel()->OnRun();
// Restore system timer resolution
timeEndPeriod(1);
// Destroy the dynamic objects
GetKernel(true);
GetTimer(true);
GetCommandLineData(true);
// Uninit COM
CoUninitialize();
// Close mutex
CloseHandle(mutex);
#ifdef _DEBUG
_CrtDumpMemoryLeaks();
#endif
// Return the value previously returned by our app's main function
return ret;
}
Kernel::Kernel() :
mCreated(false),
mWindowHandle(NULL),
mGraphics(NULL),
mAudio(NULL),
mMenus(NULL),
mUserInterface(NULL),
mProcessor(NULL),
mElapsedTime(NULL),
mAbsoluteTime(NULL),
mCursorPositionTime(NULL),
mLed(false) // Default
{
}
Kernel::~Kernel()
{
DestroyKernel();
}
void Kernel::CreateModuleInfo(void)
{
// Get the current module directory
wchar_t buffer[MAX_PATH];
GetModuleFileName(NULL,buffer,MAX_PATH);
// We only need the directory path
PathRemoveFileSpec(buffer);
PathAddBackslash(buffer);
mModulePath = buffer;
GetModuleFileName(NULL,buffer,MAX_PATH);
PathStripPath(buffer);
mModuleName = buffer;
TRACE(L"Module path is: %s\n",GetModulePath().GetBuffer());
TRACE(L"Module name is: %s\n",GetModuleName().GetBuffer());
}
bool Kernel::CreateKernel(void)
{
// Enable loging
if(GetCommandLineData()->GetVar(L"/log"))
if(!mLog.OpeLog(GetCombinedPath(GetCommandLineData()->GetVar(L"/log",GetModulePath()),L"Kernel.log")))
TRACE(L"Failed to open log file \"%s\"\n",GetCombinedPath(GetCommandLineData()->GetVar(L"/log",GetModulePath()).GetBuffer(),L"Kernel.log"));
// Increase our priority
if(GetCommandLineData()->GetVar(L"/highpriority",ANALYZER_HIGHPRIORITY))
{
TRACE(L"Setting process priority class to: Above Normal.\n");
SetPriorityClass(GetCurrentProcess(),ABOVE_NORMAL_PRIORITY_CLASS);
}
// Start our app timer, start stop it just to get the current time
GetTimer()->Start();
GetTimer()->Stop();
// Update the absolute time so any outputed strings douring initialization are visible
mAbsoluteTime = GetTimer()->GetAbsoluteTime();
// Create the processor
mProcessor = new Processor;
if(!mProcessor)
{
MessageErrorLast(L"Failed to allocate processor.",L"Error");
TRACE(L"Failed to allocate processor.\n");
return false;
}
// Set the processor type
#ifdef _X86_
if(IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE))
{
CreateSSEProcessor(mProcessor);
TRACE(L"Math: Using SSE Instructions\n");
}
else
#endif
{
CreateGenericProcessor(mProcessor);
TRACE(L"Math: Using Generic Instructions\n");
}
TRACE(L"Allocating graphics...\n");
// Create the graphics object
mGraphics = new Graphics;
if(!mGraphics)
{
MessageErrorLast(L"Failed to allocate graphics.",L"Error");
TRACE(L"Failed to allocate graphics.\n");
return false;
}
TRACE(L"Allocating audio...\n");
// Create the audio object
mAudio = new Audio;
if(!mAudio)
{
MessageErrorLast(L"Failed to allocate audio.",L"Error");
TRACE(L"Failed to allocate audio.\n");
return false;
}
TRACE(L"Allocating menus...\n");
// Create the menus object
mMenus = new Menus;
if(!mMenus)
{
MessageErrorLast(L"Failed to allocate menus.",L"Error");
TRACE(L"Failed to allocate menus.\n");
return false;
}
TRACE(L"Allocating user interface...\n");
// Create the user interface
mUserInterface = new UserInterface;
if(!mUserInterface)
{
MessageErrorLast(L"Failed to allocate user interface.",L"Error");
TRACE(L"Failed to allocate user interface.\n");
return false;
}
TRACE(L"Creating window...\n");
DWORD style;
if(GetCommandLineData()->GetVar(L"/border",true))
style = WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
else
style = WS_POPUP|WS_SYSMENU;
// Create the window
if(!CreateWindow(WINDOW_WIDTH,WINDOW_HEIGHT,style))
{
MessageErrorLast(L"Failed to create window.",L"Error");
TRACE(L"Failed to create window.\n");
return false;
}
// Create a fiew DEBUG windows
if(GetCommandLineData()->GetVar(L"/ui",false))
{
WindowHandle window1 = mUserInterface->NewWindow(Point(40,80),Size(300,280),Size(300,280),Size(500,280),L"Color Editor");
window1->SetMinimizeVisible(false);
window1->SetMinimizeEnabled(false);
window1->SetCallbackClass(this);
window1->AttachChild(mUserInterface->NewButton(10,Point(216,248),Size(75,23),L"Copy"));
window1->AttachChild(mUserInterface->NewComboBox(20,Point(10,30),Size(280,19)));
window1->AttachChild(mUserInterface->NewStaticText(Point(10,60),Size(150,20),L"Red: 0"));
window1->AttachChild(mUserInterface->NewTrackBar(30,Point(10,75),Size(280,18),255,0));
window1->AttachChild(mUserInterface->NewStaticText(Point(10,105),Size(150,20),L"Green: 0"));
window1->AttachChild(mUserInterface->NewTrackBar(31,Point(10,120),Size(280,18),255,0));
window1->AttachChild(mUserInterface->NewStaticText(Point(10,150),Size(150,20),L"Blue: 0"));
window1->AttachChild(mUserInterface->NewTrackBar(32,Point(10,165),Size(280,18),255,0));
window1->AttachChild(mUserInterface->NewStaticText(Point(10,195),Size(150,20),L"Alpha: 0"));
window1->AttachChild(mUserInterface->NewTrackBar(33,Point(10,210),Size(280,18),255,0));
window1->AttachChild(mUserInterface->NewButton(11,Point(10,248),Size(75,23),L"Sync Controls"));
window1->GetChild(0)->SetSnap(Control::SnapRight | Control::SnapBottom);
window1->GetChild(1)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(2)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(3)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(4)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(5)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(6)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(7)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(8)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
window1->GetChild(9)->SetSnap(Control::SnapLeft | Control::SnapRight | Control::SnapTop);
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Foreground");
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Background");
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Peaks");
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Text1");
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Text2");
((ComboBoxHandle)window1->GetChild(1))->AddItem(L"Text3");
}
// Init the direct3d device in the main application thread
if(!mGraphics->CreateGraphics())
{
MessageErrorLast(L"Failed to initialize graphics.",L"Error");
TRACE(L"Failed to initialize graphics.\n");
return false;
}
// Create the fonts
if(!mGraphics->CreateFonts())
{
MessageErrorLast(L"Failed to initialize resources.",L"Error");
TRACE(L"Failed to initialize resources.\n");
return false;
}
// Create the render targets
if(!mGraphics->CreateRenderTargets())
{
MessageErrorLast(L"Failed to initialize resources.",L"Error");
TRACE(L"Failed to initialize resources.\n");
return false;
}
// Init textures
if(!mGraphics->CreateTextures())
{
MessageErrorLast(L"Failed to initialize resources.",L"Error");
TRACE(L"Failed to initialize resources.\n");
return false;
}
if(!mGraphics->CreateSprites())
{
MessageErrorLast(L"Failed to initialize resource.",L"Error");
TRACE(L"Failed to initialize resource.\n");
return false;
}
// Init the sound capture objects
if(!mAudio->CreateAudio())
{
MessageErrorLast(L"Failed to initialize audio system.",L"Error");
TRACE(L"Failed to initialize resources.\n");
return false;
}
// Start the capture of audio
if(!mAudio->StartCapture())
{
MessageErrorLast(L"Failed to start capturing audio.",L"Error");
TRACE(L"Failed to initialize resources.\n");
return false;
}
// Load the default color presets file
mGraphics->ReadColorPresets();
// Add the visualizations
//#ifdef _DEBUG
mGraphics->AddVisualization(new PowerSpectrum());
mGraphics->AddVisualization(new LazySpectrumA());
mGraphics->AddVisualization(new LazySpectrumB());
//#endif
mGraphics->AddVisualization(new AnalyzerRedesigned());
mGraphics->AddVisualization(new Scope());
mGraphics->AddVisualization(new DoubleScope());
mGraphics->AddVisualization(new VuMeter());
//#ifdef _DEBUG
mGraphics->AddVisualization(new AmoebaScope());
//#endif
// Add the transitions
mGraphics->AddTransition(new TransitionTVHorizontal());
mGraphics->AddTransition(new TransitionTVVertical());
mGraphics->AddTransition(new TransitionTVCenter());
mGraphics->AddTransition(new TransitionStretchLeft());
mGraphics->AddTransition(new TransitionStretchTop());
mGraphics->AddTransition(new TransitionStretchRight());
mGraphics->AddTransition(new TransitionStretchBottom());
mGraphics->AddTransition(new TransitionStretchInLeft());
mGraphics->AddTransition(new TransitionStretchInTop());
mGraphics->AddTransition(new TransitionSlideInTop());
mGraphics->AddTransition(new TransitionSlideInBottom());
mGraphics->AddTransition(new TransitionSlideInLeft());
mGraphics->AddTransition(new TransitionSlideInRight());
// Load the config
ReadConfig();
// Init the menus
if(!mMenus->CreateMenus())
{
MessageErrorLast(L"Failed to initialize menu system.",L"Error");
TRACE(L"Failed to initialize menu system.\n");
return false;
}
mGraphics->PrintOutputString(L"press \002F1\001 for help");
// Actualy start the timer
GetTimer()->Start();
return true;
}
void Kernel::DestroyKernel(void)
{
// Save the config
//WriteConfig(NULL);
SAFEDELETE(mGraphics);
SAFEDELETE(mAudio);
SAFEDELETE(mMenus);
SAFEDELETE(mUserInterface);
SAFEDELETE(mProcessor);
DestroyWindow();
}
#pragma region Command Event Handlers
bool Kernel::OnCommandEvent(const ControlHandle& sender,WPARAM wparam,LPARAM /*lparam*/)
{
static wchar_t text[1024];
switch(sender->GetID())
{
case 10:
swprintf(text,L"[Untitled]\r\n"
L"Foreground=%g %g %g %g\r\n"
L"Background=%g %g %g %g\r\n"
L"Peak=%g %g %g %g\r\n"
L"Text1=%g %g %g %g\r\n"
L"Text2=%g %g %g %g\r\n"
L"Text3=%g %g %g %g\r\n",
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.b,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.b,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.b,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].b,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].b,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].a,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].r,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].g,
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].b);
if(OpenClipboard(mWindowHandle))
{
EmptyClipboard();
HGLOBAL clipboardData = GlobalAlloc(GMEM_DDESHARE,sizeof(wchar_t)*(wcslen(text)+1));
LPVOID data = GlobalLock(clipboardData);
CopyMemory(data,text,sizeof(wchar_t)*(wcslen(text)+1));
GlobalUnlock(clipboardData);
SetClipboardData(CF_UNICODETEXT,clipboardData);
CloseClipboard();
}
return true;
case 11:
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(1),Control::EventChildCommand,NULL);
return true;
case 30:
swprintf(text,L"Red: %g",(float)((TrackBarHandle)sender)->GetTrackValue()/255.0f);
((StaticTextHandle)mUserInterface->GetChild(0)->GetChild(2))->SetText(text);
switch(((ComboBoxHandle)mUserInterface->GetChild(0)->GetChild(1))->GetSelectedItem())
{
case 0:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 1:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 2:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 3:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 4:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 5:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].r = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
}
return true;
case 31:
swprintf(text,L"Green: %g",(float)((TrackBarHandle)sender)->GetTrackValue()/255.0f);
((StaticTextHandle)mUserInterface->GetChild(0)->GetChild(4))->SetText(text);
switch(((ComboBoxHandle)mUserInterface->GetChild(0)->GetChild(1))->GetSelectedItem())
{
case 0:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 1:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 2:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 3:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 4:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 5:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].g = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
}
return true;
case 32:
swprintf(text,L"Blue: %g",(float)((TrackBarHandle)sender)->GetTrackValue()/255.0f);
((StaticTextHandle)mUserInterface->GetChild(0)->GetChild(6))->SetText(text);
switch(((ComboBoxHandle)mUserInterface->GetChild(0)->GetChild(1))->GetSelectedItem())
{
case 0:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 1:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 2:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 3:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 4:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 5:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].b = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
}
return true;
case 33:
swprintf(text,L"Alpha: %g",(float)((TrackBarHandle)sender)->GetTrackValue()/255.0f);
((StaticTextHandle)mUserInterface->GetChild(0)->GetChild(8))->SetText(text);
switch(((ComboBoxHandle)mUserInterface->GetChild(0)->GetChild(1))->GetSelectedItem())
{
case 0:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->foreground.a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 1:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->background.a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 2:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->peak.a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 3:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[0].a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 4:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[1].a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
case 5:
mGraphics->GetColorPreset(mGraphics->GetColorPresetIndex())->text[2].a = (float)((TrackBarHandle)sender)->GetTrackValue()/255.0f;
break;
}
return true;
case 20:
switch(((ComboBoxHandle)sender)->GetSelectedItem())
{
case 0:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->foreground.r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->foreground.g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->foreground.b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->foreground.a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
case 1:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->background.r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->background.g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->background.b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->background.a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
case 2:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->peak.r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->peak.g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->peak.b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->peak.a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
case 3:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->text[0].r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->text[0].g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->text[0].b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->text[0].a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
case 4:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->text[1].r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->text[1].g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->text[1].b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->text[1].a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
case 5:
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(3))->SetTrackValue(mGraphics->GetColorPreset()->text[2].r * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(5))->SetTrackValue(mGraphics->GetColorPreset()->text[2].g * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(7))->SetTrackValue(mGraphics->GetColorPreset()->text[2].b * 255);
((TrackBarHandle)mUserInterface->GetChild(0)->GetChild(9))->SetTrackValue(mGraphics->GetColorPreset()->text[2].a * 255);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(3),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(5),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(7),Control::EventChildCommand,NULL);
OnCommandEvent(mUserInterface->GetChild(0)->GetChild(9),Control::EventChildCommand,NULL);
break;
}
return true;
}
TRACE(L"Got command event %u (control %u).\n",wparam,sender->GetID());
return false;
}
#pragma endregion
bool Kernel::CreateWindow(unsigned long width,unsigned long height,unsigned long style)
{
// Register the window class
ZeroMemory(&mWindowClass,sizeof(mWindowClass));
mWindowClass.cbSize = sizeof(WNDCLASSEX);
if(GetCommandLineData()->GetVar(L"/shadow",false))
mWindowClass.style = CS_CLASSDC | CS_DBLCLKS | 0x00020000 /*CS_DROPSHADOW*/;
else
mWindowClass.style = CS_CLASSDC | CS_DBLCLKS;
mWindowClass.lpfnWndProc = Kernel::WindowProcedure;
mWindowClass.hInstance = GetModuleHandle(NULL);
mWindowClass.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MAIN_ICON));
mWindowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
mWindowClass.lpszClassName = ANALYZER_CLASSNAME;
if(!RegisterClassEx(&mWindowClass))
{
GetKernel()->SetLastError(L"Failed to register window class.");
TRACE(L"Failed to register window class.\n");
return false;
}
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// Create the application's window
mWindowHandle = CreateWindowEx(NULL,ANALYZER_CLASSNAME, ANALYZER_WINDOWTITLE, style, screenWidth / 2 - width / 2, screenHeight / 2 - height / 2, width, height, GetDesktopWindow(), NULL, mWindowClass.hInstance, NULL);
if(!mWindowHandle)
{
GetKernel()->SetLastError(L"Failed to create window.");
TRACE(L"Failed to create window.\n");
return false;
}
// Set the correct client size
Rect rect(0,0,width,height);
AdjustWindowRect((LPRECT)&rect,style,FALSE);
SetWindowPos(mWindowHandle,NULL,0,0,rect.GetWidth(),rect.GetHeight(),SWP_NOMOVE);
mWindowStyle = style;
TRACE(L"Window %dx%d, style %#X\n",width,height,style);
return true;
}
void Kernel::DestroyWindow(void)
{
// Destroy the window object
::DestroyWindow(mWindowHandle);
// Unregister the window class registrated at the begining of this function
UnregisterClass(ANALYZER_CLASSNAME, mWindowClass.hInstance);
}
bool Kernel::ShowWindow(void)
{
if(!mWindowHandle)
return false;
return ::ShowWindow(mWindowHandle,SW_SHOW) ? true : false;
}
bool Kernel::HideWindow(void)
{
if(!mWindowHandle)
return false;
return ::ShowWindow(mWindowHandle,SW_HIDE) ? true : false;
}
bool Kernel::GetWindowVisible(void)
{
if(!mWindowHandle)
return false;
return ::IsWindowVisible(mWindowHandle) ? true : false;
}
int Kernel::OnRun(void)
{
// Get the module info
CreateModuleInfo();
// Set the command line string
GetCommandLineData()->Set(::GetCommandLine());
// Create the kernel
if(!CreateKernel())
return -1;
// This will hold our messages
MSG msg;
ZeroMemory(&msg, sizeof(msg)); // Must do this otherwise the app would hang
// Enter the message loop
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
{
// We got a message so translate and dispatch it
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if(GetTimer()->GetStopped()) // Don't idle if we are paused
Sleep(10);
else
OnIdle();
}
// Destroy the kernel objects
DestroyKernel();
// Return the wParam cause it contains our exit code
return (int)msg.wParam;
}
void Kernel::OnIdle(void)
{
// Update the speed factor
double elapsed = GetTimer()->GetElapsedTime();
mAbsoluteTime += elapsed;
mElapsedTime = elapsed * ANALYZER_FRAMERATE;
if(mElapsedTime > 5.0f)
{
TRACE(L"Overhead by %g, reset to 5.0\n",mElapsedTime);
mElapsedTime = 5.0f;
}
// Update the cursor position over our window
POINT pos;
GetCursorPos(&pos);
RECT rect;
GetClientRect(mWindowHandle,&rect);
ScreenToClient(mWindowHandle,&pos);
if(!PtInRect(&rect,pos))
SetCursorPositionTime(0);
// Process the capture and preparation of audio
if(mAudio && mAudio->GetCreated())
mAudio->Process();
// Update windows
if(mUserInterface)
mUserInterface->OnUpdate();
// Render the captured data
if(mGraphics && mGraphics->GetCreated())
mGraphics->Render();
}
void Kernel::MessageFormat(const wchar_t* fmt,...)
{
static wchar_t buffer[8096];
va_list args;
va_start(args,fmt);
_vsnwprintf(buffer,_countof(buffer),fmt,args);
va_end(args);
if(mLog.GetOpen())
mLog.Write(buffer);
OutputDebugString(buffer);
}
void Kernel::MessageLocation(const char* location,const wchar_t* fmt,...)
{
static wchar_t buffer[8096];
va_list args;
va_start(args,fmt);
_vsnwprintf(buffer,_countof(buffer),fmt,args);
va_end(args);
MessageFormat(L"%S: %s",location,buffer);
}
void Kernel::MessageLine(const char* file,unsigned long line,const wchar_t* fmt,...)
{
static wchar_t buffer[8096];
va_list args;
va_start(args,fmt);
_vsnwprintf(buffer,_countof(buffer),fmt,args);
va_end(args);
MessageFormat(L"%S(%d): %s",file,line,buffer);
}
void Kernel::MessageModule(const wchar_t* fmt,...)
{
wchar_t buffer[8096];
va_list args;
va_start(args,fmt);
_vsnwprintf(buffer,_countof(buffer),fmt,args);
va_end(args);
MessageFormat(L"'%s': %s",GetModuleName().GetBuffer(),buffer);
}
void Kernel::MessageErrorLast(const wchar_t* section,const wchar_t* title)
{
String messsage;
messsage += section;
messsage += L"\n\n";
messsage += GetKernel()->GetLastError();
MessageError(messsage,title);
}
void Kernel::MessageError(const wchar_t* message,const wchar_t* title)
{
MessageBox(GetDesktopWindow(),message,title,MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND);
}
void Kernel::SetLastError(const wchar_t* fmt,...)
{
static wchar_t buffer[8096];
va_list args;
va_start(args,fmt);
_vsnwprintf(buffer,_countof(buffer),fmt,args);
va_end(args);
mLastError = buffer;
}
bool Kernel::Dump(const wchar_t* /*path*/)
{
/*
String pathString;
if(!path)
pathString = GetKernel()->GetCombinedModulePath(L"Dump.dmp");
else
pathString = path;
HANDLE file = CreateFile(pathString,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,NULL,NULL);
if(file == INVALID_HANDLE_VALUE)
return false;
MiniDumpWriteDump(GetCurrentProcess(),GetCurrentProcessId(),file,MiniDumpNormal,NULL,NULL,NULL);
CloseHandle(file);
*/
return true;
}
void Kernel::SetLed(float bmax)
{
// Get the current keyboard state
BYTE kstate[256];
GetKeyboardState(kstate);
if(bmax > 0.2f) // Numlock should be ON
{
if(!(kstate[VK_NUMLOCK] & 1))
{
keybd_event(VK_NUMLOCK,0,NULL,0);
keybd_event(VK_NUMLOCK,0,KEYEVENTF_KEYUP,0);
}
}
else // Numlock should be OFF
{
if(kstate[VK_NUMLOCK] & 1)
{
keybd_event(VK_NUMLOCK,0,NULL,0);
keybd_event(VK_NUMLOCK,0,KEYEVENTF_KEYUP,0);
}
}
if(bmax > 0.5f) // Capslock should be ON
{
if(!(kstate[VK_CAPITAL] & 1))
{
keybd_event(VK_CAPITAL,0,NULL,0);
keybd_event(VK_CAPITAL,0,KEYEVENTF_KEYUP,0);
}
}
else // Capslock should be OFF
{
if(kstate[VK_CAPITAL] & 1)
{
keybd_event(VK_CAPITAL,0,NULL,0);
keybd_event(VK_CAPITAL,0,KEYEVENTF_KEYUP,0);
}
}
if(bmax > 0.9f) // Scorlllock should be ON
{
if(!(kstate[VK_SCROLL] & 1))
{
keybd_event(VK_SCROLL,0,NULL,0);
keybd_event(VK_SCROLL,0,KEYEVENTF_KEYUP,0);
}
}
else // Scorlllock should be OFF
{
if(kstate[VK_SCROLL] & 1)
{
keybd_event(VK_SCROLL,0,NULL,0);
keybd_event(VK_SCROLL,0,KEYEVENTF_KEYUP,0);
}
}
}
bool Kernel::ReadConfig(const wchar_t* filePath)
{
String pathString;
if(!filePath)
pathString = GetKernel()->GetCombinedModulePath(L"Config.ini");
else
pathString = filePath;
Configuration config(pathString);
mGraphics->SetColorPreset(config[L"Main"][L"Preset"](mGraphics->GetColorPreset()->name));
mGraphics->SetVisualization(config[L"Main"][L"Visualization"](mGraphics->GetVisualizationName(mGraphics->GetVisualizationIndex())));
mAudio->SetSource(config[L"Main"][L"Mixer"]);
mGraphics->SetDrawPeaks(config[L"Main"][L"Peaks"](mGraphics->GetDrawPeaks()));
mGraphics->SetDrawCursor(config[L"Main"][L"Cursor"](mGraphics->GetDrawCursor()));
mGraphics->SetDrawFps(config[L"Main"][L"Fps"](mGraphics->GetDrawFps()));
mGraphics->SetDrawOutputStrings(config[L"Main"][L"Output"](mGraphics->GetDrawOutputStrings()));
mGraphics->SetDrawTimer(config[L"Main"][L"Timer"](mGraphics->GetDrawTimer()));
mGraphics->SetDrawVisualizationName(config[L"Main"][L"Name"](mGraphics->GetDrawVisualizationName()));
mAudio->SetEqFalloff(config[L"Main"][L"Eq Falloff"](mAudio->GetEqFalloff()));
mAudio->SetPeakFalloff(config[L"Main"][L"Peak Falloff"](mAudio->GetPeakFalloff()));
mAudio->SetPeakDelay(config[L"Main"][L"Peak Delay"](mAudio->GetPeakDelay()));
mGraphics->PrintOutputString(L"configuration loaded: \002%s\001",GetKernel()->GetStripedPath(pathString).GetBuffer());
return true;
}
bool Kernel::WriteConfig(const wchar_t* filePath)
{
String pathString;
if(!filePath)
pathString = GetKernel()->GetCombinedModulePath(L"Config.ini");