Mixxx

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

Go to the documentation of this file.
00001 /***************************************************************************
00002                           controlbeat.cpp  -  description
00003                              -------------------
00004     begin                : Mon Apr 7 2003
00005     copyright            : (C) 2003 by Tue & Ken 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 "controlbeat.h"
00019 
00020 ControlBeat::ControlBeat(ConfigKey key, bool bMidiSimulateLatching) : ControlObject(key)
00021 {
00022     m_bMidiSimulateLatching = bMidiSimulateLatching;
00023     m_dValue = 0.;
00024     time.start();
00025     m_bPressed = false;
00026     m_iValidPresses = 0;
00027 
00028     // Filter buffer
00029     buffer = new CSAMPLE[filterLength];
00030     for (int i=0; i<filterLength; i++)
00031         buffer[i] = 0.;
00032 }
00033 
00034 ControlBeat::~ControlBeat()
00035 {
00036     delete [] buffer;
00037 }
00038 
00039 void ControlBeat::setValueFromMidi(MidiCategory, double v)
00040 {
00041     if (!m_bPressed || !m_bMidiSimulateLatching)
00042     {
00043         beatTap();
00044         m_bPressed = true;
00045     }
00046     else
00047         m_bPressed = false;
00048 }
00049 
00050 void ControlBeat::setValueFromThread(double dValue) {
00051     if (dValue > 0) {
00052         beatTap();
00053     }
00054 }
00055 
00056 void ControlBeat::beatTap()
00057 {
00058     int elapsed = time.restart();
00059 
00060     if (elapsed <= maxInterval) {
00061         // Move back in filter one sample
00062         for (int i = filterLength-1; i > 0; i--)
00063             buffer[i] = buffer[i-1];
00064 
00065         buffer[0] = 1000.*(60./elapsed);
00066         if (buffer[0] > maxBPM)
00067             buffer[0] = maxBPM;
00068 
00069         m_iValidPresses++;
00070         if (m_iValidPresses > filterLength)
00071             m_iValidPresses = filterLength;
00072 
00073         double temp = 0.;
00074         for (int i = 0; i < m_iValidPresses; ++i)
00075             temp += buffer[i];
00076         temp /= m_iValidPresses;
00077         m_dValue = temp;
00078 
00079         emit(valueChanged(m_dValue));
00080     } else {
00081         m_iValidPresses = 0;
00082     }
00083 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines