Loading...
Searching...
No Matches
WaveformRenderer.hpp
1#pragma once
2#include <Media/Sound/WaveformComputer.hpp>
3
4#include <QObject>
5#include <QRectF>
6#include <QString>
7#include <QVector>
8
9#include <nano_observer.hpp>
10#include <score_plugin_media_export.h>
11
12#include <verdigris>
13
14#include <memory>
15#include <optional>
16
17class QImage;
18class QPainter;
19
20namespace Media::Sound
21{
31class SCORE_PLUGIN_MEDIA_EXPORT WaveformRenderer final
32 : public QObject
33 , public Nano::Observer
34{
35 W_OBJECT(WaveformRenderer)
36
37public:
39 explicit WaveformRenderer(QSizeF size, bool threaded = true, QObject* parent = nullptr);
41
44 void setFile(const QString& path);
45 const QString& path() const noexcept { return m_path; }
46 const std::shared_ptr<AudioFile>& file() const noexcept { return m_file; }
47
49 void setRange(double begin, double end);
50 void setSize(QSizeF size, double devicePixelRatio);
51
53 bool hasWaveform() const noexcept { return !m_images.empty(); }
54
57 void paint(QPainter& painter, const QRectF& rect, double devicePixelRatio);
58
59 void updated() E_SIGNAL(SCORE_PLUGIN_MEDIA_EXPORT, updated);
60
61private:
62 void on_finishedDecoding();
63 void request();
64 void clearImages();
65
66 QString m_path;
67 std::shared_ptr<AudioFile> m_file;
68 WaveformComputer* m_computer{};
69
70 QVector<QImage*> m_images;
71 ComputedWaveform m_wf{};
72 std::optional<WaveformRequest> m_lastRequest;
73
74 QSizeF m_size{};
75 double m_dpr{1.};
76 double m_begin{0.};
77 double m_end{1.};
78
79 // Width of the whole file at the zoom of the last request, and that zoom.
80 double m_layerWidth{};
81 double m_zoom{};
82};
83}
Definition WaveformRenderer.hpp:34
bool hasWaveform() const noexcept
Whether there is a waveform to draw.
Definition WaveformRenderer.hpp:53
STL namespace.
Definition MediaFileHandle.hpp:72
Definition WaveformComputer.hpp:65