Skip to content

Commit

Permalink
Beats: Move deserialization logic from BeatFactory class
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Aug 19, 2021
1 parent 6ae4c0a commit 8299a06
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ bool setTrackBeats(const QSqlRecord& record, const int column, Track* pTrack) {
QString beatsSubVersion = record.value(column + 2).toString();
QByteArray beatsBlob = record.value(column + 3).toByteArray();
bool bpmLocked = record.value(column + 4).toBool();
const mixxx::BeatsPointer pBeats = BeatFactory::loadBeatsFromByteArray(
const mixxx::BeatsPointer pBeats = mixxx::Beats::fromByteArray(
pTrack->getSampleRate(), beatsVersion, beatsSubVersion, beatsBlob);
if (pBeats) {
if (bpmLocked) {
Expand Down
19 changes: 0 additions & 19 deletions src/track/beatfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@ const QString kRoundingVersion = QStringLiteral("V4");

} // namespace

mixxx::BeatsPointer BeatFactory::loadBeatsFromByteArray(
mixxx::audio::SampleRate sampleRate,
const QString& beatsVersion,
const QString& beatsSubVersion,
const QByteArray& beatsSerialized) {
if (beatsVersion == BEAT_GRID_1_VERSION ||
beatsVersion == BEAT_GRID_2_VERSION) {
auto pGrid = mixxx::BeatGrid::fromByteArray(sampleRate, beatsSubVersion, beatsSerialized);
qDebug() << "Successfully deserialized BeatGrid";
return pGrid;
} else if (beatsVersion == BEAT_MAP_VERSION) {
auto pMap = mixxx::BeatMap::fromByteArray(sampleRate, beatsSubVersion, beatsSerialized);
qDebug() << "Successfully deserialized BeatMap";
return pMap;
}
qDebug() << "BeatFactory::loadBeatsFromByteArray could not parse serialized beats.";
return mixxx::BeatsPointer();
}

mixxx::BeatsPointer BeatFactory::makeBeatGrid(
mixxx::audio::SampleRate sampleRate,
mixxx::Bpm bpm,
Expand Down
5 changes: 0 additions & 5 deletions src/track/beatfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ class Track;

class BeatFactory {
public:
static mixxx::BeatsPointer loadBeatsFromByteArray(
mixxx::audio::SampleRate sampleRate,
const QString& beatsVersion,
const QString& beatsSubVersion,
const QByteArray& beatsSerialized);
static mixxx::BeatsPointer makeBeatGrid(
mixxx::audio::SampleRate sampleRate,
mixxx::Bpm bpm,
Expand Down
30 changes: 30 additions & 0 deletions src/track/beats.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
#include "track/beats.h"

#include "track/beatgrid.h"
#include "track/beatmap.h"

namespace mixxx {

// static
mixxx::BeatsPointer Beats::fromByteArray(
mixxx::audio::SampleRate sampleRate,
const QString& beatsVersion,
const QString& beatsSubVersion,
const QByteArray& beatsSerialized) {
mixxx::BeatsPointer pBeats = nullptr;
if (beatsVersion == BEAT_GRID_1_VERSION || beatsVersion == BEAT_GRID_2_VERSION) {
pBeats = mixxx::BeatGrid::fromByteArray(sampleRate, beatsSubVersion, beatsSerialized);
} else if (beatsVersion == BEAT_MAP_VERSION) {
pBeats = mixxx::BeatMap::fromByteArray(sampleRate, beatsSubVersion, beatsSerialized);
} else {
qWarning().nospace() << "Failed to deserialize Beats (" << beatsVersion
<< "): Invalid beats version";
return nullptr;
}

if (!pBeats) {
qWarning().nospace() << "Failed to deserialize Beats (" << beatsVersion
<< "): Parsing failed";
return nullptr;
}

qDebug().nospace() << "Successfully deserialized Beats (" << beatsVersion << ")";
return pBeats;
}

int Beats::numBeatsInRange(audio::FramePos startPosition, audio::FramePos endPosition) const {
audio::FramePos lastPosition = audio::kStartFramePos;
int i = 1;
Expand Down
6 changes: 6 additions & 0 deletions src/track/beats.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Beats {
public:
virtual ~Beats() = default;

static mixxx::BeatsPointer fromByteArray(
mixxx::audio::SampleRate sampleRate,
const QString& beatsVersion,
const QString& beatsSubVersion,
const QByteArray& beatsSerialized);

enum class BpmScale {
Double,
Halve,
Expand Down

0 comments on commit 8299a06

Please sign in to comment.