mirror of
https://github.com/AxioDL/amuse.git
synced 2025-12-10 22:17:56 +00:00
Common: Replace amuse::clamp with std::clamp
We can use the standardized facility for this now with C++17
This commit is contained in:
@@ -41,7 +41,7 @@ void Envelope::reset(const ADSRDLS* adsr, int8_t note, int8_t vel) {
|
||||
void Envelope::keyOff(const Voice& vox) {
|
||||
double releaseTime = m_releaseTime;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
releaseTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
||||
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
||||
|
||||
m_phase = (releaseTime != 0.0) ? State::Release : State::Complete;
|
||||
m_curTime = 0.0;
|
||||
@@ -63,7 +63,7 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||
case State::Attack: {
|
||||
double attackTime = m_attackTime;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
attackTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 103)] / 1000.0;
|
||||
attackTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 103)] / 1000.0;
|
||||
|
||||
if (attackTime == 0.0) {
|
||||
m_phase = State::Decay;
|
||||
@@ -84,11 +84,11 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||
case State::Decay: {
|
||||
double decayTime = m_decayTime;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
decayTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 103)] / 1000.0;
|
||||
decayTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 103)] / 1000.0;
|
||||
|
||||
double sustainFactor = m_sustainFactor;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
sustainFactor = clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
||||
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
||||
|
||||
if (decayTime == 0.0) {
|
||||
m_phase = State::Sustain;
|
||||
@@ -109,14 +109,14 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||
case State::Sustain: {
|
||||
double sustainFactor = m_sustainFactor;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
sustainFactor = clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
||||
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
||||
|
||||
return sustainFactor;
|
||||
}
|
||||
case State::Release: {
|
||||
double releaseTime = m_releaseTime;
|
||||
if (vox.m_state.m_useAdsrControllers)
|
||||
releaseTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
||||
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
||||
|
||||
if (releaseTime == 0.0) {
|
||||
m_phase = State::Complete;
|
||||
|
||||
Reference in New Issue
Block a user