Skip to content

Commit

Permalink
cursor row is locked when following
Browse files Browse the repository at this point in the history
selecting a pattern jumps to it when following
  • Loading branch information
stoneface86 committed Jul 7, 2021
1 parent b394ddc commit 31a49ea
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/trackerboy/engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Engine {
//
void halt();

void jump(int pattern);

//
// Lock the given channel. Channel is reloaded with music settings.
//
Expand Down
2 changes: 2 additions & 0 deletions include/trackerboy/engine/MusicRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MusicRuntime {

void unlock(RuntimeContext const& rc, ChType ch);

void jump(int pattern);

bool step(RuntimeContext const& rc, Frame &frame);

void repeatPattern(bool repeat);
Expand Down
6 changes: 6 additions & 0 deletions libtrackerboy/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ void Engine::halt() {
}
}

void Engine::jump(int pattern) {
if (mMusicContext) {
mMusicContext->jump(pattern);
}
}

void Engine::lock(ChType ch) {
if (mMusicContext) {
mMusicContext->lock(*mRc, ch);
Expand Down
5 changes: 5 additions & 0 deletions libtrackerboy/engine/MusicRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ void MusicRuntime::halt(RuntimeContext const &rc) {
haltChannels(rc);
}

void MusicRuntime::jump(int pattern) {
mOrderCounter = pattern;
mRowCounter = 0;
}

void MusicRuntime::lock(RuntimeContext const& rc, ChType ch) {
// do nothing if channel is already locked
if (mFlags.test(+ch)) {
Expand Down
7 changes: 7 additions & 0 deletions ui/core/audio/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ void Renderer::stepFromCursor() {
}
}

void Renderer::jumpToPattern(int pattern) {
if (mStream.isEnabled()) {
auto ctx = mContext.access();
ctx->engine.jump(pattern);
}
}

void Renderer::setPatternRepeat(bool repeat) {

if (mStream.isEnabled()) {
Expand Down
5 changes: 5 additions & 0 deletions ui/core/audio/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public slots:

void stepFromCursor();

//
// Jumps to the given pattern if currently playing music
//
void jumpToPattern(int pattern);

//
// Stop previewing an instrument, waveform or row.
//
Expand Down
16 changes: 14 additions & 2 deletions ui/core/model/PatternModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ PatternClip PatternModel::clip() {
// slots -------------------------------

void PatternModel::moveCursorRow(int amount, SelectMode mode) {
if (mPlaying && mFollowing) {
return;
}

if (mode == SelectionModify) {
selectCursor();
} else if (mode == SelectionRemove) {
Expand Down Expand Up @@ -221,6 +225,10 @@ void PatternModel::moveCursorTrack(int amount) {
}

void PatternModel::setCursorRow(int row) {
if (mPlaying && mFollowing) {
return;
}

CursorChangeFlags flags = CursorUnchanged;
setCursorRowImpl(row, flags);
emitIfChanged(flags);
Expand Down Expand Up @@ -319,7 +327,9 @@ void PatternModel::setCursorTrackImpl(int track, CursorChangeFlags &flags) {

void PatternModel::setCursor(PatternCursor const cursor) {
CursorChangeFlags flags = CursorUnchanged;
setCursorRowImpl(cursor.row, flags);
if (!(mPlaying && mFollowing)) {
setCursorRowImpl(cursor.row, flags);
}
setCursorColumnImpl(cursor.column, flags);
setCursorTrackImpl(cursor.track, flags);
emitIfChanged(flags);
Expand Down Expand Up @@ -357,7 +367,9 @@ void PatternModel::setTrackerCursor(int row, int pattern) {
if (changed) {
if (mFollowing) {
mDocument.orderModel().selectPattern(pattern);
setCursorRow(row);
CursorChangeFlags flags = CursorUnchanged;
setCursorRowImpl(row, flags);
emitIfChanged(flags);
}
emit trackerCursorChanged(row, pattern);
}
Expand Down
2 changes: 2 additions & 0 deletions ui/forms/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,8 @@ void MainWindow::setupUi() {
mContextMenuOrder.popup(pos);
});

connect(&mSidebar, &Sidebar::patternJumpRequested, &mRenderer, &Renderer::jumpToPattern);

// order actions
connect(&mActions[ActionSongOrderInsert], &QAction::triggered, this,
[this]() {
Expand Down
10 changes: 7 additions & 3 deletions ui/widgets/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ void PatternEditor::wheelEvent(QWheelEvent *evt) {
}

if (amount) {
mDocument->patternModel().moveCursorRow(amount);
auto &patternModel = mDocument->patternModel();
patternModel.moveCursorRow(amount);
}

evt->accept();
Expand All @@ -375,12 +376,15 @@ void PatternEditor::hscrollAction(int action) {
}

void PatternEditor::vscrollAction(int action) {

auto &patternModel = mDocument->patternModel();

switch (action) {
case QAbstractSlider::SliderSingleStepAdd:
mDocument->patternModel().moveCursorRow(1);
patternModel.moveCursorRow(1);
break;
case QAbstractSlider::SliderSingleStepSub:
mDocument->patternModel().moveCursorRow(-1);
patternModel.moveCursorRow(-1);
break;
default:
break;
Expand Down
12 changes: 11 additions & 1 deletion ui/widgets/Sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,17 @@ void Sidebar::currentChanged(QModelIndex const &current, QModelIndex const &prev

if (mDocument) {
mIgnoreSelect = true;
mDocument->orderModel().select(current.row(), current.column());
auto &orderModel = mDocument->orderModel();
auto &patternModel = mDocument->patternModel();
if (patternModel.isPlaying() && patternModel.isFollowing()) {
if (orderModel.currentPattern() != current.row()) {
// jump to this pattern instead of selecting it
emit patternJumpRequested(current.row());
}
orderModel.selectTrack(current.column());
} else {
orderModel.select(current.row(), current.column());
}
mIgnoreSelect = false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions ui/widgets/Sidebar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Sidebar : public QWidget {
signals:
void orderMenuRequested(QPoint const& pos);

void patternJumpRequested(int pattern);

private:

void currentIndexChanged(QModelIndex const& index);
Expand Down

0 comments on commit 31a49ea

Please sign in to comment.