Skip to content

Commit

Permalink
left/right arrow with and without ctrl/command during playback moves …
Browse files Browse the repository at this point in the history
…from playback cursor location

- left/right arrow: move between beats
- left/right arrow + ctrl/command: move between measures
  • Loading branch information
22justinl committed Dec 16, 2023
1 parent 17bca49 commit 2a12b95
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,45 @@ void NotationActionController::move(MoveDirection direction, bool quickly)
return;
}

if (playbackController()->isPlaying()) {
// Use current playback location (instead of selection) to move
auto beat = playbackController()->currentBeat();
int targetBeatIdx = beat.beatIndex;
int targetMeasureIdx = beat.measureIndex;
int increment = (direction == MoveDirection::Right ? 1 : -1);

if (quickly) {
// Move to next/prev measure
targetBeatIdx = 0;
targetMeasureIdx += increment;
} else {
// Move to next/prev beat
targetBeatIdx += increment;
if (targetBeatIdx > beat.maxBeatIndex) {
// Next measure
targetBeatIdx = 0;
targetMeasureIdx += 1;
} else if (targetBeatIdx < 0) {
// Previous measure
targetBeatIdx = beat.maxBeatIndex;
targetMeasureIdx -= 1;
}
}

//Check invalid measure
if (targetMeasureIdx > beat.maxMeasureIndex) {
targetBeatIdx = beat.maxBeatIndex;
targetMeasureIdx = beat.maxMeasureIndex;
} else if (targetMeasureIdx < 0) {
targetBeatIdx = 0;
targetMeasureIdx = 0;
}

audio::msecs_t targetMs = playbackController()->beatToMilliseconds(targetMeasureIdx, targetBeatIdx);
playbackController()->seek(targetMs);
return;
}

if (selectedElement && selectedElement->isTextBase()) {
interaction->nudge(direction, quickly);
} else {
Expand Down

0 comments on commit 2a12b95

Please sign in to comment.