-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommands.cpp
More file actions
1433 lines (1096 loc) · 39.4 KB
/
Commands.cpp
File metadata and controls
1433 lines (1096 loc) · 39.4 KB
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 "Commands.h"
#include <time.h>
#include <map>
#include <unordered_map>
#include "StringVar.h"
#include "ArrayVar.h"
#include "Globals.h"
#include "Multiplier.h"
#include "MusicType.h"
#include "MusicState.h"
#include "MusicPlayer.h"
#include "MusicTimes.h"
#include "Playlist.h"
#include "ActivePlaylist.h"
#include "ThreadRequest.h"
#include "FadeThread.h"
#include "PlayMusicFile.h"
#include "IniData.h"
#include "OBSEInterfaces.h"
using namespace std;
//No input
//Returns the MusicType Oblivion wants to be played.
bool Cmd_GetMusicType_Execute (COMMAND_ARGS) {
int mode = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &mode)) {
return true;
}
WaitForSingleObject (hMusicStateMutex, INFINITE);
switch (mode) {
case 0: *result = musicState.getCurrentMusicType (); break;
case 1: *result = musicState.getWorldType (); break;
case 2: *result = musicState.getOverrideType (); break;
case 3: *result = musicState.getSpecialType (); break;
case 4: *result = musicState.isLocked() ? 1 : 0; break;
}
ReleaseMutex (hMusicStateMutex);
Console_PrintC ("Current music type >> %.0f", *result);
return true;
};
bool Cmd_SetMusicType_Execute (COMMAND_ARGS) {
*result = 0;
int musicType = 255;
int locked = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &musicType, &locked)) {
return true;
}
if (musicType > 4) {
Console_PrintC ("Set music type >> Failed: music type is not valid > Type: %d, Lock: %d", musicType, locked);
_MESSAGE ("Command >> emcSetMusicType >> Failed: music type is not valid > Type: %d, Lock: %d", musicType, locked);
return true;
}
WaitForSingleObject (hMusicStateMutex, INFINITE);
if (locked < 0 || musicType < 0) {
musicState.overrideType (MusicType::mtNotKnown, false);
} else {
musicState.overrideType (MusicType(musicType), locked>0);
}
ReleaseMutex (hMusicStateMutex);
Console_PrintC ("Set music type >> Type: %d, Lock: %d", musicType, locked);
_MESSAGE ("Command >> emcSetMusicType >> Type: %d, Lock: %d", musicType, locked);
*result = 1;
return true;
}
bool Cmd_CreatePlaylist_Execute (COMMAND_ARGS) {
//Specifically, if the playlist does allready exist (by name)
//it will return 1. Else, it will create it. If it succeeds
//in it's creation, it will return 1. Otherwise, 0.
*result = 0;
//Parameters
char pPlaylistName[512];
char plPaths[512];
int shuffle = 1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPlaylistName, &plPaths, &shuffle)) {
return true;
}
if (strlen(pPlaylistName) <= 0) { //Empty name. Can't proceed
Console_PrintC ("Playlist manager >> Failed: Name is empty");
_MESSAGE ("Command >> emcCreatePlaylist >> Failed: Name is empty");
return true;
}
const string &paths = plPaths;
PlaylistEmplaceResult insResult = emplacePlaylist (pPlaylistName, false);
if (insResult.second || insResult.first->second.isDestroyed()) { //Create new playlist (destroyed playlists are considered as not existent)
if (playlists.size () >= numPlaylists) { //won't happend with destroyed playlists
Console_PrintC ("Playlist manager >> Failed: Max playlists limit reached: %d", numPlaylists);
_MESSAGE ("Command >> emcCreatePlaylist >> Failed: Max playlists limit reached: %d", numPlaylists);
playlists.erase (insResult.first);
} else if (insResult.first->second.setPaths (paths, shuffle != 0)) {
Console_PrintC ("Create playlist >> Succeed (create)");
_MESSAGE ("Command >> emcCreatePlaylist >> Succeed (create): \"%s\" >> %s", pPlaylistName, plPaths);
*result = 1;
} else {
Console_PrintC ("Create playlist >> Failed: No track found.");
_MESSAGE ("Command >> emcCreatePlaylist >> Failed: No track found for playlist \"%s\" in paths %s", pPlaylistName, plPaths);
}
} else { //Alter/Delete existing playlist
PlaylistsMap::iterator it = insResult.first;
Playlist* playlist = &it->second;
WaitForSingleObject (playlist->hMutex, INFINITE);
if (playlist->isVanilla ()) { //Playlist is vanilla
Console_PrintC ("Playlist manager >> Failed: This is a vanilla playlist and can't be altered");
_MESSAGE ("Command >> emcCreatePlaylist >> Failed: \"%s\" is a vanilla playlist and can't be altered", pPlaylistName);
} else if (paths.empty ()) { //Empty path -> destroy playlist
ActivePlaylist* activePlaylist;
while ((activePlaylist = getActivePlaylist (playlist)) != nullptr) { //Playlist is assigned
activePlaylist->restorePlaylist ();
}
playlist->destroy ();
threadRequest.requestNextTrack (false);
*result = 1;
} else { //Not empty path -> alter playlist
const string ¤tTrack = playlist->getCurrentTrack ();
if (playlist->setPaths (paths, shuffle != 0)) { //If recreation succeed...
if (!currentTrack.empty () && isPlaylistActive (playlist)) {
playlist->restoreTrackIndex (currentTrack);
}
Console_PrintC ("Recreate playlist >> Succeed (rebuild)");
_MESSAGE ("Command >> emcCreatePlaylist >> Succeed (rebuild): \"%s\" >> %s", pPlaylistName, plPaths);
*result = 1;
} else { //Recreation failed
Console_PrintC ("Recreate playlist >> Failed: No tracks found");
_MESSAGE ("Command >> emcCreatePlaylist >> Failed: No tracks found");
}
}
ReleaseMutex (playlist->hMutex);
}
return true;
}
//Required Input: 2 Strings
//Returns 1 on success, 0 on failure.
bool Cmd_AddPathToPlaylist_Execute (COMMAND_ARGS) {
//If the playlist does not exist, it will return 0.
//If the recreation fails, it will return 0.
//If everything goes to plan, it returns 1.
*result = 0;
//Parameters
char pPlaylistName[512];
char plPath[512];
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPlaylistName, &plPath)) {
return true;
}
string playlistName = string (pPlaylistName);
const string &path = plPath;
if (playlistName.empty ()) { //Empty name. Can't proceed
Console_PrintC ("Playlist manager >> Failed: Name is empty");
_MESSAGE ("Command >> emcAddPath >> Failed: Name is empty");
return true;
} else if (path.empty ()) {
Console_PrintC ("Playlist manager >> Failed: Path is empty");
_MESSAGE ("Command >> emcAddPath >> Failed: Path is empty for playlist \"%s\"", pPlaylistName);
return true;
}
PlaylistsMap::iterator it = playlists.find (playlistName);
if (it == playlists.end () || it->second.isDestroyed()) {
Console_PrintC ("Add path >> Failed: Playlist does not exist");
_MESSAGE ("Command >> emcAddPath >> Failed: Playlist does not exist");
} else {
Playlist* playlist = &it->second;
WaitForSingleObject (playlist->hMutex, INFINITE);
//Make sure its not one of the default playlists.
if (playlist->isVanilla ()) {
Console_PrintC ("Add path >> Failed: This is a vanilla playlist and can't be altered");
_MESSAGE ("Command >> emcAddPath >> Failed: \"%s\" is a vanilla playlist and can't be altered", pPlaylistName);
} else {
const string ¤tTrack = playlist->getCurrentTrack ();
if (playlist->addPath (path)) { //Try to add the new path
if (!currentTrack.empty () && isPlaylistActive (playlist)) {
playlist->restoreTrackIndex (currentTrack);
}
Console_PrintC ("Add path >> Succeed: Playlist updated", pPlaylistName, plPath);
_MESSAGE ("Command >> emcAddPath >> Succeed: Playlist updated: \"%s\" >> %s", pPlaylistName, plPath);
*result = 1;
} else { //Addition failed.
Console_PrintC ("Add path >> Failed: No track found", pPlaylistName, plPath);
_MESSAGE ("Command >> emcAddPath >> Failed: No track found for playlist \"%s\" in %s", pPlaylistName, plPath);
}
}
ReleaseMutex (playlist->hMutex);
}
return true;
}
//Required Input: 1 String
//Returns 1 is the playlist was found, else 0.
bool Cmd_PlaylistExists_Execute (COMMAND_ARGS) {
//result == 1 if exists, 0 otherwise.
*result = 0;
//Parameters
char pPlaylistName[512];
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPlaylistName)) {
return true;
}
if (strlen(pPlaylistName) > 0) {
PlaylistsMap::iterator pos = playlists.find (string (pPlaylistName));
if (pos != playlists.end () && (pos->second.isVanilla() || pos->second.isInitialized ())) {
*result = 1;
}
}
Console_PrintC ("Playlist exists >> %.0f", *result);
return true;
}
//Required Input: 1 String
//Returns 1 is the playlist is assigned to a MusicType, else 0.
bool Cmd_IsPlaylistActive_Execute (COMMAND_ARGS) {
//result == 1 if it is an active playlist, 0 otherwise.
*result = 0;
//Parameters
char pPlaylistName[512];
int musicType = -1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPlaylistName, &musicType)) {
return true;
}
if (musicType < 0) {
if (isPlaylistActive (pPlaylistName)) {
*result = 1;
Console_PrintC ("Playlist is active");
} else {
Console_PrintC ("Playlist is not active");
}
} else if (musicType <= 4) {
if (strcmp (pPlaylistName, activePlaylists[musicType]->playlist->name) != 0) {
*result = 1;
Console_PrintC ("Playlist is assigned to music type %d", musicType);
} else {
Console_PrintC ("Playlist is not assigned to music type %d", musicType);
}
} else {
Console_PrintC ("Music type %d is not valid", musicType);
}
return true;
}
bool Cmd_SetPlaylist_Execute (COMMAND_ARGS) {
*result = 0;
WaitForSingleObject (hMusicPlayerMutex, INFINITE);
bool isReady = musicPlayer.isReady ();
ReleaseMutex (hMusicPlayerMutex);
if (!isReady) {
return true;
}
//Parameters
int pMusicType = 0;
char pPlaylistName[512];
int pQueueMode = 0;
float pDelay = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pMusicType, &pPlaylistName, &pQueueMode, &pDelay)) {
return true;
}
string playlistName = string (pPlaylistName);
if (playlistName.empty ()) {
Console_PrintC ("Set playlist >> Failed: Name is empty");
_MESSAGE ("Command >> emcSetPlaylist >> Failed: Name is empty");
return true;
} else if (pMusicType > 4) {
Console_PrintC ("Set playlist >> Failed: Music type doesn't exists");
_MESSAGE ("Command >> emcSetPlaylist >> Failed: Music type %d doesn't exists", pMusicType);
return true;
}
PlaylistsMap::iterator it = playlists.find (playlistName);
if (it == playlists.end () || it->second.isDestroyed ()) {
Console_PrintC ("Set playlist >> Failed: Playlist does not exist: \"%s\"", pPlaylistName);
_MESSAGE ("Command >> emcSetPlaylist >> Failed: Playlist does not exist: \"%s\"", pPlaylistName);
return true;
}
ActivePlaylist* apl;
if (pMusicType >= 0) {
//Let other threads know the playlists are being manipulated.
MusicType musicType = static_cast<MusicType>(pMusicType);
apl = getActivePlaylist (musicType); //Can't return nullptr, as 0 <= pMusicType <= 4
} else {
apl = selectedActivePlaylist;
}
Playlist* playlist = &it->second;
if (apl->playlist != playlist || pQueueMode != 0 || pDelay > 0) {
threadRequest.requestSetPlaylist (apl, playlist, pQueueMode != 0, pDelay * 1000);
Console_PrintC ("Set playlist >> Succeed: Target: %d, Name: \"%s\", Mode: %d, Delay: %f", pMusicType, pPlaylistName, pQueueMode, pDelay);
_MESSAGE ("Command >> emcSetPlaylist >> Succeed: Target: %d, Name: \"%s\", Mode: %d, Delay: %f", pMusicType, pPlaylistName, pQueueMode, pDelay);
*result = 1;
} else {
Console_PrintC ("Set playlist >> Failed: Target: %d, Name: \"%s\", Mode: %d, Delay: %f", pMusicType, pPlaylistName, pQueueMode, pDelay);
_MESSAGE ("Command >> emcSetPlaylist >> Failed: Target: %d, Name: \"%s\", Mode: %d, Delay: %f", pMusicType, pPlaylistName, pQueueMode, pDelay);
}
return true;
}
bool Cmd_RestorePlaylist_Execute (COMMAND_ARGS) {
*result = 0;
WaitForSingleObject (hMusicPlayerMutex, INFINITE);
bool isReady = musicPlayer.isReady ();
ReleaseMutex (hMusicPlayerMutex);
if (!isReady) {
return true;
}
//Parameters
int pMusicType = -1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pMusicType)) {
return true;
}
WaitForSingleObject (hMusicStateMutex, INFINITE);
MusicType currentMusicType = musicState.getCurrentMusicType ();
ReleaseMutex (hMusicStateMutex);
if (pMusicType < 0) { //Restore all.
bool restored = false;
ActivePlaylist* activePlaylist;
for (int i = 0; i <= 4; i++) {
activePlaylist = getActivePlaylist (static_cast<MusicType>(i));
if (activePlaylist->restorePlaylist ()){
restored = true;
}
}
if (restored) {
threadRequest.requestNextTrack (false);
*result = 1;
Console_PrintC ("Restore playlist >> Succeed: All music types restored");
_MESSAGE ("Command >> emcRestorePlaylist >> Succeed: All music types restored to default playlist");
} else {
Console_PrintC ("Restore playlist >> Failed: All music types are already using their default playlists");
_MESSAGE ("Command >> emcRestorePlaylist >> Failed: All music types are already using their default playlists");
}
} else if (pMusicType <= 4) {
ActivePlaylist* activePlaylist = getActivePlaylist (static_cast<MusicType>(pMusicType));
if (activePlaylist->restorePlaylist ()) {
if (currentMusicType == pMusicType) {
threadRequest.requestNextTrack (false);
}
*result = 1;
Console_PrintC ("Restore playlist >> Succeed: Music type restored");
_MESSAGE ("Command >> emcRestorePlaylist >> Succeed: Music type %d restored to default playlist", pMusicType);
} else {
Console_PrintC ("Restore playlist >> Failed: Music type %d is already using the default playlist", pMusicType);
_MESSAGE ("Command >> emcRestorePlaylist >> Failed: Music type %d is already using the default playlist", pMusicType);
}
} else {
Console_PrintC ("Restore playlist >> Failed: Invalid music type");
_MESSAGE ("Command >> emcRestorePlaylist >> Failed: Invalid music type %d", pMusicType);
}
return true;
}
bool Cmd_IsMusicSwitching_Execute (COMMAND_ARGS) {
*result = musicPlayer.isReady () ? 0 : 1;
Console_PrintC ("Music switching >> %.0f", *result);
return true;
}
bool Cmd_GetAllPlaylists_Execute (COMMAND_ARGS) {
*result = 0;
int pOnlyActive = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pOnlyActive)) {
return true;
}
bool console = inConsole;
const char* playlistName;
OBSEArray* newArray = g_arrayIntfc->CreateArray (nullptr, 0, scriptObj);
if (pOnlyActive == 0) {
for (PlaylistsMap::const_iterator it = playlists.cbegin (); it != playlists.cend (); it++) {
playlistName = (it->second).name;
g_arrayIntfc->AppendElement (newArray, playlistName);
if (console) Console_Print (playlistName);
}
} else {
for (ActivePlaylist* activePlaylist : activePlaylists) {
playlistName = activePlaylist->playlist->name;
g_arrayIntfc->AppendElement (newArray, playlistName);
if (console) Console_Print ("%s -> %s", activePlaylist->name, playlistName);
}
}
g_arrayIntfc->AssignCommandResult (newArray, result);
return true;
}
bool Cmd_GetPlaylist_Execute (COMMAND_ARGS) {
*result = 0;
int pMusicType = -1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pMusicType)) {
return true;
}
if (pMusicType > 4) {
Console_PrintC ("Invalid music type");
return true;
}
ActivePlaylist* activePlaylist;
if (pMusicType < 0) {
activePlaylist = selectedActivePlaylist;
} else {
activePlaylist = getActivePlaylist (static_cast<MusicType>(pMusicType));
}
if (activePlaylist != &apl_NULL) {
const char* playlistName = activePlaylist->playlist->name;
g_stringIntfc->Assign (PASS_COMMAND_ARGS, playlistName);
Console_PrintC ("Playlist >> %s", playlistName);
} else {
Console_PrintC ("No playlist assigned to type %d", pMusicType);
}
return true;
}
bool Cmd_GetPlaylistTracks_Execute (COMMAND_ARGS) {
*result = 0;
char pPlaylistName[512];
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPlaylistName)) {
return true;
}
Playlist* playlist = nullptr;
string playlistName = string (pPlaylistName);
if (playlistName.empty ()) {
playlist = selectedActivePlaylist->playlist;
} else {
PlaylistsMap::iterator it = playlists.find (playlistName);
if (it != playlists.end ()) {
playlist = &it->second;
}
}
if (playlist != nullptr) {
OBSEArray* newArray = g_arrayIntfc->CreateArray (nullptr, 0, scriptObj);
for (const string& track : playlist->getTracks ()) {
g_arrayIntfc->AppendElement (newArray, track.c_str ());
}
g_arrayIntfc->AssignCommandResult (newArray, result);
if (inConsole) {
playlist->printTracks ();
}
} else {
Console_PrintC ("Playlist not found");
}
return true;
}
bool Cmd_GetTrack_Execute (COMMAND_ARGS) {
const char* songPath = musicPlayer.getTrack ().c_str();
Console_PrintC ("Currently track >> %s", songPath);
g_stringIntfc->Assign (PASS_COMMAND_ARGS, songPath);
return true;
}
bool Cmd_GetTrackDuration_Execute (COMMAND_ARGS) {
*result = musicPlayer.getTrackDuration () / ONE_SECOND;
Console_PrintC ("Track duration >> %f", *result);
return true;
}
bool Cmd_GetTrackPosition_Execute (COMMAND_ARGS) {
*result = musicPlayer.getTrackPosition () / ONE_SECOND;
double duration = musicPlayer.getTrackDuration () / ONE_SECOND;
Console_PrintC ("Track position >> %.0f / %.0f", *result, duration);
return true;
}
bool Cmd_SetTrackPosition_Execute (COMMAND_ARGS) {
*result = 0;
float pPosition = 0;
int pFadeOut = 1;
int pFadeIn = 1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pPosition, &pFadeOut, &pFadeIn)) {
return true;
}
pFadeOut *= 1000;
pFadeIn *= 1000;
if (pPosition < 0) pPosition = 0;
WaitForSingleObject (hMusicPlayerMutex, INFINITE);
LONGLONG longPos = pPosition * ONE_SECOND;
LONGLONG longDur = musicPlayer.getTrackDuration ();
if (longPos > longDur - ONE_SECOND) {
longPos = longDur - ONE_SECOND;
}
musicPlayer.setTrackPosition (longPos, pFadeOut, pFadeIn);
ReleaseMutex (hMusicPlayerMutex);
Console_PrintC ("Set track position >> Position %.2f, Fade out/in: %f/%f", longPos, pFadeOut, pFadeIn);
_MESSAGE ("Command >> emcSetTrackPosition >> Position %.2f, Fade out/in: %f/%f", longPos, pFadeOut, pFadeIn);
*result = 1;
return true;
}
//Required input: None
//Returns 1 if the override is active, else 0.
bool Cmd_IsBattleOverridden_Execute (COMMAND_ARGS) {
*result = musicState.isBattleOverridden() ? 1 : 0;
Console_PrintC ("Battle overridden >> %.0f", *result);
return true;
}
//Required input: None
//Returns 1 if the override was set, else 0.
bool Cmd_SetBattleOverride_Execute (COMMAND_ARGS) {
*result = 0;
int battleOverride = -1;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &battleOverride)) {
return true;
}
bool battleOverrideBool = (battleOverride != 0);
WaitForSingleObject (hMusicStateMutex, INFINITE);
if (musicState.setBattleOverride (battleOverrideBool)) {
Console_PrintC ("Set battle override >> %d", battleOverrideBool);
_MESSAGE ("Command >> emcSetBattleOverride >> %d", battleOverrideBool);
*result = 1;
} else {
Console_PrintC ("Set battle override >> %d (unchanged)", battleOverrideBool);
}
ReleaseMutex (hMusicStateMutex);
return true;
}
bool Cmd_IsMusicOnHold_Execute (COMMAND_ARGS) {
*result = threadRequest.hasRequestedHoldMusicPlayer () ? 1 : 0;
Console_PrintC ("Hold music >> %.0f", *result);
return true;
}
bool Cmd_SetMusicHold_Execute (COMMAND_ARGS) {
*result = 0;
int pHoldMusic;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &pHoldMusic)) {
return true;
}
bool holdMusic = (pHoldMusic != 0);
if (threadRequest.requestHoldMusicPlayer (holdMusic)) {
Console_PrintC ("Set music hold >> %d", holdMusic);
_MESSAGE ("Command >> emcSetMusicHold >> %d", holdMusic);
*result = 1;
} else {
Console_PrintC ("Set music hold >> %d (unchanged)", holdMusic);
}
return true;
}
bool Cmd_GetMasterVolume_Execute (COMMAND_ARGS) {
*result = 0;
int method = 0;
int target = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &method, &target)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObMaster : &multObMasterIni;
WaitForSingleObject (mult->hThread, INFINITE);
switch (target) {
case 1: *result = mult->isFading ? mult->startValue : mult->getValue (); break;
case 2: *result = mult->isFading ? mult->targetValue : mult->getValue (); break;
case 3: *result = mult->isFading ? mult->fadeTime : -1; break;
default: *result = mult->getValue ();
}
ReleaseMutex (mult->hThread);
Console_PrintC ("Master volume >> %f", *result);
return true;
}
bool Cmd_SetMasterVolume_Execute (COMMAND_ARGS) {
*result = 0;
float volume = 0;
int method = 0;
float fadeTime = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &volume, &method, &fadeTime)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObMaster : &multObMasterIni;
WaitForSingleObject (mult->hThread, INFINITE);
Console_PrintC ("Set master volume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
_MESSAGE ("Command >> emcSetMasterVolume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
*result = 1;
return true;
}
bool Cmd_GetMusicVolume_Execute (COMMAND_ARGS) {
*result = 0;
int method = 0;
int target = 0;
char key[MAX_PATH];
if (!ExtractArgs (PASS_EXTRACT_ARGS, &method, &target, &key)) {
return true;
}
Multiplier* mult;
if (method < 2) {
mult = (method == 0) ? &multObMusic : &multObMusicIni;
} else {
MultipliersMap::iterator pos = multipliersCustom.find (key);
if (pos != multipliersCustom.end ()) {
mult = &pos->second;
} else {
*result = -1.0;
Console_PrintC ("This multiplier doesn't exists");
return true;
}
}
WaitForSingleObject (mult->hThread, INFINITE);
switch (target) {
case 1: *result = mult->isFading ? mult->startValue : mult->getValue (); break;
case 2: *result = mult->isFading ? mult->targetValue : mult->getValue (); break;
case 3: *result = mult->isFading ? mult->fadeTime : -1; break;
case 4: *result = (method < 2 || mult->saveGame) ? 1 : 0; break;
case 5: *result = (method < 2 || mult->saveSession) ? 1 : 0; break;
default: *result = mult->getValue ();
}
ReleaseMutex (mult->hThread);
Console_PrintC ("Music multiplier >> %f", *result);
return true;
}
bool Cmd_SetMusicVolume_Execute (COMMAND_ARGS) {
*result = 0;
float volume = 1.0;
int method = 0;
float fadeTime = 0;
char pKey[MAX_PATH];
if (!ExtractArgs (PASS_EXTRACT_ARGS, &volume, &method, &fadeTime, &pKey)) {
return true;
}
Multiplier* mult = nullptr;
if (method < 2) {
mult = (method == 0) ? &multObMusic : &multObMusicIni;
WaitForSingleObject (mult->hThread, INFINITE);
Console_PrintC ("Set music volume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
_MESSAGE ("Command >> emcSetMusicVolume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
} else {
string key = string (pKey);
if (key.empty ()) {
Console_PrintC ("Set music volume >> Can't create/destroy a custom multiplier without a key");
return true;
}
_MESSAGE ("Command >> emcSetMusicVolume >> Method: %d, Key: %s", method, pKey);
if (volume == 1.0) {
MultipliersMap::iterator pos = multipliersCustom.find (key);
if (pos == multipliersCustom.end () || pos->second.isDestroyed) {
Console_PrintC ("Set music volume >> Can't create a new multiplier with volume 1.0");
_MESSAGE ("Command >> emcSetMusicVolume >> Can't create a new multiplier with volume 1.0");
return true;
} else if (fadeTime <= 0) {
mult = &pos->second;
WaitForSingleObject (mult->hThread, INFINITE);
mult->destroy ();
ReleaseMutex (mult->hThread);
Console_PrintC ("Set music volume >> Multiplier destroyed");
_MESSAGE ("Command >> emcSetMusicVolume >> Multiplier destroyed");
*result = 1;
return true;
}
} else {
MultiplierEmplaced insResult = multipliersCustom.emplace (constructInPlace (key, 1.0)); //If not present add it... in one shot, for best performance
mult = &insResult.first->second;
if (insResult.second || mult->isDestroyed) {
if (multipliersCustom.size () > numMultipliers) { //The capacity is (numMultipliers + 1)... the +1 avoid to reallocate the map when emplace surpass the limit. Still, it should be hard to reach...
Console_PrintC ("Set music volume >> Failed: Max multipliers limit reached: %d", numMultipliers);
_MESSAGE ("Command >> emcSetMusicVolume >> Failed: Max multipliers limit reached: %d", numMultipliers);
multipliersCustom.erase (insResult.first); //Remove it, so we will fall <= numMultipliers
return true;
}
Console_PrintC ("Set music volume >> Create new multiplier");
_MESSAGE ("Command >> emcSetMusicVolume >> Create new multiplier");
}
}
Console_PrintC ("Set music volume >> Set/Fade multiplier \"%s\" from %f to %f Time: %f", pKey, mult->getValue (), volume, fadeTime);
_MESSAGE ("Command >> emcSetMusicVolume >> Set/Fade multiplier \"%s\" from %f to %f Time: %f", pKey, mult->getValue (), volume, fadeTime);
WaitForSingleObject (mult->hThread, INFINITE);
mult->saveGame = (method == 3);
mult->saveSession = (method == 4);
mult->isDestroyed = false;
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
}
*result = 1;
return true;
}
bool Cmd_GetEffectsVolume_Execute (COMMAND_ARGS) {
*result = 0;
int method = 0;
int target = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &method, &target)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObEffects : &multObEffectsIni;
WaitForSingleObject (mult->hThread, INFINITE);
switch (target) {
case 1: *result = mult->isFading ? mult->startValue : mult->getValue (); break;
case 2: *result = mult->isFading ? mult->targetValue : mult->getValue (); break;
case 3: *result = mult->isFading ? mult->fadeTime : -1; break;
default: *result = mult->getValue ();
}
ReleaseMutex (mult->hThread);
Console_PrintC ("Effects volume >> %f", *result);
return true;
}
bool Cmd_SetEffectsVolume_Execute (COMMAND_ARGS) {
*result = 0;
float volume = 0;
int method = 0;
float fadeTime = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &volume, &method, &fadeTime)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObEffects : &multObEffectsIni;
WaitForSingleObject (mult->hThread, INFINITE);
Console_PrintC ("Set effects volume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
_MESSAGE ("Command >> emcSetEffectsVolume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
*result = 1;
return true;
}
bool Cmd_GetFootVolume_Execute (COMMAND_ARGS) {
*result = 0;
int method = 0;
int target = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &method, &target)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObFoot : &multObFootIni;
WaitForSingleObject (mult->hThread, INFINITE);
switch (target) {
case 1: *result = mult->isFading ? mult->startValue : mult->getValue (); break;
case 2: *result = mult->isFading ? mult->targetValue : mult->getValue (); break;
case 3: *result = mult->isFading ? mult->fadeTime : -1; break;
default: *result = mult->getValue ();
}
ReleaseMutex (mult->hThread);
Console_PrintC ("Foot volume >> %f", *result);
return true;
}
bool Cmd_SetFootVolume_Execute (COMMAND_ARGS) {
*result = 0;
float volume = 0;
int method = 0;
float fadeTime = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &volume, &method, &fadeTime)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObFoot : &multObFootIni;
WaitForSingleObject (mult->hThread, INFINITE);
Console_PrintC ("Set foot volume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
_MESSAGE ("Command >> emcSetFootVolume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
*result = 1;
return true;
}
bool Cmd_GetVoiceVolume_Execute (COMMAND_ARGS) {
*result = 0;
int method = 0;
int target = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &method, &target)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObVoice : &multObVoiceIni;
WaitForSingleObject (mult->hThread, INFINITE);
switch (target) {
case 1: *result = mult->isFading ? mult->startValue : mult->getValue (); break;
case 2: *result = mult->isFading ? mult->targetValue : mult->getValue (); break;
case 3: *result = mult->isFading ? mult->fadeTime : -1; break;
default: *result = mult->getValue ();
}
ReleaseMutex (mult->hThread);
Console_PrintC ("Voice volume >> %f", *result);
return true;
}
bool Cmd_SetVoiceVolume_Execute (COMMAND_ARGS) {
*result = 0;
float volume = 0;
int method = 0;
float fadeTime = 0;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &volume, &method, &fadeTime)) {
return true;
}
Multiplier *mult = (method == 0) ? &multObVoice : &multObVoiceIni;
WaitForSingleObject (mult->hThread, INFINITE);
Console_PrintC ("Set voice volume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
_MESSAGE ("Command >> emcSetVoiceVolume >> Set/Fade volume from %f to %f, Method: %d, Time: %f", mult->getValue (), volume, method, fadeTime);
mult->fadeVolume (volume, fadeTime);
ReleaseMutex (mult->hThread);
*result = 1;
return true;
}
bool Cmd_GetMusicSpeed_Execute (COMMAND_ARGS) {
*result = musicPlayer.getMusicSpeed ();
Console_PrintC ("Music speed >> %f", *result);
return true;
}
bool Cmd_SetMusicSpeed_Execute (COMMAND_ARGS) {
*result = 0;
float speed;
if (!ExtractArgs (PASS_EXTRACT_ARGS, &speed)) {
return true;
}
if (speed <= 0.1) {
speed = 0.1;
} else if (speed > 100) {
speed = 100;
}
WaitForSingleObject (hMusicPlayerMutex, INFINITE);
if (musicPlayer.setMusicSpeed ((double)speed)) {
_MESSAGE ("Command >> emcSetMusicSpeed >> Speed: %f", speed);
*result = 1;