![]() |
Mixxx
|
00001 /*************************************************************************** 00002 controlpushbutton.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 00020 /* -------- ------------------------------------------------------ 00021 Purpose: Creates a new simulated latching push-button. 00022 Input: key - Key for the configuration file 00023 -------- ------------------------------------------------------ */ 00024 ControlPushButton::ControlPushButton(ConfigKey key) : 00025 ControlObject(key, false) { 00026 m_bIsToggleButton = false; 00027 m_iNoStates = 2; 00028 } 00029 00030 ControlPushButton::~ControlPushButton() 00031 { 00032 } 00033 00034 //Tell this PushButton whether or not it's a "toggle" push button... 00035 void ControlPushButton::setToggleButton(bool bIsToggleButton) 00036 { 00037 //qDebug() << "Setting " << m_Key.group << m_Key.item << "as toggle"; 00038 m_bIsToggleButton = bIsToggleButton; 00039 } 00040 00041 void ControlPushButton::setStates(int num_states) 00042 { 00043 m_iNoStates = num_states; 00044 } 00045 00046 void ControlPushButton::setValueFromMidi(MidiCategory c, double v) 00047 { 00048 //if (m_bMidiSimulateLatching) 00049 00050 //qDebug() << "bMidiSimulateLatching is true!"; 00051 // Only react on NOTE_ON midi events if simulating latching... 00052 00053 //qDebug() << c << v; 00054 00055 if (m_bIsToggleButton) { //This block makes push-buttons act as toggle buttons. 00056 if (m_iNoStates > 2) { //multistate button 00057 if (v > 0.) { //looking for NOTE_ON doesn't seem to work... 00058 m_dValue++; 00059 if (m_dValue >= m_iNoStates) 00060 m_dValue = 0; 00061 } 00062 } else { 00063 if (c == NOTE_ON) { 00064 if (v > 0.) { 00065 m_dValue = !m_dValue; 00066 } 00067 } 00068 } 00069 } else { //Not a toggle button (trigger only when button pushed) 00070 if (c == NOTE_ON) { 00071 m_dValue = v; 00072 } else if (c == NOTE_OFF) { 00073 m_dValue = 0.0; 00074 } 00075 } 00076 00077 emit(valueChanged(m_dValue)); 00078 } 00079