From 325df3b2d4450e2af6c401122f0aa696593cb3c0 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Sat, 25 Nov 2023 13:39:11 +0100 Subject: [PATCH] Refactor arpdirdown, arpdirdownup Fix issue with wrong pattern when going down and cycle is over 0. --- src/core/InstrumentFunctions.cpp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 976363d3d08..17739b9eba7 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -433,16 +433,11 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) int cur_arp_idx = 0; // process according to arpeggio-direction... - if( dir == ArpDirection::Up ) + if (dir == ArpDirection::Up || dir == ArpDirection::Down) { cur_arp_idx = ( cur_frame / arp_frames ) % range; } - else if( dir == ArpDirection::Down ) - { - cur_arp_idx = range - ( cur_frame / arp_frames ) % - range - 1; - } - else if( dir == ArpDirection::UpAndDown && range > 1 ) + else if ((dir == ArpDirection::UpAndDown || dir == ArpDirection::DownAndUp) && range > 1) { // imagine, we had to play the arp once up and then // once down -> makes 2 * range possible notes... @@ -456,19 +451,6 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) cur_arp_idx = range - cur_arp_idx % ( range - 1 ) - 1; } } - else if( dir == ArpDirection::DownAndUp && range > 1 ) - { - // copied from ArpDirection::UpAndDown above - cur_arp_idx = ( cur_frame / arp_frames ) % ( range * 2 - 2 ); - // if greater than range, we have to play down... - // looks like the code for arp_dir==DOWN... :) - if( cur_arp_idx >= range ) - { - cur_arp_idx = range - cur_arp_idx % ( range - 1 ) - 1; - } - // inverts direction - cur_arp_idx = range - cur_arp_idx - 1; - } else if( dir == ArpDirection::Random ) { // just pick a random chord-index @@ -485,6 +467,12 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) cur_arp_idx %= static_cast( range / m_arpRepeatsModel.value() ); } + // If ArpDirection::Down or ArpDirection::DownAndUp, invert the final range. + if (dir == ArpDirection::Down || dir == ArpDirection::DownAndUp) + { + cur_arp_idx = static_cast(range) - cur_arp_idx - 1; + } + // now calculate final key for our arp-note const int sub_note_key = base_note_key + (cur_arp_idx / cur_chord_size ) * KeysPerOctave + chord_table.chords()[selected_arp][cur_arp_idx % cur_chord_size];