EqCurve.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * EqCurve.h - defination of EqCurve and EqHandle classes.
  3. *
  4. * Copyright (c) 2015 Steffen Baranowsky <BaraMGB/at/freenet/dot/de>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef EQCURVE_H
  25. #define EQCURVE_H
  26. #include <QGraphicsItem>
  27. #include <QPainter>
  28. #include <QGraphicsSceneWheelEvent>
  29. #include "lmms_math.h"
  30. #include "AutomatableModelView.h"
  31. enum{
  32. highpass=1,
  33. lowshelf,
  34. para,
  35. highshelf,
  36. lowpass
  37. };
  38. // implements the Eq_Handle to control a band
  39. class EqHandle : public QGraphicsObject
  40. {
  41. Q_OBJECT
  42. public:
  43. EqHandle( int num, int x, int y );
  44. static float freqToXPixel( float freq, int w );
  45. static float xPixelToFreq( float x , int w );
  46. static float gainToYPixel( float gain, int h, float pixelPerUnitHeight );
  47. static float yPixelToGain( float y, int h, float pixelPerUnitHeight );
  48. QRectF boundingRect() const;
  49. QPainterPath getCurvePath();
  50. float getPeakCurve( float x );
  51. float getHighShelfCurve( float x );
  52. float getLowShelfCurve( float x );
  53. float getLowCutCurve( float x );
  54. float getHighCutCurve( float x );
  55. float getResonance();
  56. int getNum();
  57. int getType();
  58. void setType( int t );
  59. void setResonance( float r );
  60. bool isMouseHover();
  61. void setMouseHover( bool d );
  62. bool isActiveHandle();
  63. void setHandleActive( bool a );
  64. bool mousePressed() const;
  65. void sethp12();
  66. void sethp24();
  67. void sethp48();
  68. void setlp12();
  69. void setlp24();
  70. void setlp48();
  71. signals:
  72. void positionChanged();
  73. protected:
  74. void mousePressEvent( QGraphicsSceneMouseEvent *event );
  75. void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
  76. void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
  77. void wheelEvent( QGraphicsSceneWheelEvent *wevent );
  78. void hoverEnterEvent( QGraphicsSceneHoverEvent *hevent );
  79. void hoverLeaveEvent( QGraphicsSceneHoverEvent *hevent );
  80. QVariant itemChange( GraphicsItemChange change, const QVariant &value );
  81. private:
  82. double calculateGain( const double freq, const double a1, const double a2, const double b0, const double b1, const double b2 );
  83. void loadPixmap();
  84. float m_pixelsPerUnitWidth;
  85. float m_pixelsPerUnitHeight;
  86. float m_scale;
  87. bool m_hp12;
  88. bool m_hp24;
  89. bool m_hp48;
  90. bool m_lp12;
  91. bool m_lp24;
  92. bool m_lp48;
  93. bool m_mouseHover;
  94. int m_type, m_numb;
  95. float m_width, m_heigth;
  96. float m_resonance;
  97. bool m_mousePressed;
  98. bool m_active;
  99. QPixmap m_circlePixmap;
  100. };
  101. class EqCurve : public QGraphicsObject
  102. {
  103. Q_OBJECT
  104. public:
  105. EqCurve( QList<EqHandle*> *handle, int x, int y );
  106. QRectF boundingRect() const;
  107. void setModelChanged(bool mc);
  108. protected:
  109. void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
  110. private:
  111. QList<EqHandle*> *m_handle;
  112. QPainterPath m_curve;
  113. QPixmap m_curvePixmapCache;
  114. int m_width, m_heigth;
  115. int m_alpha;
  116. bool m_modelChanged;
  117. float m_pixelsPerUnitHeight;
  118. float m_scale;
  119. };
  120. #endif // EQCURVE_H