]> git.sesse.net Git - nageru/blobdiff - shared/controller_spin_box.h
Move controller_spin_box.h to shared, so that the upcoming Futatabi MIDI editor can...
[nageru] / shared / controller_spin_box.h
diff --git a/shared/controller_spin_box.h b/shared/controller_spin_box.h
new file mode 100644 (file)
index 0000000..8a98b47
--- /dev/null
@@ -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 <QSpinBox>
+#include <QString>
+
+#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)