From d769459764197ae4e6068a66fd6e22784803045f Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Fri, 1 Jan 2021 14:43:46 +0100 Subject: [PATCH] Arpeggiator - Note repeats (#5784) Co-authored-by: Kevin Zander Co-authored-by: IanCaio --- include/InstrumentFunctionViews.h | 1 + include/InstrumentFunctions.h | 1 + src/core/InstrumentFunctions.cpp | 10 ++++++++-- src/gui/widgets/InstrumentFunctionViews.cpp | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/InstrumentFunctionViews.h b/include/InstrumentFunctionViews.h index 58f915b15..f222d8c94 100644 --- a/include/InstrumentFunctionViews.h +++ b/include/InstrumentFunctionViews.h @@ -78,6 +78,7 @@ private: GroupBox * m_arpGroupBox; ComboBox * m_arpComboBox; Knob * m_arpRangeKnob; + Knob * m_arpRepeatsKnob; Knob * m_arpCycleKnob; Knob * m_arpSkipKnob; Knob * m_arpMissKnob; diff --git a/include/InstrumentFunctions.h b/include/InstrumentFunctions.h index b45484e71..e1591ea27 100644 --- a/include/InstrumentFunctions.h +++ b/include/InstrumentFunctions.h @@ -196,6 +196,7 @@ private: BoolModel m_arpEnabledModel; ComboBoxModel m_arpModel; FloatModel m_arpRangeModel; + FloatModel m_arpRepeatsModel; FloatModel m_arpCycleModel; FloatModel m_arpSkipModel; FloatModel m_arpMissModel; diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 09854220d..0b3f2a9bf 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -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" ) ), @@ -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(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 @@ -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(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( range / m_arpRepeatsModel.value() ); } // now calculate final key for our arp-note @@ -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" ); @@ -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" ); diff --git a/src/gui/widgets/InstrumentFunctionViews.cpp b/src/gui/widgets/InstrumentFunctionViews.cpp index 30bb3af49..43f6b2b9b 100644 --- a/src/gui/widgets/InstrumentFunctionViews.cpp +++ b/src/gui/widgets/InstrumentFunctionViews.cpp @@ -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 ) ), @@ -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)" ) ); @@ -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 ); @@ -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 );