X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fcontroller_spin_box.h;fp=shared%2Fcontroller_spin_box.h;h=8a98b47689d861500f812ddbbdaa13989568403c;hb=f9a11c73b0c2ff2d44d79f856998f8cbfc88a478;hp=0000000000000000000000000000000000000000;hpb=4b84fc30175a4dfb56a25ba0b2f9b88ab54cfe7d;p=nageru diff --git a/shared/controller_spin_box.h b/shared/controller_spin_box.h new file mode 100644 index 0000000..8a98b47 --- /dev/null +++ b/shared/controller_spin_box.h @@ -0,0 +1,47 @@ +#ifndef _CONTROLLER_SPIN_BOX_H +#define _CONTROLLER_SPIN_BOX_H 1 + +// ControllerSpinBox is like QSpinBox, except it has a second special value +// "PB" (in addition to the standard minimum value of -1, representing blank), +// representing the virtual pitch bend controller. + +#include +#include + +#include "shared/midi_device.h" + +class ControllerSpinBox : public QSpinBox { + Q_OBJECT + +public: + ControllerSpinBox(QWidget *parent) : QSpinBox(parent) {} + + int valueFromText(const QString &text) const override + { + if (text == "PB") { + return MIDIReceiver::PITCH_BEND_CONTROLLER; + } else { + return QSpinBox::valueFromText(text); + } + } + + QString textFromValue(int value) const override + { + if (value == MIDIReceiver::PITCH_BEND_CONTROLLER) { + return "PB"; + } else { + return QSpinBox::textFromValue(value); + } + } + + QValidator::State validate(QString &input, int &pos) const override + { + if (input == "PB") { + return QValidator::Acceptable; + } else { + return QSpinBox::validate(input, pos); + } + } +}; + +#endif // !defined(_CONTROLLER_SPIN_BOX_H)