Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/library/preparefeature.cpp

Go to the documentation of this file.
00001 // preparefeature.cpp
00002 // Created 8/23/2009 by RJ Ryan (rryan@mit.edu)
00003 // Forked 11/11/2009 by Albert Santoni (alberts@mixxx.org)
00004 
00005 #include <QtDebug>
00006 
00007 #include "library/preparefeature.h"
00008 #include "library/librarytablemodel.h"
00009 #include "library/trackcollection.h"
00010 #include "dlgprepare.h"
00011 #include "widget/wlibrary.h"
00012 #include "widget/wlibrarysidebar.h"
00013 #include "mixxxkeyboard.h"
00014 #include "analyserqueue.h"
00015 
00016 const QString PrepareFeature::m_sPrepareViewName = QString("Prepare");
00017 
00018 PrepareFeature::PrepareFeature(QObject* parent,
00019                                ConfigObject<ConfigValue>* pConfig,
00020                                TrackCollection* pTrackCollection)
00021         : LibraryFeature(parent),
00022           m_pConfig(pConfig),
00023           m_pTrackCollection(pTrackCollection),
00024           m_pAnalyserQueue(NULL) {
00025 }
00026 
00027 PrepareFeature::~PrepareFeature() {
00028     // TODO(XXX) delete these
00029     //delete m_pLibraryTableModel;
00030     cleanupAnalyser();
00031 }
00032 
00033 QVariant PrepareFeature::title() {
00034     return tr("Analyze");
00035 }
00036 
00037 QIcon PrepareFeature::getIcon() {
00038     return QIcon(":/images/library/ic_library_prepare.png");
00039 }
00040 
00041 void PrepareFeature::bindWidget(WLibrarySidebar* sidebarWidget,
00042                                 WLibrary* libraryWidget,
00043                                 MixxxKeyboard* keyboard) {
00044     DlgPrepare* pPrepareView = new DlgPrepare(libraryWidget,
00045                                               m_pConfig,
00046                                               m_pTrackCollection);
00047     connect(pPrepareView, SIGNAL(loadTrack(TrackPointer)),
00048             this, SIGNAL(loadTrack(TrackPointer)));
00049     connect(pPrepareView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)),
00050             this, SIGNAL(loadTrackToPlayer(TrackPointer, QString)));
00051     connect(pPrepareView, SIGNAL(analyzeTracks(QList<int>)),
00052             this, SLOT(analyzeTracks(QList<int>)));
00053     connect(pPrepareView, SIGNAL(stopAnalysis()),
00054             this, SLOT(stopAnalysis()));
00055 
00056     connect(this, SIGNAL(analysisActive(bool)),
00057             pPrepareView, SLOT(analysisActive(bool)));
00058     connect(this, SIGNAL(trackAnalysisProgress(TrackPointer, int)),
00059             pPrepareView, SLOT(trackAnalysisProgress(TrackPointer, int)));
00060     connect(this, SIGNAL(trackAnalysisFinished(TrackPointer)),
00061             pPrepareView, SLOT(trackAnalysisFinished(TrackPointer)));
00062     pPrepareView->installEventFilter(keyboard);
00063 
00064     // Let the DlgPrepare know whether or not analysis is active.
00065     bool bAnalysisActive = m_pAnalyserQueue != NULL;
00066     emit(analysisActive(bAnalysisActive));
00067 
00068     libraryWidget->registerView(m_sPrepareViewName, pPrepareView);
00069 }
00070 
00071 TreeItemModel* PrepareFeature::getChildModel() {
00072     return &m_childModel;
00073 }
00074 
00075 void PrepareFeature::activate() {
00076     //qDebug() << "PrepareFeature::activate()";
00077     emit(switchToView(m_sPrepareViewName));
00078 }
00079 
00080 void PrepareFeature::activateChild(const QModelIndex& index) {
00081 }
00082 
00083 void PrepareFeature::onRightClick(const QPoint& globalPos) {
00084 }
00085 
00086 void PrepareFeature::onRightClickChild(const QPoint& globalPos,
00087                                             QModelIndex index) {
00088 }
00089 
00090 bool PrepareFeature::dropAccept(QUrl url) {
00091     return false;
00092 }
00093 
00094 bool PrepareFeature::dropAcceptChild(const QModelIndex& index, QUrl url) {
00095     return false;
00096 }
00097 
00098 bool PrepareFeature::dragMoveAccept(QUrl url) {
00099     return false;
00100 }
00101 
00102 bool PrepareFeature::dragMoveAcceptChild(const QModelIndex& index,
00103                                               QUrl url) {
00104     return false;
00105 }
00106 
00107 void PrepareFeature::onLazyChildExpandation(const QModelIndex &index){
00108     //Nothing to do because the childmodel is not of lazy nature.
00109 }
00110 
00111 void PrepareFeature::analyzeTracks(QList<int> trackIds) {
00112     if (m_pAnalyserQueue == NULL) {
00113         //Save the old BPM detection prefs setting (on or off)
00114         m_iOldBpmEnabled = m_pConfig->getValueString(ConfigKey("[BPM]","BPMDetectionEnabled")).toInt();
00115         //Force BPM detection to be on.
00116         m_pConfig->set(ConfigKey("[BPM]","BPMDetectionEnabled"), ConfigValue(1));
00117         //Note: this sucks... we should refactor the prefs/analyser to fix this hacky bit ^^^^.
00118 
00119         m_pAnalyserQueue = AnalyserQueue::createPrepareViewAnalyserQueue(m_pConfig);
00120 
00121         connect(m_pAnalyserQueue, SIGNAL(trackProgress(TrackPointer, int)),
00122                 this, SLOT(slotTrackAnalysisProgress(TrackPointer, int)));
00123         connect(m_pAnalyserQueue, SIGNAL(trackFinished(TrackPointer)),
00124                 this, SLOT(slotTrackAnalysisFinished(TrackPointer)));
00125         connect(m_pAnalyserQueue, SIGNAL(queueEmpty()),
00126                 this, SLOT(stopAnalysis()));
00127         emit(analysisActive(true));
00128     }
00129 
00130     foreach(int trackId, trackIds) {
00131         TrackPointer pTrack = m_pTrackCollection->getTrackDAO().getTrack(trackId);
00132         if (pTrack) {
00133             //qDebug() << this << "Queueing track for analysis" << pTrack->getLocation();
00134             m_pAnalyserQueue->queueAnalyseTrack(pTrack);
00135         }
00136     }
00137 }
00138 
00139 void PrepareFeature::slotTrackAnalysisProgress(TrackPointer pTrack, int progress) {
00140     //qDebug() << this << "trackAnalysisProgress" << pTrack->getInfo() << progress;
00141     emit(trackAnalysisProgress(pTrack, progress));
00142 }
00143 
00144 void PrepareFeature::slotTrackAnalysisFinished(TrackPointer pTrack) {
00145     //qDebug() << this << "trackAnalysisFinished" << pTrack->getInfo();
00146     emit(trackAnalysisFinished(pTrack));
00147 }
00148 
00149 void PrepareFeature::stopAnalysis() {
00150     //qDebug() << this << "stopAnalysis()";
00151     cleanupAnalyser();
00152     emit(analysisActive(false));
00153 }
00154 
00155 void PrepareFeature::cleanupAnalyser() {
00156     if (m_pAnalyserQueue != NULL) {
00157         delete m_pAnalyserQueue;
00158         m_pAnalyserQueue = NULL;
00159         //Restore old BPM detection setting for preferences...
00160         m_pConfig->set(ConfigKey("[BPM]","BPMDetectionEnabled"), ConfigValue(m_iOldBpmEnabled));
00161     }
00162 
00163 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines