Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/controlpotmeter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           controlpotmeter.cpp  -  description
00003                              -------------------
00004     begin                : Wed Feb 20 2002
00005     copyright            : (C) 2002 by Tue and Ken Haste Andersen
00006     email                :
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 ***************************************************************************/
00017 
00018 #include "controlpushbutton.h"
00019 #include "controlpotmeter.h"
00020 
00021 /* -------- ------------------------------------------------------
00022    Purpose: Creates a new potmeter
00023    Input:   n - name
00024             midino - number of the midi controller.
00025             master - pointer to the control to which the potmeter is
00026                      attached. This control is acknowledged when the
00027                      potmeter is changed.
00028             midicontroller - pointer to the midi controller.
00029    -------- ------------------------------------------------------ */
00030 ControlPotmeter::ControlPotmeter(ConfigKey key, double dMinValue, double dMaxValue) : ControlObject(key)
00031 {
00032     setRange(dMinValue,dMaxValue);
00033     setStep(m_dValueRange/10.f);
00034     setSmallStep(m_dValueRange/100.f);
00035 
00036     // These controls are deleted when this ControlPotmeter is since we set
00037     // their parent as this.
00038     ControlPushButton* controlUp = new ControlPushButton(
00039         ConfigKey(key.group, QString(key.item)+"_up"));
00040     controlUp->setParent(this);
00041     connect(controlUp, SIGNAL(valueChanged(double)),
00042             this, SLOT(incValue(double)));
00043     ControlPushButton* controlDown = new ControlPushButton(
00044         ConfigKey(key.group, QString(key.item)+"_down"));
00045     controlDown->setParent(this);
00046     connect(controlDown, SIGNAL(valueChanged(double)),
00047             this, SLOT(decValue(double)));
00048     ControlPushButton* controlUpSmall = new ControlPushButton(
00049         ConfigKey(key.group, QString(key.item)+"_up_small"));
00050     controlUpSmall->setParent(this);
00051     connect(controlUpSmall, SIGNAL(valueChanged(double)),
00052             this, SLOT(incSmallValue(double)));
00053     ControlPushButton* controlDownSmall = new ControlPushButton(
00054         ConfigKey(key.group, QString(key.item)+"_down_small"));
00055     controlDownSmall->setParent(this);
00056     connect(controlDownSmall, SIGNAL(valueChanged(double)),
00057             this, SLOT(decSmallValue(double)));
00058 }
00059 
00060 ControlPotmeter::~ControlPotmeter()
00061 {
00062 }
00063 
00064 double ControlPotmeter::getMin()
00065 {
00066     return m_dMinValue;
00067 }
00068 
00069 double ControlPotmeter::getMax()
00070 {
00071     return m_dMaxValue;
00072 }
00073 
00074 void ControlPotmeter::setStep(double dValue)
00075 {
00076     m_dStep = dValue;
00077 }
00078 
00079 void ControlPotmeter::setSmallStep(double dValue)
00080 {
00081     m_dSmallStep = dValue;
00082 }
00083 
00084 void ControlPotmeter::setRange(double dMinValue, double dMaxValue)
00085 {
00086     m_dMinValue = dMinValue;
00087     m_dMaxValue = dMaxValue;
00088     m_dValueRange = m_dMaxValue-m_dMinValue;
00089     m_dValue = m_dMinValue + 0.5*m_dValueRange;
00090     //qDebug() << "" << this << ", min " << m_dMinValue << ", max " << m_dMaxValue << ", range " << m_dValueRange << ", val " << m_dValue;
00091 }
00092 
00093 double ControlPotmeter::getValueToWidget(double dValue)
00094 {
00095     double out = (dValue-m_dMinValue)/m_dValueRange;
00096     return (out < 0.5) ? out*128. : out*126. + 1.;
00097 }
00098 
00099 double ControlPotmeter::GetMidiValue()
00100 {
00101     double out = (m_dValue-m_dMinValue)/m_dValueRange;
00102     return (out < 0.5) ? out*128. : out*126. + 1.;
00103 }
00104 
00105 double ControlPotmeter::getValueFromWidget(double dValue)
00106 {
00107     double out = (dValue < 64) ? dValue / 128. : (dValue-1) / 126.;
00108     return m_dMinValue + out * m_dValueRange;
00109 }
00110 
00111 void ControlPotmeter::setValueFromThread(double dValue)
00112 {
00113     if (dValue == m_dValue) return;
00114 
00115     if (dValue>m_dMaxValue)
00116         m_dValue = m_dMaxValue;
00117     else if (dValue<m_dMinValue)
00118         m_dValue = m_dMinValue;
00119     else
00120         m_dValue = dValue;
00121     emit(valueChanged(m_dValue));
00122 }
00123 
00124 void ControlPotmeter::setValueFromEngine(double dValue)
00125 {
00126     if (dValue>m_dMaxValue)
00127         m_dValue = m_dMaxValue;
00128     else if (dValue<m_dMinValue)
00129         m_dValue = m_dMinValue;
00130     else
00131         m_dValue = dValue;
00132     emit(valueChangedFromEngine(m_dValue));
00133 }
00134 
00135 void ControlPotmeter::setValueFromMidi(MidiCategory, double v)
00136 {
00137     double out = (v < 64) ? v / 128. : (v-1) / 126.;
00138     m_dValue = m_dMinValue + out*m_dValueRange;
00139     emit(valueChanged(m_dValue));
00140 }
00141 
00142 void ControlPotmeter::incValue(double keypos)
00143 {
00144     if (keypos>0)
00145     {
00146         m_dValue += m_dStep;
00147         if (m_dValue > m_dMaxValue)
00148             m_dValue = m_dMaxValue;
00149         emit(valueChanged(m_dValue));
00150 
00151         // incValue will be activated by assosiated _up or _down ControlObject, and thus it is safe to update all proxies.
00152         updateProxies(0);
00153     }
00154 }
00155 
00156 void ControlPotmeter::decValue(double keypos)
00157 {
00158     if (keypos>0)
00159     {
00160         m_dValue -= m_dStep;
00161         if (m_dValue < m_dMinValue)
00162             m_dValue = m_dMinValue;
00163         emit(valueChanged(m_dValue));
00164 
00165         // decValue will be activated by assosiated _up or _down ControlObject, and thus it is safe to update all proxies.
00166         updateProxies(0);
00167     }
00168 }
00169 
00170 void ControlPotmeter::incSmallValue(double keypos)
00171 {
00172     if (keypos>0)
00173     {
00174         m_dValue += m_dSmallStep;
00175         if (m_dValue > m_dMaxValue)
00176             m_dValue = m_dMaxValue;
00177         emit(valueChanged(m_dValue));
00178 
00179         // incSmallValue will be activated by assosiated _up_small or _down_small ControlObject, and thus it is safe to update all proxies.
00180         updateProxies(0);
00181     }
00182 }
00183 
00184 void ControlPotmeter::decSmallValue(double keypos)
00185 {
00186     if (keypos>0)
00187     {
00188         m_dValue -= m_dSmallStep;
00189         if (m_dValue < m_dMinValue)
00190             m_dValue = m_dMinValue;
00191         emit(valueChanged(m_dValue));
00192 
00193         // decSmallValue will be activated by assosiated _up_small or _down_small ControlObject, and thus it is safe to update all proxies.
00194         updateProxies(0);
00195     }
00196 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines