Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mallets - Some small fixes #6913

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions plugins/Stk/Mallets/Mallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,33 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
float position = m_positionModel.value();
float modulator = m_modulatorModel.value();
float crossfade = m_crossfadeModel.value();
float pressure = m_pressureModel.value();
float speed = m_velocityModel.value();

if (p < 9)
{
hardness += random * static_cast<float>(fast_rand() % 128) - 64.0;
hardness += random * (static_cast<float>(fast_rand() % 128) - 64.0);
hardness = std::clamp(hardness, 0.0f, 128.0f);

position += random * static_cast<float>(fast_rand() % 64) - 32.0;
position += random * (static_cast<float>(fast_rand() % 64) - 32.0);
position = std::clamp(position, 0.0f, 64.0f);
}
else if (p == 9)
{
modulator += random * static_cast<float>(fast_rand() % 128) - 64.0;
modulator += random * (static_cast<float>(fast_rand() % 128) - 64.0);
modulator = std::clamp(modulator, 0.0f, 128.0f);

crossfade += random * static_cast<float>(fast_rand() % 128) - 64.0;
crossfade += random * (static_cast<float>(fast_rand() % 128) - 64.0);
crossfade = std::clamp(crossfade, 0.0f, 128.0f);
}
else
{
pressure += random * (static_cast<float>(fast_rand() % 128) - 64.0);
pressure = std::clamp(pressure, 0.0f, 128.0f);

speed += random * (static_cast<float>(fast_rand() % 128) - 64.0);
speed = std::clamp(speed, 0.0f, 128.0f);
}

// critical section as STK is not thread-safe
static QMutex m;
Expand Down Expand Up @@ -352,12 +362,12 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
{
_n->m_pluginData = new MalletsSynth( freq,
vel,
m_pressureModel.value(),
pressure,
m_motionModel.value(),
m_vibratoModel.value(),
p - 10,
m_strikeModel.value() * 128.0,
m_velocityModel.value(),
speed,
(uint8_t) m_spreadModel.value(),
Engine::audioEngine()->processingSampleRate() );
}
Expand All @@ -369,8 +379,20 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
const f_cnt_t offset = _n->noteOffset();

auto ps = static_cast<MalletsSynth*>(_n->m_pluginData);
ps->setFrequency( freq );
ps->setFrequency(freq);

p = ps->presetIndex();
if (p < 9) // ModalBar updates
{
ps->setVibratoGain(m_vibratoGainModel.value());
ps->setVibratoFreq(m_vibratoFreqModel.value());
}
else if (p == 9) // Tubular Bells updates
{
ps->setADSR(m_adsrModel.value());
ps->setLFODepth(m_lfoDepthModel.value());
ps->setLFOSpeed(m_lfoSpeedModel.value());
}

sample_t add_scale = 0.0f;
if( p == 10 && m_isOldVersionModel.value() == true )
Expand Down
36 changes: 31 additions & 5 deletions plugins/Stk/Mallets/Mallets.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,38 @@ class MalletsSynth
return( s );
}

inline void setFrequency( const StkFloat _pitch )
inline void setFrequency(const StkFloat _pitch)
{
if( m_voice )
{
m_voice->setFrequency( _pitch );
}
if (m_voice) { m_voice->setFrequency(_pitch); }
}

// ModalBar updates
inline void setVibratoGain(const StkFloat _control8)
{
// bug in stk, Control Number 8 and 1 swapped in ModalBar
// we send the control number for stick direct mix instead
if (m_voice) { m_voice->controlChange(8, _control8); }
}

inline void setVibratoFreq(const StkFloat _control11)
{
if (m_voice) { m_voice->controlChange(11, _control11); }
}

// Tubular Bells updates
inline void setADSR(const StkFloat _control128)
{
if (m_voice) { m_voice->controlChange(128, _control128); }
}

inline void setLFODepth(const StkFloat _control1)
{
if (m_voice) { m_voice->controlChange(1, _control1); }
}

inline void setLFOSpeed(const StkFloat _control11)
{
if (m_voice) { m_voice->controlChange(11, _control11); }
}

inline int presetIndex()
Expand Down
Loading