summaryrefslogtreecommitdiffstats
path: root/src/library/export/engineprimeexportjob.cpp
diff options
context:
space:
mode:
authorAdam Szmigin <smidge@xsco.net>2023-06-23 23:16:52 +0100
committerAdam Szmigin <smidge@xsco.net>2023-06-23 23:16:52 +0100
commitab66ed6670e62d651ded088015a2cf0a00af1b0c (patch)
treeb5cee833f48d21a29df13481baa22f6f94c4b65b /src/library/export/engineprimeexportjob.cpp
parentd763be606148a1047522b21a8840d50d882cf1c2 (diff)
Update to libdjinterop 0.19.0enh/djinterop-0.19.0
Diffstat (limited to 'src/library/export/engineprimeexportjob.cpp')
-rw-r--r--src/library/export/engineprimeexportjob.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/library/export/engineprimeexportjob.cpp b/src/library/export/engineprimeexportjob.cpp
index d5db7057d6..840f4fa32c 100644
--- a/src/library/export/engineprimeexportjob.cpp
+++ b/src/library/export/engineprimeexportjob.cpp
@@ -18,7 +18,7 @@
#include "util/thread_affinity.h"
#include "waveform/waveformfactory.h"
-namespace el = djinterop::enginelibrary;
+namespace el = djinterop::engine;
namespace mixxx {
@@ -168,7 +168,9 @@ bool tryGetBeatgrid(BeatsPointer pBeats,
return true;
}
-void exportMetadata(djinterop::database* pDatabase,
+void exportMetadata(
+ djinterop::database* pDatabase,
+ const el::engine_version& dbVersion,
QHash<TrackId, int64_t>* pMixxxToEnginePrimeTrackIdMap,
TrackPointer pTrack,
const Waveform* pWaveform,
@@ -182,12 +184,11 @@ void exportMetadata(djinterop::database* pDatabase,
: djinterop::track_snapshot{};
snapshot.relative_path = relativePath.toStdString();
- // Note that the Engine Prime format has the scope for recording meta-data
- // about whether track was imported from an external database. However,
- // that meta-data only extends as far as other Engine Prime databases,
- // which Mixxx is not. So we do not set any import information on the
- // exported track.
snapshot.track_number = pTrack->getTrackNumber().toInt();
+ if (snapshot.track_number == 0) {
+ snapshot.track_number = djinterop::stdx::nullopt;
+ }
+
snapshot.duration = std::chrono::milliseconds{
static_cast<int64_t>(1000 * pTrack->getDuration())};
snapshot.bpm = pTrack->getBpm();
@@ -199,24 +200,14 @@ void exportMetadata(djinterop::database* pDatabase,
snapshot.comment = pTrack->getComment().toStdString();
snapshot.composer = pTrack->getComposer().toStdString();
snapshot.key = toDjinteropKey(pTrack->getKey());
- int64_t lastModifiedMillisSinceEpoch = 0;
- const QDateTime fileLastModified = pTrack->getFileInfo().lastModified();
- if (fileLastModified.isValid()) {
- // Only defined if valid
- lastModifiedMillisSinceEpoch = fileLastModified.toMSecsSinceEpoch();
- }
- std::chrono::system_clock::time_point lastModifiedAt{
- std::chrono::milliseconds{lastModifiedMillisSinceEpoch}};
- snapshot.last_modified_at = lastModifiedAt;
- snapshot.last_accessed_at = lastModifiedAt;
snapshot.bitrate = pTrack->getBitrate();
snapshot.rating = pTrack->getRating() * 20; // note rating is in range 0-100
snapshot.file_bytes = pTrack->getFileInfo().sizeInBytes();
// Frames used interchangeably with "samples" here.
const auto frameCount = static_cast<int64_t>(pTrack->getDuration() * pTrack->getSampleRate());
- snapshot.sampling = djinterop::sampling_info{
- static_cast<double>(pTrack->getSampleRate()), frameCount};
+ snapshot.sample_count = frameCount;
+ snapshot.sample_rate = pTrack->getSampleRate();
// Set track loudness.
// Note that the djinterop API method for setting loudness may be revised
@@ -229,16 +220,14 @@ void exportMetadata(djinterop::database* pDatabase,
// Set main cue-point.
mixxx::audio::FramePos cuePlayPos = pTrack->getMainCuePosition();
const auto cuePlayPosValue = cuePlayPos.isValid() ? cuePlayPos.value() : 0;
- snapshot.default_main_cue = cuePlayPosValue;
- snapshot.adjusted_main_cue = cuePlayPosValue;
+ snapshot.main_cue = cuePlayPosValue;
// Fill in beat grid.
BeatsPointer beats = pTrack->getBeats();
if (beats != nullptr) {
std::vector<djinterop::beatgrid_marker> beatgrid;
if (tryGetBeatgrid(beats, cuePlayPos, frameCount, &beatgrid)) {
- snapshot.default_beatgrid = beatgrid;
- snapshot.adjusted_beatgrid = beatgrid;
+ snapshot.beatgrid = beatgrid;
} else {
qWarning() << "Beats data exists but is invalid for track"
<< pTrack->getId() << "("
@@ -252,7 +241,7 @@ void exportMetadata(djinterop::database* pDatabase,
// Note that any existing hot cues on the track are kept in place, if Mixxx
// does not have a hot cue at that location.
const auto cues = pTrack->getCuePoints();
- snapshot.hot_cues.fill(djinterop::stdx::nullopt);
+ snapshot.hot_cues.resize(kMaxHotCues);
for (const CuePointer& pCue : cues) {
// We are only interested in hot cues.
if (pCue->getType() != CueType::HotCue) {
@@ -303,16 +292,15 @@ void exportMetadata(djinterop::database* pDatabase,
// Note also that the loops on any existing track are not modified here.
// Write waveform.
- // Note that writing a single waveform will automatically calculate an
- // overview waveform too.
if (pWaveform) {
- int64_t samplesPerEntry =
- el::required_waveform_samples_per_entry(pTrack->getSampleRate());
- int64_t externalWaveformSize = (frameCount + samplesPerEntry - 1) / samplesPerEntry;
+ djinterop::waveform_extents extents = dbVersion.is_v2_schema()
+ ? el::calculate_overview_waveform_extents(
+ frameCount, pTrack->getSampleRate())
+ : el::calculate_high_resolution_waveform_extents(frameCount, pTrack->getSampleRate());
std::vector<djinterop::waveform_entry> externalWaveform;
- externalWaveform.reserve(externalWaveformSize);
- for (int64_t i = 0; i < externalWaveformSize; ++i) {
- int64_t j = pWaveform->getDataSize() * i / externalWaveformSize;
+ externalWaveform.reserve(extents.size);
+ for (uint64_t i = 0; i < extents.size; ++i) {
+ uint64_t j = pWaveform->getDataSize() * i / extents.size;
externalWaveform.push_back({{pWaveform->getLow(j), kDefaultWaveformOpacity},
{pWaveform->getMid(j), kDefaultWaveformOpacity},
{pWaveform->getHigh(j), kDefaultWaveformOpacity}});
@@ -339,6 +327,7 @@ void exportMetadata(djinterop::database* pDatabase,
void exportTrack(
const QSharedPointer<EnginePrimeExportRequest> pRequest,
djinterop::database* pDatabase,
+ const el::engine_version& dbVersion,
QHash<TrackId, int64_t>* pMixxxToEnginePrimeTrackIdMap,
const TrackPointer pTrack,
const Waveform* pWaveform) {
@@ -355,6 +344,7 @@ void exportTrack(
// Export meta-data.
exportMetadata(pDatabase,
+ dbVersion,
pMixxxToEnginePrimeTrackIdMap,
pTrack,
pWaveform,
@@ -366,8 +356,12 @@ void exportCrate(
const QHash<TrackId, int64_t>& mixxxToEnginePrimeTrackIdMap,
const Crate& crate,
const QList<TrackId>& trackIds) {
- // Create a new crate as a sub-crate of the top-level Mixxx crate.
- auto extCrate = pExtRootCrate->create_sub_crate(crate.getName().toStdString());
+ // Create a new crate as a sub-crate of the top-level Mixxx crate, if one does not already exist.
+ auto crateName = crate.getName().toStdString();
+ const auto optionalExtCrate = pExtRootCrate->sub_crate_by_name(crateName);
+ auto extCrate = optionalExtCrate
+ ? *optionalExtCrate
+ : pExtRootCrate->create_sub_crate(crateName);
// Loop through all track ids in this crate and add.
for (const auto& trackId : trackIds) {
@@ -520,12 +514,18 @@ void EnginePrimeExportJob::run() {
// Ensure that the database exists, creating an empty one if not.
std::unique_ptr<djinterop::database> pDb;
+ el::engine_version dbVersion;
try {
bool created;
pDb = std::make_unique<djinterop::database>(el::create_or_load_database(
m_pRequest->engineLibraryDbDir.path().toStdString(),
m_pRequest->exportVersion,
- created));
+ created,
+ dbVersion));
+
+ if (!created) {
+ dbVersion = m_pRequest->exportVersion;
+ }
} catch (std::exception& e) {
qWarning() << "Failed to create/load database:" << e.what();
m_lastErrorMessage = e.what();
@@ -561,6 +561,7 @@ void EnginePrimeExportJob::run() {
try {
exportTrack(m_pRequest,
pDb.get(),
+ dbVersion,
&mixxxToEnginePrimeTrackIdMap,
m_pLastLoadedTrack,
m_pLastLoadedWaveform.get());