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

Refactor ArpDirection::Down and ArpDirection::DownAndUp #7007

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Changes from all 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
34 changes: 11 additions & 23 deletions src/core/InstrumentFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,42 +433,24 @@ 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...
// because we don't play the lower and upper notes
// twice, we have to subtract 2
cur_arp_idx = ( cur_frame / arp_frames ) % ( range * 2 - 2 );
cur_arp_idx = (cur_frame / arp_frames) % (range * 2 - (2 * static_cast<int>(m_arpRepeatsModel.value())));
// if greater than range, we have to play down...
// looks like the code for arp_dir==DOWN... :)
if( cur_arp_idx >= range )
if (cur_arp_idx >= range)
{
cur_arp_idx = range - cur_arp_idx % ( range - 1 ) - 1;
cur_arp_idx = range - cur_arp_idx % (range - 1) - static_cast<int>(m_arpRepeatsModel.value());
}
}
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
Expand All @@ -485,6 +467,12 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n )
cur_arp_idx %= static_cast<int>( 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<int>(range / m_arpRepeatsModel.value()) - 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];
Expand Down
Loading