Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/controllogpotmeter.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 <math.h>
00019 #include "controllogpotmeter.h"
00020 
00021 #define maxPosition 127
00022 #define minPosition 0
00023 #define middlePosition ((maxPosition-minPosition)/2)
00024 #define positionrange (maxPosition-minPosition)
00025 
00026 /* -------- ------------------------------------------------------
00027    Purpose: Creates a new logarithmic potmeter, where the value is
00028             given by:
00029 
00030                 value = 10^(b*midibyte) - 1
00031 
00032             The lower value is 0, for midibyte=64 the value is 1 and the upper
00033             value is set by maxvalue.
00034 
00035             If the maxvalue is set to 1, the potmeter operates with only
00036             one logarithmid scale between 0 (for midi 0) and 1 (midivalue 128).
00037    Input:   n - name
00038             midino - number of the midi controller.
00039             midicontroller - pointer to the midi controller.
00040    -------- ------------------------------------------------------ */
00041 ControlLogpotmeter::ControlLogpotmeter(ConfigKey key, double dMaxValue) : ControlPotmeter(key)
00042 {
00043     m_dMinValue = 0.;
00044     m_dMaxValue = dMaxValue;
00045 
00046     if (m_dMaxValue==1.)
00047     {
00048         m_bTwoState = false;
00049 
00050         m_fB1 = log10(2.)/maxPosition;
00051     }
00052     else
00053     {
00054         m_bTwoState = true;
00055 
00056         m_fB1 = log10(2.)/middlePosition;
00057         m_fB2 = log10(dMaxValue)/(maxPosition-middlePosition);
00058     }
00059 
00060     m_dValueRange = m_dMaxValue-m_dMinValue;
00061 
00062     m_dValue = 1.;
00063 }
00064 
00065 double ControlLogpotmeter::getValueFromWidget(double dValue)
00066 {
00067     double dResult = 0;
00068 
00069     // Calculate the value linearly:
00070     if (!m_bTwoState)
00071     {
00072         dResult = pow(10., (double)(m_fB1*dValue)) - 1;
00073     }
00074     else
00075     {
00076         if (dValue <= middlePosition)
00077             dResult = pow(10., m_fB1*dValue) - 1;
00078         else
00079             dResult = pow(10., m_fB2*(dValue - middlePosition));
00080     }
00081 
00082     //qDebug() << "Midi: " << dValue << " ValueFromWidget : " << m_dValue;
00083     return dResult;
00084 }
00085 
00086 double ControlLogpotmeter::getValueToWidget(double dValue)
00087 {
00088     double pos;
00089 
00090     if (!m_bTwoState)
00091     {
00092         pos = log10(dValue+1)/m_fB1;
00093     }
00094     else
00095     {
00096         if (m_dValue>1.)
00097             pos = log10(dValue)/m_fB2 + middlePosition;
00098         else
00099             pos = log10(dValue+1)/m_fB1;
00100     }
00101     //qDebug() << "GetValueToWidget : " << pos;
00102     return pos;
00103 }
00104 
00105 double ControlLogpotmeter::GetMidiValue()
00106 {
00107     double midival = 0.;
00108 
00109     midival = getValueToWidget(m_dValue);
00110     //    midival = 127.*(midival-m_dMinValue)/m_dValueRange
00111     //qDebug() << "GetMidiValue : " << midival;
00112     return midival;
00113 }
00114 
00115 void ControlLogpotmeter::setValueFromMidi(MidiCategory, double v) {
00116   //    m_dValue = m_dMinValue + (v/127.)*m_dValueRange;
00117     m_dValue = getValueFromWidget(v);
00118     //    qDebug() << "SetValueFromMidiValue : " << m_dValue;
00119     emit(valueChanged(m_dValue));
00120 }
00121 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines