Skip to content

Commit

Permalink
movement - e (#145)
Browse files Browse the repository at this point in the history
* rename FocusCursor() and add CursorAlignGrid()

* add movement - e
  • Loading branch information
wang-edward authored Jan 4, 2025
1 parent 02a4cde commit 963e915
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/core/timeline.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ struct Timeline
Timeline();
~Timeline();

void FocusCursor();
void CursorFocus();
void CursorAlignGrid();

void Render(Interface &interface);
void HandleEvent(const Event &event);
Expand Down
35 changes: 31 additions & 4 deletions src/core/timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void Timeline::print_timeline()
}
}

void Timeline::FocusCursor()
void Timeline::CursorFocus()
{
assert(cursor_.len < frame_.Width());
if (cursor_.LeftEdge() < frame_.LeftEdge())
Expand All @@ -292,6 +292,11 @@ void Timeline::FocusCursor()
}
}

void Timeline::CursorAlignGrid()
{
cursor_.start = std::floor(cursor_.start / bar_width_) * bar_width_;
}

void Timeline::HandleEvent(const Event &event)
{
switch (screen_state_)
Expand All @@ -308,12 +313,12 @@ void Timeline::HandleEvent(const Event &event)
case KEY_H:
cursor_.start -= step_size_;
LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge());
FocusCursor();
CursorFocus();
break;
case KEY_L:
cursor_.start += step_size_;
LOG_VAR(cursor_.RightEdge() > frame_.RightEdge());
FocusCursor();
CursorFocus();
break;
case KEY_J:
if (!APP->edit_.getTransport().isRecording())
Expand Down Expand Up @@ -362,7 +367,29 @@ void Timeline::HandleEvent(const Event &event)
if (auto clip = dynamic_cast<te::Clip *>(item))
{
cursor_.start = clip->getStartBeat().inBeats();
FocusCursor();
CursorFocus();
CursorAlignGrid();
}
}
}
break;
case KEY_E:
{
const te::TempoSequence &tempo = APP->edit_.tempoSequence;
auto pos = tempo.toTime(te::BeatPosition::fromBeats(cursor_.RightEdge()));

te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos);
if (item == nullptr)
{
LOG_MSG("KEY_E found NONE");
}
else
{
if (auto clip = dynamic_cast<te::Clip *>(item))
{
cursor_.start = clip->getEndBeat().inBeats();
CursorFocus();
CursorAlignGrid();
}
}
}
Expand Down

0 comments on commit 963e915

Please sign in to comment.