Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/widget/wnumberpos.cpp

Go to the documentation of this file.
00001 // Tue Haste Andersen <haste@diku.dk>, (C) 2003
00002 
00003 #include <QTime>
00004 #include <math.h>
00005 
00006 #include "wnumberpos.h"
00007 #include "mathstuff.h"
00008 #include "controlobject.h"
00009 #include "controlobjectthreadwidget.h"
00010 #include "controlobjectthreadmain.h"
00011 
00012 WNumberPos::WNumberPos(const char * group, QWidget * parent)
00013         : WNumber(parent),
00014           m_dOldValue(0.0f),
00015           m_dTrackSamples(0.0),
00016           m_dTrackSampleRate(0.0f),
00017           m_bRemain(false) {
00018     m_qsText = "";
00019 
00020     m_pShowDurationRemaining = new ControlObjectThreadMain(ControlObject::getControl(ConfigKey("[Controls]", "ShowDurationRemaining")));
00021     connect(m_pShowDurationRemaining, SIGNAL(valueChanged(double)),
00022             this, SLOT(slotSetRemain(double)));
00023     slotSetRemain(m_pShowDurationRemaining->get());
00024 
00025     // TODO(xxx) possible unused m_pRateControl and m_pRateDirControl?
00026     m_pRateControl = new ControlObjectThreadWidget(
00027         ControlObject::getControl(ConfigKey(group, "rate")));
00028     m_pRateDirControl = new ControlObjectThreadWidget(
00029         ControlObject::getControl(ConfigKey(group, "rate_dir")));
00030 
00031     m_pTrackSamples = new ControlObjectThreadWidget(
00032         ControlObject::getControl(ConfigKey(group, "track_samples")));
00033     connect(m_pTrackSamples, SIGNAL(valueChanged(double)),
00034             this, SLOT(slotSetTrackSamples(double)));
00035     // Tell the CO to re-emit its value since we could be created after it was
00036     // set to a valid value.
00037     m_pTrackSamples->emitValueChanged();
00038 
00039     m_pTrackSampleRate = new ControlObjectThreadWidget(
00040         ControlObject::getControl(ConfigKey(group, "track_samplerate")));
00041     connect(m_pTrackSampleRate, SIGNAL(valueChanged(double)),
00042             this, SLOT(slotSetTrackSampleRate(double)));
00043     // Tell the CO to re-emit its value since we could be created after it was
00044     // set to a valid value.
00045     m_pTrackSampleRate->emitValueChanged();
00046 }
00047 
00048 WNumberPos::~WNumberPos() {
00049     delete m_pTrackSampleRate;
00050     delete m_pTrackSamples;
00051     delete m_pShowDurationRemaining;
00052     delete m_pRateControl;
00053     delete m_pRateDirControl;
00054 }
00055 
00056 void WNumberPos::mousePressEvent(QMouseEvent* pEvent) {
00057     bool leftClick = pEvent->buttons() & Qt::LeftButton;
00058 
00059     if (leftClick) {
00060         setRemain(!m_bRemain);
00061         m_pShowDurationRemaining->slotSet(m_bRemain ? 1.0f : 0.0f);
00062     }
00063 }
00064 
00065 void WNumberPos::slotSetTrackSamples(double dSamples) {
00066     m_dTrackSamples = dSamples;
00067     setValue(m_dOldValue);
00068 }
00069 
00070 void WNumberPos::slotSetTrackSampleRate(double dSampleRate) {
00071     m_dTrackSampleRate = dSampleRate;
00072     setValue(m_dOldValue);
00073 }
00074 
00075 void WNumberPos::setValue(double dValue) {
00076     m_dOldValue = dValue;
00077 
00078     double valueMillis = 0.0f;
00079     double durationMillis = 0.0f;
00080     if (m_dTrackSamples > 0 && m_dTrackSampleRate > 0) {
00081         //map midi value taking in to account 14 = 0 and 114 = 1
00082         double dDuration = m_dTrackSamples / m_dTrackSampleRate / 2.0;
00083         valueMillis = (dValue - 14) * 1000.0f * m_dTrackSamples / 2.0f / 100.0f / m_dTrackSampleRate;
00084         durationMillis = dDuration * 1000.0f;
00085         if (m_bRemain)
00086             valueMillis = math_max(durationMillis - valueMillis, 0.0f);
00087     }
00088 
00089     QString valueString;
00090     if (valueMillis >= 0) {
00091         QTime valueTime = QTime().addMSecs(valueMillis);
00092         valueString = valueTime.toString((valueTime.hour() >= 1) ? "hh:mm:ss.zzz" : "mm:ss.zzz");
00093     } else {
00094         QTime valueTime = QTime().addMSecs(0 - valueMillis);
00095         valueString = valueTime.toString((valueTime.hour() >= 1) ? "-hh:mm:ss.zzz" : "-mm:ss.zzz");
00096     }
00097 
00098     // The format string gives us one extra digit of millisecond precision than
00099     // we care about. Slice it off.
00100     valueString = valueString.left(valueString.length() - 1);
00101 
00102     m_pLabel->setText(QString("%1%2").arg(m_qsText).arg(valueString));
00103 }
00104 
00105 void WNumberPos::slotSetRemain(double remain) {
00106     setRemain(remain > 0.0f);
00107 }
00108 
00109 void WNumberPos::setRemain(bool bRemain)
00110 {
00111     m_bRemain = bRemain;
00112 
00113     // Shift display state between showing position and remaining
00114     if (m_bRemain)
00115         m_qsText = "-";
00116     else
00117         m_qsText = "";
00118 
00119     // Have the widget redraw itself with its current value.
00120     setValue(m_dOldValue);
00121 }
00122 
00123 
00124 
00125 
00126 
00127 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines