Skip to content

Commit

Permalink
Looping/Beatjump: use seconds if track has no beats
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Mar 14, 2024
1 parent 1b63888 commit 514b71e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 52 deletions.
21 changes: 12 additions & 9 deletions src/engine/controls/loopingcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,15 +1228,18 @@ void LoopingControl::trackLoaded(TrackPointer pNewTrack) {

void LoopingControl::trackBeatsUpdated(mixxx::BeatsPointer pBeats) {
clearActiveBeatLoop();
m_pBeats = pBeats;
if (m_pBeats) {
LoopInfo loopInfo = m_loopInfo.getValue();
if (loopInfo.startPosition.isValid() && loopInfo.endPosition.isValid()) {
double loaded_loop_size = findBeatloopSizeForLoop(
loopInfo.startPosition, loopInfo.endPosition);
if (loaded_loop_size != -1) {
m_pCOBeatLoopSize->setAndConfirm(loaded_loop_size);
}
if (pBeats) {
m_pBeats = pBeats;
} else {
m_pBeats = getFake60BpmBeats();
}
// TODO All "if (m_pBeats)" checks are now obsolete actually...
LoopInfo loopInfo = m_loopInfo.getValue();
if (loopInfo.startPosition.isValid() && loopInfo.endPosition.isValid()) {
double loaded_loop_size = findBeatloopSizeForLoop(
loopInfo.startPosition, loopInfo.endPosition);
if (loaded_loop_size != -1) {
m_pCOBeatLoopSize->setAndConfirm(loaded_loop_size);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/engine/controls/loopingcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ class LoopingControl : public EngineControl {
void updateBeatLoopingControls();
bool currentLoopMatchesBeatloopSize(const LoopInfo& loopInfo) const;

// Fake beats that allow using looping/beatjump controls with no beats:
// one 'beat' = one second
mixxx::BeatsPointer getFake60BpmBeats() {
auto fakeBeats = mixxx::Beats::fromConstTempo(
frameInfo().sampleRate,
mixxx::audio::kStartFramePos,
mixxx::Bpm(60.0));
return fakeBeats;
}

// Given loop in and out points, determine if this is a beatloop of a particular
// size.
double findBeatloopSizeForLoop(mixxx::audio::FramePos startPosition,
Expand Down
22 changes: 0 additions & 22 deletions src/test/hotcuecontrol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,28 +1092,6 @@ TEST_F(HotcueControlTest, CueLoopWithSavedLoopToggles) {
EXPECT_TRUE(m_pLoopEnabled->toBool());
}

TEST_F(HotcueControlTest, CueLoopWithoutLoopOrBeats) {
createAndLoadFakeTrack();

EXPECT_DOUBLE_EQ(static_cast<double>(HotcueControl::Status::Empty), m_pHotcue1Enabled->get());
EXPECT_FALSE(mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pHotcue1Position->get())
.isValid());
EXPECT_FALSE(mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pHotcue1EndPosition->get())
.isValid());

m_pHotcue1CueLoop->set(1);
m_pHotcue1CueLoop->set(0);

EXPECT_DOUBLE_EQ(static_cast<double>(HotcueControl::Status::Set), m_pHotcue1Enabled->get());
EXPECT_FRAMEPOS_EQ_CONTROL(mixxx::audio::kStartFramePos, m_pHotcue1Position);
EXPECT_FALSE(mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pHotcue1EndPosition->get())
.isValid());
EXPECT_FALSE(m_pLoopEnabled->toBool());
}

TEST_F(HotcueControlTest, SavedLoopToggleDoesNotSeek) {
// Setup fake track with 120 bpm and calculate loop size
TrackPointer pTrack = loadTestTrackWithBpm(120.0);
Expand Down
21 changes: 0 additions & 21 deletions src/test/looping_control_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,6 @@ TEST_F(LoopingControlTest, LoopInButton_QuantizeDisabled) {
EXPECT_FRAMEPOS_EQ_CONTROL(mixxx::audio::FramePos{50}, m_pLoopStartPoint);
}

TEST_F(LoopingControlTest, LoopInButton_QuantizeEnabledNoBeats) {
m_pQuantizeEnabled->set(1);
m_pClosestBeat->set(-1);
m_pNextBeat->set(-1);
setCurrentPosition(mixxx::audio::FramePos{50});
m_pButtonLoopIn->set(1);
m_pButtonLoopIn->set(0);
EXPECT_FRAMEPOS_EQ_CONTROL(mixxx::audio::FramePos{50}, m_pLoopStartPoint);
}

TEST_F(LoopingControlTest, LoopInButton_AdjustLoopInPointOutsideLoop) {
m_pLoopStartPoint->set(mixxx::audio::FramePos{1000}.toEngineSamplePos());
m_pLoopEndPoint->set(mixxx::audio::FramePos{2000}.toEngineSamplePos());
Expand Down Expand Up @@ -289,17 +279,6 @@ TEST_F(LoopingControlTest, LoopOutButton_QuantizeDisabled) {
EXPECT_FRAMEPOS_EQ_CONTROL(mixxx::audio::FramePos{500}, m_pLoopEndPoint);
}

TEST_F(LoopingControlTest, LoopOutButton_QuantizeEnabledNoBeats) {
m_pQuantizeEnabled->set(1);
m_pClosestBeat->set(-1);
m_pNextBeat->set(-1);
setCurrentPosition(mixxx::audio::FramePos{500});
m_pLoopStartPoint->set(mixxx::audio::kStartFramePos.toEngineSamplePos());
m_pButtonLoopOut->set(1);
m_pButtonLoopOut->set(0);
EXPECT_FRAMEPOS_EQ_CONTROL(mixxx::audio::FramePos{500}, m_pLoopEndPoint);
}

TEST_F(LoopingControlTest, LoopOutButton_AdjustLoopOutPointOutsideLoop) {
m_pLoopStartPoint->set(mixxx::audio::FramePos{1000}.toEngineSamplePos());
m_pLoopEndPoint->set(mixxx::audio::FramePos{2000}.toEngineSamplePos());
Expand Down

0 comments on commit 514b71e

Please sign in to comment.