Skip to content

Commit

Permalink
improved backtrace note
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofsalvation committed Nov 28, 2024
1 parent ffb9c7c commit dbda84a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/tracker/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3262,25 +3262,36 @@ void Tracker::backtraceInstrument(pp_uint8 channelIncrement, bool currentPosOnly
PatternEditorTools::Position cursor = p->getCursor();
pp_int8 chan = cursor.channel + channelIncrement;
pp_int32 ins = -1;

// check current position
patternTools.setPosition( p->getPattern(), chan, cursor.row);
if ( patternTools.getNote() != 0 ){ ins = patternTools.getInstrument(); }

// backtrace last instrument on pattern-channel
for (pp_int32 i = cursor.row; i >= 0; i--)
{
patternTools.setPosition( p->getPattern(), chan, cursor.row);
if ( patternTools.getInstrument() != 0 ){
ins = patternTools.getInstrument();
break;
}
if( currentPosOnly ) return;
}
if( ins == -1 && !currentPosOnly ){
for (pp_int32 i = cursor.row; i >= 0; i--)
{
patternTools.setPosition( p->getPattern(), chan, i);
if ( patternTools.getNote() != 0 ){
ins = patternTools.getInstrument();
break;
}
if( currentPosOnly ) return;
}
}

// find future note if backtrace wasn't possible
if( ins == -1 && !currentPosOnly ){
for (pp_int32 i = cursor.row; i < p->getNumRows(); i++)
{
patternTools.setPosition( p->getPattern(), chan, i);
ins = patternTools.getInstrument();
if (ins != 0 ) break;
if( patternTools.getNote() != 0 ){
ins = patternTools.getInstrument();
break;
}
}
}

if( ins == -1 ) return;
getPatternEditor()->setCurrentInstrument(ins);
moduleEditor->setCurrentInstrumentIndex(ins-1);
Expand Down

0 comments on commit dbda84a

Please sign in to comment.