SaWaterfallView.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SaWaterfallView.h - declaration of SaWaterfallView class.
  2. *
  3. * Copyright (c) 2019 Martin Pavelek <he29/dot/HS/at/gmail/dot/com>
  4. *
  5. * This file is part of LMMS - https://lmms.io
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this program (see COPYING); if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #ifndef SAWATERFALLVIEW_H
  24. #define SAWATERFALLVIEW_H
  25. #include <string>
  26. #include <utility>
  27. #include <vector>
  28. #include <QPainter>
  29. #include <QWidget>
  30. #include "SaControls.h"
  31. #include "SaProcessor.h"
  32. class QMouseEvent;
  33. // Widget that displays a spectrum waterfall (spectrogram) and time labels.
  34. class SaWaterfallView : public QWidget
  35. {
  36. Q_OBJECT
  37. public:
  38. explicit SaWaterfallView(SaControls *controls, SaProcessor *processor, QWidget *_parent = 0);
  39. virtual ~SaWaterfallView() {}
  40. QSize sizeHint() const override {return QSize(400, 350);}
  41. // Check if waterfall should be displayed and adjust window size if needed.
  42. void updateVisibility();
  43. protected:
  44. void paintEvent(QPaintEvent *event) override;
  45. void mouseMoveEvent(QMouseEvent *event) override;
  46. void mousePressEvent(QMouseEvent *event) override;
  47. void resizeEvent(QResizeEvent *event) override;
  48. private slots:
  49. void periodicUpdate();
  50. private:
  51. const SaControls *m_controls;
  52. SaProcessor *m_processor;
  53. const EffectControlDialog *m_controlDialog;
  54. // Methods and data used to make time labels
  55. float m_oldSecondsPerLine;
  56. float m_oldHeight;
  57. float samplesPerLine();
  58. float secondsPerLine();
  59. float timeToYPixel(float time, int height);
  60. float yPixelToTime(float position, int height);
  61. std::vector<std::pair<float, std::string>> makeTimeTics();
  62. std::vector<std::pair<float, std::string>> m_timeTics; // 0..n (s)
  63. // current cursor location and a method to draw it
  64. QPointF m_cursor;
  65. void drawCursor(QPainter &painter);
  66. // current boundaries for drawing
  67. unsigned int m_displayTop;
  68. unsigned int m_displayBottom;
  69. unsigned int m_displayLeft;
  70. unsigned int m_displayRight;
  71. unsigned int m_displayWidth;
  72. unsigned int m_displayHeight;
  73. #ifdef SA_DEBUG
  74. float m_execution_avg;
  75. #endif
  76. };
  77. #endif // SAWATERFALLVIEW_H