Collection of tools useful for audio production
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.

85 lines
2.0KB

  1. /*
  2. * Pixmap Keyboard, a custom Qt4 widget
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef PIXMAPKEYBOARD_H
  18. #define PIXMAPKEYBOARD_H
  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 sendNoteOn(int note, bool sendSignal=true);
  35. void sendNoteOff(int note, bool sendSignal=true);
  36. void setMode(Orientation mode, Color color=COLOR_ORANGE);
  37. void setOctaves(int octaves);
  38. signals:
  39. void noteOn(int);
  40. void noteOff(int);
  41. void notesOn();
  42. void notesOff();
  43. protected:
  44. void handleMousePos(const QPoint&);
  45. void keyPressEvent(QKeyEvent*);
  46. void keyReleaseEvent(QKeyEvent*);
  47. void mousePressEvent(QMouseEvent*);
  48. void mouseMoveEvent(QMouseEvent*);
  49. void mouseReleaseEvent(QMouseEvent*);
  50. void paintEvent(QPaintEvent*);
  51. private Q_SLOTS:
  52. void updateOnce();
  53. private:
  54. QPixmap m_pixmap;
  55. Orientation m_pixmap_mode;
  56. QString m_colorStr;
  57. QFont m_font;
  58. int m_octaves;
  59. int m_lastMouseNote;
  60. int p_width, p_height;
  61. bool m_needsUpdate;
  62. QList<int> m_enabledKeys;
  63. QMap<int, QRectF> *m_midi_map;
  64. bool _isNoteBlack(int note);
  65. QRectF _getRectFromMidiNote(int note);
  66. };
  67. #endif // PIXMAPKEYBOARD_H