Mixxx

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

Go to the documentation of this file.
00001 /***************************************************************************
00002                           rotary.cpp  -  description
00003                              -------------------
00004     begin                : Tue Sep 21 2004
00005     copyright            : (C) 2004 by Tue Haste Andersen
00006     email                : haste@diku.dk
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 "rotary.h"
00019 #include "mathstuff.h"
00020 #include "controlobject.h"
00021 #include <QDebug>
00022 
00023 Rotary::Rotary()
00024 {
00025     m_dCalibration = 1.;
00026     m_dLastValue = 0.;
00027 
00028     m_iFilterLength = kiRotaryFilterMaxLen;
00029     m_iFilterPos = 0;
00030     m_pFilter = new double[m_iFilterLength];
00031     for (int i=0; i<m_iFilterLength; ++i)
00032         m_pFilter[i] = 0.;
00033 }
00034 
00035 Rotary::~Rotary()
00036 {
00037     delete [] m_pFilter;
00038 }
00039 
00040 /* Note: There's probably a bug in this function (or this class) somewhere.
00041    The filter function seems to be the cause of the "drifting" bug in the Hercules stuff.
00042    What happens is that filter() gets called to do some magic to a value that's returned
00043    from the Hercules device, and that magic adds "momentum" to it's motion (ie. it doesn't
00044    stop dead when you stop spinning the jog wheels.) The problem with this "magic" is that
00045    when herculeslinux.cpp passes the filtered value off to the wheel ControlObject (or what
00046    have you), the ControlObject's internal value never goes back to zero properly.
00047    - Albert (March 13, 2007)
00048  */
00049 double Rotary::filter(double dValue)
00050 {
00051     // Update filter buffer
00052     m_pFilter[m_iFilterPos] = dValue/m_dCalibration;
00053     m_iFilterPos = (m_iFilterPos+1)%m_iFilterLength;
00054 
00055     double dMagnitude = 0.;
00056     for (int i=0; i<m_iFilterLength; i++)
00057     {
00058         dMagnitude += m_pFilter[i];
00059     }
00060     dMagnitude /= (double)m_iFilterLength;
00061     //qDebug() << "filter in " << dValue << ", out " << dMagnitude;
00062 
00063     m_dLastValue = dMagnitude;
00064 
00065     return dMagnitude;
00066 }
00067 
00068 double Rotary::fillBuffer(double dValue)
00069 {
00070         for (int i=0; i<m_iFilterLength; ++i)
00071         {
00072                 m_pFilter[i] = dValue/m_dCalibration;
00073         }
00074         return dValue/m_dCalibration;
00075 }
00076 
00077 void Rotary::calibrate(double dValue)
00078 {
00079     m_dCalibration += dValue;
00080     m_iCalibrationCount += 1;
00081 }
00082 
00083 void Rotary::calibrateStart()
00084 {
00085     // Reset calibration data
00086     m_dCalibration = 0.;
00087     m_iCalibrationCount = 0;
00088 }
00089 
00090 double Rotary::calibrateEnd()
00091 {
00092     m_dCalibration /= (double)m_iCalibrationCount;
00093 
00094     qDebug() << "Calibration " << m_dCalibration << ", count " << m_iCalibrationCount;
00095 
00096     return m_dCalibration;
00097 }
00098 
00099 void Rotary::setCalibration(double c)
00100 {
00101     m_dCalibration = c;
00102 }
00103 
00104 double Rotary::getCalibration()
00105 {
00106     return m_dCalibration;
00107 }
00108 
00109 void Rotary::setFilterLength(int i)
00110 {
00111     if (i>kiRotaryFilterMaxLen)
00112         m_iFilterLength = kiRotaryFilterMaxLen;
00113     else if (i<1)
00114         m_iFilterLength = 1;
00115     else
00116         m_iFilterLength = i;
00117 }
00118 
00119 int Rotary::getFilterLength()
00120 {
00121     return  m_iFilterLength;
00122 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines