-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enhance precision of track duration #970
Changes from 5 commits
4e82485
b0debc7
8ce8f1f
1d8d933
db2e002
99f990a
c160ca9
86c9a63
b762633
1070a48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
#define kConfigKey "[Auto DJ]" | ||
const char* kTransitionPreferenceName = "Transition"; | ||
const int kTransitionPreferenceDefault = 10; | ||
const double kTransitionPreferenceDefault = 10.0; | ||
|
||
static const bool sDebug = false; | ||
|
||
|
@@ -73,7 +73,7 @@ AutoDJProcessor::AutoDJProcessor(QObject* pParent, | |
m_pPlayerManager(pPlayerManager), | ||
m_pAutoDJTableModel(NULL), | ||
m_eState(ADJ_DISABLED), | ||
m_iTransitionTime(kTransitionPreferenceDefault), | ||
m_transitionTime(kTransitionPreferenceDefault), | ||
m_nextTransitionTime(kTransitionPreferenceDefault) { | ||
m_pAutoDJTableModel = new PlaylistTableModel(this, pTrackCollection, | ||
"mixxx.db.model.autodj"); | ||
|
@@ -123,8 +123,8 @@ AutoDJProcessor::AutoDJProcessor(QObject* pParent, | |
QString str_autoDjTransition = m_pConfig->getValueString( | ||
ConfigKey(kConfigKey, kTransitionPreferenceName)); | ||
if (!str_autoDjTransition.isEmpty()) { | ||
m_iTransitionTime = str_autoDjTransition.toInt(); | ||
m_nextTransitionTime = m_iTransitionTime; | ||
m_transitionTime = str_autoDjTransition.toDouble(); | ||
m_nextTransitionTime = m_transitionTime; | ||
} | ||
} | ||
|
||
|
@@ -707,37 +707,35 @@ void AutoDJProcessor::calculateTransition(DeckAttributes* pFromDeck, | |
if (fromTrack) { | ||
// TODO(rryan): Duration is super inaccurate! We should be using | ||
// track_samples / track_samplerate instead. | ||
int fromTrackDuration = fromTrack->getDuration(); | ||
double fromTrackDuration = fromTrack->getDuration(); | ||
qDebug() << fromTrack->getLocation() | ||
<< "fromTrackDuration =" << fromTrackDuration; | ||
|
||
// The track might be shorter than the transition period. Use a | ||
// sensible cap. | ||
m_nextTransitionTime = math_min(m_iTransitionTime, | ||
fromTrackDuration / 2); | ||
m_nextTransitionTime = math_min(m_transitionTime, | ||
fromTrackDuration / 2.0); | ||
|
||
if (pToDeck) { | ||
TrackPointer toTrack = pToDeck->getLoadedTrack(); | ||
if (toTrack) { | ||
// TODO(rryan): Duration is super inaccurate! We should be using | ||
// track_samples / track_samplerate instead. | ||
int toTrackDuration = toTrack->getDuration(); | ||
double toTrackDuration = toTrack->getDuration(); | ||
qDebug() << toTrack->getLocation() | ||
<< "toTrackDuration = " << toTrackDuration; | ||
m_nextTransitionTime = math_min(m_nextTransitionTime, | ||
toTrackDuration / 2); | ||
toTrackDuration / 2.0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same here |
||
} | ||
} | ||
|
||
if (fromTrackDuration > 0) { | ||
pFromDeck->fadeDuration = | ||
static_cast<double>(m_nextTransitionTime) / | ||
static_cast<double>(fromTrackDuration); | ||
if (fromTrackDuration > 0.0) { | ||
pFromDeck->fadeDuration = m_nextTransitionTime / fromTrackDuration; | ||
} else { | ||
pFromDeck->fadeDuration = 0; | ||
pFromDeck->fadeDuration = 0.0; | ||
} | ||
|
||
if (m_nextTransitionTime > 0) { | ||
if (m_nextTransitionTime > 0.0) { | ||
pFromDeck->posThreshold = 1.0 - pFromDeck->fadeDuration; | ||
} else { | ||
// in case of pause transition | ||
|
@@ -826,7 +824,7 @@ void AutoDJProcessor::setTransitionTime(int time) { | |
// Update the transition time first. | ||
m_pConfig->set(ConfigKey(kConfigKey, kTransitionPreferenceName), | ||
ConfigValue(time)); | ||
m_iTransitionTime = time; | ||
m_transitionTime = time; | ||
|
||
// Then re-calculate fade thresholds for the decks. | ||
if (m_eState == ADJ_IDLE) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,15 +390,15 @@ void TrackDAO::addTracksPrepare() { | |
m_pQueryLibraryInsert->prepare("INSERT INTO library " | ||
"(" | ||
"artist,title,album,album_artist,year,genre,tracknumber,tracktotal,composer," | ||
"grouping,filetype,location,comment,url,duration,rating,key,key_id," | ||
"grouping,filetype,location,comment,url,duration,duration_real,rating,key,key_id," | ||
"bitrate,samplerate,cuepoint,bpm,replaygain,replaygain_peak,wavesummaryhex," | ||
"timesplayed,channels,mixxx_deleted,header_parsed," | ||
"beats_version,beats_sub_version,beats,bpm_lock," | ||
"keys_version,keys_sub_version,keys," | ||
"coverart_source,coverart_type,coverart_location,coverart_hash" | ||
") VALUES (" | ||
":artist,:title,:album,:album_artist,:year,:genre,:tracknumber,:tracktotal,:composer," | ||
":grouping,:filetype,:location,:comment,:url,:duration,:rating,:key,:key_id," | ||
":grouping,:filetype,:location,:comment,:url,:duration,:duration_real,:rating,:key,:key_id," | ||
":bitrate,:samplerate,:cuepoint,:bpm,:replaygain,:replaygain_peak,:wavesummaryhex," | ||
":timesplayed,:channels,:mixxx_deleted,:header_parsed," | ||
":beats_version,:beats_sub_version,:beats,:bpm_lock," | ||
|
@@ -465,7 +465,8 @@ namespace { | |
pTrackLibraryQuery->bindValue(":filetype", track.getType()); | ||
pTrackLibraryQuery->bindValue(":comment", track.getComment()); | ||
pTrackLibraryQuery->bindValue(":url", track.getURL()); | ||
pTrackLibraryQuery->bindValue(":duration", track.getDuration()); | ||
pTrackLibraryQuery->bindValue(":duration", track.getDurationInt()); | ||
pTrackLibraryQuery->bindValue(":duration_real", track.getDuration()); | ||
pTrackLibraryQuery->bindValue(":rating", track.getRating()); | ||
pTrackLibraryQuery->bindValue(":bitrate", track.getBitrate()); | ||
pTrackLibraryQuery->bindValue(":samplerate", track.getSampleRate()); | ||
|
@@ -1088,7 +1089,7 @@ bool setTrackUrl(const QSqlRecord& record, const int column, | |
|
||
bool setTrackDuration(const QSqlRecord& record, const int column, | ||
TrackPointer pTrack) { | ||
pTrack->setDuration(record.value(column).toInt()); | ||
pTrack->setDuration(record.value(column).toDouble()); | ||
return false; | ||
} | ||
|
||
|
@@ -1279,7 +1280,7 @@ TrackPointer TrackDAO::getTrackFromDB(TrackId trackId) const { | |
{ "rating", setTrackRating }, | ||
{ "comment", setTrackComment }, | ||
{ "url", setTrackUrl }, | ||
{ "duration", setTrackDuration }, | ||
{ "duration_real", setTrackDuration }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover |
||
{ "bitrate", setTrackBitrate }, | ||
{ "samplerate", setTrackSampleRate }, | ||
{ "cuepoint", setTrackCuePoint }, | ||
|
@@ -1542,6 +1543,7 @@ bool TrackDAO::updateTrack(Track* pTrack) { | |
"comment=:comment," | ||
"url=:url," | ||
"duration=:duration," | ||
"duration_real=:duration_real," | ||
"rating=:rating," | ||
"key=:key," | ||
"key_id=:key_id," | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ Result SoundSourceOpus::parseTrackMetadataAndCoverArt( | |
pTrackMetadata->setSampleRate(kSamplingRate); | ||
pTrackMetadata->setBitrate(op_bitrate(l_ptrOpusFile, -1) / 1000); | ||
pTrackMetadata->setDuration( | ||
op_pcm_total(l_ptrOpusFile, -1) / pTrackMetadata->getSampleRate()); | ||
double(op_pcm_total(l_ptrOpusFile, -1)) / double(pTrackMetadata->getSampleRate())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second cast is not required. I think we use static_cast() elsewhere |
||
|
||
bool hasDate = false; | ||
for (i = 0; i < l_ptrOpusTags->comments; ++i) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Pentium is able to divide a float by an integer. No need for .0 here.