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.

88 lines
2.1KB

  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. #include <QtGui/QWidget>
  22. class PixmapKeyboard : public QWidget
  23. {
  24. Q_OBJECT
  25. public:
  26. enum Color {
  27. COLOR_CLASSIC = 0,
  28. COLOR_ORANGE = 1
  29. };
  30. enum Orientation {
  31. HORIZONTAL = 0,
  32. VERTICAL = 1
  33. };
  34. PixmapKeyboard(QWidget* parent);
  35. void allNotesOff();
  36. void sendNoteOn(int note, bool sendSignal=true);
  37. void sendNoteOff(int note, bool sendSignal=true);
  38. void setMode(Orientation mode, Color color=COLOR_ORANGE);
  39. void setOctaves(int octaves);
  40. signals:
  41. void noteOn(int);
  42. void noteOff(int);
  43. void notesOn();
  44. void notesOff();
  45. protected:
  46. void handleMousePos(const QPoint&);
  47. void keyPressEvent(QKeyEvent*);
  48. void keyReleaseEvent(QKeyEvent*);
  49. void mousePressEvent(QMouseEvent*);
  50. void mouseMoveEvent(QMouseEvent*);
  51. void mouseReleaseEvent(QMouseEvent*);
  52. void paintEvent(QPaintEvent*);
  53. private Q_SLOTS:
  54. void updateOnce();
  55. private:
  56. QPixmap fPixmap;
  57. Orientation fPixmapMode;
  58. QString fColorStr;
  59. QFont fFont;
  60. int fOctaves;
  61. int fLastMouseNote;
  62. int fWidth;
  63. int fHeight;
  64. bool fNeedsUpdate;
  65. QList<int> fEnabledKeys;
  66. std::map<int, QRectF>& fMidiMap;
  67. bool _isNoteBlack(int note) const;
  68. const QRectF& _getRectFromMidiNote(int note) const;
  69. };
  70. #endif // __PIXMAPKEYBOARD_HPP__