-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMultiplier.cpp
More file actions
103 lines (78 loc) · 2.16 KB
/
Multiplier.cpp
File metadata and controls
103 lines (78 loc) · 2.16 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
#include "Multiplier.h"
#include <process.h>
#include "Globals.h"
#include "FadeThread.h"
bool recalculateMultipliers = true;
Multiplier multObMaster;
Multiplier multObMasterIni;
Multiplier multObMusic;
Multiplier multObMusicIni;
Multiplier multObEffects;
Multiplier multObEffectsIni;
Multiplier multObVoice;
Multiplier multObVoiceIni;
Multiplier multObFoot;
Multiplier multObFootIni;
MultipliersMap multipliersCustom;
Multiplier::~Multiplier () {
if (userMultiplier) {
delete value;
}
CloseHandle (hThread);
}
volatile float Multiplier::getValue () {
return *value;
}
void Multiplier::setValue (float newValue) {
newValue = clamp(newValue, 0, 1);
if (*value != newValue) {
*value = newValue;
recalculateMultipliers = true;
}
}
bool Multiplier::setValueLimit (float newValue, float limit) {
if (isBetweenLimits(*value,limit,newValue,<=)) {
//If limit is beween *value and newValue, then we need to cross it (but we don't want to cross it, so...).
setValue(limit);
return true;
} else {
setValue(newValue);
return false;
}
}
FadeThreadState Multiplier::fadeVolume (float newTargetValue, float newFadeTime) {
//Assume the calling function waited for the mutex
startValue = *value;
targetValue = clamp (newTargetValue, 0, 1);
fadeTime = newFadeTime > 0 ? newFadeTime : 0;
if (isFading) {
if (startValue == targetValue || fadeTime <= 0) {
_MESSAGE ("Command >> emcSetMusicVolume >> Stop fade thread");
isFading = false;
setValue (targetValue);
return FadeThreadState::ft_Stopped;
} else {
_MESSAGE ("Command >> emcSetMusicVolume >> Update fade thread");
isChanged = true;
return FadeThreadState::ft_Updated;
}
} else {
if (startValue == targetValue || fadeTime <= 0) {
setValue (targetValue);
return FadeThreadState::ft_NotRunning;
} else {
_MESSAGE ("Command >> emcSetMusicVolume >> Start fade thread");
isFading = true;
_beginthread (FadeThread, 0, this);
return FadeThreadState::ft_Started;
}
}
//Assume the calling function will release the mutex
}
void Multiplier::destroy () {
recalculateMultipliers = true;
isDestroyed = true;
}
float Multiplier::operator=(float value) {
setValue (value);
}