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

AutoDj: Option to start the Crossfader centered so the track starts at full volume (default off). #13619

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
72 changes: 42 additions & 30 deletions src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ DeckAttributes::DeckAttributes(int index,
m_sampleRate(group, "track_samplerate"),
m_rateRatio(group, "rate_ratio"),
m_pPlayer(pPlayer) {
connect(m_pPlayer, &BaseTrackPlayer::newTrackLoaded,
this, &DeckAttributes::slotTrackLoaded);
connect(m_pPlayer, &BaseTrackPlayer::loadingTrack,
this, &DeckAttributes::slotLoadingTrack);
connect(m_pPlayer, &BaseTrackPlayer::playerEmpty,
this, &DeckAttributes::slotPlayerEmpty);
connect(m_pPlayer, &BaseTrackPlayer::newTrackLoaded, this, &DeckAttributes::slotTrackLoaded);
connect(m_pPlayer, &BaseTrackPlayer::loadingTrack, this, &DeckAttributes::slotLoadingTrack);
connect(m_pPlayer, &BaseTrackPlayer::playerEmpty, this, &DeckAttributes::slotPlayerEmpty);
m_playPos.connectValueChanged(this, &DeckAttributes::slotPlayPosChanged);
m_play.connectValueChanged(this, &DeckAttributes::slotPlayChanged);
m_introStartPos.connectValueChanged(this, &DeckAttributes::slotIntroStartPositionChanged);
Expand Down Expand Up @@ -91,7 +88,7 @@ void DeckAttributes::slotTrackLoaded(TrackPointer pTrack) {
}

void DeckAttributes::slotLoadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack) {
//qDebug() << "DeckAttributes::slotLoadingTrack";
// qDebug() << "DeckAttributes::slotLoadingTrack";
emit loadingTrack(this, pNewTrack, pOldTrack);
}

Expand Down Expand Up @@ -120,20 +117,17 @@ AutoDJProcessor::AutoDJProcessor(
m_eState(ADJ_DISABLED),
m_transitionProgress(0.0),
m_transitionTime(kTransitionPreferenceDefault) {
m_pAutoDJTableModel = new PlaylistTableModel(this, pTrackCollectionManager,
"mixxx.db.model.autodj");
m_pAutoDJTableModel = new PlaylistTableModel(this, pTrackCollectionManager, "mixxx.db.model.autodj");
m_pAutoDJTableModel->selectPlaylist(iAutoDJPlaylistId);
m_pAutoDJTableModel->select();

m_pShufflePlaylist = new ControlPushButton(
ConfigKey("[AutoDJ]", "shuffle_playlist"));
connect(m_pShufflePlaylist, &ControlPushButton::valueChanged,
this, &AutoDJProcessor::controlShuffle);
connect(m_pShufflePlaylist, &ControlPushButton::valueChanged, this, &AutoDJProcessor::controlShuffle);

m_pSkipNext = new ControlPushButton(
ConfigKey("[AutoDJ]", "skip_next"));
connect(m_pSkipNext, &ControlObject::valueChanged,
this, &AutoDJProcessor::controlSkipNext);
connect(m_pSkipNext, &ControlObject::valueChanged, this, &AutoDJProcessor::controlSkipNext);

m_pAddRandomTrack = new ControlPushButton(
ConfigKey("[AutoDJ]", "add_random_track"));
Expand All @@ -144,8 +138,7 @@ AutoDJProcessor::AutoDJProcessor(

m_pFadeNow = new ControlPushButton(
ConfigKey("[AutoDJ]", "fade_now"));
connect(m_pFadeNow, &ControlObject::valueChanged,
this, &AutoDJProcessor::controlFadeNow);
connect(m_pFadeNow, &ControlObject::valueChanged, this, &AutoDJProcessor::controlFadeNow);

m_pEnabledAutoDJ = new ControlPushButton(
ConfigKey("[AutoDJ]", "enabled"));
Expand Down Expand Up @@ -364,7 +357,7 @@ AutoDJProcessor::AutoDJError AutoDJProcessor::skipNext() {
TrackId leftId = pLeftDeck->getLoadedTrack()->getId();
TrackId rightId = pRightDeck->getLoadedTrack()->getId();
if (nextId == leftId || nextId == rightId) {
// One of the playing tracks is still on top of playlist, remove second item
// One of the playing tracks is still on top of playlist, remove second item
m_pAutoDJTableModel->removeTrack(m_pAutoDJTableModel->index(1, 0));
} else {
m_pAutoDJTableModel->removeTrack(m_pAutoDJTableModel->index(0, 0));
Expand Down Expand Up @@ -566,6 +559,8 @@ AutoDJProcessor::AutoDJError AutoDJProcessor::toggleAutoDJ(bool enable) {
setCrossfader(1.0);
}
}
m_crossfaderStartCenter = m_pConfig->getValue<bool>(ConfigKey(kConfigKey,
QStringLiteral("center_xfader_when_starting_xfade")));
davidlmorris marked this conversation as resolved.
Show resolved Hide resolved
emitAutoDJStateChanged(m_eState);
} else { // Disable Auto DJ
m_pEnabledAutoDJ->setAndConfirm(0.0);
Expand Down Expand Up @@ -660,7 +655,7 @@ void AutoDJProcessor::crossfaderChanged(double value) {
}

void AutoDJProcessor::playerPositionChanged(DeckAttributes* pAttributes,
double thisPlayPosition) {
double thisPlayPosition) {
// qDebug() << "player" << pAttributes->group << "PositionChanged(" << value << ")";
if (m_eState == ADJ_DISABLED) {
// nothing to do
Expand Down Expand Up @@ -832,6 +827,7 @@ void AutoDJProcessor::playerPositionChanged(DeckAttributes* pAttributes,
double crossfaderTarget;
if (m_eState == ADJ_LEFT_FADING) {
crossfaderTarget = 1.0;

} else if (m_eState == ADJ_RIGHT_FADING) {
crossfaderTarget = -1.0;
} else {
Expand Down Expand Up @@ -859,17 +855,28 @@ void AutoDJProcessor::playerPositionChanged(DeckAttributes* pAttributes,
double transitionProgress = (thisPlayPosition - thisDeck->fadeBeginPos) /
(thisDeck->fadeEndPos - thisDeck->fadeBeginPos);
double transitionStep = transitionProgress - m_transitionProgress;

if ((transitionProgress == 0.0) &&
(m_crossfaderStartCenter)) {
setCrossfader(0.0); // So we start at the mid point before we make any fader moves.
}
if (transitionStep > 0.0) {
// We have made progress.
// Backward seeks pause the transitions; forward seeks speed up
// the transitions. If there has been a seek beyond endPos, end
// the transition immediately.
double remainingCrossfader = crossfaderTarget - currentCrossfader;
double adjustment = remainingCrossfader /
(1.0 - m_transitionProgress) * transitionStep;
// we move the crossfader linearly with
// movements in this track's play position.
setCrossfader(currentCrossfader + adjustment);
if ((m_crossfaderStartCenter) &&
(transitionProgress <= ((thisDeck->fadeEndPos - thisDeck->fadeBeginPos) / 2))) {
// We want the cross fader to remain in the middle.
davidlmorris marked this conversation as resolved.
Show resolved Hide resolved
setCrossfader(0.0);
} else {
double remainingCrossfader = crossfaderTarget - currentCrossfader;
double adjustment = remainingCrossfader /
(1.0 - m_transitionProgress) * transitionStep;
// we move the crossfader linearly with
// movements in this track's play position.
setCrossfader(currentCrossfader + adjustment);
}
}
m_transitionProgress = transitionProgress;
// if we are at 1.0 here, we need an additional callback until the last
Expand All @@ -883,7 +890,8 @@ TrackPointer AutoDJProcessor::getNextTrackFromQueue() {
bool randomQueueEnabled = m_pConfig->getValue<bool>(
ConfigKey("[Auto DJ]", "EnableRandomQueue"));
int minAutoDJCrateTracks = m_pConfig->getValueString(
ConfigKey(kConfigKey, "RandomQueueMinimumAllowed")).toInt();
ConfigKey(kConfigKey, "RandomQueueMinimumAllowed"))
.toInt();
int tracksToAdd = minAutoDJCrateTracks - m_pAutoDJTableModel->rowCount();
// In case we start off with < minimum tracks
if (randomQueueEnabled && (tracksToAdd > 0)) {
Expand All @@ -892,7 +900,7 @@ TrackPointer AutoDJProcessor::getNextTrackFromQueue() {

while (true) {
TrackPointer nextTrack = m_pAutoDJTableModel->getTrack(
m_pAutoDJTableModel->index(0, 0));
m_pAutoDJTableModel->index(0, 0));

if (nextTrack) {
if (nextTrack->getFileInfo().checkFileExists()) {
Expand Down Expand Up @@ -971,9 +979,11 @@ bool AutoDJProcessor::removeTrackFromTopOfQueue(TrackPointer pTrack) {

void AutoDJProcessor::maybeFillRandomTracks() {
int minAutoDJCrateTracks = m_pConfig->getValueString(
ConfigKey(kConfigKey, "RandomQueueMinimumAllowed")).toInt();
ConfigKey(kConfigKey, "RandomQueueMinimumAllowed"))
.toInt();
bool randomQueueEnabled = (((m_pConfig->getValueString(
ConfigKey("[Auto DJ]", "EnableRandomQueue")).toInt())) == 1);
ConfigKey("[Auto DJ]", "EnableRandomQueue"))
.toInt())) == 1);

int tracksToAdd = minAutoDJCrateTracks - m_pAutoDJTableModel->rowCount();
if (randomQueueEnabled && (tracksToAdd > 0)) {
Expand Down Expand Up @@ -1343,6 +1353,7 @@ void AutoDJProcessor::calculateTransition(DeckAttributes* pFromDeck,
}

switch (m_transitionMode) {
// case TransitionMode::RadioFullIntroOutro:
case TransitionMode::FullIntroOutro: {
// Use the outro or intro length for the transition time, whichever is
// shorter. Let the full outro and intro play; do not cut off any part
Expand Down Expand Up @@ -1474,7 +1485,7 @@ void AutoDJProcessor::calculateTransition(DeckAttributes* pFromDeck,
startPoint = toDeckPositionSeconds;
}
useFixedFadeTime(pFromDeck, pToDeck, fromDeckPosition, fromDeckEndPosition, startPoint);
}
}
}

// These are expected to be a fraction of the track length.
Expand Down Expand Up @@ -1605,7 +1616,8 @@ void AutoDJProcessor::playerTrackLoaded(DeckAttributes* pDeck, TrackPointer pTra
}

void AutoDJProcessor::playerLoadingTrack(DeckAttributes* pDeck,
TrackPointer pNewTrack, TrackPointer pOldTrack) {
TrackPointer pNewTrack,
TrackPointer pOldTrack) {
if constexpr (sDebug) {
qDebug() << this << "playerLoadingTrack" << pDeck->group
<< "new:" << (pNewTrack ? pNewTrack->getLocation() : "(null)")
Expand Down Expand Up @@ -1675,7 +1687,7 @@ void AutoDJProcessor::setTransitionTime(int time) {

// Update the transition time first.
m_pConfig->set(ConfigKey(kConfigKey, kTransitionPreferenceName),
ConfigValue(time));
ConfigValue(time));
m_transitionTime = time;

// Then re-calculate fade thresholds for the decks.
Expand Down
2 changes: 2 additions & 0 deletions src/library/autodj/autodjprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ class AutoDJProcessor : public QObject {
double m_transitionProgress;
double m_transitionTime; // the desired value set by the user
TransitionMode m_transitionMode;
bool m_crossfaderStartCenter;

QList<DeckAttributes*> m_decks;


ControlProxy* m_pCOCrossfader;
Comment on lines 292 to 294
Copy link
Member

Choose a reason for hiding this comment

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

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think m_pCOCrossfader has anything to do with my code, other than I used it as a template for some of my changes. I think m_pCOCrossfader refers to #13303.

ControlProxy* m_pCOCrossfaderReverse;

Expand Down
8 changes: 8 additions & 0 deletions src/preferences/dialog/dlgprefautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void DlgPrefAutoDJ::slotUpdate() {
// Re-center the crossfader instantly when AutoDJ is disabled
CenterXfaderCheckBox->setChecked(m_pConfig->getValue(
ConfigKey("[Auto DJ]", "center_xfader_when_disabling"), false));

CrossfaderStartCenterCheckBox->setChecked(m_pConfig->getValue(
ConfigKey("[Auto DJ]", "center_xfader_when_starting_xfade"), false));

}

void DlgPrefAutoDJ::slotApply() {
Expand All @@ -81,8 +85,11 @@ void DlgPrefAutoDJ::slotApply() {

m_pConfig->setValue(ConfigKey("[Auto DJ]", "center_xfader_when_disabling"),
CenterXfaderCheckBox->isChecked());
m_pConfig->setValue(ConfigKey("[Auto DJ]", "center_xfader_when_starting_xfade"),
CrossfaderStartCenterCheckBox->isChecked());
}


void DlgPrefAutoDJ::slotResetToDefaults() {
MinimumAvailableSpinBox->setValue(20);

Expand All @@ -96,6 +103,7 @@ void DlgPrefAutoDJ::slotResetToDefaults() {
RandomQueueMinimumSpinBox->setValue(5);

CenterXfaderCheckBox->setChecked(false);
CrossfaderStartCenterCheckBox->setChecked(false);
}

void DlgPrefAutoDJ::slotToggleRequeueIgnore(int buttonState) {
Expand Down
23 changes: 22 additions & 1 deletion src/preferences/dialog/dlgprefautodjdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,27 @@
<widget class="QCheckBox" name="CenterXfaderCheckBox"/>
</item>

<item row="1" column="0">
<widget class="QLabel" name="CrossfaderStartCenterLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Set the Crossfader to the center as AutoDj starts a crossfade so the track starts at full volume</string>
</property>
<property name="buddy">
<cstring>CrossfaderStartCenterCheckBox</cstring>
</property>
</widget>
</item>

<item row="1" column="1">
<widget class="QCheckBox" name="CrossfaderStartCenterCheckBox"/>
</item>

<item row="0" column="2">
<spacer name="horizontalSpacerxfaderbehaviour">
<property name="orientation">
Expand All @@ -298,7 +319,7 @@
</spacer>
</item>

<item row="1" column="0" colspan="3">
<item row="2" column="0" colspan="3">
<widget class="QLabel" name="CenterXfaderHintText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
Expand Down
Loading