Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pixmapkeyboard.hpp 2.1KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Pixmap Keyboard, a custom Qt4 widget
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #ifndef __PIXMAPKEYBOARD_HPP__
  18. #define __PIXMAPKEYBOARD_HPP__
  19. #include <map>
  20. #include <QtGui/QPixmap>
  21. #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
  22. # include <QtWidgets/QWidget>
  23. #else
  24. # include <QtGui/QWidget>
  25. #endif
  26. class PixmapKeyboard : public QWidget
  27. {
  28. Q_OBJECT
  29. public:
  30. enum Color {
  31. COLOR_CLASSIC = 0,
  32. COLOR_ORANGE = 1
  33. };
  34. enum Orientation {
  35. HORIZONTAL = 0,
  36. VERTICAL = 1
  37. };
  38. PixmapKeyboard(QWidget* parent);
  39. void allNotesOff();
  40. void sendNoteOn(int note, bool sendSignal=true);
  41. void sendNoteOff(int note, bool sendSignal=true);
  42. void setMode(Orientation mode, Color color=COLOR_ORANGE);
  43. void setOctaves(int octaves);
  44. signals:
  45. void noteOn(int);
  46. void noteOff(int);
  47. void notesOn();
  48. void notesOff();
  49. protected:
  50. void handleMousePos(const QPoint&);
  51. void keyPressEvent(QKeyEvent*);
  52. void keyReleaseEvent(QKeyEvent*);
  53. void mousePressEvent(QMouseEvent*);
  54. void mouseMoveEvent(QMouseEvent*);
  55. void mouseReleaseEvent(QMouseEvent*);
  56. void paintEvent(QPaintEvent*);
  57. private Q_SLOTS:
  58. void updateOnce();
  59. private:
  60. QPixmap fPixmap;
  61. Orientation fPixmapMode;
  62. QString fColorStr;
  63. QFont fFont;
  64. int fOctaves;
  65. int fLastMouseNote;
  66. int fWidth;
  67. int fHeight;
  68. bool fNeedsUpdate;
  69. QList<int> fEnabledKeys;
  70. std::map<int, QRectF>& fMidiMap;
  71. bool _isNoteBlack(int note) const;
  72. const QRectF& _getRectFromMidiNote(int note) const;
  73. };
  74. #endif // __PIXMAPKEYBOARD_HPP__