From a58029de7535e1ed367dab557e080e7483304cd0 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sat, 5 Mar 2016 02:27:17 +0100 Subject: [PATCH] Mallets reworked. Various fixes. Modalbar - activate knobs, BandedWG - remove scaling for Uniform Bar( noisy ). --- plugins/stk/mallets/mallets.cpp | 145 +++++++++++++++++++++++++------- plugins/stk/mallets/mallets.h | 9 +- 2 files changed, 119 insertions(+), 35 deletions(-) diff --git a/plugins/stk/mallets/mallets.cpp b/plugins/stk/mallets/mallets.cpp index d99c36820..ae12036ab 100644 --- a/plugins/stk/mallets/mallets.cpp +++ b/plugins/stk/mallets/mallets.cpp @@ -3,6 +3,7 @@ * * Copyright (c) 2006-2008 Danny McRae * Copyright (c) 2009-2015 Tobias Doerffel + * Copyright (c) 2016 Oskar Wallgren * * This file is part of LMMS - http://lmms.io * @@ -63,21 +64,24 @@ Plugin::Descriptor PLUGIN_EXPORT malletsstk_plugin_descriptor = malletsInstrument::malletsInstrument( InstrumentTrack * _instrument_track ): Instrument( _instrument_track, &malletsstk_plugin_descriptor ), m_hardnessModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Hardness" )), - m_positionModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Position" )), - m_vibratoGainModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Gain" )), - m_vibratoFreqModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Freq" )), - m_stickModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Stick Mix" )), + m_positionModel(64.0f, 0.0f, 64.0f, 0.1f, this, tr( "Position" )), + m_vibratoGainModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Gain" )), + m_vibratoFreqModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Vibrato Freq" )), + m_stickModel(0.0f, 0.0f, 128.0f, 0.1f, this, tr( "Stick Mix" )), m_modulatorModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Modulator" )), m_crossfadeModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Crossfade" )), m_lfoSpeedModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "LFO Speed" )), m_lfoDepthModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "LFO Depth" )), m_adsrModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "ADSR" )), - m_pressureModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Pressure" )), + m_pressureModel(64.0f, 0.1f, 128.0f, 0.1f, this, tr( "Pressure" )), m_motionModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Motion" )), - m_velocityModel(64.0f, 0.0f, 128.0f, 0.1f, this, tr( "Speed" )), - m_strikeModel( false, this, tr( "Bowed" ) ), +// TODO: m_vibratoModel + m_velocityModel(64.0f, 0.1f, 128.0f, 0.1f, this, tr( "Speed" )), + m_strikeModel( true, this, tr( "Bowed" ) ), m_presetsModel(this), m_spreadModel(0, 0, 255, 1, this, tr( "Spread" )), + m_versionModel( MALLETS_PRESET_VERSION, 0, MALLETS_PRESET_VERSION, this, "" ), + m_isOldVersionModel( false, this, "" ), m_filesMissing( !QDir( ConfigManager::inst()->stkDir() ).exists() || !QFileInfo( ConfigManager::inst()->stkDir() + "/sinewave.raw" ).exists() ) { @@ -144,13 +148,15 @@ void malletsInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this ) // BandedWG m_pressureModel.saveSettings( _doc, _this, "pressure" ); - m_motionModel.saveSettings( _doc, _this, "motion" ); - m_vibratoModel.saveSettings( _doc, _this, "vibrato" ); +// m_motionModel.saveSettings( _doc, _this, "motion" ); +// m_vibratoModel.saveSettings( _doc, _this, "vibrato" ); m_velocityModel.saveSettings( _doc, _this, "velocity" ); m_strikeModel.saveSettings( _doc, _this, "strike" ); m_presetsModel.saveSettings( _doc, _this, "preset" ); m_spreadModel.saveSettings( _doc, _this, "spread" ); + m_versionModel.saveSettings( _doc, _this, "version" ); + m_isOldVersionModel.saveSettings( _doc, _this, "oldversion" ); } @@ -158,6 +164,8 @@ void malletsInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this ) void malletsInstrument::loadSettings( const QDomElement & _this ) { + m_versionModel.loadSettings( _this, "version" ); + // ModalBar m_hardnessModel.loadSettings( _this, "hardness" ); m_positionModel.loadSettings( _this, "position" ); @@ -174,13 +182,86 @@ void malletsInstrument::loadSettings( const QDomElement & _this ) // BandedWG m_pressureModel.loadSettings( _this, "pressure" ); - m_motionModel.loadSettings( _this, "motion" ); - m_vibratoModel.loadSettings( _this, "vibrato" ); +// m_motionModel.loadSettings( _this, "motion" ); +// m_vibratoModel.loadSettings( _this, "vibrato" ); m_velocityModel.loadSettings( _this, "velocity" ); m_strikeModel.loadSettings( _this, "strike" ); m_presetsModel.loadSettings( _this, "preset" ); m_spreadModel.loadSettings( _this, "spread" ); + m_isOldVersionModel.loadSettings( _this, "oldversion" ); + + // To maintain backward compatibility + if( !_this.hasAttribute( "version" ) ) + { + m_isOldVersionModel.setValue( true ); + m_vibratoGainModel.setValue( 0.0f ); + if( m_presetsModel.value() == 1 ) + { + /* Earlier mallets used the stk internal + default of 0.2. 0.2 * 128.0 = 25.6 */ + m_vibratoGainModel.setValue( 25.6f ); + } + if( ! m_presetsModel.value() == 1 ) + { + // Frequency actually worked for Vibraphone! + m_vibratoFreqModel.setValue( 0.0f ); + } + /* Modalbar preset values, see stk, ModalBar.cpp + void ModalBar :: setPreset( int preset ) + Stick Mix * 128.0 + m_positionModel values over 64 is formatted to the + new knob by 128 - x */ + + switch( m_presetsModel.value() ) + { + case 0: + m_hardnessModel.setValue( 55.0f ); + m_positionModel.setValue( 57.0f ); + m_stickModel.setValue( 12.0f ); + break; + case 1: + m_hardnessModel.setValue( 50.0f ); + m_positionModel.setValue( 55.0f );// 128 - 73! + m_stickModel.setValue( 10.0f ); + break; + case 2: + m_hardnessModel.setValue( 78.0f ); + m_positionModel.setValue( 46.0f ); + m_stickModel.setValue( 18.0f ); + break; + case 3: + m_hardnessModel.setValue( 59.0f ); + m_positionModel.setValue( 48.0f ); + m_stickModel.setValue( 6.0f ); + break; + case 4: + m_hardnessModel.setValue( 58.0f ); + m_positionModel.setValue( 32.0f ); + m_stickModel.setValue( 13.0f ); + break; + case 5: + m_hardnessModel.setValue( 40.0f ); + m_positionModel.setValue( 57.0f ); + m_stickModel.setValue( 14.0f ); + break; + case 6: + m_hardnessModel.setValue( 51.0f ); + m_positionModel.setValue( 38.0f ); + m_stickModel.setValue( 9.0f ); + break; + case 7: + m_hardnessModel.setValue( 58.0f ); + m_positionModel.setValue( 58.0f ); + m_stickModel.setValue( 9.0f ); + break; + case 8: + m_hardnessModel.setValue( 50.0f ); + m_positionModel.setValue( 55.0f );// 128 - 73! + m_stickModel.setValue( 10.0f ); + break; + } + } } @@ -216,10 +297,10 @@ void malletsInstrument::playNote( NotePlayHandle * _n, { _n->m_pluginData = new malletsSynth( freq, vel, - m_vibratoGainModel.value(), + m_stickModel.value(), m_hardnessModel.value(), m_positionModel.value(), - m_stickModel.value(), + m_vibratoGainModel.value(), m_vibratoFreqModel.value(), p, (uint8_t) m_spreadModel.value(), @@ -261,18 +342,19 @@ void malletsInstrument::playNote( NotePlayHandle * _n, ps->setFrequency( freq ); sample_t add_scale = 0.0f; - if( p == 10 ) + if( p == 10 && m_isOldVersionModel.value() == true ) { add_scale = static_cast( m_strikeModel.value() ) * freq * 2.5f; } + for( fpp_t frame = offset; frame < frames + offset; ++frame ) { - _working_buffer[frame][0] = ps->nextSampleLeft() * + _working_buffer[frame][0] = ps->nextSampleLeft() * ( m_scalers[m_presetsModel.value()] + add_scale ); - _working_buffer[frame][1] = ps->nextSampleRight() * + _working_buffer[frame][1] = ps->nextSampleRight() * ( m_scalers[m_presetsModel.value()] + add_scale ); } - + instrumentTrack()->processAudioBuffer( _working_buffer, frames + offset, _n ); } @@ -301,19 +383,18 @@ malletsInstrumentView::malletsInstrumentView( malletsInstrument * _instrument, { m_modalBarWidget = setupModalBarControls( this ); setWidgetBackground( m_modalBarWidget, "artwork" ); - m_modalBarWidget->show(); m_modalBarWidget->move( 0,0 ); m_tubeBellWidget = setupTubeBellControls( this ); setWidgetBackground( m_tubeBellWidget, "artwork" ); - m_tubeBellWidget->hide(); m_tubeBellWidget->move( 0,0 ); m_bandedWGWidget = setupBandedWGControls( this ); setWidgetBackground( m_bandedWGWidget, "artwork" ); - m_bandedWGWidget->hide(); m_bandedWGWidget->move( 0,0 ); - + + changePreset(); // Show widget + m_presetsCombo = new ComboBox( this, tr( "Instrument" ) ); m_presetsCombo->setGeometry( 140, 50, 99, 22 ); m_presetsCombo->setFont( pointSize<8>( m_presetsCombo->font() ) ); @@ -436,28 +517,28 @@ QWidget * malletsInstrumentView::setupBandedWGControls( QWidget * _parent ) QWidget * widget = new QWidget( _parent ); widget->setFixedSize( 250, 250 ); - m_strikeLED = new LedCheckBox( tr( "Bowed" ), widget ); - m_strikeLED->move( 138, 25 ); +/* m_strikeLED = new LedCheckBox( tr( "Bowed" ), widget ); + m_strikeLED->move( 138, 25 );*/ m_pressureKnob = new Knob( knobVintage_32, widget ); m_pressureKnob->setLabel( tr( "Pressure" ) ); m_pressureKnob->move( 30, 90 ); m_pressureKnob->setHintText( tr( "Pressure:" ), "" ); - m_motionKnob = new Knob( knobVintage_32, widget ); +/* m_motionKnob = new Knob( knobVintage_32, widget ); m_motionKnob->setLabel( tr( "Motion" ) ); m_motionKnob->move( 110, 90 ); - m_motionKnob->setHintText( tr( "Motion:" ), "" ); - + m_motionKnob->setHintText( tr( "Motion:" ), "" );*/ + m_velocityKnob = new Knob( knobVintage_32, widget ); m_velocityKnob->setLabel( tr( "Speed" ) ); m_velocityKnob->move( 30, 140 ); m_velocityKnob->setHintText( tr( "Speed:" ), "" ); - m_vibratoKnob = new Knob( knobVintage_32, widget, tr( "Vibrato" ) ); +/* m_vibratoKnob = new Knob( knobVintage_32, widget, tr( "Vibrato" ) ); m_vibratoKnob->setLabel( tr( "Vibrato" ) ); m_vibratoKnob->move( 110, 140 ); - m_vibratoKnob->setHintText( tr( "Vibrato:" ), "" ); + m_vibratoKnob->setHintText( tr( "Vibrato:" ), "" );*/ return( widget ); } @@ -479,10 +560,10 @@ void malletsInstrumentView::modelChanged() m_lfoDepthKnob->setModel( &inst->m_lfoDepthModel ); m_adsrKnob->setModel( &inst->m_adsrModel ); m_pressureKnob->setModel( &inst->m_pressureModel ); - m_motionKnob->setModel( &inst->m_motionModel ); - m_vibratoKnob->setModel( &inst->m_vibratoModel ); +// m_motionKnob->setModel( &inst->m_motionModel ); +// m_vibratoKnob->setModel( &inst->m_vibratoModel ); m_velocityKnob->setModel( &inst->m_velocityModel ); - m_strikeLED->setModel( &inst->m_strikeModel ); +// m_strikeLED->setModel( &inst->m_strikeModel ); m_presetsCombo->setModel( &inst->m_presetsModel ); m_spreadKnob->setModel( &inst->m_spreadModel ); } @@ -537,12 +618,12 @@ malletsSynth::malletsSynth( const StkFloat _pitch, m_voice = new ModalBar(); + m_voice->controlChange( 16, _control16 ); m_voice->controlChange( 1, _control1 ); m_voice->controlChange( 2, _control2 ); m_voice->controlChange( 4, _control4 ); m_voice->controlChange( 8, _control8 ); m_voice->controlChange( 11, _control11 ); - m_voice->controlChange( 16, _control16 ); m_voice->controlChange( 128, 128.0f ); m_voice->noteOn( _pitch, _velocity ); diff --git a/plugins/stk/mallets/mallets.h b/plugins/stk/mallets/mallets.h index a194479bf..1fe5bbebb 100644 --- a/plugins/stk/mallets/mallets.h +++ b/plugins/stk/mallets/mallets.h @@ -42,6 +42,7 @@ namespace stk { } ; using namespace stk; +static const int MALLETS_PRESET_VERSION = 1; class malletsSynth { @@ -173,6 +174,8 @@ private: ComboBoxModel m_presetsModel; FloatModel m_spreadModel; + IntModel m_versionModel; + BoolModel m_isOldVersionModel; QVector m_scalers; @@ -219,10 +222,10 @@ private: QWidget * m_bandedWGWidget; Knob * m_pressureKnob; - Knob * m_motionKnob; - Knob * m_vibratoKnob; +// Knob * m_motionKnob; +// Knob * m_vibratoKnob; Knob * m_velocityKnob; - LedCheckBox * m_strikeLED; +// LedCheckBox * m_strikeLED; ComboBox * m_presetsCombo; Knob * m_spreadKnob;