Skip to content

Commit

Permalink
Arpeggiator - Note repeats (LMMS#5784)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Zander <[email protected]>
Co-authored-by: IanCaio <[email protected]>
  • Loading branch information
3 people authored Jan 1, 2021
1 parent 58e911d commit 8947264
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/InstrumentFunctionViews.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class InstrumentFunctionArpeggioView : public QWidget, public ModelView
GroupBox * m_arpGroupBox;
ComboBox * m_arpComboBox;
Knob * m_arpRangeKnob;
Knob * m_arpRepeatsKnob;
Knob * m_arpCycleKnob;
Knob * m_arpSkipKnob;
Knob * m_arpMissKnob;
Expand Down
1 change: 1 addition & 0 deletions include/InstrumentFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class InstrumentFunctionArpeggio : public Model, public JournallingObject
BoolModel m_arpEnabledModel;
ComboBoxModel m_arpModel;
FloatModel m_arpRangeModel;
FloatModel m_arpRepeatsModel;
FloatModel m_arpCycleModel;
FloatModel m_arpSkipModel;
FloatModel m_arpMissModel;
Expand Down
10 changes: 8 additions & 2 deletions src/core/InstrumentFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ InstrumentFunctionArpeggio::InstrumentFunctionArpeggio( Model * _parent ) :
m_arpEnabledModel( false ),
m_arpModel( this, tr( "Arpeggio type" ) ),
m_arpRangeModel( 1.0f, 1.0f, 9.0f, 1.0f, this, tr( "Arpeggio range" ) ),
m_arpRepeatsModel( 1.0f, 1.0f, 8.0f, 1.0f, this, tr( "Note repeats" ) ),
m_arpCycleModel( 0.0f, 0.0f, 6.0f, 1.0f, this, tr( "Cycle steps" ) ),
m_arpSkipModel( 0.0f, 0.0f, 100.0f, 1.0f, this, tr( "Skip rate" ) ),
m_arpMissModel( 0.0f, 0.0f, 100.0f, 1.0f, this, tr( "Miss rate" ) ),
Expand Down Expand Up @@ -369,7 +370,7 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n )

const InstrumentFunctionNoteStacking::ChordTable & chord_table = InstrumentFunctionNoteStacking::ChordTable::getInstance();
const int cur_chord_size = chord_table[selected_arp].size();
const int range = (int)( cur_chord_size * m_arpRangeModel.value() );
const int range = static_cast<int>(cur_chord_size * m_arpRangeModel.value() * m_arpRepeatsModel.value());
const int total_range = range * cnphv.size();

// number of frames that every note should be played
Expand Down Expand Up @@ -479,11 +480,14 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n )
cur_arp_idx = (int)( range * ( (float) rand() / (float) RAND_MAX ) );
}

// Divide cur_arp_idx with wanted repeats. The repeat feature will not affect random notes.
cur_arp_idx = static_cast<int>(cur_arp_idx / m_arpRepeatsModel.value());

// Cycle notes
if( m_arpCycleModel.value() && dir != ArpDirRandom )
{
cur_arp_idx *= m_arpCycleModel.value() + 1;
cur_arp_idx %= range;
cur_arp_idx %= static_cast<int>( range / m_arpRepeatsModel.value() );
}

// now calculate final key for our arp-note
Expand Down Expand Up @@ -525,6 +529,7 @@ void InstrumentFunctionArpeggio::saveSettings( QDomDocument & _doc, QDomElement
m_arpEnabledModel.saveSettings( _doc, _this, "arp-enabled" );
m_arpModel.saveSettings( _doc, _this, "arp" );
m_arpRangeModel.saveSettings( _doc, _this, "arprange" );
m_arpRepeatsModel.saveSettings( _doc, _this, "arprepeats" );
m_arpCycleModel.saveSettings( _doc, _this, "arpcycle" );
m_arpSkipModel.saveSettings( _doc, _this, "arpskip" );
m_arpMissModel.saveSettings( _doc, _this, "arpmiss" );
Expand All @@ -542,6 +547,7 @@ void InstrumentFunctionArpeggio::loadSettings( const QDomElement & _this )
m_arpEnabledModel.loadSettings( _this, "arp-enabled" );
m_arpModel.loadSettings( _this, "arp" );
m_arpRangeModel.loadSettings( _this, "arprange" );
m_arpRepeatsModel.loadSettings( _this, "arprepeats" );
m_arpCycleModel.loadSettings( _this, "arpcycle" );
m_arpSkipModel.loadSettings( _this, "arpskip" );
m_arpMissModel.loadSettings( _this, "arpmiss" );
Expand Down
17 changes: 12 additions & 5 deletions src/gui/widgets/InstrumentFunctionViews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ InstrumentFunctionArpeggioView::InstrumentFunctionArpeggioView( InstrumentFuncti
m_arpGroupBox( new GroupBox( tr( "ARPEGGIO" ) ) ),
m_arpComboBox( new ComboBox() ),
m_arpRangeKnob( new Knob( knobBright_26 ) ),
m_arpRepeatsKnob( new Knob( knobBright_26 ) ),
m_arpCycleKnob( new Knob( knobBright_26 ) ),
m_arpSkipKnob( new Knob( knobBright_26 ) ),
m_arpMissKnob( new Knob( knobBright_26 ) ),
Expand All @@ -117,6 +118,10 @@ InstrumentFunctionArpeggioView::InstrumentFunctionArpeggioView( InstrumentFuncti
m_arpRangeKnob->setHintText( tr( "Arpeggio range:" ), " " + tr( "octave(s)" ) );


m_arpRepeatsKnob->setLabel( tr( "REP" ) );
m_arpRepeatsKnob->setHintText( tr( "Note repeats:" ) + " ", " " + tr( "time(s)" ) );


m_arpCycleKnob->setLabel( tr( "CYCLE" ) );
m_arpCycleKnob->setHintText( tr( "Cycle notes:" ) + " ", " " + tr( "note(s)" ) );

Expand Down Expand Up @@ -154,11 +159,12 @@ InstrumentFunctionArpeggioView::InstrumentFunctionArpeggioView( InstrumentFuncti
mainLayout->addWidget( m_arpModeComboBox, 7, 0 );

mainLayout->addWidget( m_arpRangeKnob, 0, 1, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpCycleKnob, 0, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpSkipKnob, 3, 1, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpMissKnob, 3, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpGateKnob, 6, 1, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpTimeKnob, 6, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpRepeatsKnob, 0, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpCycleKnob, 0, 3, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpSkipKnob, 3, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpMissKnob, 3, 3, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpGateKnob, 6, 2, 2, 1, Qt::AlignHCenter );
mainLayout->addWidget( m_arpTimeKnob, 6, 3, 2, 1, Qt::AlignHCenter );

mainLayout->setRowMinimumHeight( 2, 10 );
mainLayout->setRowMinimumHeight( 5, 10 );
Expand All @@ -181,6 +187,7 @@ void InstrumentFunctionArpeggioView::modelChanged()
m_arpGroupBox->setModel( &m_a->m_arpEnabledModel );
m_arpComboBox->setModel( &m_a->m_arpModel );
m_arpRangeKnob->setModel( &m_a->m_arpRangeModel );
m_arpRepeatsKnob->setModel( &m_a->m_arpRepeatsModel );
m_arpCycleKnob->setModel( &m_a->m_arpCycleModel );
m_arpSkipKnob->setModel( &m_a->m_arpSkipModel );
m_arpMissKnob->setModel( &m_a->m_arpMissModel );
Expand Down

0 comments on commit 8947264

Please sign in to comment.