diff --git a/src/library/export/engineprimeexportjob.cpp b/src/library/export/engineprimeexportjob.cpp index 971099eeef1..7cabce4e73f 100644 --- a/src/library/export/engineprimeexportjob.cpp +++ b/src/library/export/engineprimeexportjob.cpp @@ -65,16 +65,6 @@ std::optional toDjinteropKey( return keyMap[key]; } -inline double playPosToSampleOffset(double playPos) { - // Play positions are twice the sample offset expected by libdjinterop. - return playPos / 2; -} - -inline double sampleOffsetToPlayPos(double sampleOffset) { - // Play positions are twice the sample offset expected by libdjinterop. - return sampleOffset * 2; -} - QString exportFile(const QSharedPointer pRequest, TrackPointer pTrack) { if (!pRequest->engineLibraryDbDir.exists()) { @@ -164,9 +154,9 @@ void exportMetadata(djinterop::database* pDatabase, snapshot.rating = pTrack->getRating() * 20; // note rating is in range 0-100 // Frames used interchangeably with "samples" here. - const auto sampleCount = static_cast(pTrack->getDuration() * pTrack->getSampleRate()); + const auto frameCount = static_cast(pTrack->getDuration() * pTrack->getSampleRate()); snapshot.sampling = djinterop::sampling_info{ - static_cast(pTrack->getSampleRate()), sampleCount}; + static_cast(pTrack->getSampleRate()), frameCount}; // Set track loudness. // Note that the djinterop API method for setting loudness may be revised @@ -177,10 +167,10 @@ void exportMetadata(djinterop::database* pDatabase, snapshot.average_loudness = pTrack->getReplayGain().getRatio(); // Set main cue-point. - double cuePlayPos = pTrack->getCuePoint().getPosition(); - double cueSampleOffset = playPosToSampleOffset(cuePlayPos); - snapshot.default_main_cue = cueSampleOffset; - snapshot.adjusted_main_cue = cueSampleOffset; + mixxx::audio::FramePos cuePlayPos = pTrack->getMainCuePosition(); + // FIXME: What if the cuePlayPos is invalid? + snapshot.default_main_cue = cuePlayPos.value(); + snapshot.adjusted_main_cue = cuePlayPos.value(); // Fill in beat grid. For now, assume a constant average BPM across // the whole track. Note that points in the track are specified as @@ -194,8 +184,7 @@ void exportMetadata(djinterop::database* pDatabase, // beginning of the track in 4-beat decrements to find the first beat // in the track that also aligns with the start of a bar. const auto firstBeatPlayPos = beats->firstBeat(); - const auto cueBeatPlayPos = beats->findClosestBeat( - mixxx::audio::FramePos::fromEngineSamplePos(cuePlayPos)); + const auto cueBeatPlayPos = beats->findClosestBeat(cuePlayPos); int numBeatsToCue = beats->numBeatsInRange(firstBeatPlayPos, cueBeatPlayPos); const auto firstBarAlignedBeatPlayPos = beats->findNBeatsFromPosition( cueBeatPlayPos, numBeatsToCue & ~0x3); @@ -203,15 +192,13 @@ void exportMetadata(djinterop::database* pDatabase, // We will treat the first bar-aligned beat as beat zero. Find the // number of beats from there until the end of the track in order to // correctly assign an index for the last beat. - const auto lastBeatPlayPos = - beats->findPrevBeat(mixxx::audio::FramePos::fromEngineSamplePos( - sampleOffsetToPlayPos(sampleCount))); + const auto lastBeatPlayPos = beats->findPrevBeat(mixxx::audio::kStartFramePos + frameCount); int numBeats = beats->numBeatsInRange(firstBarAlignedBeatPlayPos, lastBeatPlayPos); if (numBeats > 0) { std::vector beatgrid{ - {0, playPosToSampleOffset(firstBarAlignedBeatPlayPos.toEngineSamplePos())}, - {numBeats, playPosToSampleOffset(lastBeatPlayPos.toEngineSamplePos())}}; - beatgrid = el::normalize_beatgrid(std::move(beatgrid), sampleCount); + {0, firstBarAlignedBeatPlayPos.value()}, + {numBeats, lastBeatPlayPos.value()}}; + beatgrid = el::normalize_beatgrid(std::move(beatgrid), frameCount); snapshot.default_beatgrid = beatgrid; snapshot.adjusted_beatgrid = beatgrid; } else { @@ -248,7 +235,7 @@ void exportMetadata(djinterop::database* pDatabase, djinterop::hot_cue hotCue{}; hotCue.label = label.toStdString(); - hotCue.sample_offset = playPosToSampleOffset(pCue->getPosition().toEngineSamplePos()); + hotCue.sample_offset = pCue->getPosition().value(); auto color = mixxx::RgbColor::toQColor(pCue->getColor()); hotCue.color = djinterop::pad_color{ @@ -266,6 +253,8 @@ void exportMetadata(djinterop::database* pDatabase, // from a set of stored loops (and is easily overwritten), we do not export // it to the external database here. // + // TODO: This comment above is wrong, it does support saved loops now. + // // Note also that the loops on any existing track are not modified here. // Write waveform. @@ -274,7 +263,7 @@ void exportMetadata(djinterop::database* pDatabase, if (pWaveform) { int64_t samplesPerEntry = el::required_waveform_samples_per_entry(pTrack->getSampleRate()); - int64_t externalWaveformSize = (sampleCount + samplesPerEntry - 1) / samplesPerEntry; + int64_t externalWaveformSize = (frameCount + samplesPerEntry - 1) / samplesPerEntry; std::vector externalWaveform; externalWaveform.reserve(externalWaveformSize); for (int64_t i = 0; i < externalWaveformSize; ++i) {