Skip to content

Commit

Permalink
movement - w (#130)
Browse files Browse the repository at this point in the history
* make LeftEdge() and RightEdge() const

* FocusCursor() convenience function

* use FocusCursor

* log msg

* fix frame_.radius != radius_

* actual KEY_W functionality

* fix DOWNLOAD_CACHE_VERSION and check .ccache
  • Loading branch information
wang-edward authored Dec 25, 2024
1 parent 9a985b2 commit 0c1f718
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
12 changes: 7 additions & 5 deletions include/core/timeline.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ struct Timeline {
struct BeatWindow {
float start;
float len;
float LeftEdge() {return start;}
float RightEdge() {return start + len;}
float LeftEdge() const {return start;}
float RightEdge() const {return start + len;}
};

struct BeatFrame {
float center;
float radius;
float LeftEdge() {return center - radius;}
float RightEdge() {return center + radius;}
float Width() {return radius * 2;}
float LeftEdge() const {return center - radius;}
float RightEdge() const {return center + radius;}
float Width() const {return radius * 2;}
BeatFrame(float c, float &r): center{c}, radius{r} {}
};

Expand Down Expand Up @@ -57,6 +57,8 @@ struct Timeline {
Timeline();
~Timeline();

void FocusCursor();

void Render(Interface& interface);
void HandleEvent(const Event& event);
private:
Expand Down
51 changes: 40 additions & 11 deletions src/core/timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ void Timeline:: print_timeline()
}
}

void Timeline:: FocusCursor()
{
assert(cursor_.len < frame_.Width());
if (cursor_.LeftEdge() < frame_.LeftEdge())
{
const float diff = frame_.LeftEdge() - cursor_.LeftEdge();
frame_.center -= diff;
}
else if (cursor_.RightEdge() > frame_.RightEdge())
{
const float diff = cursor_.RightEdge() - frame_.RightEdge();
frame_.center += diff;
}
}

void Timeline:: HandleEvent(const Event &event)
{
switch (screen_state_)
Expand All @@ -299,20 +314,12 @@ void Timeline:: HandleEvent(const Event &event)
case KEY_H:
cursor_.start -= step_size_;
LOG_VAR(cursor_.LeftEdge() < frame_.LeftEdge());
if (cursor_.LeftEdge() < frame_.LeftEdge())
{
const float diff = frame_.LeftEdge() - cursor_.LeftEdge();
frame_.center -= diff;
}
FocusCursor();
break;
case KEY_L:
cursor_.start += step_size_;
LOG_VAR(cursor_.RightEdge() > frame_.RightEdge());
if (cursor_.RightEdge() > frame_.RightEdge())
{
const float diff = cursor_.RightEdge() - frame_.RightEdge();
frame_.center += diff;
}
FocusCursor();
break;
case KEY_J:
if (!APP->edit_.getTransport().isRecording())
Expand Down Expand Up @@ -347,6 +354,26 @@ void Timeline:: HandleEvent(const Event &event)
APP->AddTrack();
}
break;
case KEY_W:
{
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_W found NONE");
}
else
{
if (auto clip = dynamic_cast<te::Clip*>(item))
{
cursor_.start = clip->getStartBeat().inBeats();
FocusCursor();
}
}
}
break;
case KEY_D:
{
const te::TempoSequence &tempo = APP->edit_.tempoSequence;
Expand All @@ -355,7 +382,7 @@ void Timeline:: HandleEvent(const Event &event)
te::TrackItem *item = APP->CurrTrack().base_.getNextTrackItemAt(pos);
if (item == nullptr)
{
LOG_MSG("NONE");
LOG_MSG("KEY_D found NONE");
}
else
{
Expand Down Expand Up @@ -452,9 +479,11 @@ void Timeline:: HandleEvent(const Event &event)
break;
case KEY_MINUS:
radius_ *= 2;
frame_.radius *= 2; // TODO centralize this
break;
case KEY_EQUAL:
radius_ /= 2;
frame_.radius /= 2; // TODO centralize this
break;
}
break;
Expand Down

0 comments on commit 0c1f718

Please sign in to comment.