Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VinylControlControl: Use mixxx::audio::FramePos internally #4079

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/engine/controls/vinylcontrolcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,34 @@ void VinylControlControl::slotControlVinylSeek(double fractionalPos) {
return;
}

double total_samples = getSampleOfTrack().total;
double new_playpos = round(fractionalPos * total_samples);
const auto trackEndPosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
getSampleOfTrack().total);
if (!trackEndPosition.isValid()) {
return;
}
const auto newPlayPos = trackEndPosition * fractionalPos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newPlayPos = kStartFramePos + (trackEndPosition - kStartFramePos) * fractionalPos;?

I suppose there are much more spots where positions and offsets/distances are used confused. Those could only be detected and fixed by introducing a distinct type for FrameDiff_t.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (m_pControlVinylEnabled->get() > 0.0 && m_pControlVinylMode->get() == MIXXX_VCMODE_RELATIVE) {
int cuemode = (int)m_pControlVinylCueing->get();

//if in preroll, always seek
if (new_playpos < 0) {
seekExact(new_playpos);
if (newPlayPos < mixxx::audio::kStartFramePos) {
seekExact(newPlayPos.toEngineSamplePos());
return;
}

switch (cuemode) {
case MIXXX_RELATIVE_CUE_OFF:
return; // If off, do nothing.
case MIXXX_RELATIVE_CUE_ONECUE:
case MIXXX_RELATIVE_CUE_ONECUE: {
//if onecue, just seek to the regular cue
seekExact(pTrack->getCuePoint().getPosition());
const mixxx::audio::FramePos mainCuePosition = pTrack->getMainCuePosition();
if (mainCuePosition.isValid()) {
seekExact(mainCuePosition.toEngineSamplePos());
}
return;
}
case MIXXX_RELATIVE_CUE_HOTCUE:
// Continue processing in this function.
break;
Expand All @@ -116,8 +125,8 @@ void VinylControlControl::slotControlVinylSeek(double fractionalPos) {
return;
}

double shortest_distance = 0;
double nearest_playpos = -1;
mixxx::audio::FrameDiff_t shortestDistance = 0;
mixxx::audio::FramePos nearestPlayPos;

const QList<CuePointer> cuePoints(pTrack->getCuePoints());
QListIterator<CuePointer> it(cuePoints);
Expand All @@ -127,32 +136,34 @@ void VinylControlControl::slotControlVinylSeek(double fractionalPos) {
continue;
}

double cue_position = pCue->getPosition().toEngineSamplePosMaybeInvalid();
// pick cues closest to new_playpos
if ((nearest_playpos == -1) ||
(fabs(new_playpos - cue_position) < shortest_distance)) {
nearest_playpos = cue_position;
shortest_distance = fabs(new_playpos - cue_position);
const mixxx::audio::FramePos cuePosition = pCue->getPosition();
if (!cuePosition.isValid()) {
continue;
}
// pick cues closest to newPlayPos
if (!nearestPlayPos.isValid() || (fabs(newPlayPos - cuePosition) < shortestDistance)) {
nearestPlayPos = cuePosition;
shortestDistance = fabs(newPlayPos - cuePosition);
}
}

if (nearest_playpos == -1) {
if (new_playpos >= 0) {
if (!nearestPlayPos.isValid()) {
if (newPlayPos >= mixxx::audio::kStartFramePos) {
//never found an appropriate cue, so don't seek?
return;
}
//if negative, allow a seek by falling down to the bottom
} else {
m_bSeekRequested = true;
seekExact(nearest_playpos);
seekExact(nearestPlayPos.toEngineSamplePos());
m_bSeekRequested = false;
return;
}
}

// Just seek where it wanted to originally.
m_bSeekRequested = true;
seekExact(new_playpos);
seekExact(newPlayPos.toEngineSamplePos());
m_bSeekRequested = false;
}

Expand Down