forked from dliganov/Chaotic-DAW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Awful_parammodule.cpp
1125 lines (981 loc) · 30 KB
/
Awful_parammodule.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 Section
//=================================================================================================
#include "awful_params.h"
#include "awful_parammodule.h"
#include <direct.h>
#include <errno.h>
//=================================================================================================
// ParamModule Class Implementation
//=================================================================================================
ParamModule::ParamModule()
{
to_be_deleted = false;
temp = false;
internalModule = true;
wnd = NULL;
paramWnd = NULL;
memset(&scope, 0, sizeof(Scope));
strcpy(current_preset_name, "Untitled");
strcpy(this->preset_path, "");
first_param = last_param = NULL;
first_pcell = last_pcell = NULL;
lastparamidx = 0;
this->NativePresets = NULL;
this->NP_last = NULL;
this->children = NULL;
this->parent = NULL;
this->prev_sibling = NULL;
this->next_sibling = NULL;
uniqueID = -1;
this->CurrentPreset = NULL;
m_ParamLocked = false;
}
ParamModule::~ParamModule()
{
if(wnd != NULL)
MainWnd->DeleteChild(wnd);
// this->DeleteWindowIfAny(); // Need to do this first of all to avoid asliders receiving messages from already deleted params
// Delete all paramcells
Paramcell* pcellnext;
Paramcell* pcell = first_pcell;
while(pcell != NULL)
{
pcellnext = pcell->next;
delete pcell;
pcell = pcellnext;
}
// Delete all params
Parameter* param = this->first_param;
Parameter* paramnext;
while (param != NULL)
{
paramnext = param->next;
RemoveParam(param);
param = paramnext;
}
//Kill all children ("Kill All Human"(c) Bender Bending Rodriguez )
ParamModule* pKid = this->children;
ParamModule* pTmpKid;
while (pKid != NULL)
{
pTmpKid = pKid;
pKid = pKid->next_sibling;
delete pTmpKid;
}
DeletePresets();
DeleteControls();
}
void ParamModule::DeleteControls()
{
Control* ctrlnext;
Control* ctrl = firstCtrl;
while(ctrl != NULL)
{
ctrlnext = ctrl->next;
if(ctrl->scope != NULL && (ctrl->scope == &this->scope))
{
ctrl->Deactivate();
RemoveControlCommon(ctrl);
}
ctrl = ctrlnext;
}
}
void ParamModule::DeletePresets()
{
// Delete all presets
Preset *preset, *preset1;
preset = this->NativePresets;
while(preset != NULL)
{
RemovePreset(preset);
preset1 = preset;
preset = preset->next;
delete preset1;
}
this->NativePresets = NULL;
this->NP_last = NULL;
NumNativePresets = 0;
NumPresets = 0;
}
void ParamModule::ScanForPresets()
{
WIN32_FIND_DATA founddata = {0};
HANDLE shandle = INVALID_HANDLE_VALUE;
char temp_path[MAX_PATH_STRING] = {0};
char filename[MAX_PATH_STRING] = {0};
Preset *pPreset = NULL;
if (this->preset_path[0] == 0)
{
return;
}
/* File with user-saved preset is named in this way: <FX name>'_'<preset name>'.cpf' */
/* cpf - Chaotic Preset File */
sprintf(temp_path,"%s%s",this->preset_path, "*.cxml\0");
shandle = FindFirstFile(temp_path, &founddata);
if (shandle != INVALID_HANDLE_VALUE)
{
do
{
sprintf(filename, "%s%s",this->preset_path, founddata.cFileName);
String sFilePath(filename);
File myFile(sFilePath);
XmlDocument myPreset(myFile);
XmlElement* xmlMainNode = myPreset.getDocumentElement();
if(xmlMainNode != NULL)
{
/* Sanity check */
if(xmlMainNode->hasTagName(T("ChaoticPreset"))/* && xmlMainNode->hasAttribute(T("FormatVersion"))*/)
{
pPreset = new Preset((Object*)this);
pPreset->index = this->NumNativePresets;
XmlElement* xmlHeader = xmlMainNode->getChildByName(T("Module"));
if (xmlHeader != NULL)
{
String Str1 = xmlHeader->getStringAttribute(T("Preset"));
Str1.copyToBuffer(pPreset->name, min(Str1.length(), 255));
pPreset->native = true;
strcpy(pPreset->path, filename);
this->AddPreset(pPreset);
if(strcmp(pPreset->name, current_preset_name) == 0)
{
CurrentPreset = pPreset;
}
}
}
}
}while(FindNextFile(shandle, &founddata));
FindClose(shandle);
}
}
void ParamModule::AddParam(Parameter* param)
{
AddGlobalParam(param);
param->index = lastparamidx++;
param->module = this;
param->scope = &scope;
param->setEnvDirect(false);
if(first_param == NULL && last_param == NULL)
{
param->prev = NULL;
param->next = NULL;
first_param = param;
}
else
{
last_param->next = param;
param->prev = last_param;
param->next = NULL;
}
last_param = param;
}
void ParamModule::AddParamcell(Paramcell* pcell)
{
if(first_pcell == NULL && last_pcell == NULL)
{
pcell->prev = NULL;
pcell->next = NULL;
first_pcell = pcell;
}
else
{
last_pcell->next = pcell;
pcell->prev = last_pcell;
pcell->next = NULL;
}
last_pcell = pcell;
}
void ParamModule::RemoveParamcell(Paramcell* pcell)
{
if((pcell == first_pcell)&&(pcell == last_pcell))
{
first_pcell = NULL;
last_pcell = NULL;
}
else if(pcell == first_pcell)
{
first_pcell = pcell->next;
first_pcell->prev = NULL;
}
else if(pcell == last_pcell)
{
last_pcell = pcell->prev;
last_pcell->next = NULL;
}
else
{
if(pcell->prev != NULL)
{
pcell->prev->next = pcell->next;
}
if(pcell->next != NULL)
{
pcell->next->prev = pcell->prev;
}
}
}
Paramcell* ParamModule::AddParamWithParamcell(Parameter* param)
{
AddParam(param);
Paramcell* pcell;
if(param->type == Param_Bool)
{
pcell = new Paramcell(PCType_MixToggle, param, NULL, &scope);
}
else
{
pcell = new Paramcell(PCType_MixSlider, param, NULL, &scope);
}
AddParamcell(pcell);
return pcell;
}
void ParamModule::AddParamToParamcell(Parameter* param, Paramcell* pcell)
{
AddParam(param);
pcell->AddParamEntry(param);
}
void ParamModule::AddPreset(Preset* preset)
{
if(NativePresets == NULL && NP_last == NULL)
{
preset->next = NULL;
preset->prev = NULL;
NativePresets = preset;
}
else
{
NP_last->next = preset;
preset->next = NULL;
preset->prev = NP_last;
}
NP_last = preset;
++(this->NumNativePresets);
++(this->NumPresets);
}
void ParamModule::RemoveParam(Parameter* param)
{
RemoveGlobalParam(param);
if((param == first_param)&&(param == last_param))
{
first_param = NULL;
last_param = NULL;
}
else if(param == first_param)
{
first_param = param->next;
first_param->prev = NULL;
}
else if(param == last_param)
{
last_param = param->prev;
last_param->next = NULL;
}
else
{
if(param->prev != NULL)
{
param->prev->next = param->next;
}
if(param->next != NULL)
{
param->next->prev = param->prev;
}
}
delete param;
}
void ParamModule::RemovePreset(Preset* preset)
{
if (preset->native == true)
{
if((preset == NativePresets)&&(preset == NP_last))
{
NativePresets = NULL;
NP_last = NULL;
}
else if(preset == NativePresets)
{
NativePresets = preset->next;
NativePresets->prev = NULL;
}
else if(preset == NP_last)
{
NP_last = preset->prev;
NP_last->next = NULL;
}
else
{
if(preset->prev != NULL)
{
preset->prev->next = preset->next;
}
if(preset->next != NULL)
{
preset->next->prev = preset->prev;
}
}
--(this->NumNativePresets);
}
--(this->NumPresets);
}
/*==================================================================================================
BRIEF:
Dumps parameters data of the effect and all its children into XML. The method branches a
child-node from the parent node passed in, and fills it up with its parameters, name and so on.
This method provides recursive tree traversing approach.
PARAMETERS:
[in]
xmlParentNode - Reference to a parent node (where to branch from)
pPresetName - name of the preset, which should be used in the child-node (optional)
[out]
none
OUTPUT:
State of the effect (this) is added into parent xml node
==================================================================================================*/
void ParamModule::SaveStateData(XmlElement & xmlParentNode, char* pPresetName, bool global)
{
XmlElement *xmlStateNode = new XmlElement(T("Module"));
xmlStateNode->setAttribute(T("Name"), this->name);
xmlStateNode->setAttribute(T("ID"), uniqueID);
//xmlEffectHeader->setAttribute(T("Type"), this->type);
if (pPresetName != NULL)
{
xmlStateNode->setAttribute(T("Preset"), pPresetName);
}
else if (this->CurrentPreset != NULL)
{
xmlStateNode->setAttribute(T("Preset"), this->CurrentPreset->name);
}
else
{
xmlStateNode->setAttribute(T("Preset"), "default");
}
Parameter* pParam = this->first_param;
while (pParam != NULL)
{
if(pParam->IsPresetable())
{
XmlElement * xmlParam = (global == true ? pParam->Save() : pParam->Save4Preset());
xmlStateNode->addChildElement(xmlParam);
}
pParam = pParam->next;
}
//Now let the child-class a chance to save anything it wants as a custom tag
this->SaveCustomStateData(*xmlStateNode);
ParamModule* kid = this->children;
while(kid != NULL)
{
kid->SaveStateData(*xmlStateNode, NULL, global);
kid = kid->next_sibling;
}
xmlParentNode.addChildElement(xmlStateNode);
}
/*==================================================================================================
BRIEF:
Loads parameters of the effect with values from XML node passed in.
PARAMETERS:
[in]
xmlStateNode - Reference to a state node (where to get parameter values)
[out]
none
OUTPUT:
none
==================================================================================================*/
void ParamModule::RestoreStateData(XmlElement & xmlStateNode, bool global)
{
ParamModule* pChildEffect = NULL;
Parameter Param;
Parameter* pParam;
char szName[MAX_NAME_STRING];
XmlElement* xmlChildNode = xmlStateNode.getFirstChildElement();
//traverse XML tree and load parameters
//When we meet "module" sub-node, pass it down to a proper child
while (xmlChildNode != NULL)
{
// "Parameter" node we handle right here, it's ours to process
if(xmlChildNode->hasTagName(T("Parameter")) == true)
{
//int idx = xmlChildNode->getIntAttribute(T("index"));
//pParam = this->GetParamByIndex(idx);
String name = xmlChildNode->getStringAttribute(T("name"));
name.copyToBuffer(szName, min(name.length(), MAX_NAME_STRING));
pParam = this->GetParamByName(szName);
if(pParam != NULL)
{
if(global)
pParam->Load(xmlChildNode);
else
pParam->Load4Preset(xmlChildNode);
}
}
//This sub-node describes a child-effect's state, so pass it down to a child object
else if (xmlChildNode->hasTagName(T("Module")) == true)
{
//Extract module name from XML and convert it to C-style string
String StrName = xmlChildNode->getStringAttribute(T("name"));
memset(szName, 0, MAX_NAME_STRING * sizeof(char));
StrName.copyToBuffer(szName, min(StrName.length(), MAX_NAME_STRING));
//Go through the children list and find a kid with equal name
pChildEffect = this->FindChild(szName);
//If we don't find proper child, just skip the node silently and go furhter
if (NULL != pChildEffect)
{
//Let the child to do its part of the job (delegation is the key to success ;) )
pChildEffect->RestoreStateData(*xmlChildNode, global);
}
}
//if sub-node has custom tag, we need to give a child-class a chance to process it
else
{
this->RestoreCustomStateData(*xmlChildNode);
}
xmlChildNode = xmlChildNode->getNextElement();
}
}
/*==================================================================================================
BRIEF:
Saves state of the effect in XML document (preset file) and adds the preset into the list of
available resets, which the effect holds.
PARAMETERS:
[in]
preset_name - Name which should be used for the preset being created
[out]
none
OUTPUT:
A new preset-file is created in file system and corresponding preset item is added into
effect's preset list
==================================================================================================*/
void ParamModule::SavePresetAs(char * preset_name)
{
Preset *pPreset = NULL;
char path[MAX_PATH_STRING] = {0};
char cur_path[MAX_PATH_STRING] = {0};
char working_dir[MAX_PATH_STRING] = {};
int preset_index = 0;
char* pCurPos = NULL;
int result = 0;
int length;
int drive = _getdrive();
//Get current working directory
_getdcwd(drive, working_dir, MAX_PATH_STRING - 1);
//save the preset path into path variable
sprintf_s(path, MAX_PATH_STRING - 1, "%s", preset_path);
//let's save the length of the working directory, we gonna use it later
length = strlen(working_dir);
//concatenate working dir and preset path, now we have an absolute path to preset location
//we ignore leading '.' in the path variable, hence copying from an address of the second symbol
strcat_s(working_dir, MAX_PATH_STRING - 1, &(path[1]));
//sanity check, if we can't create a dir with this name, then it does already exist
//or requires additional parent dirs to be created first
//result = _mkdir(working_dir);
result = GetFileAttributes((LPCSTR)working_dir);
if (result == INVALID_FILE_ATTRIBUTES)
{
//set initial position in the absolute path to the end of working directory
//we gonna go through the rest of the path and check whether the path exists
pCurPos = &(working_dir[length + 1]);
//find next/next durectory to examine
while ((pCurPos = strstr(pCurPos, "\\")) != NULL)
{
//length of current processing directory
length = pCurPos - working_dir;
strncpy_s(cur_path, MAX_PATH_STRING -1, working_dir, length);
//try to create the dir
_mkdir(cur_path);
memset(cur_path, 0, length);
++pCurPos;
}
}
sprintf_s(path, MAX_PATH_STRING - 1, "%s%s%s", preset_path, preset_name, ".cxml\0");
XmlElement xmlPresetMain(T("ChaoticPreset"));
//xmlPresetMain.setAttribute(T("FormatVersion"), MAIN_PROJECT_VERSION);
this->SaveStateData(xmlPresetMain, preset_name);
String sFilePath(path);
File myFile(sFilePath);
xmlPresetMain.writeToFile(myFile, String::empty);
pPreset = new Preset((Object*)this);
/* Num is 0-based so its value is equal to the index of the next preset */
pPreset->index = this->NumNativePresets;
pPreset->native = true;
strncpy_s(pPreset->path, MAX_PATH_STRING - 1, path, MAX_PATH_STRING - 1);
strncpy_s(pPreset->name, MAX_PATH_STRING - 1, preset_name, MAX_PATH_STRING - 1);
this->AddPreset(pPreset);
this->CurrentPreset = pPreset;
strcpy(current_preset_name, pPreset->name);
}
long ParamModule::GetPresetIndex(char* name)
{
long ret_val = -1;
if (name != NULL)
{
Preset* pPreset = this->NativePresets;
while (pPreset != NULL)
{
if(_stricmp(pPreset->name, name) == 0)
{
ret_val = pPreset->index;
break;
}
pPreset = pPreset->next;
}
}
return ret_val;
}
bool ParamModule::SetPresetByName(char * name)
{
bool ret_val = false;
if (name != NULL)
{
Preset* pPreset = NULL;
pPreset = this->NativePresets;
while (pPreset != NULL)
{
if(_stricmp(pPreset->name, name) == 0)
{
ret_val = this->SetPreset(pPreset);
break;
}
pPreset = pPreset->next;
}
}
return ret_val;
}
bool ParamModule::KillPreset(Preset* pPreset)
{
RemovePreset(pPreset);
String sFilePath(pPreset->path);
File myFile(sFilePath);
return myFile.deleteFile();
}
bool ParamModule::SetPreset(Preset* pPreset)
{
bool ret_val = false;
ForceDeactivate();
String sFilePath(pPreset->path);
File myFile(sFilePath);
XmlDocument myPreset(myFile);
XmlElement* xmlMainNode = myPreset.getDocumentElement();
if(NULL == xmlMainNode)
{
AlertWindow::showMessageBox(AlertWindow::WarningIcon,
T("Error"),
T("Can't open preset file"),
T("OK"));
}
else
{
if(xmlMainNode->hasTagName(T("ChaoticPreset"))/* && xmlMainNode->hasAttribute(T("FormatVersion"))*/)
{
/*
if (MAIN_PROJECT_VERSION != xmlMainNode->getIntAttribute(T("FormatVersion")))
{
AlertWindow::showMessageBox(AlertWindow::WarningIcon,
T(""),
T("Format version doesn't match. Preset could be loaded incorrectly."),
T("OK"));
}*/
try
{
//First child is always a master plugin/effect
XmlElement* xmlMasterHeader = xmlMainNode->getFirstChildElement();
//Check whether the preset is for right plugin
if(this->uniqueID != xmlMasterHeader->getDoubleAttribute(T("ID")))
{
AlertWindow::showMessageBox(AlertWindow::WarningIcon,
T("Error"),
T("Preset and plugin doesn't match"),
T("OK"));
}
else
{
//Start recursive traversing of XML tree and loading of the preset
this->RestoreStateData(*xmlMasterHeader);
strcpy(current_preset_name, pPreset->name);
ret_val = true;
}
}
catch(...)
{
AlertWindow::showMessageBox(AlertWindow::WarningIcon,
T("Error"),
T("Cannot parse preset file"),
T("OK"));
}
}
else
{
AlertWindow::showMessageBox(AlertWindow::WarningIcon,
T("Error"),
T("Wrong preset format"),
T("OK"));
}
}
return ret_val;
}
Parameter* ParamModule::GetParamByName(char *param_name)
{
Parameter * pParam = NULL;
if(param_name[0] != '\0')
{
pParam = this->first_param;
while((pParam != NULL) && (_stricmp(pParam->name, param_name) != 0))
{
pParam = pParam->next;
}
}
return pParam;
}
Parameter* ParamModule::GetParamByIndex(int index)
{
Parameter * pParam = first_param;
while(pParam != NULL)
{
if(pParam->index == index)
return pParam;
pParam = pParam->next;
}
return pParam;
}
void ParamModule::DisableParamCells()
{
Paramcell* pcell = first_pcell;
while(pcell != NULL)
{
pcell->Disable();
pcell = pcell->next;
}
}
void ParamModule::EnableParamCells()
{
Paramcell* pcell = first_pcell;
while(pcell != NULL)
{
if(pcell->visible == true)
{
pcell->Enable();
}
pcell = pcell->next;
}
}
/*==================================================================================================
BRIEF:
This member function is used to add child-effect into master-effect.
Any Chaotic Effect can be a composition of various effects connected to each other, hence
producing a new complex effect
PARAMETERS:
[in]
pEffect - pointer to an Eff object which should be added into children list
[out]
none
OUTPUT:
A new child is addded into linked list of all children
==================================================================================================*/
void ParamModule::AddChild(ParamModule* pEffect)
{
//Link a new kid with other children in the list
pEffect->next_sibling = this->children;
if(this->children != NULL)
this->children->prev_sibling = pEffect;
//Nullify its back-link
pEffect->prev_sibling = NULL;
//re-direct pointer to the children list, now it looks to the new kid
this->children = pEffect;
//And the last but not least, set parent link of the effect being added
pEffect->parent = this;
}
/*==================================================================================================
BRIEF:
Helper method allowing to remove reference to a child-effect from the children list of
master-effect
PARAMETERS:
[in]
message - pointer to an Eff object, which reference should be removed from the children list
[out]
none
OUTPUT:
Referenced effect is removed from the children list of master-effect
==================================================================================================*/
void ParamModule::RemoveChild(ParamModule* pEffect)
{
ParamModule* pCurrentEffect = this->children;
//traverse through the list of all children
while (pCurrentEffect != NULL)
{
//found a match
if (pCurrentEffect == pEffect)
{
//Not the last one in the list
if (pCurrentEffect->next_sibling != NULL)
{
pCurrentEffect->next_sibling->prev_sibling = pCurrentEffect->prev_sibling;
}
//this is not the first kid in the list
if (pCurrentEffect->prev_sibling != NULL)
{
pCurrentEffect->prev_sibling->next_sibling = pCurrentEffect->next_sibling;
}
else //the first kid is a head of the list, we need to update the head then
{
this->children = pCurrentEffect->next_sibling;
}
//erase parent link, we don't own the effect any more
pCurrentEffect->parent = NULL;
//Break is used to stop traversing.
//We could use bool flag and check it in while() condition but it would be slower
break;
}
pCurrentEffect = pCurrentEffect->next_sibling;
}
}
/*==================================================================================================
BRIEF:
Goes through the children list and looks for the kid with specified name.
PARAMETERS:
[in]
name - Name of the effect to look for
[out]
none
OUTPUT:
Returns pointer to a child effect (if found one)
==================================================================================================*/
ParamModule* ParamModule::FindChild(char* name)
{
ParamModule* pRetEffect = this->children;
while (pRetEffect != NULL)
{
if (_stricmp(pRetEffect->name, name) == 0)
{
break;
}
pRetEffect = pRetEffect->next_sibling;
}
return pRetEffect;
}
void ParamModule::ToggleParamWindow()
{
if(paramWnd == NULL)
{
paramWnd = MainWnd->CreateParamWindow(&scope);
wnd = paramWnd;
paramWnd->Show();
}
else
{
if(paramWnd->isVisible())
{
paramWnd->Hide();
}
else
{
paramWnd->Show();
}
}
}
void ParamModule::EnqueueParamEnvelopeTrigger(Trigger* tg)
{
tg->tgworking = true;
if(envelopes != NULL)
{
envelopes->group_next = tg;
}
tg->group_prev = envelopes;
tg->group_next = NULL;
envelopes = tg;
Parameter* param = ((Command*)tg->el)->param;
{
tg->prev_value = (param->val - param->offset)/param->range;
}
// New envelopes unblock the param ability to be changed by envelope
param->UnblockEnvAffect();
}
void ParamModule::DequeueParamEnvelopeTrigger(Trigger* tg)
{
if(envelopes == tg)
{
envelopes = tg->group_prev;
}
if(tg->group_prev != NULL)
{
tg->group_prev->group_next = tg->group_next;
}
if(tg->group_next != NULL)
{
tg->group_next->group_prev = tg->group_prev;
}
tg->group_prev = NULL;
tg->group_next = NULL;
}
void ParamModule::SetName(char* name)
{
if (NULL != name)
{
memset(this->name, 0, MAX_NAME_STRING * sizeof(char));
strncpy(this->name, name, min(MAX_NAME_STRING - 1, strlen(name)));
}
}
void ParamModule::SetPath(char* path)
{
if (NULL != name)
{
memset(this->path, 0, MAX_PATH_STRING * sizeof(char));
strncpy(this->path, path, min(MAX_PATH_STRING - 1, strlen(path)));
}
}
void ParamModule::SetPresetPath(char* presetpath)
{
if (NULL != name)
{
memset(this->preset_path, 0, MAX_PATH_STRING * sizeof(char));
strncpy(this->preset_path, presetpath, min(MAX_PATH_STRING - 1, strlen(presetpath)));
}
}
String ParamModule::GetModuleTypeString(ModuleType mtype)
{
switch(mtype)
{
case ModuleType_Instrument:
return "ModuleType_Instrument";
break;
case ModuleType_Effect:
return "ModuleType_Effect";
break;
default:
return "";
}
}
ModuleType ParamModule::GetModuleTypeFromString(String mtype)
{
if(mtype == String("ModuleType_Instrument"))
{
return ModuleType_Instrument;
}
else if(mtype == String("ModuleType_Effect"))
{
return ModuleType_Effect;
}
else
{
return ModuleType_Invalid;
}
}