![]() |
Mixxx
|
00001 /*************************************************************************** 00002 playerinfo.cpp - Helper class to have easy access 00003 to a lot of data (singleton) 00004 ------------------- 00005 copyright : (C) 2007 by Wesley Stessens 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include <QMutexLocker> 00018 00019 #include "playerinfo.h" 00020 #include "controlobject.h" 00021 #include "controlobjectthread.h" 00022 #include "engine/enginexfader.h" 00023 00024 PlayerInfo::PlayerInfo() 00025 { 00026 int i; 00027 m_iNumDecks = ControlObject::getControl(ConfigKey("[Master]","num_decks"))->get(); 00028 00029 for (i = 1; i <= m_iNumDecks; i++) { 00030 QString chan = QString("[Channel%1]").arg(i); 00031 00032 m_listCOPlay[chan] = new ControlObjectThread(ControlObject::getControl(ConfigKey(chan, "play"))); 00033 m_listCOVolume[chan] = new ControlObjectThread(ControlObject::getControl(ConfigKey(chan, "volume"))); 00034 m_listCOOrientation[chan] = new ControlObjectThread(ControlObject::getControl(ConfigKey(chan, "orientation"))); 00035 m_listCOpregain[chan] = new ControlObjectThread(ControlObject::getControl(ConfigKey(chan, "pregain"))); 00036 } 00037 00038 m_COxfader = new ControlObjectThread(ControlObject::getControl(ConfigKey("[Master]","crossfader"))); 00039 } 00040 00041 PlayerInfo::~PlayerInfo() 00042 { 00043 int i; 00044 00045 00046 m_loadedTrackMap.clear(); 00047 00048 for (i = 1; i <= m_iNumDecks; i++) { 00049 QString chan = QString("[Channel%1]").arg(i); 00050 00051 delete m_listCOPlay[chan]; 00052 delete m_listCOVolume[chan]; 00053 delete m_listCOOrientation[chan]; 00054 delete m_listCOpregain[chan]; 00055 } 00056 00057 delete m_COxfader; 00058 } 00059 00060 PlayerInfo &PlayerInfo::Instance() 00061 { 00062 static PlayerInfo playerInfo; 00063 return playerInfo; 00064 } 00065 00066 TrackPointer PlayerInfo::getTrackInfo(QString group) 00067 { 00068 QMutexLocker locker(&m_mutex); 00069 00070 if (m_loadedTrackMap.contains(group)) { 00071 return m_loadedTrackMap[group]; 00072 } 00073 00074 return TrackPointer(); 00075 } 00076 00077 void PlayerInfo::setTrackInfo(QString group, TrackPointer track) 00078 { 00079 QMutexLocker locker(&m_mutex); 00080 m_loadedTrackMap[group] = track; 00081 } 00082 00083 int PlayerInfo::getCurrentPlayingDeck() 00084 { 00085 QMutexLocker locker(&m_mutex); 00086 int MaxVolume = 0; 00087 int MaxDeck = 0; 00088 int i; 00089 00090 00091 for (i = 1; i <= m_iNumDecks; i++) { 00092 QString chan = QString("[Channel%1]").arg(i); 00093 float fvol; 00094 float xfl, xfr, xfvol; 00095 float dvol; 00096 int orient; 00097 00098 if ( m_listCOPlay[chan]->get() == 0.0 ) 00099 continue; 00100 00101 if ( m_listCOpregain[chan]->get() <= 0.5 ) 00102 continue; 00103 00104 if ((fvol = m_listCOVolume[chan]->get()) == 0.0 ) 00105 continue; 00106 00107 EngineXfader::getXfadeGains(xfl, xfr, m_COxfader->get(), 1.0, 0.0); 00108 00109 // Orientation goes: left is 0, center is 1, right is 2. 00110 // Leave math out of it... 00111 orient = m_listCOOrientation[chan]->get(); 00112 if ( orient == 0 ) 00113 xfvol = xfl; 00114 else if ( orient == 2 ) 00115 xfvol = xfr; 00116 else 00117 xfvol = 1; 00118 00119 dvol = fvol * xfvol; 00120 if ( dvol > MaxVolume ) { 00121 MaxDeck = i; 00122 MaxVolume = dvol; 00123 } 00124 } 00125 00126 return MaxDeck; 00127 } 00128 00129 TrackPointer PlayerInfo::getCurrentPlayingTrack() 00130 { 00131 int deck = getCurrentPlayingDeck(); 00132 if ( deck ) { 00133 QString chan = QString("[Channel%1]").arg(deck); 00134 return getTrackInfo(chan); 00135 } 00136 00137 return TrackPointer(); 00138 } 00139