Skip to content

Commit

Permalink
Beats: Remove unnecessary capabilities
Browse files Browse the repository at this point in the history
We currently have two beats implementations (`BeatGrid` and `BeatMap`)
and both support scaling and translating. Hence, it's unnecessary to
maintain these flags. In fact, the `BEATSCAP_SCALE` capability wasn't
even checked in the calling code but nobody noticed because both support
it anyway.
  • Loading branch information
Holzhaus committed Jul 12, 2021
1 parent 0979e8e commit baa5fbd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
10 changes: 4 additions & 6 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ void BpmControl::slotTranslateBeatsEarlier(double v) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats &&
(pBeats->getCapabilities() & mixxx::Beats::BEATSCAP_TRANSLATE)) {
if (pBeats) {
const double sampleOffset = getSampleOfTrack().rate * -0.01;
const mixxx::audio::FrameDiff_t frameOffset = sampleOffset / mixxx::kEngineChannelCount;
pTrack->trySetBeats(pBeats->translate(frameOffset));
Expand All @@ -221,8 +220,7 @@ void BpmControl::slotTranslateBeatsLater(double v) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats &&
(pBeats->getCapabilities() & mixxx::Beats::BEATSCAP_TRANSLATE)) {
if (pBeats) {
// TODO(rryan): Track::getSampleRate is possibly inaccurate!
const double sampleOffset = getSampleOfTrack().rate * 0.01;
const mixxx::audio::FrameDiff_t frameOffset = sampleOffset / mixxx::kEngineChannelCount;
Expand Down Expand Up @@ -1043,7 +1041,7 @@ void BpmControl::slotBeatsTranslate(double v) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats && (pBeats->getCapabilities() & mixxx::Beats::BEATSCAP_TRANSLATE)) {
if (pBeats) {
const auto currentPosition =
mixxx::audio::FramePos::fromEngineSamplePos(
getSampleOfTrack().current)
Expand All @@ -1063,7 +1061,7 @@ void BpmControl::slotBeatsTranslateMatchAlignment(double v) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats && (pBeats->getCapabilities() & mixxx::Beats::BEATSCAP_TRANSLATE)) {
if (pBeats) {
// Must reset the user offset *before* calling getPhaseOffset(),
// otherwise it will always return 0 if master sync is active.
m_dUserOffset.setValue(0.0);
Expand Down
2 changes: 1 addition & 1 deletion src/track/beatgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BeatGrid final : public Beats {
// comments in beats.h

Beats::CapabilitiesFlags getCapabilities() const override {
return BEATSCAP_TRANSLATE | BEATSCAP_SCALE | BEATSCAP_SETBPM;
return BEATSCAP_SETBPM;
}

QByteArray toByteArray() const override;
Expand Down
3 changes: 1 addition & 2 deletions src/track/beatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class BeatMap final : public Beats {
const QVector<mixxx::audio::FramePos>& beats);

Beats::CapabilitiesFlags getCapabilities() const override {
return BEATSCAP_TRANSLATE | BEATSCAP_SCALE | BEATSCAP_ADDREMOVE |
BEATSCAP_MOVEBEAT;
return BEATSCAP_ADDREMOVE | BEATSCAP_MOVEBEAT;
}

QByteArray toByteArray() const override;
Expand Down
18 changes: 6 additions & 12 deletions src/track/beats.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ class Beats {
virtual ~Beats() = default;

enum Capabilities {
BEATSCAP_NONE = 0x0000,
BEATSCAP_NONE = 0,
/// Add or remove a single beat
BEATSCAP_ADDREMOVE = 0x0001,
/// Move all beat markers earlier or later
BEATSCAP_TRANSLATE = 0x0002,
/// Scale beat distance by a fixed ratio
BEATSCAP_SCALE = 0x0004,
BEATSCAP_ADDREMOVE = 1,
/// Move a single Beat
BEATSCAP_MOVEBEAT = 0x0008,
BEATSCAP_MOVEBEAT = 1 << 1,
/// Set new bpm, beat grid only
BEATSCAP_SETBPM = 0x0010
BEATSCAP_SETBPM = 1 << 2
};
/// Allows us to do ORing
typedef int CapabilitiesFlags;
Expand Down Expand Up @@ -153,12 +149,10 @@ class Beats {

/// Translate all beats in the song by `offset` frames. Beats that lie
/// before the start of the track or after the end of the track are *not*
/// removed. The `Beats` instance must have the capability
/// `BEATSCAP_TRANSLATE`.
/// removed.
virtual BeatsPointer translate(audio::FrameDiff_t offset) const = 0;

/// Scale the position of every beat in the song by `scale`. The `Beats`
/// class must have the capability `BEATSCAP_SCALE`.
/// Scale the position of every beat in the song by `scale`.
virtual BeatsPointer scale(BpmScale scale) const = 0;

/// Adjust the beats so the global average BPM matches `bpm`. The `Beats`
Expand Down

0 comments on commit baa5fbd

Please sign in to comment.