waveform.h Example File
multimedia/spectrum/app/waveform.h
#ifndef WAVEFORM_H
#define WAVEFORM_H
#include <QAudioFormat>
#include <QPixmap>
#include <QScopedPointer>
#include <QWidget>
class Waveform : public QWidget
{
Q_OBJECT
public:
explicit Waveform(QWidget *parent = 0);
~Waveform();
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void initialize(const QAudioFormat &format, qint64 audioBufferSize, qint64 windowDurationUs);
void reset();
void setAutoUpdatePosition(bool enabled);
public slots:
void bufferChanged(qint64 position, qint64 length, const QByteArray &buffer);
void audioPositionChanged(qint64 position);
private:
static const int NullIndex = -1;
void deletePixmaps();
void createPixmaps(const QSize &newSize);
void setWindowPosition(qint64 position);
qint64 tilePosition(int index) const;
struct TilePoint
{
TilePoint(int idx = 0, qint64 pos = 0, qint64 pix = 0)
: index(idx), positionOffset(pos), pixelOffset(pix)
{ }
int index;
qint64 positionOffset;
int pixelOffset;
};
TilePoint tilePoint(qint64 position) const;
int tilePixelOffset(qint64 positionOffset) const;
int windowPixelOffset(qint64 positionOffset) const;
bool paintTiles();
void paintTile(int index);
void shuffleTiles(int n);
void resetTiles(qint64 newStartPos);
private:
qint64 m_bufferPosition;
qint64 m_bufferLength;
QByteArray m_buffer;
qint64 m_audioPosition;
QAudioFormat m_format;
bool m_active;
QSize m_pixmapSize;
QVector<QPixmap*> m_pixmaps;
struct Tile {
QPixmap* pixmap;
bool painted;
};
QVector<Tile> m_tiles;
qint64 m_tileLength;
qint64 m_tileArrayStart;
qint64 m_windowPosition;
qint64 m_windowLength;
};
#endif // WAVEFORM_H