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.

94 lines
2.3KB

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