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 Jul 8, 2024
1 parent 6900c41 commit c75a8b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "engraving/dom/note.h"
#include "engraving/dom/text.h"
#include "engraving/playback/playbackmodel.h"

#include "translation.h"
#include "log.h"
Expand Down Expand Up @@ -977,6 +978,33 @@ void NotationActionController::move(MoveDirection direction, bool quickly)
return;
}

if (playbackController()->isPlaying()) {
MeasureBeat beat = playbackController()->currentBeat();
int targetBeatIdx = beat.beatIndex;
int targetMeasureIdx = beat.measureIndex;
int increment = (direction == MoveDirection::Right ? 1 : -1);

const engraving::RepeatList& rl = currentMasterNotation()->masterScore()->repeatList(true);

if (quickly) {
targetBeatIdx = 0;
targetMeasureIdx += increment;
} else {
targetBeatIdx += increment;
if (targetBeatIdx > beat.maxBeatIndex) {
targetBeatIdx = 0;
targetMeasureIdx += 1;
} else if (targetBeatIdx < 0) {
targetBeatIdx = beat.maxBeatIndex;
targetMeasureIdx -= 1;
}
}
int targetTick = currentMasterNotation()->playback()->beatToTick(targetMeasureIdx, targetBeatIdx);
double targetSec = rl.utick2utime(rl.tick2utick(targetTick));
playbackController()->seek(targetSec);
break;
}

if (selectedElement && selectedElement->isTextBase()) {
interaction->nudge(direction, quickly);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/playback/internal/playbackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act

bool canReceiveAction(const muse::actions::ActionCode& code) const override;

void seek(const muse::audio::secs_t secs) override;
private:
muse::audio::IPlayerPtr currentPlayer() const;

Expand All @@ -131,7 +132,6 @@ class PlaybackController : public IPlaybackController, public muse::actions::Act
void updateCurrentTempo();

void seek(const muse::midi::tick_t tick);
void seek(const muse::audio::secs_t secs);

bool isPaused() const;
bool isLoaded() const;
Expand Down
2 changes: 2 additions & 0 deletions src/playback/iplaybackcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class IPlaybackController : MODULE_EXPORT_INTERFACE

virtual void setNotation(notation::INotationPtr notation) = 0;
virtual void setIsExportingAudio(bool exporting) = 0;

virtual void seek(const muse::audio::secs_t secs) = 0;
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/playback/tests/mocks/playbackcontrollermock.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class PlaybackControllerMock : public IPlaybackController

MOCK_METHOD(void, setNotation, (notation::INotationPtr), (override));
MOCK_METHOD(void, setIsExportingAudio, (bool), (override));

MOCK_METHOD(void, seek, (const muse::audio::secs_t), (override));
};
}

Expand Down

0 comments on commit c75a8b5

Please sign in to comment.