diff options
author | Uwe Klotz <uklotz@mixxx.org> | 2021-09-29 12:24:33 +0200 |
---|---|---|
committer | Uwe Klotz <uklotz@mixxx.org> | 2021-09-29 12:39:08 +0200 |
commit | 27be2267d2d58bc30cbde3b185662513e8bf74fb (patch) | |
tree | 1841060621b00426b87cdb3ab83b4973f3e9367f | |
parent | beaf5250357d5fc0da1f40f2bdd21c3ca62ba283 (diff) |
Beats: Unify behavior of scale()/translate() operations
Do not return a nullptr to avoid unintended crashes!
-rw-r--r-- | src/track/beatgrid.cpp | 8 | ||||
-rw-r--r-- | src/track/beatmap.cpp | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/track/beatgrid.cpp b/src/track/beatgrid.cpp index a63006511f..09b0c0eafd 100644 --- a/src/track/beatgrid.cpp +++ b/src/track/beatgrid.cpp @@ -257,9 +257,10 @@ mixxx::Bpm BeatGrid::getBpmAroundPosition(audio::FramePos position, int n) const } BeatsPointer BeatGrid::translate(audio::FrameDiff_t offset) const { - if (!isValid()) { + VERIFY_OR_DEBUG_ASSERT(isValid()) { return clone(); } + mixxx::track::io::BeatGrid grid = m_grid; const audio::FramePos newFirstBeatPosition = firstBeatPosition() + offset; grid.mutable_first_beat()->set_frame_position( @@ -270,6 +271,10 @@ BeatsPointer BeatGrid::translate(audio::FrameDiff_t offset) const { } BeatsPointer BeatGrid::scale(BpmScale scale) const { + VERIFY_OR_DEBUG_ASSERT(isValid()) { + return clone(); + } + mixxx::track::io::BeatGrid grid = m_grid; auto bpm = mixxx::Bpm(grid.bpm().bpm()); @@ -311,6 +316,7 @@ BeatsPointer BeatGrid::setBpm(mixxx::Bpm bpm) const { VERIFY_OR_DEBUG_ASSERT(bpm.isValid()) { return clone(); } + mixxx::track::io::BeatGrid grid = m_grid; grid.mutable_bpm()->set_bpm(bpm.value()); const mixxx::audio::FrameDiff_t beatLengthFrames = (60.0 * m_sampleRate / bpm.value()); diff --git a/src/track/beatmap.cpp b/src/track/beatmap.cpp index 5f80ddf435..fbf6ef493e 100644 --- a/src/track/beatmap.cpp +++ b/src/track/beatmap.cpp @@ -551,7 +551,7 @@ BeatsPointer BeatMap::translate(audio::FrameDiff_t offset) const { } BeatsPointer BeatMap::scale(BpmScale scale) const { - if (!isValid() || m_beats.isEmpty()) { + VERIFY_OR_DEBUG_ASSERT(isValid()) { return clone(); } @@ -599,8 +599,8 @@ BeatsPointer BeatMap::scale(BpmScale scale) const { } BeatsPointer BeatMap::setBpm(mixxx::Bpm bpm) const { - if (!isValid()) { - return {}; + VERIFY_OR_DEBUG_ASSERT(bpm.isValid()) { + return clone(); } const auto firstBeatPosition = mixxx::audio::FramePos(m_beats.first().frame_position()); |