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 - Add random knob function #6466

Merged
merged 9 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
44 changes: 38 additions & 6 deletions plugins/Stk/Mallets/Mallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ MalletsInstrument::MalletsInstrument( InstrumentTrack * _instrument_track ):
m_strikeModel( true, this, tr( "Bowed" ) ),
m_presetsModel(this),
m_spreadModel(0, 0, 255, 1, this, tr( "Spread" )),
m_randomModel(0.0f, 0.0f, 1.0f, 0.01f, this, tr("Randomness")),
m_versionModel( MALLETS_PRESET_VERSION, 0, MALLETS_PRESET_VERSION, this, "" ),
m_isOldVersionModel( false, this, "" ),
m_filesMissing( !QDir( ConfigManager::inst()->stkDir() ).exists() ||
Expand Down Expand Up @@ -155,6 +156,7 @@ void MalletsInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this )

m_presetsModel.saveSettings( _doc, _this, "preset" );
m_spreadModel.saveSettings( _doc, _this, "spread" );
m_randomModel.saveSettings(_doc, _this, "randomness");
m_versionModel.saveSettings( _doc, _this, "version" );
m_isOldVersionModel.saveSettings( _doc, _this, "oldversion" );
}
Expand Down Expand Up @@ -189,6 +191,7 @@ void MalletsInstrument::loadSettings( const QDomElement & _this )

m_presetsModel.loadSettings( _this, "preset" );
m_spreadModel.loadSettings( _this, "spread" );
m_randomModel.loadSettings(_this, "randomness");
m_isOldVersionModel.loadSettings( _this, "oldversion" );

// To maintain backward compatibility
Expand Down Expand Up @@ -284,7 +287,7 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
}

int p = m_presetsModel.value();

zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
const float freq = _n->frequency();
if (!_n->m_pluginData)
{
Expand All @@ -293,6 +296,29 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
m_isOldVersionModel.value() ? 100.0 : 200.0;
const float vel = _n->getVolume() / velocityAdjust;

const float random = m_randomModel.value();
float hardness = m_hardnessModel.value();
float position = m_positionModel.value();
float modulator = m_modulatorModel.value();
float crossfade = m_crossfadeModel.value();

if(p < 9)
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
{
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 = std::clamp(position, 0.0f, 64.0f);
}
else if(p == 9)
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
{
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 = std::clamp(crossfade, 0.0f, 128.0f);
}

// critical section as STK is not thread-safe
static QMutex m;
m.lock();
Expand All @@ -301,8 +327,8 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
_n->m_pluginData = new MalletsSynth( freq,
vel,
m_stickModel.value(),
m_hardnessModel.value(),
m_positionModel.value(),
hardness,
position,
m_vibratoGainModel.value(),
m_vibratoFreqModel.value(),
p,
Expand All @@ -315,8 +341,8 @@ void MalletsInstrument::playNote( NotePlayHandle * _n,
vel,
p,
m_lfoDepthModel.value(),
m_modulatorModel.value(),
m_crossfadeModel.value(),
modulator,
crossfade,
m_lfoSpeedModel.value(),
m_adsrModel.value(),
(uint8_t) m_spreadModel.value(),
Expand Down Expand Up @@ -412,6 +438,11 @@ MalletsInstrumentView::MalletsInstrumentView( MalletsInstrument * _instrument,
m_spreadKnob->move( 190, 140 );
m_spreadKnob->setHintText( tr( "Spread:" ), "" );

m_randomKnob = new Knob( KnobType::Vintage32, this );
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
m_randomKnob->setLabel(tr("Random"));
m_randomKnob->move(190, 190);
m_randomKnob->setHintText(tr("Random:"),"");
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved

// try to inform user about missing Stk-installation
if( _instrument->m_filesMissing && getGUI() != nullptr )
{
Expand Down Expand Up @@ -467,7 +498,7 @@ QWidget * MalletsInstrumentView::setupModalBarControls( QWidget * _parent )
m_stickKnob->setLabel( tr( "Stick mix" ) );
m_stickKnob->move( 190, 90 );
m_stickKnob->setHintText( tr( "Stick mix:" ), "" );

zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
return( widget );
}

Expand Down Expand Up @@ -565,6 +596,7 @@ void MalletsInstrumentView::modelChanged()
// m_strikeLED->setModel( &inst->m_strikeModel );
m_presetsCombo->setModel( &inst->m_presetsModel );
m_spreadKnob->setModel( &inst->m_spreadModel );
m_randomKnob->setModel(&inst->m_randomModel);
}


Expand Down
2 changes: 2 additions & 0 deletions plugins/Stk/Mallets/Mallets.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class MalletsInstrument : public Instrument

ComboBoxModel m_presetsModel;
FloatModel m_spreadModel;
FloatModel m_randomModel;
IntModel m_versionModel;
BoolModel m_isOldVersionModel;

Expand Down Expand Up @@ -255,6 +256,7 @@ public slots:

ComboBox * m_presetsCombo;
Knob * m_spreadKnob;
Knob * m_randomKnob;
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved
};


Expand Down
Loading