void AutoDJFeature::slotAddRandomTrack(bool) { int failedRetrieveAttempts = 0; // Get access to the auto-DJ playlist PlaylistDAO& playlistDao = m_pTrackCollection->getPlaylistDAO(); if (m_iAutoDJPlaylistId >= 0) { while (failedRetrieveAttempts < kMaxRetrieveAttempts) { // Get the ID of a randomly-selected track. TrackId trackId(m_autoDjCratesDao.getRandomTrackId()); if (trackId.isValid()) { // Get Track Information TrackPointer addedTrack = (m_pTrackCollection->getTrackDAO()).getTrack(trackId); if(addedTrack->exists()) { playlistDao.appendTrackToPlaylist(trackId, m_iAutoDJPlaylistId); m_pAutoDJView->onShow(); return; } else { qDebug() << "Track does not exist:" << addedTrack->getInfo() << addedTrack->getLocation(); } } failedRetrieveAttempts += 1; } // If we couldn't get a track from the crates , get one from the library qDebug () << "Could not load tracks from crates, attempting to load from library."; failedRetrieveAttempts = 0; while ( failedRetrieveAttempts < kMaxRetrieveAttempts ) { TrackId trackId(m_autoDjCratesDao.getRandomTrackIdFromLibrary(m_iAutoDJPlaylistId)); if (trackId.isValid()) { TrackPointer addedTrack = m_pTrackCollection->getTrackDAO().getTrack(trackId); if(addedTrack->exists()) { if(!addedTrack->getPlayCounter().isPlayed()) { playlistDao.appendTrackToPlaylist(trackId, m_iAutoDJPlaylistId); m_pAutoDJView->onShow(); return; } } else { qDebug() << "Track does not exist:" << addedTrack->getInfo() << addedTrack->getLocation(); } } failedRetrieveAttempts += 1; } } // If control reaches here it implies that we couldn't load track qDebug() << "Could not load random track."; }
void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) { //qDebug() << m_group << "CachingReaderWorker::loadTrack() lock acquired for load."; // Emit that a new track is loading, stops the current track emit(trackLoading()); ReaderStatusUpdate status; status.status = TRACK_NOT_LOADED; QString filename = pTrack->getLocation(); if (filename.isEmpty() || !pTrack->exists()) { // Must unlock before emitting to avoid deadlock qDebug() << m_group << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", unlocked reader lock"; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be found.").arg(filename))); return; } Mixxx::AudioSourceConfig audioSrcCfg; audioSrcCfg.setChannelCount(CachingReaderChunk::kChannels); m_pAudioSource = openAudioSourceForReading(pTrack, audioSrcCfg); if (m_pAudioSource.isNull()) { m_maxReadableFrameIndex = Mixxx::AudioSource::getMinFrameIndex(); // Must unlock before emitting to avoid deadlock qDebug() << m_group << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", file invalid, unlocked reader lock"; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be loaded.").arg(filename))); return; } // Initially assume that the complete content offered by audio source // is available for reading. Later if read errors occur this value will // be decreased to avoid repeated reading of corrupt audio data. m_maxReadableFrameIndex = m_pAudioSource->getMaxFrameIndex(); status.maxReadableFrameIndex = m_maxReadableFrameIndex; status.status = TRACK_LOADED; m_pReaderStatusFIFO->writeBlocking(&status, 1); // Clear the chunks to read list. CachingReaderChunkReadRequest request; while (m_pChunkReadRequestFIFO->read(&request, 1) == 1) { qDebug() << "Skipping read request for " << request.chunk->getIndex(); status.status = CHUNK_READ_INVALID; status.chunk = request.chunk; m_pReaderStatusFIFO->writeBlocking(&status, 1); } // Emit that the track is loaded. const SINT sampleCount = CachingReaderChunk::frames2samples( m_pAudioSource->getFrameCount()); emit(trackLoaded(pTrack, m_pAudioSource->getSamplingRate(), sampleCount)); }
void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) { //qDebug() << m_group << "CachingReaderWorker::loadTrack() lock acquired for load."; // Emit that a new track is loading, stops the current track emit(trackLoading()); ReaderStatusUpdate status; status.status = TRACK_NOT_LOADED; status.chunk = NULL; status.trackFrameCount = 0; QString filename = pTrack->getLocation(); if (filename.isEmpty() || !pTrack->exists()) { // Must unlock before emitting to avoid deadlock qDebug() << m_group << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", unlocked reader lock"; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be found.").arg(filename))); return; } Mixxx::AudioSourceConfig audioSrcCfg; audioSrcCfg.channelCountHint = kChunkChannels; m_pAudioSource = openAudioSourceForReading(pTrack, audioSrcCfg); if (m_pAudioSource.isNull()) { // Must unlock before emitting to avoid deadlock qDebug() << m_group << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", file invalid, unlocked reader lock"; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be loaded.").arg(filename))); return; } status.trackFrameCount = m_pAudioSource->getFrameCount(); status.status = TRACK_LOADED; m_pReaderStatusFIFO->writeBlocking(&status, 1); // Clear the chunks to read list. ChunkReadRequest request; while (m_pChunkReadRequestFIFO->read(&request, 1) == 1) { qDebug() << "Skipping read request for " << request.chunk->chunk_number; status.status = CHUNK_READ_INVALID; status.chunk = request.chunk; m_pReaderStatusFIFO->writeBlocking(&status, 1); } // Emit that the track is loaded. const SINT sampleCount = m_pAudioSource->getFrameCount() * kChunkChannels; emit(trackLoaded(pTrack, m_pAudioSource->getFrameRate(), sampleCount)); }
void CachingReaderWorker::loadTrack(TrackPointer pTrack) { //qDebug() << m_pGroup << "CachingReaderWorker::loadTrack() lock acquired for load."; // Emit that a new track is loading, stops the current track emit(trackLoading()); ReaderStatusUpdate status; status.status = TRACK_LOADED; status.chunk = NULL; status.trackNumSamples = 0; if (m_pCurrentSoundSource != NULL) { delete m_pCurrentSoundSource; m_pCurrentSoundSource = NULL; } m_iTrackNumSamples = 0; QString filename = pTrack->getLocation(); if (filename.isEmpty() || !pTrack->exists()) { // Must unlock before emitting to avoid deadlock qDebug() << m_pGroup << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", unlocked reader lock"; status.status = TRACK_NOT_LOADED; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be found.").arg(filename))); return; } m_pCurrentSoundSource = new SoundSourceProxy(pTrack); bool openSucceeded = (m_pCurrentSoundSource->open() == OK); //Open the song for reading unsigned int trackSampleRate = m_pCurrentSoundSource->getSampleRate(); m_iTrackNumSamples = status.trackNumSamples = m_pCurrentSoundSource->length(); if (!openSucceeded || m_iTrackNumSamples == 0 || trackSampleRate == 0) { // Must unlock before emitting to avoid deadlock qDebug() << m_pGroup << "CachingReaderWorker::loadTrack() load failed for\"" << filename << "\", file invalid, unlocked reader lock"; status.status = TRACK_NOT_LOADED; m_pReaderStatusFIFO->writeBlocking(&status, 1); emit(trackLoadFailed( pTrack, QString("The file '%1' could not be loaded.").arg(filename))); return; } m_pReaderStatusFIFO->writeBlocking(&status, 1); // Clear the chunks to read list. ChunkReadRequest request; while (m_pChunkReadRequestFIFO->read(&request, 1) == 1) { qDebug() << "Skipping read request for " << request.chunk->chunk_number; status.status = CHUNK_READ_INVALID; status.chunk = request.chunk; m_pReaderStatusFIFO->writeBlocking(&status, 1); } // Emit that the track is loaded. emit(trackLoaded(pTrack, trackSampleRate, m_iTrackNumSamples)); }