Skip to content

Commit

Permalink
Merge pull request #4076 from Holzhaus/frame-refactor-autodj
Browse files Browse the repository at this point in the history
AutoDJProcessor: Return mixxx::audio::FramePos from DeckAttributes
  • Loading branch information
uklotzde authored Jul 8, 2021
2 parents 68edc11 + 7bf19d0 commit e19b1bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
48 changes: 24 additions & 24 deletions src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const char* kTransitionModePreferenceName = "TransitionMode";
const double kTransitionPreferenceDefault = 10.0;
const double kKeepPosition = -1.0;

const mixxx::audio::ChannelCount kChannelCount = mixxx::kEngineChannelCount;

static const bool sDebug = false;
} // anonymous namespace

Expand Down Expand Up @@ -1057,43 +1055,44 @@ void AutoDJProcessor::playerOutroEndChanged(DeckAttributes* pAttributes, double
}

double AutoDJProcessor::getIntroStartSecond(DeckAttributes* pDeck) {
double introStartSample = pDeck->introStartPosition();
if (introStartSample == Cue::kNoPosition) {
const mixxx::audio::FramePos introStartPosition = pDeck->introStartPosition();
if (!introStartPosition.isValid()) {
return getFirstSoundSecond(pDeck);
}
return samplePositionToSeconds(introStartSample, pDeck);
return framePositionToSeconds(introStartPosition, pDeck);
}

double AutoDJProcessor::getIntroEndSecond(DeckAttributes* pDeck) {
double introEndSample = pDeck->introEndPosition();
if (introEndSample == Cue::kNoPosition) {
const mixxx::audio::FramePos introEndPosition = pDeck->introEndPosition();
if (!introEndPosition.isValid()) {
// Assume a zero length intro if introEnd is not set.
// The introStart is automatically placed by AnalyzerSilence, so use
// that as a fallback if the user has not placed outroStart. If it has
// not been placed, getIntroStartPosition will return 0:00.
return getIntroStartSecond(pDeck);
}
return samplePositionToSeconds(introEndSample, pDeck);
return framePositionToSeconds(introEndPosition, pDeck);
}

double AutoDJProcessor::getOutroStartSecond(DeckAttributes* pDeck) {
double outroStartSample = pDeck->outroStartPosition();
if (outroStartSample == Cue::kNoPosition) {
const mixxx::audio::FramePos outroStartPosition = pDeck->outroStartPosition();
if (!outroStartPosition.isValid()) {
// Assume a zero length outro if outroStart is not set.
// The outroEnd is automatically placed by AnalyzerSilence, so use
// that as a fallback if the user has not placed outroStart. If it has
// not been placed, getOutroEndPosition will return the end of the track.
return getOutroEndSecond(pDeck);
}
return samplePositionToSeconds(outroStartSample, pDeck);
return framePositionToSeconds(outroStartPosition, pDeck);
}

double AutoDJProcessor::getOutroEndSecond(DeckAttributes* pDeck) {
double outroEndSample = pDeck->outroEndPosition();
if (outroEndSample == Cue::kNoPosition) {
const mixxx::audio::FramePos outroEndPosition = pDeck->outroEndPosition();
if (!outroEndPosition.isValid()) {
return getLastSoundSecond(pDeck);
}
return samplePositionToSeconds(outroEndSample, pDeck);;
return framePositionToSeconds(outroEndPosition, pDeck);
;
}

double AutoDJProcessor::getFirstSoundSecond(DeckAttributes* pDeck) {
Expand All @@ -1104,9 +1103,9 @@ double AutoDJProcessor::getFirstSoundSecond(DeckAttributes* pDeck) {

CuePointer pFromTrackAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound);
if (pFromTrackAudibleSound) {
double firstSound = pFromTrackAudibleSound->getPosition().toEngineSamplePosMaybeInvalid();
if (firstSound > 0.0) {
return samplePositionToSeconds(firstSound, pDeck);
const mixxx::audio::FramePos firstSound = pFromTrackAudibleSound->getPosition();
if (firstSound.isValid()) {
return framePositionToSeconds(firstSound, pDeck);
}
}
return 0.0;
Expand All @@ -1123,7 +1122,7 @@ double AutoDJProcessor::getLastSoundSecond(DeckAttributes* pDeck) {
Cue::StartAndEndPositions pos = pFromTrackAudibleSound->getStartAndEndPosition();
if (pos.endPosition > mixxx::audio::kStartFramePos &&
(pos.endPosition - pos.startPosition) > 0) {
return samplePositionToSeconds(pos.endPosition.toEngineSamplePosMaybeInvalid(), pDeck);
return framePositionToSeconds(pos.endPosition, pDeck);
}
}
return getEndSecond(pDeck);
Expand All @@ -1135,17 +1134,18 @@ double AutoDJProcessor::getEndSecond(DeckAttributes* pDeck) {
return 0.0;
}

double endSamplePosition = pDeck->trackSamples();
return samplePositionToSeconds(endSamplePosition, pDeck);
mixxx::audio::FramePos trackEndPosition = pDeck->trackEndPosition();
return framePositionToSeconds(trackEndPosition, pDeck);
}

double AutoDJProcessor::samplePositionToSeconds(double samplePosition, DeckAttributes* pDeck) {
samplePosition /= kChannelCount;
double AutoDJProcessor::framePositionToSeconds(
mixxx::audio::FramePos position, DeckAttributes* pDeck) {
mixxx::audio::SampleRate sampleRate = pDeck->sampleRate();
if (!sampleRate.isValid()) {
if (!sampleRate.isValid() || !position.isValid()) {
return 0.0;
}
return samplePosition / sampleRate / pDeck->rateRatio();

return position.value() / sampleRate / pDeck->rateRatio();
}

void AutoDJProcessor::calculateTransition(DeckAttributes* pFromDeck,
Expand Down
22 changes: 11 additions & 11 deletions src/library/autodj/autodjprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ class DeckAttributes : public QObject {
m_repeat.set(enabled ? 1.0 : 0.0);
}

double introStartPosition() const {
return m_introStartPos.get();
mixxx::audio::FramePos introStartPosition() const {
return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_introStartPos.get());
}

double introEndPosition() const {
return m_introEndPos.get();
mixxx::audio::FramePos introEndPosition() const {
return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_introEndPos.get());
}

double outroStartPosition() const {
return m_outroStartPos.get();
mixxx::audio::FramePos outroStartPosition() const {
return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_outroStartPos.get());
}

double outroEndPosition() const {
return m_outroEndPos.get();
mixxx::audio::FramePos outroEndPosition() const {
return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_outroEndPos.get());
}

mixxx::audio::SampleRate sampleRate() const {
return mixxx::audio::SampleRate::fromDouble(m_sampleRate.get());
}

double trackSamples() const {
return m_trackSamples.get();
mixxx::audio::FramePos trackEndPosition() const {
return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_trackSamples.get());
}

double rateRatio() const {
Expand Down Expand Up @@ -252,7 +252,7 @@ class AutoDJProcessor : public QObject {
double getFirstSoundSecond(DeckAttributes* pDeck);
double getLastSoundSecond(DeckAttributes* pDeck);
double getEndSecond(DeckAttributes* pDeck);
double samplePositionToSeconds(double samplePosition, DeckAttributes* pDeck);
double framePositionToSeconds(mixxx::audio::FramePos position, DeckAttributes* pDeck);

TrackPointer getNextTrackFromQueue();
bool loadNextTrackFromQueue(const DeckAttributes& pDeck, bool play = false);
Expand Down

0 comments on commit e19b1bf

Please sign in to comment.