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.

86 lines
2.0KB

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